Changeset 84b86dcb in mainline


Ignore:
Timestamp:
2007-09-28T13:42:04Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
12a56fa
Parents:
13125d3
Message:

VFS work.
Add fs_name_to_handle() function to abstract away the details of walking the
list of registered file systems, and in order to avoid code duplication.

Location:
uspace/srv/vfs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    r13125d3 r84b86dcb  
    148148extern void vfs_release_phone(int);
    149149
     150extern int fs_name_to_handle(char *name, bool lock);
     151
    150152extern int vfs_lookup_internal(char *path, size_t len, vfs_node_t *result);
    151153
  • uspace/srv/vfs/vfs_register.c

    r13125d3 r84b86dcb  
    219219         * Check for duplicit registrations.
    220220         */
    221         link_t *cur;
    222         for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
    223                 fs_info_t *fi = list_get_instance(cur, fs_info_t,
    224                     fs_link);
    225                 /* TODO: replace strcmp with strncmp once we have it */
    226                 if (strcmp(fs_info->vfs_info.name, fi->vfs_info.name) == 0) {
    227                         /*
    228                          * We already register a fs like this.
    229                          */
    230                         dprintf("FS is already registered.\n");
    231                         futex_up(&fs_head_futex);
    232                         free(fs_info);
    233                         ipc_answer_fast(callid, EEXISTS, 0, 0);
    234                         ipc_answer_fast(rid, EEXISTS, 0, 0);
    235                         return;
    236                 }
     221        if (fs_name_to_handle(fs_info->vfs_info.name, false)) {
     222                /*
     223                 * We already register a fs like this.
     224                 */
     225                dprintf("FS is already registered.\n");
     226                futex_up(&fs_head_futex);
     227                free(fs_info);
     228                ipc_answer_fast(callid, EEXISTS, 0, 0);
     229                ipc_answer_fast(rid, EEXISTS, 0, 0);
     230                return;
    237231        }
    238232
     
    307301        dprintf("Sharing PLB.\n");
    308302
    309         futex_up(&fs_head_futex);
    310 
    311303        /*
    312304         * That was it. The FS has been registered.
     
    316308        fs_info->fs_handle = (int) atomic_postinc(&fs_handle_next);
    317309        ipc_answer_fast(rid, EOK, (ipcarg_t) fs_info->fs_handle, 0);
     310       
     311        futex_up(&fs_head_futex);
     312       
    318313        dprintf("\"%s\" filesystem successfully registered, handle=%d.\n",
    319314            fs_info->vfs_info.name, fs_info->fs_handle);
     
    385380}
    386381
     382/** Convert file system name to its handle.
     383 *
     384 * @param name          File system name.
     385 * @param lock          If true, the function will down and up the
     386 *                      fs_head_futex.
     387 *
     388 * @return              File system handle or zero if file system not found.
     389 */
     390int fs_name_to_handle(char *name, bool lock)
     391{
     392        int handle = 0;
     393       
     394        if (lock)
     395                futex_down(&fs_head_futex);
     396        link_t *cur;
     397        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     398                fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
     399                if (strcmp(fs->vfs_info.name, name) == 0) { /* XXX: strncmp() */
     400                        handle = fs->fs_handle;
     401                        break;
     402                }
     403        }
     404        if (lock)
     405                futex_up(&fs_head_futex);
     406        return handle;
     407}
     408
    387409/**
    388410 * @}
Note: See TracChangeset for help on using the changeset viewer.