Changeset 63c1dd5 in mainline for uspace/app


Ignore:
Timestamp:
2018-10-09T08:40:53Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63a045c
Parents:
ee9c703
git-author:
Jiri Svoboda <jiri@…> (2018-10-08 18:38:16)
git-committer:
Jiri Svoboda <jiri@…> (2018-10-09 08:40:53)
Message:

Persistence of Tetris highscore table. Detect live mode and create directory structure in init task. Reading volume configuration, vol -c.

Location:
uspace/app
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    ree9c703 r63c1dd5  
    4747#include <config.h>
    4848#include <io/logctl.h>
     49#include <vol.h>
    4950#include "untar.h"
    5051#include "init.h"
     
    7071#define srv_start(path, ...) \
    7172        srv_startl(path, path, ##__VA_ARGS__, NULL)
     73
     74static const char *sys_dirs[] = {
     75        "/w/cfg",
     76        "/w/data"
     77};
    7278
    7379/** Print banner */
     
    320326}
    321327
     328/** Init system volume.
     329 *
     330 * See if system volume is configured. If so, try to wait for it to become
     331 * available. If not, create basic directories for live image omde.
     332 */
     333static errno_t init_sysvol(void)
     334{
     335        vol_t *vol = NULL;
     336        vol_info_t vinfo;
     337        volume_id_t *volume_ids = NULL;
     338        size_t nvols;
     339        size_t i;
     340        errno_t rc;
     341        bool found_cfg;
     342        const char **cp;
     343
     344        rc = vol_create(&vol);
     345        if (rc != EOK) {
     346                printf("Error contacting volume service.\n");
     347                goto error;
     348        }
     349
     350        rc = vol_get_volumes(vol, &volume_ids, &nvols);
     351        if (rc != EOK) {
     352                printf("Error getting list of volumes.\n");
     353                goto error;
     354        }
     355
     356        /* XXX This could be handled more efficiently by volsrv itself */
     357        found_cfg = false;
     358        for (i = 0; i < nvols; i++) {
     359                rc = vol_info(vol, volume_ids[i], &vinfo);
     360                if (rc != EOK) {
     361                        printf("Error getting volume information.\n");
     362                        rc = EIO;
     363                        goto error;
     364                }
     365
     366                if (str_cmp(vinfo.path, "/w") == 0) {
     367                        found_cfg = true;
     368                        break;
     369                }
     370        }
     371
     372        vol_destroy(vol);
     373        free(volume_ids);
     374
     375        if (!found_cfg) {
     376                /* Prepare directory structure for live image mode */
     377                printf("%s: Creating live image directory structure.\n", NAME);
     378                cp = sys_dirs;
     379                while (*cp != NULL) {
     380                        rc = vfs_link_path(*cp, KIND_DIRECTORY, NULL);
     381                        if (rc != EOK) {
     382                                printf("%s: Error creating directory '%s'.\n",
     383                                    NAME, *cp);
     384                                return rc;
     385                        }
     386
     387                        ++cp;
     388                }
     389        } else {
     390                printf("%s: System volume is configured.\n", NAME);
     391        }
     392
     393        return EOK;
     394error:
     395        vol_destroy(vol);
     396        if (volume_ids != NULL)
     397                free(volume_ids);
     398
     399        return rc;
     400}
     401
    322402int main(int argc, char *argv[])
    323403{
     
    375455        srv_start("/srv/hound");
    376456
     457        init_sysvol();
     458
    377459        if (!config_key_exists("console")) {
    378460                rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
  • uspace/app/sysinst/sysinst.c

    ree9c703 r63c1dd5  
    7979#define BOOT_BLOCK_IDX 0 /* MBR */
    8080
     81static const char *sys_dirs[] = {
     82        "/cfg",
     83        "/data"
     84};
     85
    8186/** Label the destination device.
    8287 *
     
    160165        *psvc_id = pinfo.svc_id;
    161166        return EOK;
     167}
     168
     169/** Set up system volume structure.
     170 *
     171 * @return EOK on success or an error code
     172 */
     173static errno_t sysinst_setup_sysvol(void)
     174{
     175        errno_t rc;
     176        char *path = NULL;
     177        const char **cp;
     178        int rv;
     179
     180        cp = sys_dirs;
     181        while (*cp != NULL) {
     182                rv = asprintf(&path, "%s%s", MOUNT_POINT, *cp);
     183                if (rv < 0) {
     184                        rc = ENOMEM;
     185                        goto error;
     186                }
     187
     188                rc = vfs_link_path(path, KIND_DIRECTORY, NULL);
     189                if (rc != EOK) {
     190                        printf("Error creating directory '%s'.\n", path);
     191                        goto error;
     192                }
     193
     194                free(path);
     195                path = NULL;
     196                ++cp;
     197        }
     198
     199        free(path);
     200        path = NULL;
     201
     202        return EOK;
     203error:
     204        if (path != NULL)
     205                free(path);
     206        return rc;
    162207}
    163208
     
    415460                return rc;
    416461
    417         printf("FS created and mounted. Copying boot files.\n");
     462        printf("FS created and mounted. Creating system directory structure.\n");
     463        rc = sysinst_setup_sysvol();
     464        if (rc != EOK)
     465                return rc;
     466
     467        printf("Directories created. Copying boot files.\n");
    418468        rc = sysinst_copy_boot_files();
    419469        if (rc != EOK)
  • uspace/app/tetris/scores.c

    ree9c703 r63c1dd5  
    212212        int rc;
    213213
    214         f = fopen("/data/tetris.sco", "rb");
     214        f = fopen("/w/data/tetris.sco", "rb");
    215215        if (f == NULL)
    216216                return ENOENT;
     
    231231        int rc;
    232232
    233         f = fopen("/data/tetris.sco", "wb");
     233        f = fopen("/w/data/tetris.sco", "wb");
    234234        if (f == NULL) {
    235235                printf("Error creating table\n");
  • uspace/app/vol/vol.c

    ree9c703 r63c1dd5  
    4949        vcmd_help,
    5050        vcmd_list,
     51        vcmd_cfglist,
    5152} vol_cmd_t;
    5253
     
    239240}
    240241
     242/** List volume configuration entries.
     243 *
     244 * @return EOK on success or an error code
     245 */
     246static errno_t vol_cmd_cfglist(void)
     247{
     248        vol_t *vol = NULL;
     249        vol_info_t vinfo;
     250        volume_id_t *volume_ids = NULL;
     251        size_t nvols;
     252        size_t i;
     253        table_t *table = NULL;
     254        errno_t rc;
     255
     256        rc = vol_create(&vol);
     257        if (rc != EOK) {
     258                printf("Error contacting volume service.\n");
     259                goto out;
     260        }
     261
     262        rc = vol_get_volumes(vol, &volume_ids, &nvols);
     263        if (rc != EOK) {
     264                printf("Error getting list of volumes.\n");
     265                goto out;
     266        }
     267
     268        rc = table_create(&table);
     269        if (rc != EOK) {
     270                printf("Out of memory.\n");
     271                goto out;
     272        }
     273
     274        table_header_row(table);
     275        table_printf(table, "Volume Name\t" "Path\n");
     276
     277        for (i = 0; i < nvols; i++) {
     278                rc = vol_info(vol, volume_ids[i], &vinfo);
     279                if (rc != EOK) {
     280                        printf("Error getting volume information.\n");
     281                        return EIO;
     282                }
     283
     284                table_printf(table, "%s\t" "%s\n", vinfo.label, vinfo.path);
     285        }
     286
     287        rc = table_print_out(table, stdout);
     288        if (rc != EOK)
     289                printf("Error printing table.\n");
     290out:
     291        table_destroy(table);
     292        vol_destroy(vol);
     293        free(volume_ids);
     294
     295        return rc;
     296}
     297
    241298static void print_syntax(void)
    242299{
    243300        printf("Syntax:\n");
    244         printf("  %s                List volumes\n", NAME);
     301        printf("  %s                List present volumes\n", NAME);
     302        printf("  %s -c             List volume configuration entries\n", NAME);
    245303        printf("  %s -h             Print help\n", NAME);
    246304        printf("  %s eject <mp>     Eject volume mounted in a directory\n", NAME);
     
    264322                if (str_cmp(cmd, "-h") == 0) {
    265323                        vcmd = vcmd_help;
     324                } else if (str_cmp(cmd, "-c") == 0) {
     325                        vcmd = vcmd_cfglist;
    266326                } else if (str_cmp(cmd, "eject") == 0) {
    267327                        vcmd = vcmd_eject;
     
    303363                rc = vol_cmd_list();
    304364                break;
     365        case vcmd_cfglist:
     366                rc = vol_cmd_cfglist();
     367                break;
    305368        }
    306369
Note: See TracChangeset for help on using the changeset viewer.