Changeset 689f036 in mainline


Ignore:
Timestamp:
2008-06-07T14:52:29Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1fa2657
Parents:
a4dfcd2
Message:

Initialize in-core FAT root directory node during mount.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_ops.c

    ra4dfcd2 r689f036  
    113113
    114114#define FAT_CLST_RES0   0x0000
    115 #define FAT_CLST_RES1   0x0001  /* internally used to mark root directory */
     115#define FAT_CLST_RES1   0x0001
    116116#define FAT_CLST_FIRST  0x0002
    117117#define FAT_CLST_BAD    0xfff7
    118118#define FAT_CLST_LAST1  0xfff8
    119119#define FAT_CLST_LAST8  0xffff
     120
     121/* internally used to mark root directory's parent */
     122#define FAT_CLST_ROOTPAR        FAT_CLST_RES0
     123/* internally used to mark root directory */
     124#define FAT_CLST_ROOT           FAT_CLST_RES1
    120125
    121126#define fat_block_get(np, off) \
     
    152157        ssa = rscnt + fatcnt * sf + rds;
    153158
    154         if (firstc == FAT_CLST_RES1) {
     159        if (firstc == FAT_CLST_ROOT) {
    155160                /* root directory special case */
    156161                assert(offset < rds);
     
    522527static void *fat_root_get(dev_handle_t dev_handle)
    523528{
    524         return NULL;    /* TODO */
     529        return fat_node_get(dev_handle, 0);
    525530}
    526531
     
    562567{
    563568        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     569        block_t *bb;
     570        uint16_t rde;
    564571        int rc;
     572
     573        /* Read the number of root directory entries. */
     574        bb = block_get(dev_handle, BS_BLOCK);
     575        rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
     576        block_put(bb);
    565577
    566578        rc = fat_idx_init_by_dev_handle(dev_handle);
     
    570582        }
    571583
     584        /* Initialize the root node. */
     585        fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
     586        if (!rootp) {
     587                fat_idx_fini_by_dev_handle(dev_handle);
     588                ipc_answer_0(rid, ENOMEM);
     589                return;
     590        }
     591        fat_node_initialize(rootp);
     592
     593        fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
     594        if (!ridxp) {
     595                free(rootp);
     596                fat_idx_fini_by_dev_handle(dev_handle);
     597                ipc_answer_0(rid, ENOMEM);
     598                return;
     599        }
     600        assert(ridxp->index == 0);
     601        /* ridxp->lock held */
     602
     603        rootp->type = FAT_DIRECTORY;
     604        rootp->firstc = FAT_CLST_ROOT;
     605        rootp->refcnt = 1;
     606        rootp->size = rde * sizeof(fat_dentry_t);
     607        rootp->idx = ridxp;
     608        ridxp->nodep = rootp;
     609       
     610        futex_up(&ridxp->lock);
     611
    572612        ipc_answer_0(rid, EOK);
    573613}
Note: See TracChangeset for help on using the changeset viewer.