Rev 2787 | Rev 3011 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 2925 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Jakub Jermar |
2 | * Copyright (c) 2008 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
Line 36... | Line 36... | ||
36 | #include <ipc/ipc.h> |
36 | #include <ipc/ipc.h> |
37 | #include <libfs.h> |
37 | #include <libfs.h> |
38 | #include <atomic.h> |
38 | #include <atomic.h> |
39 | #include <sys/types.h> |
39 | #include <sys/types.h> |
40 | #include <bool.h> |
40 | #include <bool.h> |
- | 41 | #include "../../vfs/vfs.h" |
|
41 | 42 | ||
42 | #define dprintf(...) printf(__VA_ARGS__) |
43 | #define dprintf(...) printf(__VA_ARGS__) |
43 | 44 | ||
44 | typedef struct { |
45 | typedef struct { |
45 | uint8_t ji[3]; /**< Jump instruction. */ |
46 | uint8_t ji[3]; /**< Jump instruction. */ |
46 | uint8_t oem_name[8]; |
47 | uint8_t oem_name[8]; |
47 | /* BIOS Parameter Block */ |
48 | /* BIOS Parameter Block */ |
48 | uint16_t bps; /**< Bytes per sector. */ |
49 | uint16_t bps; /**< Bytes per sector. */ |
49 | uint8_t spc; /**< Sectors per cluster. */ |
50 | uint8_t spc; /**< Sectors per cluster. */ |
50 | uint16_t rsc; /**< Reserved sector count. */ |
51 | uint16_t rscnt; /**< Reserved sector count. */ |
51 | uint8_t fatcnt; /**< Number of FATs. */ |
52 | uint8_t fatcnt; /**< Number of FATs. */ |
52 | uint16_t root_ent_max; /**< Maximum number of root directory |
53 | uint16_t root_ent_max; /**< Maximum number of root directory |
53 | entries. */ |
54 | entries. */ |
54 | uint16_t totsec; /**< Total sectors. */ |
55 | uint16_t totsec16; /**< Total sectors. 16-bit version. */ |
55 | uint8_t mdesc; /**< Media descriptor. */ |
56 | uint8_t mdesc; /**< Media descriptor. */ |
56 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */ |
57 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */ |
57 | uint16_t sec_per_track; /**< Sectors per track. */ |
58 | uint16_t sec_per_track; /**< Sectors per track. */ |
58 | uint16_t headcnt; /**< Number of heads. */ |
59 | uint16_t headcnt; /**< Number of heads. */ |
59 | uint32_t hidden_sec; /**< Hidden sectors. */ |
60 | uint32_t hidden_sec; /**< Hidden sectors. */ |
60 | uint32_t total_sec; /**< Total sectors. */ |
61 | uint32_t totsec32; /**< Total sectors. 32-bit version. */ |
61 | 62 | ||
62 | union { |
63 | union { |
63 | struct { |
64 | struct { |
64 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */ |
65 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */ |
65 | /** Physical drive number. */ |
66 | /** Physical drive number. */ |
Line 99... | Line 100... | ||
99 | /** Extended boot signature. */ |
100 | /** Extended boot signature. */ |
100 | uint8_t ebs; |
101 | uint8_t ebs; |
101 | /** Serial number. */ |
102 | /** Serial number. */ |
102 | uint32_t id; |
103 | uint32_t id; |
103 | /** Volume label. */ |
104 | /** Volume label. */ |
104 | uint8_t label; |
105 | uint8_t label[11]; |
105 | /** FAT type. */ |
106 | /** FAT type. */ |
106 | uint8_t type[8]; |
107 | uint8_t type[8]; |
107 | /** Boot code. */ |
108 | /** Boot code. */ |
108 | uint8_t boot_code[420]; |
109 | uint8_t boot_code[420]; |
109 | /** Signature. */ |
110 | /** Signature. */ |
110 | uint16_t signature; |
111 | uint16_t signature; |
111 | } __attribute__ ((packed)); |
112 | } __attribute__ ((packed)); |
112 | }; |
113 | }; |
113 | } __attribute__ ((packed)) fat_bs_t; |
114 | } __attribute__ ((packed)) fat_bs_t; |
114 | 115 | ||
- | 116 | #define FAT_ATTR_RDONLY (1 << 0) |
|
- | 117 | #define FAT_ATTR_VOLLABEL (1 << 3) |
|
- | 118 | #define FAT_ATTR_SUBDIR (1 << 4) |
|
- | 119 | ||
115 | typedef struct { |
120 | typedef struct { |
116 | uint8_t name[8]; |
121 | uint8_t name[8]; |
117 | uint8_t ext[3]; |
122 | uint8_t ext[3]; |
118 | uint8_t attr; |
123 | uint8_t attr; |
119 | uint8_t reserved; |
124 | uint8_t reserved; |
Line 132... | Line 137... | ||
132 | uint16_t firstc_lo; /* FAT32 */ |
137 | uint16_t firstc_lo; /* FAT32 */ |
133 | }; |
138 | }; |
134 | uint32_t size; |
139 | uint32_t size; |
135 | } __attribute__ ((packed)) fat_dentry_t; |
140 | } __attribute__ ((packed)) fat_dentry_t; |
136 | 141 | ||
- | 142 | typedef uint16_t fat_cluster_t; |
|
- | 143 | ||
- | 144 | typedef enum { |
|
- | 145 | FAT_INVALID, |
|
- | 146 | FAT_DIRECTORY, |
|
- | 147 | FAT_FILE |
|
- | 148 | } fat_node_type_t; |
|
- | 149 | ||
- | 150 | struct fat_node; |
|
- | 151 | ||
- | 152 | /** FAT index structure. |
|
- | 153 | * |
|
- | 154 | * This structure exists to help us to overcome certain limitations of the FAT |
|
- | 155 | * file system design. The problem with FAT is that it is hard to find |
|
- | 156 | * an entity which could represent a VFS index. There are two candidates: |
|
- | 157 | * |
|
- | 158 | * a) number of the node's first cluster |
|
- | 159 | * b) the pair of the parent directory's first cluster and the dentry index |
|
- | 160 | * within the parent directory |
|
- | 161 | * |
|
- | 162 | * We need VFS indices to be: |
|
- | 163 | * A) unique |
|
- | 164 | * B) stable in time, at least until the next mount |
|
- | 165 | * |
|
- | 166 | * Unfortunately a) does not meet the A) criterion because zero-length files |
|
- | 167 | * will have the first cluster field cleared. And b) does not meet the B) |
|
- | 168 | * criterion because unlink() and rename() will both free up the original |
|
- | 169 | * dentry, which contains all the essential info about the file. |
|
- | 170 | * |
|
- | 171 | * Therefore, a completely opaque indices are used and the FAT server maintains |
|
- | 172 | * a mapping between them and otherwise nice b) variant. On rename(), the VFS |
|
- | 173 | * index stays unaltered, while the internal FAT "physical tree address" |
|
- | 174 | * changes. The unlink case is also handled this way thanks to an in-core node |
|
- | 175 | * pointer embedded in the index structure. |
|
- | 176 | */ |
|
- | 177 | typedef struct { |
|
- | 178 | /** Used indices (position) hash table link. */ |
|
- | 179 | link_t uph_link; |
|
- | 180 | /** Used indices (index) hash table link. */ |
|
- | 181 | link_t uih_link; |
|
- | 182 | ||
- | 183 | dev_handle_t dev_handle; |
|
- | 184 | fs_index_t index; |
|
- | 185 | /** |
|
- | 186 | * Parent node's first cluster. |
|
- | 187 | * Zero is used if this node is not linked, in which case nodep must |
|
- | 188 | * contain a pointer to the in-core node structure. |
|
- | 189 | * One is used when the parent is the root directory. |
|
- | 190 | */ |
|
- | 191 | fat_cluster_t pfc; |
|
- | 192 | /** Directory entry index within the parent node. */ |
|
- | 193 | unsigned pdi; |
|
- | 194 | /** Pointer to in-core node instance. */ |
|
- | 195 | struct fat_node *nodep; |
|
- | 196 | } fat_idx_t; |
|
- | 197 | ||
- | 198 | /** FAT in-core node. */ |
|
- | 199 | typedef struct fat_node { |
|
- | 200 | fat_node_type_t type; |
|
- | 201 | fat_idx_t *idx; |
|
- | 202 | /** |
|
- | 203 | * Node's first cluster. |
|
- | 204 | * Zero is used for zero-length nodes. |
|
- | 205 | * One is used to mark root directory. |
|
- | 206 | */ |
|
- | 207 | fat_cluster_t firstc; |
|
- | 208 | /** FAT in-core node free list link. */ |
|
- | 209 | link_t ffn_link; |
|
- | 210 | size_t size; |
|
- | 211 | unsigned lnkcnt; |
|
- | 212 | unsigned refcnt; |
|
- | 213 | bool dirty; |
|
- | 214 | } fat_node_t; |
|
- | 215 | ||
137 | extern fs_reg_t fat_reg; |
216 | extern fs_reg_t fat_reg; |
138 | 217 | ||
139 | extern void fat_lookup(ipc_callid_t, ipc_call_t *); |
218 | extern void fat_lookup(ipc_callid_t, ipc_call_t *); |
140 | 219 | ||
- | 220 | extern fat_idx_t *fat_idx_get_by_pos(dev_handle_t, fat_cluster_t, unsigned); |
|
- | 221 | extern fat_idx_t *fat_idx_get_by_index(dev_handle_t, fs_index_t); |
|
- | 222 | ||
141 | #endif |
223 | #endif |
142 | 224 | ||
143 | /** |
225 | /** |
144 | * @} |
226 | * @} |
145 | */ |
227 | */ |