Changeset 4f100f4 in mainline


Ignore:
Timestamp:
2011-11-06T16:58:23Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41047bf
Parents:
3ce78580 (diff), 460514d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge support for listing mounted file systems.

Location:
uspace
Files:
1 added
7 edited

Legend:

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

    r3ce78580 r4f100f4  
    3030#include <stdlib.h>
    3131#include <vfs/vfs.h>
     32#include <adt/list.h>
    3233#include <errno.h>
    3334#include <getopt.h>
     
    6061        }
    6162        return;
     63}
     64
     65static void print_mtab_list(void)
     66{
     67        LIST_INITIALIZE(mtab_list);
     68        get_mtab_list(&mtab_list);
     69
     70        mtab_ent_t *old_ent = NULL;
     71
     72        list_foreach(mtab_list, cur) {
     73                mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
     74                    link);
     75
     76                if (old_ent)
     77                        free(old_ent);
     78
     79                old_ent = mtab_ent;
     80
     81                printf("%s on %s ", mtab_ent->fs_name, mtab_ent->mp);
     82
     83                if (str_size(mtab_ent->opts) > 0)
     84                        printf("opts=%s ", mtab_ent->opts);
     85
     86                printf("(instance=%d, service_id=%" PRIu64 ")\n",
     87                    mtab_ent->instance, mtab_ent->service_id);
     88        }
     89
     90        if (old_ent)
     91                free(old_ent);
    6292}
    6393
     
    94124                t_argv = &argv[0];
    95125
    96         if ((argc < 3) || (argc > 5)) {
     126        if ((argc == 2) || (argc > 5)) {
    97127                printf("%s: invalid number of arguments. Try `mount --help'\n",
    98128                    cmdname);
    99129                return CMD_FAILURE;
     130        }
     131        if (argc == 1) {
     132                print_mtab_list();
     133                return CMD_SUCCESS;
    100134        }
    101135        if (argc > 3)
  • uspace/lib/c/generic/vfs/vfs.c

    r3ce78580 r4f100f4  
    831831}
    832832
     833int get_mtab_list(list_t *mtab_list)
     834{
     835        sysarg_t rc;
     836        aid_t req;
     837        size_t i;
     838        sysarg_t num_mounted_fs;
     839       
     840        async_exch_t *exch = vfs_exchange_begin();
     841
     842        req = async_send_0(exch, VFS_IN_MTAB_GET, NULL);
     843
     844        /* Ask VFS how many filesystems are mounted */
     845        rc = async_req_0_1(exch, VFS_IN_PING, &num_mounted_fs);
     846        if (rc != EOK)
     847                goto exit;
     848
     849        for (i = 0; i < num_mounted_fs; ++i) {
     850                mtab_ent_t *mtab_ent;
     851
     852                mtab_ent = malloc(sizeof(mtab_ent_t));
     853                if (!mtab_ent) {
     854                        rc = ENOMEM;
     855                        goto exit;
     856                }
     857
     858                memset(mtab_ent, 0, sizeof(mtab_ent_t));
     859
     860                rc = async_data_read_start(exch, (void *) mtab_ent->mp,
     861                    MAX_PATH_LEN);
     862                if (rc != EOK)
     863                        goto exit;
     864
     865                rc = async_data_read_start(exch, (void *) mtab_ent->opts,
     866                        MAX_MNTOPTS_LEN);
     867                if (rc != EOK)
     868                        goto exit;
     869
     870                rc = async_data_read_start(exch, (void *) mtab_ent->fs_name,
     871                        FS_NAME_MAXLEN);
     872                if (rc != EOK)
     873                        goto exit;
     874
     875                sysarg_t p[2];
     876
     877                rc = async_req_0_2(exch, VFS_IN_PING, &p[0], &p[1]);
     878                if (rc != EOK)
     879                        goto exit;
     880
     881                mtab_ent->instance = p[0];
     882                mtab_ent->service_id = p[1];
     883
     884                link_initialize(&mtab_ent->link);
     885                list_append(&mtab_ent->link, mtab_list);
     886        }
     887
     888exit:
     889        async_wait_for(req, &rc);
     890        vfs_exchange_end(exch);
     891        return rc;
     892}
     893
    833894/** @}
    834895 */
  • uspace/lib/c/include/ipc/vfs.h

    r3ce78580 r4f100f4  
    4242#define FS_NAME_MAXLEN  20
    4343#define MAX_PATH_LEN    (64 * 1024)
     44#define MAX_MNTOPTS_LEN 256
    4445#define PLB_SIZE        (2 * MAX_PATH_LEN)
    4546
     
    8081        VFS_IN_DUP,
    8182        VFS_IN_WAIT_HANDLE,
     83        VFS_IN_MTAB_GET,
    8284} vfs_in_request_t;
    8385
  • uspace/lib/c/include/vfs/vfs.h

    r3ce78580 r4f100f4  
    3939#include <ipc/vfs.h>
    4040#include <ipc/loc.h>
     41#include <adt/list.h>
    4142#include <stdio.h>
    4243#include <async.h>
     44#include "vfs_mtab.h"
    4345
    4446enum vfs_change_state_type {
     
    5557
    5658extern int fd_wait(void);
     59extern int get_mtab_list(list_t *mtab_list);
    5760
    5861extern async_exch_t *vfs_exchange_begin(void);
  • uspace/srv/vfs/vfs.c

    r3ce78580 r4f100f4  
    127127                        vfs_wait_handle(callid, &call);
    128128                        break;
     129                case VFS_IN_MTAB_GET:
     130                        vfs_get_mtab(callid, &call);
     131                        break;
    129132                default:
    130133                        async_answer_0(callid, ENOTSUP);
  • uspace/srv/vfs/vfs.h

    r3ce78580 r4f100f4  
    150150extern list_t fs_list;          /**< List of registered file systems. */
    151151
     152extern fibril_mutex_t fs_mntlist_lock;
     153extern list_t fs_mntlist;       /**< List of mounted file systems. */
     154
    152155extern vfs_pair_t rootfs;       /**< Root file system. */
    153156
     
    162165extern uint8_t *plb;            /**< Path Lookup Buffer */
    163166extern list_t plb_entries;      /**< List of active PLB entries. */
    164 
    165 #define MAX_MNTOPTS_LEN         256
    166167
    167168/** Holding this rwlock prevents changes in file system namespace. */
     
    219220extern void vfs_rename(ipc_callid_t, ipc_call_t *);
    220221extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *);
     222extern void vfs_get_mtab(ipc_callid_t, ipc_call_t *);
    221223
    222224#endif
  • uspace/srv/vfs/vfs_ops.c

    r3ce78580 r4f100f4  
    5252#include <assert.h>
    5353#include <vfs/canonify.h>
     54#include <vfs/vfs_mtab.h>
     55
     56FIBRIL_MUTEX_INITIALIZE(mtab_list_lock);
     57LIST_INITIALIZE(mtab_list);
     58static size_t mtab_size = 0;
    5459
    5560/* Forward declarations of static functions. */
     
    6873};
    6974
    70 static void vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,
     75static int vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,
    7176    fs_handle_t fs_handle, char *mp, char *opts)
    7277{
     
    9196                        fibril_rwlock_write_unlock(&namespace_rwlock);
    9297                        async_answer_0(rid, EBUSY);
    93                         return;
     98                        return EBUSY;
    9499                }
    95100               
     
    99104                        fibril_rwlock_write_unlock(&namespace_rwlock);
    100105                        async_answer_0(rid, rc);
    101                         return;
     106                        return rc;
    102107                }
    103108               
     
    106111                        fibril_rwlock_write_unlock(&namespace_rwlock);
    107112                        async_answer_0(rid, ENOMEM);
    108                         return;
     113                        return ENOMEM;
    109114                }
    110115               
     
    135140                                fibril_rwlock_write_unlock(&namespace_rwlock);
    136141                                async_answer_0(rid, rc);
    137                                 return;
     142                                return rc;
    138143                        }
    139144                        async_wait_for(msg, &rc);
     
    142147                                fibril_rwlock_write_unlock(&namespace_rwlock);
    143148                                async_answer_0(rid, rc);
    144                                 return;
     149                                return rc;
    145150                        }
    146151
     
    166171                        fibril_rwlock_write_unlock(&namespace_rwlock);
    167172                        async_answer_0(rid, rc);
    168                         return;
     173                        return rc;
    169174                } else {
    170175                        /*
     
    174179                        fibril_rwlock_write_unlock(&namespace_rwlock);
    175180                        async_answer_0(rid, ENOENT);
    176                         return;
     181                        return ENOENT;
    177182                }
    178183        }
     
    207212                async_answer_0(rid, rc);
    208213                fibril_rwlock_write_unlock(&namespace_rwlock);
    209                 return;
     214                return rc;
    210215        }
    211216       
     
    222227                fibril_rwlock_write_unlock(&namespace_rwlock);
    223228                async_answer_0(rid, rc);
    224                 return;
     229                return rc;
    225230        }
    226231       
     
    258263        async_answer_0(rid, rc);
    259264        fibril_rwlock_write_unlock(&namespace_rwlock);
     265        return rc;
    260266}
    261267
     
    352358        }
    353359        fibril_mutex_unlock(&fs_list_lock);
    354        
    355         /* Acknowledge that we know fs_name. */
    356         async_answer_0(callid, EOK);
    357        
     360
     361        /* Add the filesystem info to the list of mounted filesystems */
     362        mtab_ent_t *mtab_ent = malloc(sizeof(mtab_ent_t));
     363        if (!mtab_ent) {
     364                async_answer_0(callid, ENOMEM);
     365                async_answer_0(rid, ENOMEM);
     366                free(mp);
     367                free(fs_name);
     368                free(opts);
     369                return;
     370        }
     371
    358372        /* Do the mount */
    359         vfs_mount_internal(rid, service_id, fs_handle, mp, opts);
     373        rc = vfs_mount_internal(rid, service_id, fs_handle, mp, opts);
     374        if (rc != EOK) {
     375                async_answer_0(callid, ENOTSUP);
     376                async_answer_0(rid, ENOTSUP);
     377                free(mtab_ent);
     378                free(mp);
     379                free(opts);
     380                free(fs_name);
     381                return;
     382        }
     383
     384        /* Add the filesystem info to the list of mounted filesystems */
     385
     386        str_cpy(mtab_ent->mp, MAX_PATH_LEN, mp);
     387        str_cpy(mtab_ent->fs_name, FS_NAME_MAXLEN, fs_name);
     388        str_cpy(mtab_ent->opts, MAX_MNTOPTS_LEN, opts);
     389        mtab_ent->instance = instance;
     390        mtab_ent->service_id = service_id;
     391
     392        link_initialize(&mtab_ent->link);
     393
     394        fibril_mutex_lock(&mtab_list_lock);
     395        list_append(&mtab_ent->link, &mtab_list);
     396        mtab_size++;
     397        fibril_mutex_unlock(&mtab_list_lock);
     398
    360399        free(mp);
    361400        free(fs_name);
    362401        free(opts);
     402
     403        /* Acknowledge that we know fs_name. */
     404        async_answer_0(callid, EOK);
    363405}
    364406
     
    433475                 */
    434476               
    435                 free(mp);
    436                
    437477                exch = vfs_exchange_grab(mr_node->fs_handle);
    438478                rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED,
     
    442482                if (rc != EOK) {
    443483                        fibril_rwlock_write_unlock(&namespace_rwlock);
     484                        free(mp);
    444485                        vfs_node_put(mr_node);
    445486                        async_answer_0(rid, rc);
     
    459500               
    460501                rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
    461                 free(mp);
    462502                if (rc != EOK) {
    463503                        fibril_rwlock_write_unlock(&namespace_rwlock);
     504                        free(mp);
    464505                        vfs_node_put(mr_node);
    465506                        async_answer_0(rid, rc);
     
    470511                if (!mp_node) {
    471512                        fibril_rwlock_write_unlock(&namespace_rwlock);
     513                        free(mp);
    472514                        vfs_node_put(mr_node);
    473515                        async_answer_0(rid, ENOMEM);
     
    482524                if (rc != EOK) {
    483525                        fibril_rwlock_write_unlock(&namespace_rwlock);
     526                        free(mp);
    484527                        vfs_node_put(mp_node);
    485528                        vfs_node_put(mr_node);
     
    499542         */
    500543        vfs_node_forget(mr_node);
    501        
    502544        fibril_rwlock_write_unlock(&namespace_rwlock);
     545
     546        fibril_mutex_lock(&mtab_list_lock);
     547
     548        int found = 0;
     549
     550        list_foreach(mtab_list, cur) {
     551                mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
     552                    link);
     553
     554                if (str_cmp(mtab_ent->mp, mp) == 0) {
     555                        list_remove(&mtab_ent->link);
     556                        mtab_size--;
     557                        free(mtab_ent);
     558                        found = 1;
     559                        break;
     560                }
     561        }
     562        assert(found);
     563        fibril_mutex_unlock(&mtab_list_lock);
     564
     565        free(mp);
     566
    503567        async_answer_0(rid, EOK);
    504568}
     
    12891353}
    12901354
     1355void vfs_get_mtab(ipc_callid_t rid, ipc_call_t *request)
     1356{
     1357        ipc_callid_t callid;
     1358        ipc_call_t data;
     1359        sysarg_t rc = EOK;
     1360        size_t len;
     1361
     1362        fibril_mutex_lock(&mtab_list_lock);
     1363
     1364        /* Send to the caller the number of mounted filesystems */
     1365        callid = async_get_call(&data);
     1366        if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
     1367                rc = ENOTSUP;
     1368                async_answer_0(callid, rc);
     1369                goto exit;
     1370        }
     1371        async_answer_1(callid, EOK, mtab_size);
     1372
     1373        list_foreach(mtab_list, cur) {
     1374                mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
     1375                    link);
     1376
     1377                rc = ENOTSUP;
     1378
     1379                if (!async_data_read_receive(&callid, &len))
     1380                        goto exit;
     1381
     1382                (void) async_data_read_finalize(callid, mtab_ent->mp,
     1383                    str_size(mtab_ent->mp));
     1384
     1385                if (!async_data_read_receive(&callid, &len))
     1386                        goto exit;
     1387
     1388                (void) async_data_read_finalize(callid, mtab_ent->opts,
     1389                    str_size(mtab_ent->opts));
     1390
     1391                if (!async_data_read_receive(&callid, &len))
     1392                        goto exit;
     1393
     1394                (void) async_data_read_finalize(callid, mtab_ent->fs_name,
     1395                    str_size(mtab_ent->fs_name));
     1396
     1397                callid = async_get_call(&data);
     1398
     1399                if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
     1400                        rc = ENOTSUP;
     1401                        async_answer_0(callid, rc);
     1402                        goto exit;
     1403                }
     1404
     1405                rc = EOK;
     1406                async_answer_2(callid, rc, mtab_ent->instance,
     1407                    mtab_ent->service_id);
     1408        }
     1409
     1410exit:
     1411        fibril_mutex_unlock(&mtab_list_lock);
     1412        async_answer_0(rid, rc);
     1413}
     1414
    12911415/**
    12921416 * @}
Note: See TracChangeset for help on using the changeset viewer.