Changes in uspace/srv/fs/fat/fat_fat.c [991f645:3f93cdbe] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r991f645 r3f93cdbe 49 49 #include <mem.h> 50 50 51 /*52 * Convenience macros for computing some frequently used values from the53 * primitive boot sector members.54 */55 #define RDS(bs) ((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \56 (((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0)57 #define SSA(bs) (RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs))58 59 #define CLBN2PBN(bs, cl, bn) \60 (SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))61 62 51 /** 63 52 * The fat_alloc_lock mutex protects all copies of the File Allocation Table … … 70 59 * 71 60 * @param bs Buffer holding the boot sector for the file. 72 * @param dev map_handle Device handle of the device with the file.61 * @param dev_handle Device handle of the device with the file. 73 62 * @param firstc First cluster to start the walk with. 74 63 * @param lastc If non-NULL, output argument hodling the last cluster … … 81 70 */ 82 71 int 83 fat_cluster_walk(fat_bs_t *bs, dev map_handle_t devmap_handle, fat_cluster_t firstc,72 fat_cluster_walk(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, 84 73 fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters) 85 74 { 86 75 block_t *b; 76 unsigned bps; 77 unsigned rscnt; /* block address of the first FAT */ 87 78 uint16_t clusters = 0; 88 79 fat_cluster_t clst = firstc; 89 80 int rc; 81 82 bps = uint16_t_le2host(bs->bps); 83 rscnt = uint16_t_le2host(bs->rscnt); 90 84 91 85 if (firstc == FAT_CLST_RES0) { … … 99 93 100 94 while (clst < FAT_CLST_LAST1 && clusters < max_clusters) { 101 aoff64_t fsec; /* sector offset relative to FAT1 */95 bn_t fsec; /* sector offset relative to FAT1 */ 102 96 unsigned fidx; /* FAT1 entry index */ 103 97 … … 105 99 if (lastc) 106 100 *lastc = clst; /* remember the last cluster number */ 107 fsec = (clst * sizeof(fat_cluster_t)) / BPS(bs);108 fidx = clst % ( BPS(bs)/ sizeof(fat_cluster_t));101 fsec = (clst * sizeof(fat_cluster_t)) / bps; 102 fidx = clst % (bps / sizeof(fat_cluster_t)); 109 103 /* read FAT1 */ 110 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec, 111 BLOCK_FLAGS_NONE); 104 rc = block_get(&b, dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE); 112 105 if (rc != EOK) 113 106 return rc; … … 132 125 * @param block Pointer to a block pointer for storing result. 133 126 * @param bs Buffer holding the boot sector of the file system. 134 * @param nodep FAT node. 127 * @param dev_handle Device handle of the file system. 128 * @param firstc First cluster used by the file. Can be zero if the file 129 * is empty. 135 130 * @param bn Block number. 136 131 * @param flags Flags passed to libblock. … … 139 134 */ 140 135 int 141 fat_block_get(block_t **block, struct fat_bs *bs, fat_node_t *nodep, 142 aoff64_t bn, int flags) 143 { 144 fat_cluster_t firstc = nodep->firstc; 145 fat_cluster_t currc; 146 aoff64_t relbn = bn; 147 int rc; 148 149 if (!nodep->size) 150 return ELIMIT; 151 152 if (nodep->firstc == FAT_CLST_ROOT) 153 goto fall_through; 154 155 if (((((nodep->size - 1) / BPS(bs)) / SPC(bs)) == bn / SPC(bs)) && 156 nodep->lastc_cached_valid) { 157 /* 158 * This is a request to read a block within the last cluster 159 * when fortunately we have the last cluster number cached. 160 */ 161 return block_get(block, nodep->idx->devmap_handle, 162 CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags); 163 } 164 165 if (nodep->currc_cached_valid && bn >= nodep->currc_cached_bn) { 166 /* 167 * We can start with the cluster cached by the previous call to 168 * fat_block_get(). 169 */ 170 firstc = nodep->currc_cached_value; 171 relbn -= (nodep->currc_cached_bn / SPC(bs)) * SPC(bs); 172 } 173 174 fall_through: 175 rc = _fat_block_get(block, bs, nodep->idx->devmap_handle, firstc, 176 &currc, relbn, flags); 177 if (rc != EOK) 178 return rc; 179 180 /* 181 * Update the "current" cluster cache. 182 */ 183 nodep->currc_cached_valid = true; 184 nodep->currc_cached_bn = bn; 185 nodep->currc_cached_value = currc; 186 187 return rc; 188 } 189 190 /** Read block from file located on a FAT file system. 191 * 192 * @param block Pointer to a block pointer for storing result. 193 * @param bs Buffer holding the boot sector of the file system. 194 * @param devmap_handle Device handle of the file system. 195 * @param fcl First cluster used by the file. Can be zero if the file 196 * is empty. 197 * @param clp If not NULL, address where the cluster containing bn 198 * will be stored. 199 * stored 200 * @param bn Block number. 201 * @param flags Flags passed to libblock. 202 * 203 * @return EOK on success or a negative error code. 204 */ 205 int 206 _fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle, 207 fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags) 208 { 136 _fat_block_get(block_t **block, fat_bs_t *bs, dev_handle_t dev_handle, 137 fat_cluster_t firstc, bn_t bn, int flags) 138 { 139 unsigned bps; 140 unsigned rscnt; /* block address of the first FAT */ 141 unsigned rde; 142 unsigned rds; /* root directory size */ 143 unsigned sf; 144 unsigned ssa; /* size of the system area */ 209 145 uint16_t clusters; 210 146 unsigned max_clusters; 211 fat_cluster_t c; 212 int rc; 213 214 /* 215 * This function can only operate on non-zero length files. 216 */ 217 if (fcl == FAT_CLST_RES0) 218 return ELIMIT; 219 220 if (fcl == FAT_CLST_ROOT) { 147 fat_cluster_t lastc; 148 int rc; 149 150 bps = uint16_t_le2host(bs->bps); 151 rscnt = uint16_t_le2host(bs->rscnt); 152 rde = uint16_t_le2host(bs->root_ent_max); 153 sf = uint16_t_le2host(bs->sec_per_fat); 154 155 rds = (sizeof(fat_dentry_t) * rde) / bps; 156 rds += ((sizeof(fat_dentry_t) * rde) % bps != 0); 157 ssa = rscnt + bs->fatcnt * sf + rds; 158 159 if (firstc == FAT_CLST_ROOT) { 221 160 /* root directory special case */ 222 assert(bn < RDS(bs));223 rc = block_get(block, dev map_handle,224 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn,flags);161 assert(bn < rds); 162 rc = block_get(block, dev_handle, rscnt + bs->fatcnt * sf + bn, 163 flags); 225 164 return rc; 226 165 } 227 166 228 max_clusters = bn / SPC(bs); 229 rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters); 167 max_clusters = bn / bs->spc; 168 rc = fat_cluster_walk(bs, dev_handle, firstc, &lastc, &clusters, 169 max_clusters); 230 170 if (rc != EOK) 231 171 return rc; 232 172 assert(clusters == max_clusters); 233 173 234 rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags); 235 236 if (clp) 237 *clp = c; 174 rc = block_get(block, dev_handle, 175 ssa + (lastc - FAT_CLST_FIRST) * bs->spc + bn % bs->spc, flags); 238 176 239 177 return rc; … … 252 190 * @return EOK on success or a negative error code. 253 191 */ 254 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos) 255 { 192 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos) 193 { 194 uint16_t bps; 195 unsigned spc; 256 196 block_t *b; 257 aoff64_t o, boundary; 258 int rc; 259 260 boundary = ROUND_UP(nodep->size, BPS(bs) * SPC(bs)); 197 off_t o, boundary; 198 int rc; 199 200 bps = uint16_t_le2host(bs->bps); 201 spc = bs->spc; 202 203 boundary = ROUND_UP(nodep->size, bps * spc); 261 204 262 205 /* zero out already allocated space */ 263 206 for (o = nodep->size; o < pos && o < boundary; 264 o = ALIGN_DOWN(o + BPS(bs), BPS(bs))) {265 int flags = (o % BPS(bs)== 0) ?207 o = ALIGN_DOWN(o + bps, bps)) { 208 int flags = (o % bps == 0) ? 266 209 BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE; 267 rc = fat_block_get(&b, bs, nodep, o / BPS(bs), flags);268 if (rc != EOK) 269 return rc; 270 memset(b->data + o % BPS(bs), 0, BPS(bs) - o % BPS(bs));210 rc = fat_block_get(&b, bs, nodep, o / bps, flags); 211 if (rc != EOK) 212 return rc; 213 memset(b->data + o % bps, 0, bps - o % bps); 271 214 b->dirty = true; /* need to sync node */ 272 215 rc = block_put(b); … … 279 222 280 223 /* zero out the initial part of the new cluster chain */ 281 for (o = boundary; o < pos; o += BPS(bs)) {282 rc = _fat_block_get(&b, bs, nodep->idx->dev map_handle, mcl,283 NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD);284 if (rc != EOK) 285 return rc; 286 memset(b->data, 0, min( BPS(bs), pos - o));224 for (o = boundary; o < pos; o += bps) { 225 rc = _fat_block_get(&b, bs, nodep->idx->dev_handle, mcl, 226 (o - boundary) / bps, BLOCK_FLAGS_NOREAD); 227 if (rc != EOK) 228 return rc; 229 memset(b->data, 0, min(bps, pos - o)); 287 230 b->dirty = true; /* need to sync node */ 288 231 rc = block_put(b); … … 297 240 * 298 241 * @param bs Buffer holding the boot sector for the file system. 299 * @param dev map_handle Device handle for the file system.242 * @param dev_handle Device handle for the file system. 300 243 * @param clst Cluster which to get. 301 244 * @param value Output argument holding the value of the cluster. … … 304 247 */ 305 248 int 306 fat_get_cluster(fat_bs_t *bs, dev map_handle_t devmap_handle, unsigned fatno,249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 307 250 fat_cluster_t clst, fat_cluster_t *value) 308 251 { 309 252 block_t *b; 253 uint16_t bps; 254 uint16_t rscnt; 255 uint16_t sf; 310 256 fat_cluster_t *cp; 311 257 int rc; 312 258 313 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 314 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 259 bps = uint16_t_le2host(bs->bps); 260 rscnt = uint16_t_le2host(bs->rscnt); 261 sf = uint16_t_le2host(bs->sec_per_fat); 262 263 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 264 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 315 265 if (rc != EOK) 316 266 return rc; 317 cp = (fat_cluster_t *)b->data + 318 clst % (BPS(bs) / sizeof(fat_cluster_t)); 267 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 319 268 *value = uint16_t_le2host(*cp); 320 269 rc = block_put(b); … … 326 275 * 327 276 * @param bs Buffer holding the boot sector for the file system. 328 * @param dev map_handle Device handle for the file system.277 * @param dev_handle Device handle for the file system. 329 278 * @param fatno Number of the FAT instance where to make the change. 330 279 * @param clst Cluster which is to be set. … … 334 283 */ 335 284 int 336 fat_set_cluster(fat_bs_t *bs, dev map_handle_t devmap_handle, unsigned fatno,285 fat_set_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 337 286 fat_cluster_t clst, fat_cluster_t value) 338 287 { 339 288 block_t *b; 289 uint16_t bps; 290 uint16_t rscnt; 291 uint16_t sf; 340 292 fat_cluster_t *cp; 341 293 int rc; 342 294 343 assert(fatno < FATCNT(bs)); 344 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 345 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 295 bps = uint16_t_le2host(bs->bps); 296 rscnt = uint16_t_le2host(bs->rscnt); 297 sf = uint16_t_le2host(bs->sec_per_fat); 298 299 assert(fatno < bs->fatcnt); 300 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 301 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 346 302 if (rc != EOK) 347 303 return rc; 348 cp = (fat_cluster_t *)b->data + 349 clst % (BPS(bs) / sizeof(fat_cluster_t)); 304 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 350 305 *cp = host2uint16_t_le(value); 351 306 b->dirty = true; /* need to sync block */ … … 357 312 * 358 313 * @param bs Buffer holding the boot sector of the file system. 359 * @param dev map_handle Device handle of the file system.314 * @param dev_handle Device handle of the file system. 360 315 * @param lifo Chain of allocated clusters. 361 316 * @param nclsts Number of clusters in the lifo chain. … … 363 318 * @return EOK on success or a negative error code. 364 319 */ 365 int fat_alloc_shadow_clusters(fat_bs_t *bs, dev map_handle_t devmap_handle,320 int fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, 366 321 fat_cluster_t *lifo, unsigned nclsts) 367 322 { … … 372 327 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 373 328 for (c = 0; c < nclsts; c++) { 374 rc = fat_set_cluster(bs, dev map_handle, fatno, lifo[c],329 rc = fat_set_cluster(bs, dev_handle, fatno, lifo[c], 375 330 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 376 331 if (rc != EOK) … … 390 345 * 391 346 * @param bs Buffer holding the boot sector of the file system. 392 * @param dev map_handle Device handle of the file system.347 * @param dev_handle Device handle of the file system. 393 348 * @param nclsts Number of clusters to allocate. 394 349 * @param mcl Output parameter where the first cluster in the chain … … 400 355 */ 401 356 int 402 fat_alloc_clusters(fat_bs_t *bs, dev map_handle_t devmap_handle, unsigned nclsts,357 fat_alloc_clusters(fat_bs_t *bs, dev_handle_t dev_handle, unsigned nclsts, 403 358 fat_cluster_t *mcl, fat_cluster_t *lcl) 404 359 { 360 uint16_t bps; 361 uint16_t rscnt; 362 uint16_t sf; 363 uint32_t ts; 364 unsigned rde; 365 unsigned rds; 366 unsigned ssa; 405 367 block_t *blk; 406 368 fat_cluster_t *lifo; /* stack for storing free cluster numbers */ … … 413 375 return ENOMEM; 414 376 377 bps = uint16_t_le2host(bs->bps); 378 rscnt = uint16_t_le2host(bs->rscnt); 379 sf = uint16_t_le2host(bs->sec_per_fat); 380 rde = uint16_t_le2host(bs->root_ent_max); 381 ts = (uint32_t) uint16_t_le2host(bs->totsec16); 382 if (ts == 0) 383 ts = uint32_t_le2host(bs->totsec32); 384 385 rds = (sizeof(fat_dentry_t) * rde) / bps; 386 rds += ((sizeof(fat_dentry_t) * rde) % bps != 0); 387 ssa = rscnt + bs->fatcnt * sf + rds; 388 415 389 /* 416 390 * Search FAT1 for unused clusters. 417 391 */ 418 392 fibril_mutex_lock(&fat_alloc_lock); 419 for (b = 0, cl = 0; b < SF(bs); b++) { 420 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b, 421 BLOCK_FLAGS_NONE); 393 for (b = 0, cl = 0; b < sf; b++) { 394 rc = block_get(&blk, dev_handle, rscnt + b, BLOCK_FLAGS_NONE); 422 395 if (rc != EOK) 423 396 goto error; 424 for (c = 0; c < BPS(bs)/ sizeof(fat_cluster_t); c++, cl++) {397 for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) { 425 398 /* 426 * Check if the entire cluster is physically there. 427 * This check becomes necessary when the file system is 428 * created with fewer total sectors than how many is 429 * inferred from the size of the file allocation table 430 * or when the last cluster ends beyond the end of the 431 * device. 399 * Check if the cluster is physically there. This check 400 * becomes necessary when the file system is created 401 * with fewer total sectors than how many is inferred 402 * from the size of the file allocation table. 432 403 */ 433 if ((cl >= FAT_CLST_FIRST) && 434 CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) { 404 if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) { 435 405 rc = block_put(blk); 436 406 if (rc != EOK) … … 457 427 /* update the shadow copies of FAT */ 458 428 rc = fat_alloc_shadow_clusters(bs, 459 dev map_handle, lifo, nclsts);429 dev_handle, lifo, nclsts); 460 430 if (rc != EOK) 461 431 goto error; … … 484 454 */ 485 455 while (found--) { 486 rc = fat_set_cluster(bs, dev map_handle, FAT1, lifo[found],456 rc = fat_set_cluster(bs, dev_handle, FAT1, lifo[found], 487 457 FAT_CLST_RES0); 488 458 if (rc != EOK) { … … 499 469 * 500 470 * @param bs Buffer hodling the boot sector of the file system. 501 * @param dev map_handle Device handle of the file system.471 * @param dev_handle Device handle of the file system. 502 472 * @param firstc First cluster in the chain which is to be freed. 503 473 * … … 505 475 */ 506 476 int 507 fat_free_clusters(fat_bs_t *bs, dev map_handle_t devmap_handle, fat_cluster_t firstc)477 fat_free_clusters(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc) 508 478 { 509 479 unsigned fatno; … … 514 484 while (firstc < FAT_CLST_LAST1) { 515 485 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 516 rc = fat_get_cluster(bs, dev map_handle, FAT1, firstc, &nextc);486 rc = fat_get_cluster(bs, dev_handle, FAT1, firstc, &nextc); 517 487 if (rc != EOK) 518 488 return rc; 519 489 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 520 rc = fat_set_cluster(bs, dev map_handle, fatno, firstc,490 rc = fat_set_cluster(bs, dev_handle, fatno, firstc, 521 491 FAT_CLST_RES0); 522 492 if (rc != EOK) … … 535 505 * @param nodep Node representing the file. 536 506 * @param mcl First cluster of the cluster chain to append. 537 * @param lcl Last cluster of the cluster chain to append.538 507 * 539 508 * @return EOK on success or a negative error code. 540 509 */ 541 int 542 fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, 543 fat_cluster_t lcl) 544 { 545 devmap_handle_t devmap_handle = nodep->idx->devmap_handle; 546 fat_cluster_t lastc; 510 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 511 { 512 dev_handle_t dev_handle = nodep->idx->dev_handle; 513 fat_cluster_t lcl; 514 uint16_t numc; 547 515 uint8_t fatno; 548 516 int rc; 549 517 550 if (nodep->firstc == FAT_CLST_RES0) { 518 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc, 519 (uint16_t) -1); 520 if (rc != EOK) 521 return rc; 522 523 if (numc == 0) { 551 524 /* No clusters allocated to the node yet. */ 552 525 nodep->firstc = mcl; 553 nodep->dirty = true; /* need to sync node */ 554 } else { 555 if (nodep->lastc_cached_valid) { 556 lastc = nodep->lastc_cached_value; 557 nodep->lastc_cached_valid = false; 558 } else { 559 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 560 &lastc, NULL, (uint16_t) -1); 561 if (rc != EOK) 562 return rc; 563 } 564 565 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 566 rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno, 567 lastc, mcl); 568 if (rc != EOK) 569 return rc; 570 } 571 } 572 573 nodep->lastc_cached_valid = true; 574 nodep->lastc_cached_value = lcl; 526 nodep->dirty = true; /* need to sync node */ 527 return EOK; 528 } 529 530 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 531 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl, 532 mcl); 533 if (rc != EOK) 534 return rc; 535 } 575 536 576 537 return EOK; … … 581 542 * @param bs Buffer holding the boot sector of the file system. 582 543 * @param nodep FAT node where the chopping will take place. 583 * @param l clLast cluster which will remain in the node. If this544 * @param lastc Last cluster which will remain in the node. If this 584 545 * argument is FAT_CLST_RES0, then all clusters will 585 546 * be chopped off. … … 587 548 * @return EOK on success or a negative return code. 588 549 */ 589 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl) 590 { 591 int rc; 592 devmap_handle_t devmap_handle = nodep->idx->devmap_handle; 593 594 /* 595 * Invalidate cached cluster numbers. 596 */ 597 nodep->lastc_cached_valid = false; 598 if (nodep->currc_cached_value != lcl) 599 nodep->currc_cached_valid = false; 600 601 if (lcl == FAT_CLST_RES0) { 550 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 551 { 552 int rc; 553 554 dev_handle_t dev_handle = nodep->idx->dev_handle; 555 if (lastc == FAT_CLST_RES0) { 602 556 /* The node will have zero size and no clusters allocated. */ 603 rc = fat_free_clusters(bs, dev map_handle, nodep->firstc);557 rc = fat_free_clusters(bs, dev_handle, nodep->firstc); 604 558 if (rc != EOK) 605 559 return rc; … … 610 564 unsigned fatno; 611 565 612 rc = fat_get_cluster(bs, dev map_handle, FAT1, lcl, &nextc);566 rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc); 613 567 if (rc != EOK) 614 568 return rc; … … 616 570 /* Terminate the cluster chain in all copies of FAT. */ 617 571 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 618 rc = fat_set_cluster(bs, dev map_handle, fatno, lcl,572 rc = fat_set_cluster(bs, dev_handle, fatno, lastc, 619 573 FAT_CLST_LAST1); 620 574 if (rc != EOK) … … 623 577 624 578 /* Free all following clusters. */ 625 rc = fat_free_clusters(bs, devmap_handle, nextc); 626 if (rc != EOK) 627 return rc; 628 } 629 630 /* 631 * Update and re-enable the last cluster cache. 632 */ 633 nodep->lastc_cached_valid = true; 634 nodep->lastc_cached_value = lcl; 579 rc = fat_free_clusters(bs, dev_handle, nextc); 580 if (rc != EOK) 581 return rc; 582 } 635 583 636 584 return EOK; … … 638 586 639 587 int 640 fat_zero_cluster(struct fat_bs *bs, dev map_handle_t devmap_handle, fat_cluster_t c)588 fat_zero_cluster(struct fat_bs *bs, dev_handle_t dev_handle, fat_cluster_t c) 641 589 { 642 590 int i; 643 591 block_t *b; 644 int rc; 645 646 for (i = 0; i < SPC(bs); i++) { 647 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i, 592 unsigned bps; 593 int rc; 594 595 bps = uint16_t_le2host(bs->bps); 596 597 for (i = 0; i < bs->spc; i++) { 598 rc = _fat_block_get(&b, bs, dev_handle, c, i, 648 599 BLOCK_FLAGS_NOREAD); 649 600 if (rc != EOK) 650 601 return rc; 651 memset(b->data, 0, BPS(bs));602 memset(b->data, 0, bps); 652 603 b->dirty = true; 653 604 rc = block_put(b); … … 665 616 * does not contain a fat file system. 666 617 */ 667 int fat_sanity_check(fat_bs_t *bs, dev map_handle_t devmap_handle)618 int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle) 668 619 { 669 620 fat_cluster_t e0, e1; … … 706 657 707 658 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 708 rc = fat_get_cluster(bs, dev map_handle, fat_no, 0, &e0);659 rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0); 709 660 if (rc != EOK) 710 661 return EIO; 711 662 712 rc = fat_get_cluster(bs, dev map_handle, fat_no, 1, &e1);663 rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1); 713 664 if (rc != EOK) 714 665 return EIO;
Note:
See TracChangeset
for help on using the changeset viewer.