Changeset b14d9f9 in mainline


Ignore:
Timestamp:
2017-05-05T17:37:36Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
951f6b9e
Parents:
75b24cd
Message:

Mount should be able to print the list of available file system types.

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    r75b24cd rb14d9f9  
    4949        { "help", no_argument, 0, 'h' },
    5050        { "instance", required_argument, 0, 'i' },
     51        { "types", no_argument, 0, 't' },
    5152        { 0, 0, 0, 0 }
    5253};
     
    5758{
    5859        static char helpfmt[] =
    59             "Usage:  %s <fstype> <mp> [dev] [<moptions>]\n";
     60            "Usage:  %s <fstype> <mp> [dev] [<moptions>]\n"
     61            "Options:\n"
     62            "  -h, --help       A short option summary\n"
     63            "  -i, --instance ## Mount a specific instance\n"
     64            "  -t, --types      List available file system types\n";
     65
    6066        if (level == HELP_SHORT) {
    6167                printf("'%s' mounts a file system.\n", cmdname);
     
    101107}
    102108
     109static void print_fstypes(void)
     110{
     111        int rc;
     112        vfs_fstypes_t fstypes;
     113        char **p;
     114
     115        rc = vfs_fstypes(&fstypes);
     116        if (rc != EOK) {
     117                printf("Error getting list of available file system types.\n");
     118                return;
     119        }
     120
     121        printf("Available file system types:\n");
     122        p = fstypes.fstypes;
     123        while (*p != NULL)
     124                printf("\t%s\n", *p++);
     125        vfs_fstypes_free(&fstypes);
     126}
     127
    103128/* Main entry point for mount, accepts an array of arguments */
    104129int cmd_mount(char **argv)
     
    115140
    116141        for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) {
    117                 c = getopt_long(argc, argv, "i:h", long_options, &opt_ind);
     142                c = getopt_long(argc, argv, "i:ht", long_options, &opt_ind);
    118143                switch (c) {
    119144                case 'h':
     
    124149                        instance_set = true;
    125150                        break;
     151                case 't':
     152                        print_fstypes();
     153                        return CMD_SUCCESS;
    126154                }
    127155        }
     
    151179                printf("Unable to mount %s filesystem to %s on %s (rc=%s)\n",
    152180                    t_argv[2], t_argv[1], t_argv[3], str_error(rc));
     181                if (rc == ENOFS)
     182                        print_fstypes();
    153183                return CMD_FAILURE;
    154184        }
  • uspace/lib/c/generic/str_error.c

    r75b24cd rb14d9f9  
    7272        // FIXME: integrate these as first-class error values
    7373        switch (e) {
     74                case ENOFS:
     75                        return "No such file system type";
    7476                case EBADCHECKSUM:
    7577                        return "Bad checksum";
  • uspace/lib/c/generic/vfs/vfs.c

    r75b24cd rb14d9f9  
    346346       
    347347        return loc_service_connect(stat.service, iface, 0);
     348}
     349
     350/** Return a list of currently available file system types
     351 *
     352 * @param fstypes Points to structure where list of filesystem types is
     353 *        stored. It is read as a null-terminated list of strings
     354 *        fstypes->fstypes[0..]. To free the list use vfs_fstypes_free().
     355 *
     356 * @return                      EOK on success or a negative error code
     357 */
     358int vfs_fstypes(vfs_fstypes_t *fstypes)
     359{
     360        sysarg_t size;
     361        char *buf;
     362        char dummybuf[1];
     363        size_t count, i;
     364
     365        async_exch_t *exch = vfs_exchange_begin();
     366        int rc = async_req_0_1(exch, VFS_IN_FSTYPES, &size);
     367
     368        if (rc != EOK) {
     369                vfs_exchange_end(exch);
     370                return rc;
     371        }
     372
     373        buf = malloc(size);
     374        if (buf == NULL) {
     375                buf = dummybuf;
     376                size = 1;
     377        }
     378
     379        rc = async_data_read_start(exch, buf, size);
     380        vfs_exchange_end(exch);
     381
     382        if (buf == dummybuf)
     383                return ENOMEM;
     384
     385        /*
     386         * Buffer should contain a number of null-terminated strings.
     387         * Count them so that we can allocate an index
     388         */
     389        count = 0;
     390        i = 0;
     391        while (i < size) {
     392                if (buf[i] == '\0')
     393                        ++count;
     394                ++i;
     395        }
     396
     397        if (count == 0) {
     398                free(buf);
     399                return EIO;
     400        }
     401
     402        fstypes->fstypes = calloc(sizeof(char *), count + 1);
     403        if (fstypes->fstypes == NULL) {
     404                free(buf);
     405                return ENOMEM;
     406        }
     407
     408        /* Now fill the index */
     409        if (buf[0] != '\0')
     410                fstypes->fstypes[0] = &buf[0];
     411        count = 0;
     412        i = 0;
     413        while (i < size) {
     414                if (buf[i] == '\0')
     415                        fstypes->fstypes[++count] = &buf[i + 1];
     416                ++i;
     417        }
     418        fstypes->fstypes[count] = NULL;
     419        fstypes->buf = buf;
     420        fstypes->size = size;
     421
     422        return rc;
     423}
     424
     425/** Free list of file system types.
     426 *
     427 * @param fstypes List of file system types
     428 */
     429void vfs_fstypes_free(vfs_fstypes_t *fstypes)
     430{
     431        free(fstypes->buf);
     432        fstypes->buf = NULL;
     433        free(fstypes->fstypes);
     434        fstypes->fstypes = NULL;
     435        fstypes->size = 0;
    348436}
    349437
  • uspace/lib/c/include/errno.h

    r75b24cd rb14d9f9  
    5555#define EMLINK        (-267)
    5656#define ENXIO         (-268)
     57#define ENOFS         (-269)
    5758
    5859/** Bad checksum. */
  • uspace/lib/c/include/ipc/vfs.h

    r75b24cd rb14d9f9  
    6464typedef enum {
    6565        VFS_IN_CLONE = IPC_FIRST_USER_METHOD,
     66        VFS_IN_FSTYPES,
    6667        VFS_IN_MOUNT,
    6768        VFS_IN_OPEN,
  • uspace/lib/c/include/vfs/vfs.h

    r75b24cd rb14d9f9  
    7373};
    7474
     75/** List of file system types */
     76typedef struct {
     77        char **fstypes;
     78        char *buf;
     79        size_t size;
     80} vfs_fstypes_t;
     81
    7582extern int vfs_fhandle(FILE *, int *);
    7683
     
    8188extern async_exch_t *vfs_exchange_begin(void);
    8289extern void vfs_exchange_end(async_exch_t *);
     90extern int vfs_fstypes(vfs_fstypes_t *);
     91extern void vfs_fstypes_free(vfs_fstypes_t *);
    8392extern int vfs_link(int, const char *, vfs_file_kind_t, int *);
    8493extern int vfs_link_path(const char *, vfs_file_kind_t, int *);
  • uspace/srv/vfs/vfs.h

    r75b24cd rb14d9f9  
    4343#include <ipc/vfs.h>
    4444#include <task.h>
     45#include <vfs/vfs.h>
    4546
    4647#ifndef dprintf
     
    174175extern fs_handle_t fs_name_to_handle(unsigned int instance, const char *, bool);
    175176extern vfs_info_t *fs_handle_to_info(fs_handle_t);
     177extern int vfs_get_fstypes(vfs_fstypes_t *);
    176178
    177179extern int vfs_lookup_internal(vfs_node_t *, char *, int, vfs_lookup_res_t *);
  • uspace/srv/vfs/vfs_ipc.c

    r75b24cd rb14d9f9  
    2727 */
    2828
     29#include <vfs/vfs.h>
    2930#include "vfs.h"
    3031
     
    4243        int ret = vfs_op_clone(oldfd, newfd, desc);
    4344        async_answer_0(rid, ret);
     45}
     46
     47static void vfs_in_fstypes(ipc_callid_t rid, ipc_call_t *request)
     48{
     49        ipc_callid_t callid;
     50        size_t len;
     51        vfs_fstypes_t fstypes;
     52        int rc;
     53
     54        rc = vfs_get_fstypes(&fstypes);
     55        if (rc != EOK) {
     56                async_answer_0(rid, ENOMEM);
     57                return;
     58        }
     59
     60        /* Send size of the data */
     61        async_answer_1(rid, EOK, fstypes.size);
     62
     63        /* Now we should get a read request */
     64        if (!async_data_read_receive(&callid, &len))
     65                goto out;
     66
     67        if (len > fstypes.size)
     68                len = fstypes.size;
     69        (void) async_data_read_finalize(callid, fstypes.buf, len);
     70
     71out:
     72        vfs_fstypes_free(&fstypes);
    4473}
    4574
     
    268297                        vfs_in_clone(callid, &call);
    269298                        break;
     299                case VFS_IN_FSTYPES:
     300                        vfs_in_fstypes(callid, &call);
     301                        break;
    270302                case VFS_IN_MOUNT:
    271303                        vfs_in_mount(callid, &call);
  • uspace/srv/vfs/vfs_ops.c

    r75b24cd rb14d9f9  
    147147
    148148        if (fs_handle == 0)
    149                 return ENOENT;
     149                return ENOFS;
    150150       
    151151        /* Tell the mountee that it is being mounted. */
  • uspace/srv/vfs/vfs_register.c

    r75b24cd rb14d9f9  
    5050#include <assert.h>
    5151#include <atomic.h>
     52#include <vfs/vfs.h>
    5253#include "vfs.h"
    5354
     
    340341}
    341342
     343/** Get list of file system types.
     344 *
     345 * @param fstypes Place to store list of file system types. Free using
     346 *                vfs_fstypes_free().
     347 *
     348 * @return EOK on success or negative error code
     349 */
     350int vfs_get_fstypes(vfs_fstypes_t *fstypes)
     351{
     352        size_t size;
     353        size_t count;
     354        size_t l;
     355
     356        fibril_mutex_lock(&fs_list_lock);
     357       
     358        size = 0;
     359        count = 0;
     360        list_foreach(fs_list, fs_link, fs_info_t, fs) {
     361                size += str_size(fs->vfs_info.name) + 1;
     362                count++;
     363        }
     364       
     365        if (size == 0)
     366                size = 1;
     367       
     368        fstypes->buf = calloc(1, size);
     369        if (fstypes->buf == NULL) {
     370                fibril_mutex_unlock(&fs_list_lock);
     371                return ENOMEM;
     372        }
     373       
     374        fstypes->fstypes = calloc(sizeof(char *), count);
     375        if (fstypes->fstypes == NULL) {
     376                free(fstypes->buf);
     377                fstypes->buf = NULL;
     378                fibril_mutex_unlock(&fs_list_lock);
     379                return ENOMEM;
     380        }
     381       
     382        fstypes->size = size;
     383       
     384        size = 0; count = 0;
     385        list_foreach(fs_list, fs_link, fs_info_t, fs) {
     386                l = str_size(fs->vfs_info.name) + 1;
     387                memcpy(fstypes->buf + size, fs->vfs_info.name, l);
     388                fstypes->fstypes[count] = &fstypes->buf[size];
     389                size += l;
     390                count++;
     391        }
     392
     393        fibril_mutex_unlock(&fs_list_lock);
     394        return EOK;
     395}
     396
    342397/**
    343398 * @}
Note: See TracChangeset for help on using the changeset viewer.