Changeset 913a821c in mainline for uspace/srv/fs/fat/fat_fat.c
- Timestamp:
- 2008-11-09T17:23:53Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ac49f5d1
- Parents:
- 6c8d267
- File:
-
- 1 edited
-
uspace/srv/fs/fat/fat_fat.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r6c8d267 r913a821c 130 130 unsigned ssa; /* size of the system area */ 131 131 unsigned clusters, max_clusters; 132 fat_cluster_t lastc , clst = firstc;132 fat_cluster_t lastc; 133 133 134 134 bps = uint16_t_le2host(bs->bps); … … 158 158 return b; 159 159 } 160 161 160 162 161 /** Fill the gap between EOF and a new file position. … … 204 203 } 205 204 206 /** Mark cluster in one instance of FAT. 205 /** Get cluster from the first FAT. 206 * 207 * @param bs Buffer holding the boot sector for the file system. 208 * @param dev_handle Device handle for the file system. 209 * @param clst Cluster which to get. 210 * 211 * @return Value found in the cluster. 212 */ 213 fat_cluster_t 214 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst) 215 { 216 block_t *b; 217 uint16_t bps; 218 uint16_t rscnt; 219 fat_cluster_t *cp, value; 220 221 bps = uint16_t_le2host(bs->bps); 222 rscnt = uint16_t_le2host(bs->rscnt); 223 224 b = block_get(dev_handle, rscnt + (clst * sizeof(fat_cluster_t)) / bps); 225 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 226 value = uint16_t_le2host(*cp); 227 block_put(b); 228 229 return value; 230 } 231 232 /** Set cluster in one instance of FAT. 207 233 * 208 234 * @param bs Buffer holding the boot sector for the file system. 209 235 * @param dev_handle Device handle for the file system. 210 236 * @param fatno Number of the FAT instance where to make the change. 211 * @param clst Cluster which is to be marked.212 * @param value Value markthe cluster with.237 * @param clst Cluster which is to be set. 238 * @param value Value to set the cluster with. 213 239 */ 214 240 void 215 fat_ mark_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,241 fat_set_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 216 242 fat_cluster_t clst, fat_cluster_t value) 217 243 { … … 250 276 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 251 277 for (c = 0; c < nclsts; c++) { 252 fat_ mark_cluster(bs, dev_handle, fatno, lifo[c],278 fat_set_cluster(bs, dev_handle, fatno, lifo[c], 253 279 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 254 280 } … … 334 360 */ 335 361 while (found--) { 336 fat_ mark_cluster(bs, dev_handle, FAT1, lifo[found],362 fat_set_cluster(bs, dev_handle, FAT1, lifo[found], 337 363 FAT_CLST_RES0); 338 364 } … … 342 368 } 343 369 370 /** Free clusters forming a cluster chain in all copies of FAT. 371 * 372 * @param bs Buffer hodling the boot sector of the file system. 373 * @param dev_handle Device handle of the file system. 374 * @param firstc First cluster in the chain which is to be freed. 375 */ 376 void 377 fat_free_clusters(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc) 378 { 379 unsigned fatno; 380 fat_cluster_t nextc; 381 382 /* Mark all clusters in the chain as free in all copies of FAT. */ 383 while (firstc < FAT_CLST_LAST1) { 384 nextc = fat_get_cluster(bs, dev_handle, firstc); 385 assert(nextc >= FAT_CLST_FIRST && nextc < FAT_CLST_BAD); 386 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 387 fat_set_cluster(bs, dev_handle, fatno, firstc, 388 FAT_CLST_RES0); 389 firstc = nextc; 390 } 391 } 392 344 393 /** Append a cluster chain to the last file cluster in all FATs. 345 394 * 346 * @param bs Buffer holding boot sector of the file system.395 * @param bs Buffer holding the boot sector of the file system. 347 396 * @param nodep Node representing the file. 348 397 * @param mcl First cluster of the cluster chain to append. … … 354 403 uint8_t fatno; 355 404 356 if (fat_cluster_walk(bs, nodep->idx->dev_handle, nodep->firstc, &lcl,405 if (fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, 357 406 (uint16_t) -1) == 0) { 358 407 /* No clusters allocated to the node yet. */ … … 363 412 364 413 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 365 fat_mark_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl); 414 fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl); 415 } 416 417 /** Chop off node clusters in all copies of FAT. 418 * 419 * @param bs Buffer holding the boot sector of the file system. 420 * @param nodep FAT node where the chopping will take place. 421 * @param lastc Last cluster which will remain in the node. If this 422 * argument is FAT_CLST_RES0, then all clusters will 423 * be choped off. 424 */ 425 void fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 426 { 427 dev_handle_t dev_handle = nodep->idx->dev_handle; 428 if (lastc == FAT_CLST_RES0) { 429 /* The node will have zero size and no clusters allocated. */ 430 fat_free_clusters(bs, dev_handle, nodep->firstc); 431 nodep->firstc = FAT_CLST_RES0; 432 nodep->dirty = true; /* need to sync node */ 433 } else { 434 fat_cluster_t nextc; 435 unsigned fatno; 436 437 nextc = fat_get_cluster(bs, dev_handle, lastc); 438 439 /* Terminate the cluster chain in all copies of FAT. */ 440 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 441 fat_set_cluster(bs, dev_handle, fatno, lastc, FAT_CLST_LAST1); 442 443 /* Free all following clusters. */ 444 fat_free_clusters(bs, dev_handle, nextc); 445 } 366 446 } 367 447
Note:
See TracChangeset
for help on using the changeset viewer.
