Changeset e2115311 in mainline
- Timestamp:
- 2008-08-15T20:02:36Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8af22d6
- Parents:
- 7c1d121
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
r7c1d121 re2115311 224 224 } 225 225 226 /** Return number of blocks allocated to a file. 227 * 228 * @param dev_handle Device handle of the device with the file. 229 * @param firstc First cluster of the file. 230 * 231 * @return Number of blocks allocated to the file. 232 */ 233 static uint16_t 234 _fat_blcks_get(dev_handle_t dev_handle, fat_cluster_t firstc) 235 { 236 block_t *bb; 237 block_t *b; 238 unsigned bps; 239 unsigned spc; 240 unsigned rscnt; /* block address of the first FAT */ 241 unsigned clusters = 0; 242 fat_cluster_t clst = firstc; 243 244 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 245 bps = uint16_t_le2host(FAT_BS(bb)->bps); 246 spc = FAT_BS(bb)->spc; 247 rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); 248 block_put(bb); 249 250 if (firstc == FAT_CLST_RES0) { 251 /* No space allocated to the file. */ 252 return 0; 253 } 254 255 while (clst < FAT_CLST_LAST1) { 256 unsigned fsec; /* sector offset relative to FAT1 */ 257 unsigned fidx; /* FAT1 entry index */ 258 259 assert(clst >= FAT_CLST_FIRST); 260 fsec = (clst * sizeof(fat_cluster_t)) / bps; 261 fidx = clst % (bps / sizeof(fat_cluster_t)); 262 /* read FAT1 */ 263 b = block_get(dev_handle, rscnt + fsec, bps); 264 clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]); 265 assert(clst != FAT_CLST_BAD); 266 block_put(b); 267 clusters++; 268 } 269 270 return clusters * spc; 271 } 272 226 273 static void fat_node_initialize(fat_node_t *node) 227 274 { … … 360 407 nodep->type = FAT_DIRECTORY; 361 408 /* 362 * TODO: determine the size by walking FAT. Surprisingly, the363 * 'size' filed of the FAT dentry is not defined forthe364 * directory entry type.409 * Unfortunately, the 'size' field of the FAT dentry is not 410 * defined for the directory entry type. We must determine the 411 * size of the directory by walking the FAT. 365 412 */ 366 nodep->size = 64 * sizeof(fat_dentry_t); 413 nodep->size = bps * _fat_blcks_get(idxp->dev_handle, 414 uint16_t_le2host(d->firstc)); 367 415 } else { 368 416 nodep->type = FAT_FILE;
Note:
See TracChangeset
for help on using the changeset viewer.