Changeset cb682eb in mainline
- Timestamp:
- 2008-10-27T12:45:08Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0ec862d
- Parents:
- e17d986
- Location:
- uspace/srv/fs/fat
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat.h
re17d986 rcb682eb 51 51 #define BS_SIZE 512 52 52 53 typedef struct {53 typedef struct fat_bs { 54 54 uint8_t ji[3]; /**< Jump instruction. */ 55 55 uint8_t oem_name[8]; -
uspace/srv/fs/fat/fat_fat.c
re17d986 rcb682eb 47 47 48 48 block_t * 49 _fat_block_get( dev_handle_t dev_handle, fat_cluster_t firstc, off_t offset)50 { 51 block_t *bb; 49 _fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, 50 off_t offset) 51 { 52 52 block_t *b; 53 53 unsigned bps; … … 63 63 unsigned i; 64 64 65 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 66 bps = uint16_t_le2host(FAT_BS(bb)->bps); 67 spc = FAT_BS(bb)->spc; 68 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 69 fatcnt = FAT_BS(bb)->fatcnt; 70 rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max); 71 sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat); 72 block_put(bb); 65 bps = uint16_t_le2host(bs->bps); 66 spc = bs->spc; 67 rscnt = uint16_t_le2host(bs->rscnt); 68 fatcnt = bs->fatcnt; 69 rde = uint16_t_le2host(bs->root_ent_max); 70 sf = uint16_t_le2host(bs->sec_per_fat); 73 71 74 72 rds = (sizeof(fat_dentry_t) * rde) / bps; … … 107 105 /** Return number of blocks allocated to a file. 108 106 * 107 * @param bs Buffer holding the boot sector for the file. 109 108 * @param dev_handle Device handle of the device with the file. 110 109 * @param firstc First cluster of the file. … … 115 114 */ 116 115 uint16_t 117 _fat_blcks_get( dev_handle_t dev_handle, fat_cluster_t firstc,116 _fat_blcks_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, 118 117 fat_cluster_t *lastc) 119 118 { 120 block_t *bb;121 119 block_t *b; 122 120 unsigned bps; … … 126 124 fat_cluster_t clst = firstc; 127 125 128 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 129 bps = uint16_t_le2host(FAT_BS(bb)->bps); 130 spc = FAT_BS(bb)->spc; 131 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 132 block_put(bb); 126 bps = uint16_t_le2host(bs->bps); 127 spc = bs->spc; 128 rscnt = uint16_t_le2host(bs->rscnt); 133 129 134 130 if (firstc == FAT_CLST_RES0) { … … 161 157 } 162 158 163 uint16_t fat_bps_get(dev_handle_t dev_handle)164 {165 block_t *bb;166 uint16_t bps;167 168 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);169 assert(bb != NULL);170 bps = uint16_t_le2host(FAT_BS(bb)->bps);171 block_put(bb);172 173 return bps;174 }175 176 159 /** Fill the gap between EOF and a new file position. 177 160 * 161 * @param bs Buffer holding the boot sector for nodep. 178 162 * @param nodep FAT node with the gap. 179 163 * @param mcl First cluster in an independent cluster chain that will … … 183 167 * @param pos Position in the last node block. 184 168 */ 185 void fat_fill_gap(fat_ node_t *nodep, fat_cluster_t mcl, off_t pos)169 void fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos) 186 170 { 187 171 uint16_t bps; 188 172 unsigned spc; 189 block_t *b b, *b;173 block_t *b; 190 174 off_t o, boundary; 191 175 192 bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE); 193 bps = uint16_t_le2host(FAT_BS(bb)->bps); 194 spc = FAT_BS(bb)->spc; 195 block_put(bb); 176 bps = uint16_t_le2host(bs->bps); 177 spc = bs->spc; 196 178 197 179 boundary = ROUND_UP(nodep->size, bps * spc); … … 200 182 for (o = nodep->size - 1; o < pos && o < boundary; 201 183 o = ALIGN_DOWN(o + bps, bps)) { 202 b = fat_block_get( nodep, o / bps);184 b = fat_block_get(bs, nodep, o / bps); 203 185 memset(b->data + o % bps, 0, bps - o % bps); 204 186 b->dirty = true; /* need to sync node */ … … 211 193 /* zero out the initial part of the new cluster chain */ 212 194 for (o = boundary; o < pos; o += bps) { 213 b = _fat_block_get( nodep->idx->dev_handle, mcl,195 b = _fat_block_get(bs, nodep->idx->dev_handle, mcl, 214 196 (o - boundary) / bps); 215 197 memset(b->data, 0, min(bps, pos - o)); … … 220 202 221 203 void 222 fat_mark_cluster( dev_handle_t dev_handle, unsigned fatno, fat_cluster_t clst,223 fat_cluster_t value)224 { 225 block_t *b b, *blk;204 fat_mark_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 205 fat_cluster_t clst, fat_cluster_t value) 206 { 207 block_t *b; 226 208 uint16_t bps; 227 209 uint16_t rscnt; 228 210 uint16_t sf; 229 uint8_t fatcnt;230 211 fat_cluster_t *cp; 231 212 232 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 233 bps = uint16_t_le2host(FAT_BS(bb)->bps); 234 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 235 sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat); 236 fatcnt = FAT_BS(bb)->fatcnt; 237 block_put(bb); 238 239 assert(fatno < fatcnt); 240 blk = block_get(dev_handle, rscnt + sf * fatno + 213 bps = uint16_t_le2host(bs->bps); 214 rscnt = uint16_t_le2host(bs->rscnt); 215 sf = uint16_t_le2host(bs->sec_per_fat); 216 217 assert(fatno < bs->fatcnt); 218 b = block_get(dev_handle, rscnt + sf * fatno + 241 219 (clst * sizeof(fat_cluster_t)) / bps, bps); 242 cp = (fat_cluster_t *)b lk->data + clst % (bps / sizeof(fat_cluster_t));220 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 243 221 *cp = host2uint16_t_le(value); 244 blk->dirty = true; /* need to sync block */ 245 block_put(blk); 246 } 247 248 void fat_alloc_shadow_clusters(dev_handle_t dev_handle, fat_cluster_t *lifo, 249 unsigned nclsts) 250 { 251 uint8_t fatcnt; 222 b->dirty = true; /* need to sync block */ 223 block_put(b); 224 } 225 226 void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, 227 fat_cluster_t *lifo, unsigned nclsts) 228 { 252 229 uint8_t fatno; 253 230 unsigned c; 254 block_t *bb; 255 256 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 257 fatcnt = FAT_BS(bb)->fatcnt; 258 block_put(bb); 259 260 for (fatno = FAT1 + 1; fatno < fatcnt; fatno++) { 231 232 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 261 233 for (c = 0; c < nclsts; c++) { 262 fat_mark_cluster( dev_handle, fatno, lifo[c],234 fat_mark_cluster(bs, dev_handle, fatno, lifo[c], 263 235 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 264 236 } … … 267 239 268 240 int 269 fat_alloc_clusters( dev_handle_t dev_handle, unsigned nclsts, fat_cluster_t *mcl,270 fat_cluster_t * lcl)241 fat_alloc_clusters(fat_bs_t *bs, dev_handle_t dev_handle, unsigned nclsts, 242 fat_cluster_t *mcl, fat_cluster_t *lcl) 271 243 { 272 244 uint16_t bps; 273 245 uint16_t rscnt; 274 246 uint16_t sf; 275 block_t *b b, *blk;247 block_t *blk; 276 248 fat_cluster_t *lifo; /* stack for storing free cluster numbers */ 277 249 unsigned found = 0; /* top of the free cluster number stack */ … … 282 254 return ENOMEM; 283 255 284 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 285 bps = uint16_t_le2host(FAT_BS(bb)->bps); 286 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 287 sf = uint16_t_le2host(FAT_BS(bb)->sec_per_fat); 288 block_put(bb); 256 bps = uint16_t_le2host(bs->bps); 257 rscnt = uint16_t_le2host(bs->rscnt); 258 sf = uint16_t_le2host(bs->sec_per_fat); 289 259 290 260 /* … … 309 279 block_put(blk); 310 280 /* update the shadow copies of FAT */ 311 fat_alloc_shadow_clusters( dev_handle,312 lifo, nclsts);281 fat_alloc_shadow_clusters(bs, 282 dev_handle, lifo, nclsts); 313 283 *mcl = lifo[found - 1]; 314 284 *lcl = lifo[0]; … … 325 295 * we have allocated so far. 326 296 */ 327 while (found--) 328 fat_mark_cluster(dev_handle, FAT1, lifo[found], FAT_CLST_RES0); 297 while (found--) { 298 fat_mark_cluster(bs, dev_handle, FAT1, lifo[found], 299 FAT_CLST_RES0); 300 } 329 301 330 302 free(lifo); … … 332 304 } 333 305 334 void fat_append_clusters(fat_ node_t *nodep, fat_cluster_t mcl)335 { 336 block_t *bb;306 void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 307 { 308 dev_handle_t dev_handle = nodep->idx->dev_handle; 337 309 fat_cluster_t lcl; 338 uint8_t fat cnt, fatno;339 340 if (_fat_blcks_get( nodep->idx->dev_handle, nodep->firstc, &lcl) == 0) {310 uint8_t fatno; 311 312 if (_fat_blcks_get(bs, dev_handle, nodep->firstc, &lcl) == 0) { 341 313 nodep->firstc = host2uint16_t_le(mcl); 342 314 nodep->dirty = true; /* need to sync node */ … … 344 316 } 345 317 346 bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE); 347 fatcnt = FAT_BS(bb)->fatcnt; 348 block_put(bb); 349 350 for (fatno = FAT1; fatno < fatcnt; fatno++) 351 fat_mark_cluster(nodep->idx->dev_handle, fatno, lcl, mcl); 318 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) 319 fat_mark_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl); 352 320 } 353 321 -
uspace/srv/fs/fat/fat_fat.h
re17d986 rcb682eb 51 51 #define FAT_CLST_ROOT FAT_CLST_RES1 52 52 53 54 53 /* forward declarations */ 55 54 struct block; 56 55 struct fat_node; 56 struct fat_bs; 57 57 58 58 typedef uint16_t fat_cluster_t; 59 59 60 #define fat_block_get( np, off) \61 _fat_block_get(( np)->idx->dev_handle, (np)->firstc, (off))60 #define fat_block_get(bs, np, off) \ 61 _fat_block_get((bs), (np)->idx->dev_handle, (np)->firstc, (off)) 62 62 63 extern struct block *_fat_block_get(dev_handle_t, fat_cluster_t, off_t); 64 extern uint16_t _fat_blcks_get(dev_handle_t, fat_cluster_t, fat_cluster_t *); 65 extern uint16_t fat_bps_get(dev_handle_t); 63 extern struct block *_fat_block_get(struct fat_bs *, dev_handle_t, 64 fat_cluster_t, off_t); 65 extern uint16_t _fat_blcks_get(struct fat_bs *, dev_handle_t, fat_cluster_t, 66 fat_cluster_t *); 66 67 67 extern void fat_append_clusters(struct fat_node *, fat_cluster_t); 68 extern int fat_alloc_clusters(dev_handle_t, unsigned, fat_cluster_t *, 69 fat_cluster_t *); 70 extern void fat_alloc_shadow_clusters(dev_handle_t, fat_cluster_t *, unsigned); 71 extern void fat_mark_cluster(dev_handle_t, unsigned, fat_cluster_t, 68 extern void fat_append_clusters(struct fat_bs *, struct fat_node *, 72 69 fat_cluster_t); 73 extern void fat_fill_gap(struct fat_node *, fat_cluster_t, off_t); 70 extern int fat_alloc_clusters(struct fat_bs *, dev_handle_t, unsigned, 71 fat_cluster_t *, fat_cluster_t *); 72 extern void fat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t, 73 fat_cluster_t *, unsigned); 74 extern void fat_mark_cluster(struct fat_bs *, dev_handle_t, unsigned, 75 fat_cluster_t, fat_cluster_t); 76 extern void fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t, 77 off_t); 74 78 75 79 #endif -
uspace/srv/fs/fat/fat_ops.c
re17d986 rcb682eb 126 126 static void *fat_node_get_core(fat_idx_t *idxp) 127 127 { 128 block_t *b ;128 block_t *bb, *b; 129 129 fat_dentry_t *d; 130 130 fat_node_t *nodep = NULL; … … 179 179 fat_node_initialize(nodep); 180 180 181 bps = fat_bps_get(idxp->dev_handle); 181 bb = block_get(idxp->dev_handle, BS_BLOCK, BS_SIZE); 182 bps = uint16_t_le2host(FAT_BS(bb)->bps); 182 183 dps = bps / sizeof(fat_dentry_t); 183 184 184 185 /* Read the block that contains the dentry of interest. */ 185 b = _fat_block_get( idxp->dev_handle, idxp->pfc,186 b = _fat_block_get(bb->data, idxp->dev_handle, idxp->pfc, 186 187 (idxp->pdi * sizeof(fat_dentry_t)) / bps); 187 188 assert(b); … … 200 201 * size of the directory by walking the FAT. 201 202 */ 202 nodep->size = bps * _fat_blcks_get( idxp->dev_handle,203 nodep->size = bps * _fat_blcks_get(bb->data, idxp->dev_handle, 203 204 uint16_t_le2host(d->firstc), NULL); 204 205 } else { … … 211 212 212 213 block_put(b); 214 block_put(bb); 213 215 214 216 /* Link the idx structure with the node structure. */ … … 276 278 unsigned blocks; 277 279 fat_dentry_t *d; 278 block_t *b ;280 block_t *bb, *b; 279 281 280 282 futex_down(&parentp->idx->lock); 281 bps = fat_bps_get(parentp->idx->dev_handle); 283 bb = block_get(parentp->idx->dev_handle, BS_BLOCK, BS_SIZE); 284 bps = uint16_t_le2host(FAT_BS(bb)->bps); 282 285 dps = bps / sizeof(fat_dentry_t); 283 286 blocks = parentp->size / bps + (parentp->size % bps != 0); … … 285 288 unsigned dentries; 286 289 287 b = fat_block_get( parentp, i);290 b = fat_block_get(bb->data, parentp, i); 288 291 dentries = (i == blocks - 1) ? 289 292 parentp->size % sizeof(fat_dentry_t) : … … 296 299 case FAT_DENTRY_LAST: 297 300 block_put(b); 301 block_put(bb); 298 302 futex_up(&parentp->idx->lock); 299 303 return NULL; … … 322 326 */ 323 327 block_put(b); 328 block_put(bb); 324 329 return NULL; 325 330 } … … 327 332 futex_up(&idx->lock); 328 333 block_put(b); 334 block_put(bb); 329 335 return node; 330 336 } … … 332 338 block_put(b); 333 339 } 340 block_put(bb); 341 334 342 futex_up(&parentp->idx->lock); 335 343 return NULL; … … 360 368 unsigned dps; 361 369 unsigned blocks; 362 block_t *b ;370 block_t *bb, *b; 363 371 unsigned i, j; 364 372 … … 367 375 368 376 futex_down(&nodep->idx->lock); 369 bps = fat_bps_get(nodep->idx->dev_handle); 377 bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE); 378 bps = uint16_t_le2host(FAT_BS(bb)->bps); 370 379 dps = bps / sizeof(fat_dentry_t); 371 380 … … 376 385 fat_dentry_t *d; 377 386 378 b = fat_block_get( nodep, i);387 b = fat_block_get(bb->data, nodep, i); 379 388 dentries = (i == blocks - 1) ? 380 389 nodep->size % sizeof(fat_dentry_t) : … … 387 396 case FAT_DENTRY_LAST: 388 397 block_put(b); 398 block_put(bb); 389 399 futex_up(&nodep->idx->lock); 390 400 return false; … … 392 402 case FAT_DENTRY_VALID: 393 403 block_put(b); 404 block_put(bb); 394 405 futex_up(&nodep->idx->lock); 395 406 return true; 396 407 } 397 408 block_put(b); 409 block_put(bb); 398 410 futex_up(&nodep->idx->lock); 399 411 return true; … … 401 413 block_put(b); 402 414 } 415 block_put(bb); 403 416 404 417 futex_up(&nodep->idx->lock); … … 553 566 off_t pos = (off_t)IPC_GET_ARG3(*request); 554 567 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 555 uint16_t bps = fat_bps_get(dev_handle);568 uint16_t bps; 556 569 size_t bytes; 557 block_t *b ;570 block_t *bb, *b; 558 571 559 572 if (!nodep) { … … 570 583 return; 571 584 } 585 586 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 587 bps = uint16_t_le2host(FAT_BS(bb)->bps); 572 588 573 589 if (nodep->type == FAT_FILE) { … … 578 594 */ 579 595 bytes = min(len, bps - pos % bps); 580 b = fat_block_get( nodep, pos / bps);596 b = fat_block_get(bb->data, nodep, pos / bps); 581 597 (void) ipc_data_read_finalize(callid, b->data + pos % bps, 582 598 bytes); … … 602 618 off_t o; 603 619 604 b = fat_block_get( nodep, bnum);620 b = fat_block_get(bb->data, nodep, bnum); 605 621 for (o = pos % (bps / sizeof(fat_dentry_t)); 606 622 o < bps / sizeof(fat_dentry_t); … … 625 641 miss: 626 642 fat_node_put(nodep); 643 block_put(bb); 627 644 ipc_answer_0(callid, ENOENT); 628 645 ipc_answer_1(rid, ENOENT, 0); … … 634 651 635 652 fat_node_put(nodep); 653 block_put(bb); 636 654 ipc_answer_1(rid, EOK, (ipcarg_t)bytes); 637 655 } … … 682 700 bps = uint16_t_le2host(FAT_BS(bb)->bps); 683 701 spc = FAT_BS(bb)->spc; 684 block_put(bb);685 702 686 703 boundary = ROUND_UP(nodep->size, bps * spc); … … 692 709 * next block size boundary. 693 710 */ 694 fat_fill_gap( nodep, FAT_CLST_RES0, pos);695 b = fat_block_get( nodep, pos / bps);711 fat_fill_gap(bb->data, nodep, FAT_CLST_RES0, pos); 712 b = fat_block_get(bb->data, nodep, pos / bps); 696 713 (void) ipc_data_write_finalize(callid, b->data + pos % bps, 697 714 bytes); … … 703 720 } 704 721 fat_node_put(nodep); 722 block_put(bb); 705 723 ipc_answer_1(rid, EOK, bytes); 706 724 return; … … 717 735 bps * spc; 718 736 /* create an independent chain of nclsts clusters in all FATs */ 719 status = fat_alloc_clusters(dev_handle, nclsts, &mcl, &lcl); 737 status = fat_alloc_clusters(bb->data, dev_handle, nclsts, &mcl, 738 &lcl); 720 739 if (status != EOK) { 721 740 /* could not allocate a chain of nclsts clusters */ 722 741 fat_node_put(nodep); 742 block_put(bb); 723 743 ipc_answer_0(callid, status); 724 744 ipc_answer_0(rid, status); … … 726 746 } 727 747 /* zero fill any gaps */ 728 fat_fill_gap(nodep, mcl, pos); 729 b = _fat_block_get(dev_handle, lcl, (pos / bps) % spc); 748 fat_fill_gap(bb->data, nodep, mcl, pos); 749 b = _fat_block_get(bb->data, dev_handle, lcl, 750 (pos / bps) % spc); 730 751 (void) ipc_data_write_finalize(callid, b->data + pos % bps, 731 752 bytes); … … 736 757 * node's cluster chain. 737 758 */ 738 fat_append_clusters( nodep, mcl);759 fat_append_clusters(bb->data, nodep, mcl); 739 760 nodep->size = pos + bytes; 740 761 nodep->dirty = true; /* need to sync node */ 741 762 fat_node_put(nodep); 763 block_put(bb); 742 764 ipc_answer_1(rid, EOK, bytes); 743 765 return;
Note:
See TracChangeset
for help on using the changeset viewer.