Changeset c6aca755 in mainline
- Timestamp:
- 2011-06-20T18:50:11Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b85c19a
- Parents:
- e65e406
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_dentry.c
re65e406 rc6aca755 222 222 if (d->attr == FAT_ATTR_LFN) { 223 223 /* long name entry */ 224 if ( d->attr& FAT_LFN_ERASED)224 if (FAT_LFN_ORDER(d) & FAT_LFN_ERASED) 225 225 return FAT_DENTRY_FREE; 226 226 else -
uspace/srv/fs/fat/fat_directory.c
re65e406 rc6aca755 40 40 #include <errno.h> 41 41 #include <byteorder.h> 42 #include <mem.h> 43 44 int fat_directory_block_load(fat_directory_t *); 45 42 46 43 47 int fat_directory_open(fat_node_t *nodep, fat_directory_t *di) 44 48 { 49 di->b = NULL; 45 50 di->nodep = nodep; 46 51 if (di->nodep->type != FAT_DIRECTORY) … … 49 54 di->bs = block_bb_get(di->nodep->idx->devmap_handle); 50 55 di->blocks = di->nodep->size / BPS(di->bs); 51 di->b = NULL;52 56 di->pos = 0; 53 57 di->bnum = 0; … … 74 78 } 75 79 76 int fat_directory_ scan(fat_directory_t *di, fat_dentry_t **d)80 int fat_directory_block_load(fat_directory_t *di) 77 81 { 78 82 uint32_t i; 79 83 int rc; 80 84 81 85 i = (di->pos * sizeof(fat_dentry_t)) / BPS(di->bs); 82 86 if (i < di->blocks) { … … 93 97 di->bnum = i; 94 98 } 99 return EOK; 100 } 101 return ENOENT; 102 } 103 104 int fat_directory_next(fat_directory_t *di) 105 { 106 int rc; 107 108 di->pos += 1; 109 rc = fat_directory_block_load(di); 110 if (rc!=EOK) 111 di->pos -= 1; 112 113 return rc; 114 } 115 116 int fat_directory_prev(fat_directory_t *di) 117 { 118 int rc=EOK; 119 120 if (di->pos > 0) { 121 di->pos -= 1; 122 rc=fat_directory_block_load(di); 123 } 124 else 125 return ENOENT; 126 127 if (rc!=EOK) 128 di->pos += 1; 129 130 return rc; 131 } 132 133 int fat_directory_seek(fat_directory_t *di, aoff64_t pos) 134 { 135 aoff64_t _pos = di->pos; 136 int rc; 137 di->pos = pos; 138 rc = fat_directory_block_load(di); 139 if (rc!=EOK) 140 di->pos = _pos; 141 142 return rc; 143 } 144 145 int fat_directory_get(fat_directory_t *di, fat_dentry_t **d) 146 { 147 int rc; 148 149 rc = fat_directory_block_load(di); 150 if (rc == EOK) { 95 151 aoff64_t o = di->pos % (BPS(di->bs) / sizeof(fat_dentry_t)); 96 152 *d = ((fat_dentry_t *)di->b->data) + o; 97 di->pos+=1; 98 return EOK; 99 } 100 return ENOENT; 153 } 154 155 return rc; 101 156 } 102 157 … … 105 160 fat_dentry_t *d = NULL; 106 161 107 while (fat_directory_scan(di, &d) == EOK && d) { 108 switch (fat_classify_dentry(d)) { 109 case FAT_DENTRY_LAST: 110 di->long_entry_count = 0; 111 di->long_entry = false; 112 return ENOENT; 113 case FAT_DENTRY_LFN: 114 if (di->long_entry) { 115 /* We found long entry */ 116 di->long_entry_count--; 117 if ((FAT_LFN_ORDER(d) == di->long_entry_count) && 118 (di->checksum == FAT_LFN_CHKSUM(d))) { 119 /* Right order! */ 120 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 121 di->lfn_offset); 162 do { 163 if (fat_directory_get(di, &d) == EOK) { 164 switch (fat_classify_dentry(d)) { 165 case FAT_DENTRY_LAST: 166 di->long_entry_count = 0; 167 di->long_entry = false; 168 return ENOENT; 169 case FAT_DENTRY_LFN: 170 if (di->long_entry) { 171 /* We found long entry */ 172 di->long_entry_count--; 173 if ((FAT_LFN_ORDER(d) == di->long_entry_count) && 174 (di->checksum == FAT_LFN_CHKSUM(d))) { 175 /* Right order! */ 176 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 177 di->lfn_offset); 178 } else { 179 /* Something wrong with order. Skip this long entries set */ 180 di->long_entry_count = 0; 181 di->long_entry = false; 182 } 122 183 } else { 123 /* Something wrong with order. Skip this long entries set */ 124 di->long_entry_count = 0; 125 di->long_entry = false; 126 } 127 } else { 128 if (FAT_IS_LFN(d)) { 129 /* We found Last long entry! */ 130 if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) { 131 di->long_entry = true; 132 di->long_entry_count = FAT_LFN_COUNT(d); 133 di->lfn_size = (FAT_LFN_ENTRY_SIZE * 134 (FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d); 135 di->lfn_offset = di->lfn_size; 136 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 137 di->lfn_offset); 138 di->checksum = FAT_LFN_CHKSUM(d); 184 if (FAT_IS_LFN(d)) { 185 /* We found Last long entry! */ 186 if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) { 187 di->long_entry = true; 188 di->long_entry_count = FAT_LFN_COUNT(d); 189 di->lfn_size = (FAT_LFN_ENTRY_SIZE * 190 (FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d); 191 di->lfn_offset = di->lfn_size; 192 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 193 di->lfn_offset); 194 di->checksum = FAT_LFN_CHKSUM(d); 195 } 139 196 } 140 197 } 198 break; 199 case FAT_DENTRY_VALID: 200 if (di->long_entry && 201 (di->checksum == fat_dentry_chksum(d->name))) { 202 int rc; 203 rc = fat_lfn_convert_name(di->lfn_utf16, di->lfn_size, 204 (uint8_t*)name, FAT_LFN_NAME_SIZE); 205 if (rc!=EOK) 206 fat_dentry_name_get(d, name); 207 } 208 else 209 fat_dentry_name_get(d, name); 210 211 *de = d; 212 di->long_entry_count = 0; 213 di->long_entry = false; 214 return EOK; 215 default: 216 case FAT_DENTRY_SKIP: 217 case FAT_DENTRY_FREE: 218 di->long_entry_count = 0; 219 di->long_entry = false; 220 break; 141 221 } 222 } 223 } while (fat_directory_next(di) == EOK); 224 225 return ENOENT; 226 } 227 228 int fat_directory_erase(fat_directory_t *di) 229 { 230 int rc; 231 fat_dentry_t *d; 232 bool flag = false; 233 234 rc = fat_directory_get(di, &d); 235 if (rc != EOK) 236 return rc; 237 di->checksum = fat_dentry_chksum(d->name); 238 239 d->name[0] = FAT_DENTRY_ERASED; 240 di->b->dirty = true; 241 242 while (!flag && fat_directory_prev(di) == EOK) { 243 if (fat_directory_get(di, &d) == EOK && 244 fat_classify_dentry(d) == FAT_DENTRY_LFN && 245 di->checksum == FAT_LFN_CHKSUM(d)) { 246 if (FAT_IS_LFN(d)) 247 flag = true; 248 memset(d, 0, sizeof(fat_dentry_t)); 249 d->name[0] = FAT_DENTRY_ERASED; 250 di->b->dirty = true; 251 } 252 else 142 253 break; 143 case FAT_DENTRY_VALID: 144 if (di->long_entry && 145 (di->checksum == fat_dentry_chksum(d->name))) { 146 int rc; 147 rc = fat_lfn_convert_name(di->lfn_utf16, di->lfn_size, 148 (uint8_t*)name, FAT_LFN_NAME_SIZE); 149 if (rc!=EOK) 150 fat_dentry_name_get(d, name); 151 } 152 else 153 fat_dentry_name_get(d, name); 154 155 *de = d; 156 di->long_entry_count = 0; 157 di->long_entry = false; 158 return EOK; 159 default: 160 case FAT_DENTRY_SKIP: 161 case FAT_DENTRY_FREE: 162 di->long_entry_count = 0; 163 di->long_entry = false; 164 break; 165 } 166 } 167 return ENOENT; 254 } 255 256 return EOK; 168 257 } 169 258 -
uspace/srv/fs/fat/fat_directory.h
re65e406 rc6aca755 59 59 extern int fat_directory_open(fat_node_t *, fat_directory_t *); 60 60 extern int fat_directory_close(fat_directory_t *); 61 extern int fat_directory_scan(fat_directory_t *, fat_dentry_t **); 61 62 extern int fat_directory_next(fat_directory_t *); 63 extern int fat_directory_prev(fat_directory_t *); 64 extern int fat_directory_seek(fat_directory_t *, aoff64_t pos); 65 extern int fat_directory_get(fat_directory_t *, fat_dentry_t **); 66 extern int fat_directory_dirty(fat_directory_t *); 67 62 68 extern int fat_directory_read(fat_directory_t *, char *, fat_dentry_t **); 69 extern int fat_directory_erase(fat_directory_t *); 63 70 64 71
Note:
See TracChangeset
for help on using the changeset viewer.