Rev 3512 | Rev 3516 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3512 | Rev 3513 | ||
---|---|---|---|
Line 106... | Line 106... | ||
106 | 106 | ||
107 | /** Return number of blocks allocated to a file. |
107 | /** Return number of blocks allocated to a file. |
108 | * |
108 | * |
109 | * @param dev_handle Device handle of the device with the file. |
109 | * @param dev_handle Device handle of the device with the file. |
110 | * @param firstc First cluster of the file. |
110 | * @param firstc First cluster of the file. |
- | 111 | * @param lastc If non-NULL, output argument holding the |
|
- | 112 | * last cluster. |
|
111 | * |
113 | * |
112 | * @return Number of blocks allocated to the file. |
114 | * @return Number of blocks allocated to the file. |
113 | */ |
115 | */ |
114 | uint16_t |
116 | uint16_t |
115 | _fat_blcks_get(dev_handle_t dev_handle, fat_cluster_t firstc) |
117 | _fat_blcks_get(dev_handle_t dev_handle, fat_cluster_t firstc, |
- | 118 | fat_cluster_t *lastc) |
|
116 | { |
119 | { |
117 | block_t *bb; |
120 | block_t *bb; |
118 | block_t *b; |
121 | block_t *b; |
119 | unsigned bps; |
122 | unsigned bps; |
120 | unsigned spc; |
123 | unsigned spc; |
Line 128... | Line 131... | ||
128 | rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); |
131 | rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); |
129 | block_put(bb); |
132 | block_put(bb); |
130 | 133 | ||
131 | if (firstc == FAT_CLST_RES0) { |
134 | if (firstc == FAT_CLST_RES0) { |
132 | /* No space allocated to the file. */ |
135 | /* No space allocated to the file. */ |
- | 136 | if (lastc) |
|
- | 137 | *lastc = firstc; |
|
133 | return 0; |
138 | return 0; |
134 | } |
139 | } |
135 | 140 | ||
136 | while (clst < FAT_CLST_LAST1) { |
141 | while (clst < FAT_CLST_LAST1) { |
137 | unsigned fsec; /* sector offset relative to FAT1 */ |
142 | unsigned fsec; /* sector offset relative to FAT1 */ |
138 | unsigned fidx; /* FAT1 entry index */ |
143 | unsigned fidx; /* FAT1 entry index */ |
139 | 144 | ||
140 | assert(clst >= FAT_CLST_FIRST); |
145 | assert(clst >= FAT_CLST_FIRST); |
- | 146 | if (lastc) |
|
- | 147 | *lastc = clst; /* remember the last cluster */ |
|
141 | fsec = (clst * sizeof(fat_cluster_t)) / bps; |
148 | fsec = (clst * sizeof(fat_cluster_t)) / bps; |
142 | fidx = clst % (bps / sizeof(fat_cluster_t)); |
149 | fidx = clst % (bps / sizeof(fat_cluster_t)); |
143 | /* read FAT1 */ |
150 | /* read FAT1 */ |
144 | b = block_get(dev_handle, rscnt + fsec, bps); |
151 | b = block_get(dev_handle, rscnt + fsec, bps); |
145 | clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]); |
152 | clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]); |
146 | assert(clst != FAT_CLST_BAD); |
153 | assert(clst != FAT_CLST_BAD); |
147 | block_put(b); |
154 | block_put(b); |
148 | clusters++; |
155 | clusters++; |
149 | } |
156 | } |
150 | 157 | ||
- | 158 | if (lastc) |
|
- | 159 | *lastc = clst; |
|
151 | return clusters * spc; |
160 | return clusters * spc; |
152 | } |
161 | } |
153 | 162 | ||
154 | uint16_t fat_bps_get(dev_handle_t dev_handle) |
163 | uint16_t fat_bps_get(dev_handle_t dev_handle) |
155 | { |
164 | { |
Line 322... | Line 331... | ||
322 | return ENOSPC; |
331 | return ENOSPC; |
323 | } |
332 | } |
324 | 333 | ||
325 | void fat_append_clusters(fat_node_t *nodep, fat_cluster_t mcl) |
334 | void fat_append_clusters(fat_node_t *nodep, fat_cluster_t mcl) |
326 | { |
335 | { |
- | 336 | block_t *bb; |
|
- | 337 | fat_cluster_t lcl; |
|
- | 338 | uint8_t fatcnt, fatno; |
|
- | 339 | ||
- | 340 | if (_fat_blcks_get(nodep->idx->dev_handle, nodep->firstc, &lcl) == 0) { |
|
- | 341 | nodep->firstc = host2uint16_t_le(mcl); |
|
- | 342 | nodep->dirty = true; /* need to sync node */ |
|
- | 343 | return; |
|
- | 344 | } |
|
- | 345 | ||
- | 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); |
|
327 | } |
352 | } |
328 | 353 | ||
329 | /** |
354 | /** |
330 | * @} |
355 | * @} |
331 | */ |
356 | */ |