Rev 2643 | Rev 2796 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2643 | Rev 2793 | ||
---|---|---|---|
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 35... | Line 35... | ||
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 <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
41 | #include <async.h> |
42 | #include <async.h> |
42 | #include <errno.h> |
43 | #include <errno.h> |
43 | - | ||
44 | #define PLB_GET_CHAR(i) (fat_reg.plb_ro[(i) % PLB_SIZE]) |
44 | #include <string.h> |
45 | 45 | ||
46 | #define FAT_NAME_LEN 8 |
46 | #define FAT_NAME_LEN 8 |
47 | #define FAT_EXT_LEN 3 |
47 | #define FAT_EXT_LEN 3 |
48 | 48 | ||
49 | #define FAT_PAD ' ' |
49 | #define FAT_PAD ' ' |
Line 51... | Line 51... | ||
51 | #define FAT_DENTRY_UNUSED 0x00 |
51 | #define FAT_DENTRY_UNUSED 0x00 |
52 | #define FAT_DENTRY_E5_ESC 0x05 |
52 | #define FAT_DENTRY_E5_ESC 0x05 |
53 | #define FAT_DENTRY_DOT 0x2e |
53 | #define FAT_DENTRY_DOT 0x2e |
54 | #define FAT_DENTRY_ERASED 0xe5 |
54 | #define FAT_DENTRY_ERASED 0xe5 |
55 | 55 | ||
56 | /** Compare one component of path to a directory entry. |
56 | static void dentry_name_canonify(fat_dentry_t *d, char *buf) |
57 | * |
57 | { |
- | 58 | int i; |
|
- | 59 | ||
58 | * @param dentry Directory entry to compare the path component with. |
60 | for (i = 0; i < FAT_NAME_LEN; i++) { |
59 | * @param start Index into PLB where the path component starts. |
61 | if (d->name[i] == FAT_PAD) { |
- | 62 | buf++; |
|
- | 63 | break; |
|
- | 64 | } |
|
60 | * @param last Index of the last character of the path in PLB. |
65 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
- | 66 | *buf++ = 0xe5; |
|
- | 67 | else |
|
- | 68 | *buf++ = d->name[i]; |
|
61 | * |
69 | } |
- | 70 | if (d->ext[0] != FAT_PAD) |
|
- | 71 | *buf++ = '.'; |
|
62 | * @return Zero on failure or delta such that (index + delta) % |
72 | for (i = 0; i < FAT_EXT_LEN; i++) { |
- | 73 | if (d->ext[i] == FAT_PAD) { |
|
- | 74 | *buf = '\0'; |
|
- | 75 | return; |
|
- | 76 | } |
|
63 | * PLB_SIZE points to a new path component in PLB. |
77 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
- | 78 | *buf++ = 0xe5; |
|
- | 79 | else |
|
- | 80 | *buf++ = d->ext[i]; |
|
64 | */ |
81 | } |
- | 82 | } |
|
- | 83 | ||
65 | static unsigned match_path_component(fat_dentry_t *dentry, unsigned start, |
84 | static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx) |
- | 85 | { |
|
66 | unsigned last) |
86 | return NULL; /* TODO */ |
- | 87 | } |
|
- | 88 | ||
- | 89 | static void fat_dentry_put(fat_dentry_t *dentry) |
|
67 | { |
90 | { |
68 | unsigned cur; /* current position in PLB */ |
91 | /* TODO */ |
- | 92 | } |
|
- | 93 | ||
69 | int pos; /* current position in dentry->name or dentry->ext */ |
94 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
- | 95 | { |
|
70 | bool name_processed = false; |
96 | return NULL; /* TODO */ |
71 | bool dot_processed = false; |
- | |
- | 97 | } |
|
- | 98 | ||
72 | bool ext_processed = false; |
99 | static void *fat_match(void *prnt, const char *component) |
73 | 100 | { |
|
- | 101 | fat_node_t *parentp = (fat_node_t *)prnt; |
|
- | 102 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
|
- | 103 | unsigned i; |
|
74 | if (last < start) |
104 | unsigned dentries; |
75 | last += PLB_SIZE; |
105 | fat_dentry_t *d; |
- | 106 | ||
76 | for (pos = 0, cur = start; (cur <= last) && (PLB_GET_CHAR(cur) != '/'); |
107 | dentries = parentp->size / sizeof(fat_dentry_t); |
77 | pos++, cur++) { |
108 | for (i = 0; i < dentries; i++) { |
78 | if (!name_processed) { |
109 | d = fat_dentry_get(parentp, i); |
79 | if ((pos == FAT_NAME_LEN - 1) || |
110 | if (d->attr & FAT_ATTR_VOLLABEL) { |
80 | (dentry->name[pos + 1] == FAT_PAD)) { |
111 | /* volume label entry */ |
81 | /* this is the last character in name */ |
112 | fat_dentry_put(d); |
82 | name_processed = true; |
113 | continue; |
83 | } |
114 | } |
84 | if (dentry->name[0] == FAT_PAD) { |
115 | if (d->name[0] == FAT_DENTRY_ERASED) { |
85 | /* name is empty */ |
116 | /* not-currently-used entry */ |
86 | name_processed = true; |
117 | fat_dentry_put(d); |
87 | } else if ((pos == 0) && (dentry->name[pos] == |
- | |
88 | FAT_DENTRY_E5_ESC)) { |
- | |
89 | if (PLB_GET_CHAR(cur) == 0xe5) |
- | |
90 | continue; |
118 | continue; |
91 | else |
119 | } |
92 | return 0; /* character mismatch */ |
120 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
93 | } else { |
121 | /* never used entry */ |
94 | if (PLB_GET_CHAR(cur) == dentry->name[pos]) |
- | |
95 | continue; |
122 | fat_dentry_put(d); |
96 | else |
123 | break; |
97 | return 0; /* character mismatch */ |
- | |
98 | } |
124 | } |
- | 125 | if (d->name[0] == FAT_DENTRY_DOT) { |
|
99 | } |
126 | /* |
100 | if (!dot_processed) { |
127 | * Most likely '.' or '..'. |
101 | dot_processed = true; |
128 | * It cannot occur in a regular file name. |
102 | pos = -1; |
129 | */ |
103 | if (PLB_GET_CHAR(cur) != '.') |
- | |
104 | return 0; |
130 | fat_dentry_put(d); |
105 | continue; |
131 | continue; |
106 | } |
132 | } |
107 | if (!ext_processed) { |
133 | |
108 | if ((pos == FAT_EXT_LEN - 1) || |
134 | dentry_name_canonify(d, name); |
109 | (dentry->ext[pos + 1] == FAT_PAD)) { |
135 | if (strcmp(name, component) == 0) { |
110 | /* this is the last character in ext */ |
- | |
111 | ext_processed = true; |
- | |
112 | } |
136 | /* hit */ |
113 | if (dentry->ext[0] == FAT_PAD) { |
137 | void *node = fat_node_get(parentp->dev_handle, |
114 | /* ext is empty; the match will fail */ |
138 | (fs_index_t)d->firstc); |
115 | ext_processed = true; |
139 | fat_dentry_put(d); |
116 | } else if (PLB_GET_CHAR(cur) == dentry->ext[pos]) { |
- | |
117 | continue; |
140 | return node; |
- | 141 | ||
118 | } else { |
142 | } else { |
119 | /* character mismatch */ |
143 | /* miss */ |
120 | return 0; |
144 | fat_dentry_put(d); |
121 | } |
- | |
122 | } |
145 | } |
123 | return 0; /* extra characters in the component */ |
- | |
124 | } |
146 | } |
125 | if (ext_processed || (name_processed && dentry->ext[0] == FAT_PAD)) |
- | |
126 | return cur - start; |
- | |
127 | else |
147 | |
128 | return 0; |
148 | return NULL; |
129 | } |
149 | } |
130 | 150 | ||
- | 151 | /** libfs operations */ |
|
- | 152 | libfs_ops_t fat_libfs_ops = { |
|
- | 153 | .match = fat_match, |
|
- | 154 | .node_get = fat_node_get, |
|
- | 155 | .create = NULL, |
|
- | 156 | .destroy = NULL, |
|
- | 157 | .link = NULL, |
|
- | 158 | .unlink = NULL, |
|
- | 159 | .index_get = NULL, |
|
- | 160 | .size_get = NULL, |
|
- | 161 | .lnkcnt_get = NULL, |
|
- | 162 | .has_children = NULL, |
|
- | 163 | .root_get = NULL, |
|
- | 164 | .plb_get_char = NULL, |
|
- | 165 | .is_directory = NULL, |
|
- | 166 | .is_file = NULL |
|
- | 167 | }; |
|
- | 168 | ||
131 | void fat_lookup(ipc_callid_t rid, ipc_call_t *request) |
169 | void fat_lookup(ipc_callid_t rid, ipc_call_t *request) |
132 | { |
170 | { |
133 | int first = IPC_GET_ARG1(*request); |
- | |
134 | int second = IPC_GET_ARG2(*request); |
- | |
135 | int dev_handle = IPC_GET_ARG3(*request); |
171 | libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
136 | - | ||
137 | - | ||
138 | } |
172 | } |
139 | 173 | ||
140 | /** |
174 | /** |
141 | * @} |
175 | * @} |
142 | */ |
176 | */ |