Changeset cca29e3c in mainline
- Timestamp:
- 2009-09-03T14:46:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2f636b6
- Parents:
- dc87ad11
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
rdc87ad11 rcca29e3c 187 187 * this argument is ignored. 188 188 * @param pos Position in the last node block. 189 */ 190 void fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos) 189 * 190 * @return EOK on success or a negative error code. 191 */ 192 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos) 191 193 { 192 194 uint16_t bps; … … 207 209 BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE; 208 210 rc = fat_block_get(&b, bs, nodep, o / bps, flags); 209 assert(rc == EOK); 211 if (rc != EOK) 212 return rc; 210 213 memset(b->data + o % bps, 0, bps - o % bps); 211 214 b->dirty = true; /* need to sync node */ 212 215 rc = block_put(b); 213 assert(rc == EOK); 216 if (rc != EOK) 217 return rc; 214 218 } 215 219 216 220 if (o >= pos) 217 return ;221 return EOK; 218 222 219 223 /* zero out the initial part of the new cluster chain */ … … 221 225 rc = _fat_block_get(&b, bs, nodep->idx->dev_handle, mcl, 222 226 (o - boundary) / bps, BLOCK_FLAGS_NOREAD); 223 assert(rc == EOK); 227 if (rc != EOK) 228 return rc; 224 229 memset(b->data, 0, min(bps, pos - o)); 225 230 b->dirty = true; /* need to sync node */ 226 231 rc = block_put(b); 227 assert(rc == EOK); 228 } 232 if (rc != EOK) 233 return rc; 234 } 235 236 return EOK; 229 237 } 230 238 … … 269 277 * @param clst Cluster which is to be set. 270 278 * @param value Value to set the cluster with. 271 */ 272 void 279 * 280 * @return EOK on success or a negative error code. 281 */ 282 int 273 283 fat_set_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 274 284 fat_cluster_t clst, fat_cluster_t value) … … 288 298 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 289 299 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 290 assert(rc == EOK); 300 if (rc != EOK) 301 return rc; 291 302 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 292 303 *cp = host2uint16_t_le(value); 293 304 b->dirty = true; /* need to sync block */ 294 305 rc = block_put(b); 295 assert(rc == EOK);306 return rc; 296 307 } 297 308 … … 302 313 * @param lifo Chain of allocated clusters. 303 314 * @param nclsts Number of clusters in the lifo chain. 304 */ 305 void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, 315 * 316 * @return EOK on success or a negative error code. 317 */ 318 int fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, 306 319 fat_cluster_t *lifo, unsigned nclsts) 307 320 { 308 321 uint8_t fatno; 309 322 unsigned c; 323 int rc; 310 324 311 325 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 312 326 for (c = 0; c < nclsts; c++) { 313 fat_set_cluster(bs, dev_handle, fatno, lifo[c],327 rc = fat_set_cluster(bs, dev_handle, fatno, lifo[c], 314 328 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 329 if (rc != EOK) 330 return rc; 315 331 } 316 332 } 333 334 return EOK; 317 335 } 318 336 … … 378 396 assert(rc == EOK); 379 397 /* update the shadow copies of FAT */ 380 fat_alloc_shadow_clusters(bs,398 rc = fat_alloc_shadow_clusters(bs, 381 399 dev_handle, lifo, nclsts); 400 assert(rc == EOK); 382 401 *mcl = lifo[found - 1]; 383 402 *lcl = lifo[0]; … … 398 417 */ 399 418 while (found--) { 400 fat_set_cluster(bs, dev_handle, FAT1, lifo[found],419 rc = fat_set_cluster(bs, dev_handle, FAT1, lifo[found], 401 420 FAT_CLST_RES0); 421 if (rc != EOK) { 422 free(lifo); 423 return rc; 424 } 402 425 } 403 426 … … 411 434 * @param dev_handle Device handle of the file system. 412 435 * @param firstc First cluster in the chain which is to be freed. 413 */ 414 void 436 * 437 * @return EOK on success or a negative return code. 438 */ 439 int 415 440 fat_free_clusters(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc) 416 441 { … … 423 448 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 424 449 rc = fat_get_cluster(bs, dev_handle, firstc, &nextc); 425 assert(rc == EOK); 426 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 427 fat_set_cluster(bs, dev_handle, fatno, firstc, 450 if (rc != EOK) 451 return rc; 452 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 453 rc = fat_set_cluster(bs, dev_handle, fatno, firstc, 428 454 FAT_CLST_RES0); 455 if (rc != EOK) 456 return rc; 457 } 458 429 459 firstc = nextc; 430 460 } 461 462 return EOK; 431 463 } 432 464 … … 436 468 * @param nodep Node representing the file. 437 469 * @param mcl First cluster of the cluster chain to append. 438 */ 439 void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 470 * 471 * @return EOK on success or a negative error code. 472 */ 473 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 440 474 { 441 475 dev_handle_t dev_handle = nodep->idx->dev_handle; … … 447 481 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc, 448 482 (uint16_t) -1); 449 assert(rc == EOK); 483 if (rc != EOK) 484 return rc; 450 485 451 486 if (numc == 0) { … … 453 488 nodep->firstc = mcl; 454 489 nodep->dirty = true; /* need to sync node */ 455 return; 456 } 457 458 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 459 fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl); 490 return EOK; 491 } 492 493 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 494 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl, 495 mcl); 496 if (rc != EOK) 497 return rc; 498 } 499 500 return EOK; 460 501 } 461 502 … … 467 508 * argument is FAT_CLST_RES0, then all clusters will 468 509 * be chopped off. 469 */ 470 void fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 510 * 511 * @return EOK on success or a negative return code. 512 */ 513 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 471 514 { 472 515 int rc; … … 475 518 if (lastc == FAT_CLST_RES0) { 476 519 /* The node will have zero size and no clusters allocated. */ 477 fat_free_clusters(bs, dev_handle, nodep->firstc); 520 rc = fat_free_clusters(bs, dev_handle, nodep->firstc); 521 if (rc != EOK) 522 return rc; 478 523 nodep->firstc = FAT_CLST_RES0; 479 524 nodep->dirty = true; /* need to sync node */ … … 483 528 484 529 rc = fat_get_cluster(bs, dev_handle, lastc, &nextc); 485 assert(rc == EOK); 530 if (rc != EOK) 531 return rc; 486 532 487 533 /* Terminate the cluster chain in all copies of FAT. */ 488 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 489 fat_set_cluster(bs, dev_handle, fatno, lastc, FAT_CLST_LAST1); 534 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 535 rc = fat_set_cluster(bs, dev_handle, fatno, lastc, 536 FAT_CLST_LAST1); 537 if (rc != EOK) 538 return rc; 539 } 490 540 491 541 /* Free all following clusters. */ 492 fat_free_clusters(bs, dev_handle, nextc); 493 } 494 } 495 496 void 542 rc = fat_free_clusters(bs, dev_handle, nextc); 543 if (rc != EOK) 544 return rc; 545 } 546 547 return EOK; 548 } 549 550 int 497 551 fat_zero_cluster(struct fat_bs *bs, dev_handle_t dev_handle, fat_cluster_t c) 498 552 { … … 507 561 rc = _fat_block_get(&b, bs, dev_handle, c, i, 508 562 BLOCK_FLAGS_NOREAD); 509 assert(rc == EOK); 563 if (rc != EOK) 564 return rc; 510 565 memset(b->data, 0, bps); 511 566 b->dirty = true; 512 567 rc = block_put(b); 513 assert(rc == EOK); 514 } 568 if (rc != EOK) 569 return rc; 570 } 571 572 return EOK; 515 573 } 516 574 -
uspace/srv/fs/fat/fat_fat.h
rdc87ad11 rcca29e3c 71 71 fat_cluster_t, bn_t, int); 72 72 73 extern voidfat_append_clusters(struct fat_bs *, struct fat_node *,73 extern int fat_append_clusters(struct fat_bs *, struct fat_node *, 74 74 fat_cluster_t); 75 extern voidfat_chop_clusters(struct fat_bs *, struct fat_node *,75 extern int fat_chop_clusters(struct fat_bs *, struct fat_node *, 76 76 fat_cluster_t); 77 77 extern int fat_alloc_clusters(struct fat_bs *, dev_handle_t, unsigned, 78 78 fat_cluster_t *, fat_cluster_t *); 79 extern voidfat_free_clusters(struct fat_bs *, dev_handle_t, fat_cluster_t);80 extern voidfat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t,79 extern int fat_free_clusters(struct fat_bs *, dev_handle_t, fat_cluster_t); 80 extern int fat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t, 81 81 fat_cluster_t *, unsigned); 82 82 extern int fat_get_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t, 83 83 fat_cluster_t *); 84 extern voidfat_set_cluster(struct fat_bs *, dev_handle_t, unsigned,84 extern int fat_set_cluster(struct fat_bs *, dev_handle_t, unsigned, 85 85 fat_cluster_t, fat_cluster_t); 86 extern voidfat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t,86 extern int fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t, 87 87 off_t); 88 extern voidfat_zero_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t);88 extern int fat_zero_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t); 89 89 90 90 #endif -
uspace/srv/fs/fat/fat_ops.c
rdc87ad11 rcca29e3c 329 329 nodep = fat_node_get_new(); 330 330 if (!nodep) { 331 fat_free_clusters(bs, dev_handle, mcl);331 (void) fat_free_clusters(bs, dev_handle, mcl); 332 332 return NULL; 333 333 } 334 334 idxp = fat_idx_get_new(dev_handle); 335 335 if (!idxp) { 336 fat_free_clusters(bs, dev_handle, mcl);336 (void) fat_free_clusters(bs, dev_handle, mcl); 337 337 fat_node_put(FS_NODE(nodep)); 338 338 return NULL; … … 341 341 if (flags & L_DIRECTORY) { 342 342 /* Populate the new cluster with unused dentries. */ 343 fat_zero_cluster(bs, dev_handle, mcl); 343 rc = fat_zero_cluster(bs, dev_handle, mcl); 344 assert(rc == EOK); 344 345 nodep->type = FAT_DIRECTORY; 345 346 nodep->firstc = mcl; … … 365 366 fat_node_t *nodep = FAT_NODE(fn); 366 367 fat_bs_t *bs; 368 int rc = EOK; 367 369 368 370 /* … … 383 385 assert(nodep->size); 384 386 /* Free all clusters allocated to the node. */ 385 fat_free_clusters(bs, nodep->idx->dev_handle, nodep->firstc); 387 rc = fat_free_clusters(bs, nodep->idx->dev_handle, 388 nodep->firstc); 386 389 } 387 390 … … 389 392 free(nodep->bp); 390 393 free(nodep); 391 return EOK;394 return rc; 392 395 } 393 396 … … 470 473 return rc; 471 474 } 472 fat_zero_cluster(bs, parentp->idx->dev_handle, mcl); 473 fat_append_clusters(bs, parentp, mcl); 475 rc = fat_zero_cluster(bs, parentp->idx->dev_handle, mcl); 476 assert(rc == EOK); 477 rc = fat_append_clusters(bs, parentp, mcl); 478 assert(rc == EOK); 474 479 parentp->size += bps * bs->spc; 475 480 parentp->dirty = true; /* need to sync node */ … … 1088 1093 * next block size boundary. 1089 1094 */ 1090 fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos); 1095 rc = fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos); 1096 assert(rc == EOK); 1091 1097 rc = fat_block_get(&b, bs, nodep, pos / bps, flags); 1092 1098 assert(rc == EOK); … … 1123 1129 } 1124 1130 /* zero fill any gaps */ 1125 fat_fill_gap(bs, nodep, mcl, pos); 1131 rc = fat_fill_gap(bs, nodep, mcl, pos); 1132 assert(rc == EOK); 1126 1133 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc, 1127 1134 flags); … … 1136 1143 * node's cluster chain. 1137 1144 */ 1138 fat_append_clusters(bs, nodep, mcl); 1145 rc = fat_append_clusters(bs, nodep, mcl); 1146 assert(rc == EOK); 1139 1147 nodep->size = pos + bytes; 1140 1148 nodep->dirty = true; /* need to sync node */ … … 1189 1197 */ 1190 1198 if (size == 0) { 1191 fat_chop_clusters(bs, nodep, FAT_CLST_RES0); 1199 rc = fat_chop_clusters(bs, nodep, FAT_CLST_RES0); 1200 if (rc != EOK) 1201 goto out; 1192 1202 } else { 1193 1203 fat_cluster_t lastc; … … 1196 1206 if (rc != EOK) 1197 1207 goto out; 1198 fat_chop_clusters(bs, nodep, lastc); 1208 rc = fat_chop_clusters(bs, nodep, lastc); 1209 if (rc != EOK) 1210 goto out; 1199 1211 } 1200 1212 nodep->size = size;
Note:
See TracChangeset
for help on using the changeset viewer.