Rev 2793 | Rev 2798 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2793 | Rev 2796 | ||
---|---|---|---|
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 | /** |
33 | /** |
34 | * @file fat_ops.c |
34 | * @file fat_ops.c |
35 | * @brief Implementation of VFS operations for the FAT file system server. |
35 | * @brief Implementation of VFS operations for the FAT file system server. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include "fat.h" |
38 | #include "fat.h" |
39 | #include "../../vfs/vfs.h" |
39 | #include "../../vfs/vfs.h" |
40 | #include <libfs.h> |
40 | #include <libfs.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | #include <errno.h> |
43 | #include <errno.h> |
44 | #include <string.h> |
44 | #include <string.h> |
- | 45 | #include <endian.h> |
|
45 | 46 | ||
46 | #define FAT_NAME_LEN 8 |
47 | #define FAT_NAME_LEN 8 |
47 | #define FAT_EXT_LEN 3 |
48 | #define FAT_EXT_LEN 3 |
48 | 49 | ||
49 | #define FAT_PAD ' ' |
50 | #define FAT_PAD ' ' |
50 | 51 | ||
51 | #define FAT_DENTRY_UNUSED 0x00 |
52 | #define FAT_DENTRY_UNUSED 0x00 |
52 | #define FAT_DENTRY_E5_ESC 0x05 |
53 | #define FAT_DENTRY_E5_ESC 0x05 |
53 | #define FAT_DENTRY_DOT 0x2e |
54 | #define FAT_DENTRY_DOT 0x2e |
54 | #define FAT_DENTRY_ERASED 0xe5 |
55 | #define FAT_DENTRY_ERASED 0xe5 |
55 | 56 | ||
56 | static void dentry_name_canonify(fat_dentry_t *d, char *buf) |
57 | static void dentry_name_canonify(fat_dentry_t *d, char *buf) |
57 | { |
58 | { |
58 | int i; |
59 | int i; |
59 | 60 | ||
60 | for (i = 0; i < FAT_NAME_LEN; i++) { |
61 | for (i = 0; i < FAT_NAME_LEN; i++) { |
61 | if (d->name[i] == FAT_PAD) { |
62 | if (d->name[i] == FAT_PAD) { |
62 | buf++; |
63 | buf++; |
63 | break; |
64 | break; |
64 | } |
65 | } |
65 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
66 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
66 | *buf++ = 0xe5; |
67 | *buf++ = 0xe5; |
67 | else |
68 | else |
68 | *buf++ = d->name[i]; |
69 | *buf++ = d->name[i]; |
69 | } |
70 | } |
70 | if (d->ext[0] != FAT_PAD) |
71 | if (d->ext[0] != FAT_PAD) |
71 | *buf++ = '.'; |
72 | *buf++ = '.'; |
72 | for (i = 0; i < FAT_EXT_LEN; i++) { |
73 | for (i = 0; i < FAT_EXT_LEN; i++) { |
73 | if (d->ext[i] == FAT_PAD) { |
74 | if (d->ext[i] == FAT_PAD) { |
74 | *buf = '\0'; |
75 | *buf = '\0'; |
75 | return; |
76 | return; |
76 | } |
77 | } |
77 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
78 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
78 | *buf++ = 0xe5; |
79 | *buf++ = 0xe5; |
79 | else |
80 | else |
80 | *buf++ = d->ext[i]; |
81 | *buf++ = d->ext[i]; |
81 | } |
82 | } |
82 | } |
83 | } |
83 | 84 | ||
84 | static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx) |
85 | static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx) |
85 | { |
86 | { |
86 | return NULL; /* TODO */ |
87 | return NULL; /* TODO */ |
87 | } |
88 | } |
88 | 89 | ||
89 | static void fat_dentry_put(fat_dentry_t *dentry) |
90 | static void fat_dentry_put(fat_dentry_t *dentry) |
90 | { |
91 | { |
91 | /* TODO */ |
92 | /* TODO */ |
92 | } |
93 | } |
93 | 94 | ||
94 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
95 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
95 | { |
96 | { |
96 | return NULL; /* TODO */ |
97 | return NULL; /* TODO */ |
97 | } |
98 | } |
98 | 99 | ||
99 | static void *fat_match(void *prnt, const char *component) |
100 | static void *fat_match(void *prnt, const char *component) |
100 | { |
101 | { |
101 | fat_node_t *parentp = (fat_node_t *)prnt; |
102 | fat_node_t *parentp = (fat_node_t *)prnt; |
102 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
103 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
103 | unsigned i; |
104 | unsigned i; |
104 | unsigned dentries; |
105 | unsigned dentries; |
105 | fat_dentry_t *d; |
106 | fat_dentry_t *d; |
106 | 107 | ||
107 | dentries = parentp->size / sizeof(fat_dentry_t); |
108 | dentries = parentp->size / sizeof(fat_dentry_t); |
108 | for (i = 0; i < dentries; i++) { |
109 | for (i = 0; i < dentries; i++) { |
109 | d = fat_dentry_get(parentp, i); |
110 | d = fat_dentry_get(parentp, i); |
110 | if (d->attr & FAT_ATTR_VOLLABEL) { |
111 | if (d->attr & FAT_ATTR_VOLLABEL) { |
111 | /* volume label entry */ |
112 | /* volume label entry */ |
112 | fat_dentry_put(d); |
113 | fat_dentry_put(d); |
113 | continue; |
114 | continue; |
114 | } |
115 | } |
115 | if (d->name[0] == FAT_DENTRY_ERASED) { |
116 | if (d->name[0] == FAT_DENTRY_ERASED) { |
116 | /* not-currently-used entry */ |
117 | /* not-currently-used entry */ |
117 | fat_dentry_put(d); |
118 | fat_dentry_put(d); |
118 | continue; |
119 | continue; |
119 | } |
120 | } |
120 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
121 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
121 | /* never used entry */ |
122 | /* never used entry */ |
122 | fat_dentry_put(d); |
123 | fat_dentry_put(d); |
123 | break; |
124 | break; |
124 | } |
125 | } |
125 | if (d->name[0] == FAT_DENTRY_DOT) { |
126 | if (d->name[0] == FAT_DENTRY_DOT) { |
126 | /* |
127 | /* |
127 | * Most likely '.' or '..'. |
128 | * Most likely '.' or '..'. |
128 | * It cannot occur in a regular file name. |
129 | * It cannot occur in a regular file name. |
129 | */ |
130 | */ |
130 | fat_dentry_put(d); |
131 | fat_dentry_put(d); |
131 | continue; |
132 | continue; |
132 | } |
133 | } |
133 | 134 | ||
134 | dentry_name_canonify(d, name); |
135 | dentry_name_canonify(d, name); |
135 | if (strcmp(name, component) == 0) { |
136 | if (strcmp(name, component) == 0) { |
136 | /* hit */ |
137 | /* hit */ |
137 | void *node = fat_node_get(parentp->dev_handle, |
138 | void *node = fat_node_get(parentp->dev_handle, |
138 | (fs_index_t)d->firstc); |
139 | (fs_index_t)uint16_t_le2host(d->firstc)); |
139 | fat_dentry_put(d); |
140 | fat_dentry_put(d); |
140 | return node; |
141 | return node; |
141 | 142 | ||
142 | } else { |
143 | } else { |
143 | /* miss */ |
144 | /* miss */ |
144 | fat_dentry_put(d); |
145 | fat_dentry_put(d); |
145 | } |
146 | } |
146 | } |
147 | } |
147 | 148 | ||
148 | return NULL; |
149 | return NULL; |
149 | } |
150 | } |
150 | 151 | ||
151 | /** libfs operations */ |
152 | /** libfs operations */ |
152 | libfs_ops_t fat_libfs_ops = { |
153 | libfs_ops_t fat_libfs_ops = { |
153 | .match = fat_match, |
154 | .match = fat_match, |
154 | .node_get = fat_node_get, |
155 | .node_get = fat_node_get, |
155 | .create = NULL, |
156 | .create = NULL, |
156 | .destroy = NULL, |
157 | .destroy = NULL, |
157 | .link = NULL, |
158 | .link = NULL, |
158 | .unlink = NULL, |
159 | .unlink = NULL, |
159 | .index_get = NULL, |
160 | .index_get = NULL, |
160 | .size_get = NULL, |
161 | .size_get = NULL, |
161 | .lnkcnt_get = NULL, |
162 | .lnkcnt_get = NULL, |
162 | .has_children = NULL, |
163 | .has_children = NULL, |
163 | .root_get = NULL, |
164 | .root_get = NULL, |
164 | .plb_get_char = NULL, |
165 | .plb_get_char = NULL, |
165 | .is_directory = NULL, |
166 | .is_directory = NULL, |
166 | .is_file = NULL |
167 | .is_file = NULL |
167 | }; |
168 | }; |
168 | 169 | ||
169 | void fat_lookup(ipc_callid_t rid, ipc_call_t *request) |
170 | void fat_lookup(ipc_callid_t rid, ipc_call_t *request) |
170 | { |
171 | { |
171 | libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
172 | libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
172 | } |
173 | } |
173 | 174 | ||
174 | /** |
175 | /** |
175 | * @} |
176 | * @} |
176 | */ |
177 | */ |
177 | 178 |