Rev 2798 | Rev 2828 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2798 | Rev 2822 | ||
---|---|---|---|
Line 80... | Line 80... | ||
80 | else |
80 | else |
81 | *buf++ = d->ext[i]; |
81 | *buf++ = d->ext[i]; |
82 | } |
82 | } |
83 | } |
83 | } |
84 | 84 | ||
- | 85 | /* TODO and also move somewhere else */ |
|
- | 86 | typedef struct { |
|
- | 87 | void *data; |
|
- | 88 | } block_t; |
|
- | 89 | ||
85 | static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx) |
90 | static block_t *block_get(dev_handle_t dev_handle, off_t offset) |
86 | { |
91 | { |
87 | return NULL; /* TODO */ |
92 | return NULL; /* TODO */ |
88 | } |
93 | } |
89 | 94 | ||
- | 95 | static block_t *fat_block_get(fat_node_t *node, off_t offset) { |
|
- | 96 | return NULL; /* TODO */ |
|
- | 97 | } |
|
- | 98 | ||
90 | static void fat_dentry_put(fat_dentry_t *dentry) |
99 | static void block_put(block_t *block) |
91 | { |
100 | { |
92 | /* TODO */ |
101 | /* TODO */ |
93 | } |
102 | } |
94 | 103 | ||
95 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
104 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
96 | { |
105 | { |
97 | return NULL; /* TODO */ |
106 | return NULL; /* TODO */ |
98 | } |
107 | } |
99 | 108 | ||
- | 109 | #define BS_BLOCK 0 |
|
- | 110 | ||
100 | static void *fat_match(void *prnt, const char *component) |
111 | static void *fat_match(void *prnt, const char *component) |
101 | { |
112 | { |
102 | fat_node_t *parentp = (fat_node_t *)prnt; |
113 | fat_node_t *parentp = (fat_node_t *)prnt; |
103 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
114 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
104 | unsigned i; |
115 | unsigned i, j; |
- | 116 | unsigned dps; /* dentries per sector */ |
|
105 | unsigned dentries; |
117 | unsigned blocks; |
106 | fat_dentry_t *d; |
118 | fat_dentry_t *d; |
- | 119 | block_t *bb; |
|
- | 120 | block_t *b; |
|
- | 121 | fat_bs_t *bs; |
|
107 | 122 | ||
- | 123 | bb = block_get(parentp->dev_handle, BS_BLOCK); |
|
- | 124 | if (!bb) |
|
- | 125 | return NULL; |
|
- | 126 | bs = (fat_bs_t *)bb->data; |
|
108 | dentries = parentp->size / sizeof(fat_dentry_t); |
127 | dps = bs->bps / sizeof(fat_dentry_t); |
- | 128 | blocks = parentp->size / bs->bps + (parentp->size % bs->bps != 0); |
|
- | 129 | block_put(bb); |
|
109 | for (i = 0; i < dentries; i++) { |
130 | for (i = 0; i < blocks; i++) { |
- | 131 | unsigned dentries; |
|
- | 132 | ||
110 | d = fat_dentry_get(parentp, i); |
133 | b = fat_block_get(parentp, i); |
- | 134 | if (!b) |
|
- | 135 | return NULL; |
|
- | 136 | ||
- | 137 | dentries = (i == blocks - 1) ? |
|
- | 138 | parentp->size % sizeof(fat_dentry_t) : |
|
- | 139 | dps; |
|
- | 140 | for (j = 0; j < dentries; j++) { |
|
- | 141 | d = ((fat_dentry_t *)b->data) + j; |
|
111 | if (d->attr & FAT_ATTR_VOLLABEL) { |
142 | if (d->attr & FAT_ATTR_VOLLABEL) { |
112 | /* volume label entry */ |
143 | /* volume label entry */ |
113 | fat_dentry_put(d); |
- | |
114 | continue; |
144 | continue; |
115 | } |
145 | } |
116 | if (d->name[0] == FAT_DENTRY_ERASED) { |
146 | if (d->name[0] == FAT_DENTRY_ERASED) { |
117 | /* not-currently-used entry */ |
147 | /* not-currently-used entry */ |
118 | fat_dentry_put(d); |
- | |
119 | continue; |
148 | continue; |
120 | } |
149 | } |
121 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
150 | if (d->name[0] == FAT_DENTRY_UNUSED) { |
122 | /* never used entry */ |
151 | /* never used entry */ |
123 | fat_dentry_put(d); |
152 | block_put(b); |
124 | break; |
153 | return NULL; |
125 | } |
154 | } |
126 | if (d->name[0] == FAT_DENTRY_DOT) { |
155 | if (d->name[0] == FAT_DENTRY_DOT) { |
127 | /* |
156 | /* |
128 | * Most likely '.' or '..'. |
157 | * Most likely '.' or '..'. |
129 | * It cannot occur in a regular file name. |
158 | * It cannot occur in a regular file name. |
130 | */ |
159 | */ |
131 | fat_dentry_put(d); |
- | |
132 | continue; |
160 | continue; |
133 | } |
161 | } |
134 | 162 | ||
135 | dentry_name_canonify(d, name); |
163 | dentry_name_canonify(d, name); |
136 | if (strcmp(name, component) == 0) { |
164 | if (strcmp(name, component) == 0) { |
137 | /* hit */ |
165 | /* hit */ |
138 | void *node = fat_node_get(parentp->dev_handle, |
166 | void *node = fat_node_get(parentp->dev_handle, |
139 | (fs_index_t)uint16_t_le2host(d->firstc)); |
167 | (fs_index_t)uint16_t_le2host(d->firstc)); |
140 | fat_dentry_put(d); |
168 | block_put(b); |
141 | return node; |
169 | return node; |
142 | - | ||
143 | } else { |
170 | } |
144 | /* miss */ |
- | |
145 | fat_dentry_put(d); |
- | |
146 | } |
171 | } |
- | 172 | block_put(b); |
|
147 | } |
173 | } |
148 | 174 | ||
149 | return NULL; |
175 | return NULL; |
150 | } |
176 | } |
151 | 177 |