Changeset bba3d90 in mainline


Ignore:
Timestamp:
2011-06-27T16:51:18Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db9aa04
Parents:
5dfb1948
Message:

Using new directory api to support creating long names

File:
1 edited

Legend:

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

    r5dfb1948 rbba3d90  
    581581        fat_bs_t *bs;
    582582        block_t *b;
    583         unsigned i, j;
    584         unsigned blocks;
    585         fat_cluster_t mcl, lcl;
     583        fat_directory_t di;
     584        fat_dentry_t de;
    586585        int rc;
    587586
     
    597596        fibril_mutex_unlock(&childp->lock);
    598597
    599         if (!fat_dentry_name_verify(name)) {
    600                 /*
    601                  * Attempt to create unsupported name.
    602                  */
     598        rc = str_to_wstr(di.wname, FAT_LFN_NAME_SIZE, name);
     599        if (rc != EOK)
     600                return rc;
     601
     602        if (!fat_lfn_valid(di.wname))
    603603                return ENOTSUP;
    604         }
    605 
    606         /*
    607          * Get us an unused parent node's dentry or grow the parent and allocate
    608          * a new one.
    609          */
    610604
    611605        fibril_mutex_lock(&parentp->idx->lock);
    612606        bs = block_bb_get(parentp->idx->devmap_handle);
    613 
    614         blocks = parentp->size / BPS(bs);
    615 
    616         for (i = 0; i < blocks; i++) {
    617                 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
    618                 if (rc != EOK) {
    619                         fibril_mutex_unlock(&parentp->idx->lock);
    620                         return rc;
    621                 }
    622                 for (j = 0; j < DPS(bs); j++) {
    623                         d = ((fat_dentry_t *)b->data) + j;
    624                         switch (fat_classify_dentry(d)) {
    625                         case FAT_DENTRY_LFN:
    626                         case FAT_DENTRY_SKIP:
    627                         case FAT_DENTRY_VALID:
    628                                 /* skipping used and meta entries */
    629                                 continue;
    630                         case FAT_DENTRY_FREE:
    631                         case FAT_DENTRY_LAST:
    632                                 /* found an empty slot */
    633                                 goto hit;
    634                         }
    635                 }
    636                 rc = block_put(b);
    637                 if (rc != EOK) {
    638                         fibril_mutex_unlock(&parentp->idx->lock);
    639                         return rc;
    640                 }
    641         }
    642         j = 0;
    643 
    644         /*
    645          * We need to grow the parent in order to create a new unused dentry.
    646          */
    647         if (!FAT_IS_FAT32(bs) && parentp->firstc == FAT_CLST_ROOT) {
    648                 /* Can't grow the root directory. */
    649                 fibril_mutex_unlock(&parentp->idx->lock);
    650                 return ENOSPC;
    651         }
    652         rc = fat_alloc_clusters(bs, parentp->idx->devmap_handle, 1, &mcl, &lcl);
    653         if (rc != EOK) {
    654                 fibril_mutex_unlock(&parentp->idx->lock);
    655                 return rc;
    656         }
    657         rc = fat_zero_cluster(bs, parentp->idx->devmap_handle, mcl);
    658         if (rc != EOK) {
    659                 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl);
    660                 fibril_mutex_unlock(&parentp->idx->lock);
    661                 return rc;
    662         }
    663         rc = fat_append_clusters(bs, parentp, mcl, lcl);
    664         if (rc != EOK) {
    665                 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl);
    666                 fibril_mutex_unlock(&parentp->idx->lock);
    667                 return rc;
    668         }
    669         parentp->size += BPS(bs) * SPC(bs);
    670         parentp->dirty = true;          /* need to sync node */
    671         rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
    672         if (rc != EOK) {
    673                 fibril_mutex_unlock(&parentp->idx->lock);
    674                 return rc;
    675         }
    676         d = (fat_dentry_t *)b->data;
    677 
    678 hit:
     607        fat_directory_open(parentp, &di);
     608
    679609        /*
    680610         * At this point we only establish the link between the parent and the
     
    683613         * dentry data is kept in the child node structure.
    684614         */
    685         memset(d, 0, sizeof(fat_dentry_t));
    686         fat_dentry_name_set(d, name);
    687         b->dirty = true;                /* need to sync block */
    688         rc = block_put(b);
     615        memset(&de, 0, sizeof(fat_dentry_t));
     616
     617        rc = fat_directory_write(&di, name, &de);
     618        if (rc!=EOK)
     619                return rc;
     620        rc = fat_directory_close(&di);
     621        if (rc!=EOK)
     622                return rc;
     623
    689624        fibril_mutex_unlock(&parentp->idx->lock);
    690625        if (rc != EOK)
     
    741676
    742677        childp->idx->pfc = parentp->firstc;
    743         childp->idx->pdi = i * DPS(bs) + j;
     678        childp->idx->pdi = di.pos;      /* di.pos holds absolute position of SFN entry */
    744679        fibril_mutex_unlock(&childp->idx->lock);
    745680
Note: See TracChangeset for help on using the changeset viewer.