Rev 3517 | Rev 3521 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3517 | Rev 3518 | ||
|---|---|---|---|
| Line 51... | Line 51... | ||
| 51 | * during allocation of clusters. The lock does not have to be held durring |
51 | * during allocation of clusters. The lock does not have to be held durring |
| 52 | * deallocation of clusters. |
52 | * deallocation of clusters. |
| 53 | */ |
53 | */ |
| 54 | static futex_t fat_alloc_lock = FUTEX_INITIALIZER; |
54 | static futex_t fat_alloc_lock = FUTEX_INITIALIZER; |
| 55 | 55 | ||
| - | 56 | /** Read block from file located on a FAT file system. |
|
| - | 57 | * |
|
| - | 58 | * @param bs Buffer holding the boot sector of the file system. |
|
| - | 59 | * @param dev_handle Device handle of the file system. |
|
| - | 60 | * @param firstc First cluster used by the file. Can be zero if the file |
|
| - | 61 | * is empty. |
|
| - | 62 | * @param offset Offset in blocks. |
|
| - | 63 | * |
|
| - | 64 | * @return Block structure holding the requested block. |
|
| - | 65 | */ |
|
| 56 | block_t * |
66 | block_t * |
| 57 | _fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, |
67 | _fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, |
| 58 | off_t offset) |
68 | off_t offset) |
| 59 | { |
69 | { |
| 60 | block_t *b; |
70 | block_t *b; |
| Line 206... | Line 216... | ||
| 206 | b->dirty = true; /* need to sync node */ |
216 | b->dirty = true; /* need to sync node */ |
| 207 | block_put(b); |
217 | block_put(b); |
| 208 | } |
218 | } |
| 209 | } |
219 | } |
| 210 | 220 | ||
| - | 221 | /** Mark cluster in one instance of FAT. |
|
| - | 222 | * |
|
| - | 223 | * @param bs Buffer holding the boot sector for the file system. |
|
| - | 224 | * @param dev_handle Device handle for the file system. |
|
| - | 225 | * @param fatno Number of the FAT instance where to make the change. |
|
| - | 226 | * @param clst Cluster which is to be marked. |
|
| - | 227 | * @param value Value mark the cluster with. |
|
| - | 228 | */ |
|
| 211 | void |
229 | void |
| 212 | fat_mark_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, |
230 | fat_mark_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, |
| 213 | fat_cluster_t clst, fat_cluster_t value) |
231 | fat_cluster_t clst, fat_cluster_t value) |
| 214 | { |
232 | { |
| 215 | block_t *b; |
233 | block_t *b; |
| Line 229... | Line 247... | ||
| 229 | *cp = host2uint16_t_le(value); |
247 | *cp = host2uint16_t_le(value); |
| 230 | b->dirty = true; /* need to sync block */ |
248 | b->dirty = true; /* need to sync block */ |
| 231 | block_put(b); |
249 | block_put(b); |
| 232 | } |
250 | } |
| 233 | 251 | ||
| - | 252 | /** Replay the allocatoin of clusters in all shadow instances of FAT. |
|
| - | 253 | * |
|
| - | 254 | * @param bs Buffer holding the boot sector of the file system. |
|
| - | 255 | * @param dev_handle Device handle of the file system. |
|
| - | 256 | * @param lifo Chain of allocated clusters. |
|
| - | 257 | * @param nclsts Number of clusters in the lifo chain. |
|
| - | 258 | */ |
|
| 234 | void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, |
259 | void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle, |
| 235 | fat_cluster_t *lifo, unsigned nclsts) |
260 | fat_cluster_t *lifo, unsigned nclsts) |
| 236 | { |
261 | { |
| 237 | uint8_t fatno; |
262 | uint8_t fatno; |
| 238 | unsigned c; |
263 | unsigned c; |
| Line 243... | Line 268... | ||
| 243 | c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); |
268 | c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); |
| 244 | } |
269 | } |
| 245 | } |
270 | } |
| 246 | } |
271 | } |
| 247 | 272 | ||
| - | 273 | /** Allocate clusters in FAT1. |
|
| - | 274 | * |
|
| - | 275 | * This function will attempt to allocate the requested number of clusters in |
|
| - | 276 | * the first FAT instance. The FAT will be altered so that the allocated |
|
| - | 277 | * clusters form an independent chain (i.e. a chain which does not belong to any |
|
| - | 278 | * file yet). |
|
| - | 279 | * |
|
| - | 280 | * @param bs Buffer holding the boot sector of the file system. |
|
| - | 281 | * @param dev_handle Device handle of the file system. |
|
| - | 282 | * @param nclsts Number of clusters to allocate. |
|
| - | 283 | * @param mcl Output parameter where the first cluster in the chain |
|
| - | 284 | * will be returned. |
|
| - | 285 | * @param lcl Output parameter where the last cluster in the chain |
|
| - | 286 | * will be returned. |
|
| - | 287 | * |
|
| - | 288 | * @return EOK on success, a negative error code otherwise. |
|
| - | 289 | */ |
|
| 248 | int |
290 | int |
| 249 | fat_alloc_clusters(fat_bs_t *bs, dev_handle_t dev_handle, unsigned nclsts, |
291 | fat_alloc_clusters(fat_bs_t *bs, dev_handle_t dev_handle, unsigned nclsts, |
| 250 | fat_cluster_t *mcl, fat_cluster_t *lcl) |
292 | fat_cluster_t *mcl, fat_cluster_t *lcl) |
| 251 | { |
293 | { |
| 252 | uint16_t bps; |
294 | uint16_t bps; |
| Line 312... | Line 354... | ||
| 312 | 354 | ||
| 313 | free(lifo); |
355 | free(lifo); |
| 314 | return ENOSPC; |
356 | return ENOSPC; |
| 315 | } |
357 | } |
| 316 | 358 | ||
| - | 359 | /** Append a cluster chain to the last file cluster in all FATs. |
|
| - | 360 | * |
|
| - | 361 | * @param bs Buffer holding boot sector of the file system. |
|
| - | 362 | * @param nodep Node representing the file. |
|
| - | 363 | * @param mcl First cluster of the cluster chain to append. |
|
| - | 364 | */ |
|
| 317 | void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) |
365 | void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) |
| 318 | { |
366 | { |
| 319 | dev_handle_t dev_handle = nodep->idx->dev_handle; |
367 | dev_handle_t dev_handle = nodep->idx->dev_handle; |
| 320 | fat_cluster_t lcl; |
368 | fat_cluster_t lcl; |
| 321 | uint8_t fatno; |
369 | uint8_t fatno; |