Changes in uspace/srv/fs/fat/fat_fat.c [3f93cdbe:991f645] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r3f93cdbe r991f645 49 49 #include <mem.h> 50 50 51 /* 52 * Convenience macros for computing some frequently used values from the 53 * 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 51 62 /** 52 63 * The fat_alloc_lock mutex protects all copies of the File Allocation Table … … 59 70 * 60 71 * @param bs Buffer holding the boot sector for the file. 61 * @param dev _handle Device handle of the device with the file.72 * @param devmap_handle Device handle of the device with the file. 62 73 * @param firstc First cluster to start the walk with. 63 74 * @param lastc If non-NULL, output argument hodling the last cluster … … 70 81 */ 71 82 int 72 fat_cluster_walk(fat_bs_t *bs, dev _handle_t dev_handle, fat_cluster_t firstc,83 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc, 73 84 fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters) 74 85 { 75 86 block_t *b; 76 unsigned bps;77 unsigned rscnt; /* block address of the first FAT */78 87 uint16_t clusters = 0; 79 88 fat_cluster_t clst = firstc; 80 89 int rc; 81 82 bps = uint16_t_le2host(bs->bps);83 rscnt = uint16_t_le2host(bs->rscnt);84 90 85 91 if (firstc == FAT_CLST_RES0) { … … 93 99 94 100 while (clst < FAT_CLST_LAST1 && clusters < max_clusters) { 95 bn_t fsec; /* sector offset relative to FAT1 */101 aoff64_t fsec; /* sector offset relative to FAT1 */ 96 102 unsigned fidx; /* FAT1 entry index */ 97 103 … … 99 105 if (lastc) 100 106 *lastc = clst; /* remember the last cluster number */ 101 fsec = (clst * sizeof(fat_cluster_t)) / bps;102 fidx = clst % ( bps/ sizeof(fat_cluster_t));107 fsec = (clst * sizeof(fat_cluster_t)) / BPS(bs); 108 fidx = clst % (BPS(bs) / sizeof(fat_cluster_t)); 103 109 /* read FAT1 */ 104 rc = block_get(&b, dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE); 110 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec, 111 BLOCK_FLAGS_NONE); 105 112 if (rc != EOK) 106 113 return rc; … … 125 132 * @param block Pointer to a block pointer for storing result. 126 133 * @param bs Buffer holding the boot sector of the file system. 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. 134 * @param nodep FAT node. 130 135 * @param bn Block number. 131 136 * @param flags Flags passed to libblock. … … 134 139 */ 135 140 int 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 */ 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 { 145 209 uint16_t clusters; 146 210 unsigned max_clusters; 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) { 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) { 160 221 /* root directory special case */ 161 assert(bn < rds);162 rc = block_get(block, dev _handle, rscnt + bs->fatcnt * sf + bn,163 flags);222 assert(bn < RDS(bs)); 223 rc = block_get(block, devmap_handle, 224 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags); 164 225 return rc; 165 226 } 166 227 167 max_clusters = bn / bs->spc; 168 rc = fat_cluster_walk(bs, dev_handle, firstc, &lastc, &clusters, 169 max_clusters); 228 max_clusters = bn / SPC(bs); 229 rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters); 170 230 if (rc != EOK) 171 231 return rc; 172 232 assert(clusters == max_clusters); 173 233 174 rc = block_get(block, dev_handle, 175 ssa + (lastc - FAT_CLST_FIRST) * bs->spc + bn % bs->spc, flags); 234 rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags); 235 236 if (clp) 237 *clp = c; 176 238 177 239 return rc; … … 190 252 * @return EOK on success or a negative error code. 191 253 */ 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; 254 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos) 255 { 196 256 block_t *b; 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); 257 aoff64_t o, boundary; 258 int rc; 259 260 boundary = ROUND_UP(nodep->size, BPS(bs) * SPC(bs)); 204 261 205 262 /* zero out already allocated space */ 206 263 for (o = nodep->size; o < pos && o < boundary; 207 o = ALIGN_DOWN(o + bps, bps)) {208 int flags = (o % bps== 0) ?264 o = ALIGN_DOWN(o + BPS(bs), BPS(bs))) { 265 int flags = (o % BPS(bs) == 0) ? 209 266 BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE; 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);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)); 214 271 b->dirty = true; /* need to sync node */ 215 272 rc = block_put(b); … … 222 279 223 280 /* zero out the initial part of the new cluster chain */ 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));281 for (o = boundary; o < pos; o += BPS(bs)) { 282 rc = _fat_block_get(&b, bs, nodep->idx->devmap_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)); 230 287 b->dirty = true; /* need to sync node */ 231 288 rc = block_put(b); … … 240 297 * 241 298 * @param bs Buffer holding the boot sector for the file system. 242 * @param dev _handle Device handle for the file system.299 * @param devmap_handle Device handle for the file system. 243 300 * @param clst Cluster which to get. 244 301 * @param value Output argument holding the value of the cluster. … … 247 304 */ 248 305 int 249 fat_get_cluster(fat_bs_t *bs, dev _handle_t dev_handle, unsigned fatno,306 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 250 307 fat_cluster_t clst, fat_cluster_t *value) 251 308 { 252 309 block_t *b; 253 uint16_t bps;254 uint16_t rscnt;255 uint16_t sf;256 310 fat_cluster_t *cp; 257 311 int rc; 258 312 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); 313 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 314 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 265 315 if (rc != EOK) 266 316 return rc; 267 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 317 cp = (fat_cluster_t *)b->data + 318 clst % (BPS(bs) / sizeof(fat_cluster_t)); 268 319 *value = uint16_t_le2host(*cp); 269 320 rc = block_put(b); … … 275 326 * 276 327 * @param bs Buffer holding the boot sector for the file system. 277 * @param dev _handle Device handle for the file system.328 * @param devmap_handle Device handle for the file system. 278 329 * @param fatno Number of the FAT instance where to make the change. 279 330 * @param clst Cluster which is to be set. … … 283 334 */ 284 335 int 285 fat_set_cluster(fat_bs_t *bs, dev _handle_t dev_handle, unsigned fatno,336 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 286 337 fat_cluster_t clst, fat_cluster_t value) 287 338 { 288 339 block_t *b; 289 uint16_t bps;290 uint16_t rscnt;291 uint16_t sf;292 340 fat_cluster_t *cp; 293 341 int rc; 294 342 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); 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); 302 346 if (rc != EOK) 303 347 return rc; 304 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 348 cp = (fat_cluster_t *)b->data + 349 clst % (BPS(bs) / sizeof(fat_cluster_t)); 305 350 *cp = host2uint16_t_le(value); 306 351 b->dirty = true; /* need to sync block */ … … 312 357 * 313 358 * @param bs Buffer holding the boot sector of the file system. 314 * @param dev _handle Device handle of the file system.359 * @param devmap_handle Device handle of the file system. 315 360 * @param lifo Chain of allocated clusters. 316 361 * @param nclsts Number of clusters in the lifo chain. … … 318 363 * @return EOK on success or a negative error code. 319 364 */ 320 int fat_alloc_shadow_clusters(fat_bs_t *bs, dev _handle_t dev_handle,365 int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, 321 366 fat_cluster_t *lifo, unsigned nclsts) 322 367 { … … 327 372 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 328 373 for (c = 0; c < nclsts; c++) { 329 rc = fat_set_cluster(bs, dev _handle, fatno, lifo[c],374 rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c], 330 375 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 331 376 if (rc != EOK) … … 345 390 * 346 391 * @param bs Buffer holding the boot sector of the file system. 347 * @param dev _handle Device handle of the file system.392 * @param devmap_handle Device handle of the file system. 348 393 * @param nclsts Number of clusters to allocate. 349 394 * @param mcl Output parameter where the first cluster in the chain … … 355 400 */ 356 401 int 357 fat_alloc_clusters(fat_bs_t *bs, dev _handle_t dev_handle, unsigned nclsts,402 fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts, 358 403 fat_cluster_t *mcl, fat_cluster_t *lcl) 359 404 { 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;367 405 block_t *blk; 368 406 fat_cluster_t *lifo; /* stack for storing free cluster numbers */ … … 374 412 if (!lifo) 375 413 return ENOMEM; 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 414 389 415 /* … … 391 417 */ 392 418 fibril_mutex_lock(&fat_alloc_lock); 393 for (b = 0, cl = 0; b < sf; b++) { 394 rc = block_get(&blk, dev_handle, rscnt + b, BLOCK_FLAGS_NONE); 419 for (b = 0, cl = 0; b < SF(bs); b++) { 420 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b, 421 BLOCK_FLAGS_NONE); 395 422 if (rc != EOK) 396 423 goto error; 397 for (c = 0; c < bps/ sizeof(fat_cluster_t); c++, cl++) {424 for (c = 0; c < BPS(bs) / sizeof(fat_cluster_t); c++, cl++) { 398 425 /* 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. 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. 403 432 */ 404 if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) { 433 if ((cl >= FAT_CLST_FIRST) && 434 CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) { 405 435 rc = block_put(blk); 406 436 if (rc != EOK) … … 427 457 /* update the shadow copies of FAT */ 428 458 rc = fat_alloc_shadow_clusters(bs, 429 dev _handle, lifo, nclsts);459 devmap_handle, lifo, nclsts); 430 460 if (rc != EOK) 431 461 goto error; … … 454 484 */ 455 485 while (found--) { 456 rc = fat_set_cluster(bs, dev _handle, FAT1, lifo[found],486 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found], 457 487 FAT_CLST_RES0); 458 488 if (rc != EOK) { … … 469 499 * 470 500 * @param bs Buffer hodling the boot sector of the file system. 471 * @param dev _handle Device handle of the file system.501 * @param devmap_handle Device handle of the file system. 472 502 * @param firstc First cluster in the chain which is to be freed. 473 503 * … … 475 505 */ 476 506 int 477 fat_free_clusters(fat_bs_t *bs, dev _handle_t dev_handle, fat_cluster_t firstc)507 fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc) 478 508 { 479 509 unsigned fatno; … … 484 514 while (firstc < FAT_CLST_LAST1) { 485 515 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 486 rc = fat_get_cluster(bs, dev _handle, FAT1, firstc, &nextc);516 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc); 487 517 if (rc != EOK) 488 518 return rc; 489 519 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 490 rc = fat_set_cluster(bs, dev _handle, fatno, firstc,520 rc = fat_set_cluster(bs, devmap_handle, fatno, firstc, 491 521 FAT_CLST_RES0); 492 522 if (rc != EOK) … … 505 535 * @param nodep Node representing the file. 506 536 * @param mcl First cluster of the cluster chain to append. 537 * @param lcl Last cluster of the cluster chain to append. 507 538 * 508 539 * @return EOK on success or a negative error code. 509 540 */ 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; 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; 515 547 uint8_t fatno; 516 548 int rc; 517 549 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) { 550 if (nodep->firstc == FAT_CLST_RES0) { 524 551 /* No clusters allocated to the node yet. */ 525 552 nodep->firstc = mcl; 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 } 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; 536 575 537 576 return EOK; … … 542 581 * @param bs Buffer holding the boot sector of the file system. 543 582 * @param nodep FAT node where the chopping will take place. 544 * @param l astcLast cluster which will remain in the node. If this583 * @param lcl Last cluster which will remain in the node. If this 545 584 * argument is FAT_CLST_RES0, then all clusters will 546 585 * be chopped off. … … 548 587 * @return EOK on success or a negative return code. 549 588 */ 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) { 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) { 556 602 /* The node will have zero size and no clusters allocated. */ 557 rc = fat_free_clusters(bs, dev _handle, nodep->firstc);603 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc); 558 604 if (rc != EOK) 559 605 return rc; … … 564 610 unsigned fatno; 565 611 566 rc = fat_get_cluster(bs, dev _handle, FAT1, lastc, &nextc);612 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc); 567 613 if (rc != EOK) 568 614 return rc; … … 570 616 /* Terminate the cluster chain in all copies of FAT. */ 571 617 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 572 rc = fat_set_cluster(bs, dev _handle, fatno, lastc,618 rc = fat_set_cluster(bs, devmap_handle, fatno, lcl, 573 619 FAT_CLST_LAST1); 574 620 if (rc != EOK) … … 577 623 578 624 /* Free all following clusters. */ 579 rc = fat_free_clusters(bs, dev_handle, nextc); 580 if (rc != EOK) 581 return rc; 582 } 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; 583 635 584 636 return EOK; … … 586 638 587 639 int 588 fat_zero_cluster(struct fat_bs *bs, dev _handle_t dev_handle, fat_cluster_t c)640 fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c) 589 641 { 590 642 int i; 591 643 block_t *b; 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, 644 int rc; 645 646 for (i = 0; i < SPC(bs); i++) { 647 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i, 599 648 BLOCK_FLAGS_NOREAD); 600 649 if (rc != EOK) 601 650 return rc; 602 memset(b->data, 0, bps);651 memset(b->data, 0, BPS(bs)); 603 652 b->dirty = true; 604 653 rc = block_put(b); … … 616 665 * does not contain a fat file system. 617 666 */ 618 int fat_sanity_check(fat_bs_t *bs, dev _handle_t dev_handle)667 int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle) 619 668 { 620 669 fat_cluster_t e0, e1; … … 657 706 658 707 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 659 rc = fat_get_cluster(bs, dev _handle, fat_no, 0, &e0);708 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0); 660 709 if (rc != EOK) 661 710 return EIO; 662 711 663 rc = fat_get_cluster(bs, dev _handle, fat_no, 1, &e1);712 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1); 664 713 if (rc != EOK) 665 714 return EIO;
Note:
See TracChangeset
for help on using the changeset viewer.