Changeset 49df572 in mainline


Ignore:
Timestamp:
2008-11-24T22:38:44Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14c331a
Parents:
e478b2a4
Message:

When creating a new directory node, allocate the first cluster for it.

File:
1 edited

Legend:

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

    re478b2a4 r49df572  
    289289        fat_idx_t *idxp;
    290290        fat_node_t *nodep;
     291        fat_bs_t *bs;
     292        fat_cluster_t mcl, lcl;
     293        uint16_t bps;
     294        int rc;
     295
     296        bs = block_bb_get(dev_handle);
     297        bps = uint16_t_le2host(bs->bps);
     298        if (flags & L_DIRECTORY) {
     299                /* allocate a cluster */
     300                rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl);
     301                if (rc != EOK)
     302                        return NULL;
     303        }
    291304
    292305        nodep = fat_node_get_new();
    293         if (!nodep)
     306        if (!nodep) {
     307                fat_free_clusters(bs, dev_handle, mcl);
    294308                return NULL;
     309        }
    295310        idxp = fat_idx_get_new(dev_handle);
    296311        if (!idxp) {
     312                fat_free_clusters(bs, dev_handle, mcl);
    297313                fat_node_put(nodep);
    298314                return NULL;
     
    300316        /* idxp->lock held */
    301317        if (flags & L_DIRECTORY) {
     318                int i;
     319                block_t *b;
     320
     321                /*
     322                 * Populate the new cluster with unused dentries.
     323                 * We don't create the '.' and '..' entries, since they are
     324                 * optional and HelenOS VFS does not need them.
     325                 */
     326                for (i = 0; i < bs->spc; i++) {
     327                        b = _fat_block_get(bs, dev_handle, mcl, i,
     328                            BLOCK_FLAGS_NOREAD);
     329                        /* mark all dentries as never-used */
     330                        memset(b->data, 0, bps);
     331                        b->dirty = false;
     332                        block_put(b);
     333                }
    302334                nodep->type = FAT_DIRECTORY;
     335                nodep->firstc = mcl;
     336                nodep->size = bps * bs->spc;
    303337        } else {
    304338                nodep->type = FAT_FILE;
    305         }
    306         nodep->size = 0;
    307         nodep->firstc = FAT_CLST_RES0;
     339                nodep->firstc = FAT_CLST_RES0;
     340                nodep->size = 0;
     341        }
    308342        nodep->lnkcnt = 0;      /* not linked anywhere */
    309343        nodep->refcnt = 1;
     344        nodep->dirty = true;
    310345
    311346        nodep->idx = idxp;
Note: See TracChangeset for help on using the changeset viewer.