Rev 2789 | Rev 2831 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2789 | Rev 2793 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 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: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup fs |
29 | /** @addtogroup fs |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | #ifndef FAT_FAT_H_ |
33 | #ifndef FAT_FAT_H_ |
34 | #define FAT_FAT_H_ |
34 | #define FAT_FAT_H_ |
35 | 35 | ||
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 | #include "../../vfs/vfs.h" |
42 | 42 | ||
43 | #define dprintf(...) printf(__VA_ARGS__) |
43 | #define dprintf(...) printf(__VA_ARGS__) |
44 | 44 | ||
45 | typedef struct { |
45 | typedef struct { |
46 | uint8_t ji[3]; /**< Jump instruction. */ |
46 | uint8_t ji[3]; /**< Jump instruction. */ |
47 | uint8_t oem_name[8]; |
47 | uint8_t oem_name[8]; |
48 | /* BIOS Parameter Block */ |
48 | /* BIOS Parameter Block */ |
49 | uint16_t bps; /**< Bytes per sector. */ |
49 | uint16_t bps; /**< Bytes per sector. */ |
50 | uint8_t spc; /**< Sectors per cluster. */ |
50 | uint8_t spc; /**< Sectors per cluster. */ |
51 | uint16_t rscnt; /**< Reserved sector count. */ |
51 | uint16_t rscnt; /**< Reserved sector count. */ |
52 | uint8_t fatcnt; /**< Number of FATs. */ |
52 | uint8_t fatcnt; /**< Number of FATs. */ |
53 | uint16_t root_ent_max; /**< Maximum number of root directory |
53 | uint16_t root_ent_max; /**< Maximum number of root directory |
54 | entries. */ |
54 | entries. */ |
55 | uint16_t totsec16; /**< Total sectors. 16-bit version. */ |
55 | uint16_t totsec16; /**< Total sectors. 16-bit version. */ |
56 | uint8_t mdesc; /**< Media descriptor. */ |
56 | uint8_t mdesc; /**< Media descriptor. */ |
57 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */ |
57 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */ |
58 | uint16_t sec_per_track; /**< Sectors per track. */ |
58 | uint16_t sec_per_track; /**< Sectors per track. */ |
59 | uint16_t headcnt; /**< Number of heads. */ |
59 | uint16_t headcnt; /**< Number of heads. */ |
60 | uint32_t hidden_sec; /**< Hidden sectors. */ |
60 | uint32_t hidden_sec; /**< Hidden sectors. */ |
61 | uint32_t totseci32; /**< Total sectors. 32-bit version. */ |
61 | uint32_t totseci32; /**< Total sectors. 32-bit version. */ |
62 | 62 | ||
63 | union { |
63 | union { |
64 | struct { |
64 | struct { |
65 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */ |
65 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */ |
66 | /** Physical drive number. */ |
66 | /** Physical drive number. */ |
67 | uint8_t pdn; |
67 | uint8_t pdn; |
68 | uint8_t reserved; |
68 | uint8_t reserved; |
69 | /** Extended boot signature. */ |
69 | /** Extended boot signature. */ |
70 | uint8_t ebs; |
70 | uint8_t ebs; |
71 | /** Serial number. */ |
71 | /** Serial number. */ |
72 | uint32_t id; |
72 | uint32_t id; |
73 | /** Volume label. */ |
73 | /** Volume label. */ |
74 | uint8_t label[11]; |
74 | uint8_t label[11]; |
75 | /** FAT type. */ |
75 | /** FAT type. */ |
76 | uint8_t type[8]; |
76 | uint8_t type[8]; |
77 | /** Boot code. */ |
77 | /** Boot code. */ |
78 | uint8_t boot_code[448]; |
78 | uint8_t boot_code[448]; |
79 | /** Boot sector signature. */ |
79 | /** Boot sector signature. */ |
80 | uint16_t signature; |
80 | uint16_t signature; |
81 | } __attribute__ ((packed)); |
81 | } __attribute__ ((packed)); |
82 | struct { |
82 | struct { |
83 | /* FAT32 only */ |
83 | /* FAT32 only */ |
84 | /** Sectors per FAT. */ |
84 | /** Sectors per FAT. */ |
85 | uint32_t sectors_per_fat; |
85 | uint32_t sectors_per_fat; |
86 | /** FAT flags. */ |
86 | /** FAT flags. */ |
87 | uint16_t flags; |
87 | uint16_t flags; |
88 | /** Version. */ |
88 | /** Version. */ |
89 | uint16_t version; |
89 | uint16_t version; |
90 | /** Cluster number of root directory. */ |
90 | /** Cluster number of root directory. */ |
91 | uint32_t root_cluster; |
91 | uint32_t root_cluster; |
92 | /** Sector number of file system information sector. */ |
92 | /** Sector number of file system information sector. */ |
93 | uint16_t fsinfo_sec; |
93 | uint16_t fsinfo_sec; |
94 | /** Sector number of boot sector copy. */ |
94 | /** Sector number of boot sector copy. */ |
95 | uint16_t bscopy_sec; |
95 | uint16_t bscopy_sec; |
96 | uint8_t reserved1[12]; |
96 | uint8_t reserved1[12]; |
97 | /** Physical drive number. */ |
97 | /** Physical drive number. */ |
98 | uint8_t pdn; |
98 | uint8_t pdn; |
99 | uint8_t reserved2; |
99 | uint8_t reserved2; |
100 | /** Extended boot signature. */ |
100 | /** Extended boot signature. */ |
101 | uint8_t ebs; |
101 | uint8_t ebs; |
102 | /** Serial number. */ |
102 | /** Serial number. */ |
103 | uint32_t id; |
103 | uint32_t id; |
104 | /** Volume label. */ |
104 | /** Volume label. */ |
105 | uint8_t label[11]; |
105 | uint8_t label[11]; |
106 | /** FAT type. */ |
106 | /** FAT type. */ |
107 | uint8_t type[8]; |
107 | uint8_t type[8]; |
108 | /** Boot code. */ |
108 | /** Boot code. */ |
109 | uint8_t boot_code[420]; |
109 | uint8_t boot_code[420]; |
110 | /** Signature. */ |
110 | /** Signature. */ |
111 | uint16_t signature; |
111 | uint16_t signature; |
112 | } __attribute__ ((packed)); |
112 | } __attribute__ ((packed)); |
113 | }; |
113 | }; |
114 | } __attribute__ ((packed)) fat_bs_t; |
114 | } __attribute__ ((packed)) fat_bs_t; |
115 | 115 | ||
- | 116 | #define FAT_ATTR_RDONLY (1 << 0) |
|
- | 117 | #define FAT_ATTR_VOLLABEL (1 << 3) |
|
- | 118 | #define FAT_ATTR_SUBDIR (1 << 4) |
|
- | 119 | ||
116 | typedef struct { |
120 | typedef struct { |
117 | uint8_t name[8]; |
121 | uint8_t name[8]; |
118 | uint8_t ext[3]; |
122 | uint8_t ext[3]; |
119 | uint8_t attr; |
123 | uint8_t attr; |
120 | uint8_t reserved; |
124 | uint8_t reserved; |
121 | uint8_t ctime_fine; |
125 | uint8_t ctime_fine; |
122 | uint16_t ctime; |
126 | uint16_t ctime; |
123 | uint16_t cdate; |
127 | uint16_t cdate; |
124 | uint16_t adate; |
128 | uint16_t adate; |
125 | union { |
129 | union { |
126 | uint16_t eaidx; /* FAT12/FAT16 */ |
130 | uint16_t eaidx; /* FAT12/FAT16 */ |
127 | uint16_t firstc_hi; /* FAT32 */ |
131 | uint16_t firstc_hi; /* FAT32 */ |
128 | }; |
132 | }; |
129 | uint16_t mtime; |
133 | uint16_t mtime; |
130 | uint16_t mdate; |
134 | uint16_t mdate; |
131 | union { |
135 | union { |
132 | uint16_t firstc; /* FAT12/FAT16 */ |
136 | uint16_t firstc; /* FAT12/FAT16 */ |
133 | uint16_t firstc_lo; /* FAT32 */ |
137 | uint16_t firstc_lo; /* FAT32 */ |
134 | }; |
138 | }; |
135 | uint32_t size; |
139 | uint32_t size; |
136 | } __attribute__ ((packed)) fat_dentry_t; |
140 | } __attribute__ ((packed)) fat_dentry_t; |
137 | 141 | ||
138 | typedef enum { |
142 | typedef enum { |
139 | FAT_DIRECTORY, |
143 | FAT_DIRECTORY, |
140 | FAT_FILE |
144 | FAT_FILE |
141 | } fat_node_type_t; |
145 | } fat_node_type_t; |
142 | 146 | ||
143 | /** FAT in-core node. */ |
147 | /** FAT in-core node. */ |
144 | typedef struct { |
148 | typedef struct { |
145 | fat_node_type_t type; |
149 | fat_node_type_t type; |
146 | /** VFS index is the node's first allocated cluster. */ |
150 | /** VFS index is the node's first allocated cluster. */ |
147 | fs_index_t index; |
151 | fs_index_t index; |
148 | dev_handle_t dev_handle; |
152 | dev_handle_t dev_handle; |
149 | /** FAT in-core node hash table link. */ |
153 | /** FAT in-core node hash table link. */ |
150 | link_t fin_link; |
154 | link_t fin_link; |
151 | size_t size; |
155 | size_t size; |
152 | unsigned lnkcnt; |
156 | unsigned lnkcnt; |
153 | } fat_node_t; |
157 | } fat_node_t; |
154 | 158 | ||
155 | extern fs_reg_t fat_reg; |
159 | extern fs_reg_t fat_reg; |
156 | 160 | ||
157 | extern void fat_lookup(ipc_callid_t, ipc_call_t *); |
161 | extern void fat_lookup(ipc_callid_t, ipc_call_t *); |
158 | 162 | ||
159 | #endif |
163 | #endif |
160 | 164 | ||
161 | /** |
165 | /** |
162 | * @} |
166 | * @} |
163 | */ |
167 | */ |
164 | 168 |