Changeset b14d9f9 in mainline for uspace/lib/c


Ignore:
Timestamp:
2017-05-05T17:37:36Z (8 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/lib/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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 *);
Note: See TracChangeset for help on using the changeset viewer.