Rev 2796 | Rev 2822 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2627 | jermar | 1 | /* |
2793 | jermar | 2 | * Copyright (c) 2008 Jakub Jermar |
2627 | jermar | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup fs |
||
30 | * @{ |
||
31 | */ |
||
32 | |||
33 | /** |
||
34 | * @file fat_ops.c |
||
35 | * @brief Implementation of VFS operations for the FAT file system server. |
||
36 | */ |
||
37 | |||
38 | #include "fat.h" |
||
2638 | jermar | 39 | #include "../../vfs/vfs.h" |
2793 | jermar | 40 | #include <libfs.h> |
2627 | jermar | 41 | #include <ipc/ipc.h> |
42 | #include <async.h> |
||
43 | #include <errno.h> |
||
2793 | jermar | 44 | #include <string.h> |
2798 | jermar | 45 | #include <byteorder.h> |
2627 | jermar | 46 | |
2638 | jermar | 47 | #define FAT_NAME_LEN 8 |
48 | #define FAT_EXT_LEN 3 |
||
49 | |||
50 | #define FAT_PAD ' ' |
||
51 | |||
52 | #define FAT_DENTRY_UNUSED 0x00 |
||
53 | #define FAT_DENTRY_E5_ESC 0x05 |
||
54 | #define FAT_DENTRY_DOT 0x2e |
||
55 | #define FAT_DENTRY_ERASED 0xe5 |
||
56 | |||
2793 | jermar | 57 | static void dentry_name_canonify(fat_dentry_t *d, char *buf) |
2638 | jermar | 58 | { |
2793 | jermar | 59 | int i; |
2639 | jermar | 60 | |
2793 | jermar | 61 | for (i = 0; i < FAT_NAME_LEN; i++) { |
62 | if (d->name[i] == FAT_PAD) { |
||
63 | buf++; |
||
64 | break; |
||
2639 | jermar | 65 | } |
2793 | jermar | 66 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
67 | *buf++ = 0xe5; |
||
68 | else |
||
69 | *buf++ = d->name[i]; |
||
70 | } |
||
71 | if (d->ext[0] != FAT_PAD) |
||
72 | *buf++ = '.'; |
||
73 | for (i = 0; i < FAT_EXT_LEN; i++) { |
||
74 | if (d->ext[i] == FAT_PAD) { |
||
75 | *buf = '\0'; |
||
76 | return; |
||
77 | } |
||
78 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
||
79 | *buf++ = 0xe5; |
||
80 | else |
||
81 | *buf++ = d->ext[i]; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx) |
||
86 | { |
||
87 | return NULL; /* TODO */ |
||
88 | } |
||
89 | |||
90 | static void fat_dentry_put(fat_dentry_t *dentry) |
||
91 | { |
||
92 | /* TODO */ |
||
93 | } |
||
94 | |||
95 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
||
96 | { |
||
97 | return NULL; /* TODO */ |
||
98 | } |
||
99 | |||
100 | static void *fat_match(void *prnt, const char *component) |
||
101 | { |
||
102 | fat_node_t *parentp = (fat_node_t *)prnt; |
||
103 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
||
104 | unsigned i; |
||
105 | unsigned dentries; |
||
106 | fat_dentry_t *d; |
||
107 | |||
108 | dentries = parentp->size / sizeof(fat_dentry_t); |
||
109 | for (i = 0; i < dentries; i++) { |
||
110 | d = fat_dentry_get(parentp, i); |
||
111 | if (d->attr & FAT_ATTR_VOLLABEL) { |
||
112 | /* volume label entry */ |
||
113 | fat_dentry_put(d); |
||
2639 | jermar | 114 | continue; |
115 | } |
||
2793 | jermar | 116 | if (d->name[0] == FAT_DENTRY_ERASED) { |
117 | /* not-currently-used entry */ |
||
118 | fat_dentry_put(d); |
||
119 | continue; |
||
2639 | jermar | 120 | } |
2793 | jermar | 121 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
122 | /* never used entry */ |
||
123 | fat_dentry_put(d); |
||
124 | break; |
||
125 | } |
||
126 | if (d->name[0] == FAT_DENTRY_DOT) { |
||
127 | /* |
||
128 | * Most likely '.' or '..'. |
||
129 | * It cannot occur in a regular file name. |
||
130 | */ |
||
131 | fat_dentry_put(d); |
||
132 | continue; |
||
133 | } |
||
134 | |||
135 | dentry_name_canonify(d, name); |
||
136 | if (strcmp(name, component) == 0) { |
||
137 | /* hit */ |
||
138 | void *node = fat_node_get(parentp->dev_handle, |
||
2796 | jermar | 139 | (fs_index_t)uint16_t_le2host(d->firstc)); |
2793 | jermar | 140 | fat_dentry_put(d); |
141 | return node; |
||
142 | |||
143 | } else { |
||
144 | /* miss */ |
||
145 | fat_dentry_put(d); |
||
146 | } |
||
2639 | jermar | 147 | } |
2793 | jermar | 148 | |
149 | return NULL; |
||
2638 | jermar | 150 | } |
151 | |||
2793 | jermar | 152 | /** libfs operations */ |
153 | libfs_ops_t fat_libfs_ops = { |
||
154 | .match = fat_match, |
||
155 | .node_get = fat_node_get, |
||
156 | .create = NULL, |
||
157 | .destroy = NULL, |
||
158 | .link = NULL, |
||
159 | .unlink = NULL, |
||
160 | .index_get = NULL, |
||
161 | .size_get = NULL, |
||
162 | .lnkcnt_get = NULL, |
||
163 | .has_children = NULL, |
||
164 | .root_get = NULL, |
||
165 | .plb_get_char = NULL, |
||
166 | .is_directory = NULL, |
||
167 | .is_file = NULL |
||
168 | }; |
||
169 | |||
2627 | jermar | 170 | void fat_lookup(ipc_callid_t rid, ipc_call_t *request) |
171 | { |
||
2793 | jermar | 172 | libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
2627 | jermar | 173 | } |
174 | |||
175 | /** |
||
176 | * @} |
||
177 | */ |