Subversion Repositories HelenOS

Rev

Rev 3595 | Rev 3637 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3595 Rev 3632
Line 283... Line 283...
283
                c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
283
                c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
284
        }
284
        }
285
    }
285
    }
286
}
286
}
287
 
287
 
288
/** Allocate clusters in FAT1.
288
/** Allocate clusters in all copies of FAT.
289
 *
289
 *
290
 * This function will attempt to allocate the requested number of clusters in
290
 * This function will attempt to allocate the requested number of clusters in
291
 * the first FAT instance.  The FAT will be altered so that the allocated
291
 * all instances of the FAT.  The FAT will be altered so that the allocated
292
 * clusters form an independent chain (i.e. a chain which does not belong to any
292
 * clusters form an independent chain (i.e. a chain which does not belong to any
293
 * file yet).
293
 * file yet).
294
 *
294
 *
295
 * @param bs        Buffer holding the boot sector of the file system.
295
 * @param bs        Buffer holding the boot sector of the file system.
296
 * @param dev_handle    Device handle of the file system.
296
 * @param dev_handle    Device handle of the file system.
Line 313... Line 313...
313
    fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
313
    fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
314
    unsigned found = 0; /* top of the free cluster number stack */
314
    unsigned found = 0; /* top of the free cluster number stack */
315
    unsigned b, c, cl;
315
    unsigned b, c, cl;
316
 
316
 
317
    lifo = (fat_cluster_t *) malloc(nclsts * sizeof(fat_cluster_t));
317
    lifo = (fat_cluster_t *) malloc(nclsts * sizeof(fat_cluster_t));
318
    if (lifo)
318
    if (!lifo)
319
        return ENOMEM;
319
        return ENOMEM;
320
   
320
   
321
    bps = uint16_t_le2host(bs->bps);
321
    bps = uint16_t_le2host(bs->bps);
322
    rscnt = uint16_t_le2host(bs->rscnt);
322
    rscnt = uint16_t_le2host(bs->rscnt);
323
    sf = uint16_t_le2host(bs->sec_per_fat);
323
    sf = uint16_t_le2host(bs->sec_per_fat);
324
   
324
   
325
    /*
325
    /*
326
     * Search FAT1 for unused clusters.
326
     * Search FAT1 for unused clusters.
327
     */
327
     */
328
    futex_down(&fat_alloc_lock);
328
    futex_down(&fat_alloc_lock);
329
    for (b = 0, cl = 0; b < sf; blk++) {
329
    for (b = 0, cl = 0; b < sf; b++) {
330
        blk = block_get(dev_handle, rscnt + b, BLOCK_FLAGS_NOREAD);
330
        blk = block_get(dev_handle, rscnt + b, BLOCK_FLAGS_NONE);
331
        for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
331
        for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
332
            fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
332
            fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
333
            if (uint16_t_le2host(*clst) == FAT_CLST_RES0) {
333
            if (uint16_t_le2host(*clst) == FAT_CLST_RES0) {
334
                /*
334
                /*
335
                 * The cluster is free. Put it into our stack
335
                 * The cluster is free. Put it into our stack