Changeset cb682eb in mainline for uspace/srv/fs/fat/fat_fat.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.