Rev 2728 | Rev 2731 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2728 | Rev 2730 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | 56 | ||
57 | #define PLB_GET_CHAR(i) (tmpfs_reg.plb_ro[(i) % PLB_SIZE]) |
57 | #define PLB_GET_CHAR(i) (tmpfs_reg.plb_ro[(i) % PLB_SIZE]) |
58 | 58 | ||
59 | #define DENTRIES_BUCKETS 256 |
59 | #define DENTRIES_BUCKETS 256 |
60 | 60 | ||
- | 61 | #define TMPFS_GET_INDEX(x) (((tmpfs_dentry_t *)(x))->index) |
|
- | 62 | #define TMPFS_GET_LNKCNT(x) 1 |
|
- | 63 | ||
61 | /* |
64 | /* |
62 | * Hash table of all directory entries. |
65 | * Hash table of all directory entries. |
63 | */ |
66 | */ |
64 | hash_table_t dentries; |
67 | hash_table_t dentries; |
65 | 68 | ||
Line 125... | Line 128... | ||
125 | return true; |
128 | return true; |
126 | } |
129 | } |
127 | 130 | ||
128 | /** Compare one component of path to a directory entry. |
131 | /** Compare one component of path to a directory entry. |
129 | * |
132 | * |
130 | * @param dentry Directory entry to compare the path component with. |
133 | * @param nodep Node to compare the path component with. |
131 | * @param component Array of characters holding component name. |
134 | * @param component Array of characters holding component name. |
132 | * |
135 | * |
133 | * @return True on match, false otherwise. |
136 | * @return True on match, false otherwise. |
134 | */ |
137 | */ |
135 | static bool match_component(tmpfs_dentry_t *dentry, const char *component) |
138 | static bool match_component(void *nodep, const char *component) |
136 | { |
139 | { |
- | 140 | tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; |
|
- | 141 | ||
137 | return !strcmp(dentry->name, component); |
142 | return !strcmp(dentry->name, component); |
138 | } |
143 | } |
139 | 144 | ||
140 | static unsigned long create_node(tmpfs_dentry_t *dentry, |
145 | static void *create_node(void *nodep, |
141 | const char *component, int lflag) |
146 | const char *component, int lflag) |
142 | { |
147 | { |
- | 148 | tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; |
|
- | 149 | ||
143 | assert(dentry->type == TMPFS_DIRECTORY); |
150 | assert(dentry->type == TMPFS_DIRECTORY); |
144 | assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); |
151 | assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); |
145 | 152 | ||
146 | tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); |
153 | tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); |
147 | if (!node) |
154 | if (!node) |
148 | return 0; |
155 | return NULL; |
149 | size_t len = strlen(component); |
156 | size_t len = strlen(component); |
150 | char *name = malloc(len + 1); |
157 | char *name = malloc(len + 1); |
151 | if (!name) { |
158 | if (!name) { |
152 | free(node); |
159 | free(node); |
153 | return 0; |
160 | return NULL; |
154 | } |
161 | } |
155 | strcpy(name, component); |
162 | strcpy(name, component); |
156 | 163 | ||
157 | tmpfs_dentry_initialize(node); |
164 | tmpfs_dentry_initialize(node); |
158 | node->index = tmpfs_next_index++; |
165 | node->index = tmpfs_next_index++; |
Line 173... | Line 180... | ||
173 | dentry->child = node; |
180 | dentry->child = node; |
174 | } |
181 | } |
175 | 182 | ||
176 | /* Insert the new node into the dentry hash table. */ |
183 | /* Insert the new node into the dentry hash table. */ |
177 | hash_table_insert(&dentries, &node->index, &node->dh_link); |
184 | hash_table_insert(&dentries, &node->index, &node->dh_link); |
178 | return node->index; |
185 | return (void *) node; |
179 | } |
186 | } |
180 | 187 | ||
181 | static int destroy_component(tmpfs_dentry_t *dentry) |
188 | static int destroy_component(void *nodeptr) |
182 | { |
189 | { |
183 | return EPERM; |
190 | return EPERM; |
184 | } |
191 | } |
185 | 192 | ||
186 | void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request) |
193 | void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request) |
Line 239... | Line 246... | ||
239 | /* no components left and L_CREATE specified */ |
246 | /* no components left and L_CREATE specified */ |
240 | if (dcur->type != TMPFS_DIRECTORY) { |
247 | if (dcur->type != TMPFS_DIRECTORY) { |
241 | ipc_answer_0(rid, ENOTDIR); |
248 | ipc_answer_0(rid, ENOTDIR); |
242 | return; |
249 | return; |
243 | } |
250 | } |
244 | unsigned long index = create_node(dcur, |
251 | void *nodep = create_node(dcur, |
245 | component, lflag); |
252 | component, lflag); |
246 | if (index > 0) { |
253 | if (nodep) { |
247 | ipc_answer_4(rid, EOK, |
254 | ipc_answer_5(rid, EOK, |
248 | tmpfs_reg.fs_handle, dev_handle, |
255 | tmpfs_reg.fs_handle, dev_handle, |
249 | index, 0); |
256 | TMPFS_GET_INDEX(nodep), 0, |
- | 257 | TMPFS_GET_LNKCNT(nodep)); |
|
250 | } else { |
258 | } else { |
251 | ipc_answer_0(rid, ENOSPC); |
259 | ipc_answer_0(rid, ENOSPC); |
252 | } |
260 | } |
253 | return; |
261 | return; |
254 | } |
262 | } |
Line 286... | Line 294... | ||
286 | } |
294 | } |
287 | assert(len); |
295 | assert(len); |
288 | component[len] = '\0'; |
296 | component[len] = '\0'; |
289 | len = 0; |
297 | len = 0; |
290 | 298 | ||
291 | unsigned long index; |
- | |
292 | index = create_node(dcur, component, lflag); |
299 | void *nodep = create_node(dcur, component, lflag); |
293 | if (index) { |
300 | if (nodep) { |
294 | ipc_answer_4(rid, EOK, tmpfs_reg.fs_handle, |
301 | ipc_answer_5(rid, EOK, tmpfs_reg.fs_handle, |
295 | dev_handle, index, 0); |
302 | dev_handle, TMPFS_GET_INDEX(nodep), 0, |
- | 303 | TMPFS_GET_LNKCNT(nodep)); |
|
296 | } else { |
304 | } else { |
297 | ipc_answer_0(rid, ENOSPC); |
305 | ipc_answer_0(rid, ENOSPC); |
298 | } |
306 | } |
299 | return; |
307 | return; |
300 | } |
308 | } |
Line 319... | Line 327... | ||
319 | if ((lflag & L_DIRECTORY) && (dcur->type != TMPFS_DIRECTORY)) { |
327 | if ((lflag & L_DIRECTORY) && (dcur->type != TMPFS_DIRECTORY)) { |
320 | ipc_answer_0(rid, ENOTDIR); |
328 | ipc_answer_0(rid, ENOTDIR); |
321 | return; |
329 | return; |
322 | } |
330 | } |
323 | 331 | ||
324 | ipc_answer_4(rid, EOK, tmpfs_reg.fs_handle, dev_handle, dcur->index, |
332 | ipc_answer_5(rid, EOK, tmpfs_reg.fs_handle, dev_handle, dcur->index, |
325 | dcur->size); |
333 | dcur->size, TMPFS_GET_LNKCNT(dcur)); |
326 | } |
334 | } |
327 | 335 | ||
328 | void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) |
336 | void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) |
329 | { |
337 | { |
330 | int dev_handle = IPC_GET_ARG1(*request); |
338 | int dev_handle = IPC_GET_ARG1(*request); |