Changeset ff0c270 in mainline
- Timestamp:
- 2011-08-25T22:15:33Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0dbe5ac
- Parents:
- abb7491c
- Location:
- uspace/srv/fs/exfat
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/exfat/exfat.h
rabb7491c rff0c270 51 51 52 52 #define BPS(bs) ((uint32_t) (1 << (bs->bytes_per_sector))) 53 #define SPC(bs) ((uint32_t) (1 << (bs->sec_per_cluster)))54 #define BPC(bs) ((uint32_t) (BPS(bs)*SPC(bs)))53 #define SPC(bs) ((uint32_t) (1 << (bs->sec_per_cluster))) 54 #define BPC(bs) ((uint32_t) (BPS(bs) * SPC(bs))) 55 55 #define VOL_FS(bs) uint64_t_le2host(bs->volume_start) 56 56 #define VOL_CNT(bs) uint64_t_le2host(bs->volume_count) … … 58 58 #define FAT_CNT(bs) uint32_t_le2host(bs->fat_sector_count) 59 59 #define DATA_FS(bs) uint32_t_le2host(bs->data_start_sector) 60 #define DATA_CNT(bs) uint32_t_le2host(bs->data_clusters)60 #define DATA_CNT(bs) uint32_t_le2host(bs->data_clusters) 61 61 #define ROOT_FC(bs) uint32_t_le2host(bs->rootdir_cluster) 62 #define VOL_FLAGS(bs) uint16_t_le2host(bs->volume_flags)62 #define VOL_FLAGS(bs) uint16_t_le2host(bs->volume_flags) 63 63 64 64 #define EXFAT_NODE(node) ((node) ? (exfat_node_t *) (node)->data : NULL) … … 181 181 extern void exfat_idx_fini_by_service_id(service_id_t); 182 182 183 extern int exfat_node_expand(service_id_t service_id, exfat_node_t *nodep, 184 exfat_cluster_t clusters); 183 extern int exfat_node_expand(service_id_t, exfat_node_t *, exfat_cluster_t); 185 184 extern int exfat_node_put(fs_node_t *); 186 185 extern int exfat_bitmap_get(fs_node_t **, service_id_t); -
uspace/srv/fs/exfat/exfat_bitmap.c
rabb7491c rff0c270 53 53 { 54 54 fs_node_t *fn; 55 block_t *b =NULL;55 block_t *b = NULL; 56 56 exfat_node_t *bitmapp; 57 57 uint8_t *bitmap; … … 94 94 { 95 95 fs_node_t *fn; 96 block_t *b =NULL;96 block_t *b = NULL; 97 97 exfat_node_t *bitmapp; 98 98 uint8_t *bitmap; … … 129 129 { 130 130 fs_node_t *fn; 131 block_t *b =NULL;131 block_t *b = NULL; 132 132 exfat_node_t *bitmapp; 133 133 uint8_t *bitmap; … … 142 142 143 143 aoff64_t offset = clst / 8; 144 rc = exfat_block_get(&b, bs, bitmapp, offset / BPS(bs), BLOCK_FLAGS_NONE); 144 rc = exfat_block_get(&b, bs, bitmapp, offset / BPS(bs), 145 BLOCK_FLAGS_NONE); 145 146 if (rc != EOK) { 146 147 (void) exfat_node_put(fn); … … 167 168 clst = firstc; 168 169 169 while (clst < firstc +count ) {170 while (clst < firstc + count ) { 170 171 rc = bitmap_set_cluster(bs, service_id, clst); 171 172 if (rc != EOK) { 172 if ((clst-firstc) > 0) 173 (void) bitmap_clear_clusters(bs, service_id, firstc, clst-firstc); 173 if (clst - firstc > 0) 174 (void) bitmap_clear_clusters(bs, service_id, 175 firstc, clst - firstc); 174 176 return rc; 175 177 } … … 186 188 clst = firstc; 187 189 188 while (clst < firstc +count) {190 while (clst < firstc + count) { 189 191 rc = bitmap_clear_cluster(bs, service_id, clst); 190 192 if (rc != EOK) … … 201 203 startc = EXFAT_CLST_FIRST; 202 204 203 while (startc < DATA_CNT(bs) +2) {205 while (startc < DATA_CNT(bs) + 2) { 204 206 endc = startc; 205 207 while (bitmap_is_free(bs, service_id, endc) == EOK) { 206 if ((endc - startc) +1 == count){208 if ((endc - startc) + 1 == count) { 207 209 *firstc = startc; 208 210 return bitmap_set_clusters(bs, service_id, startc, count); 209 } 210 else 211 } else 211 212 endc++; 212 213 } … … 227 228 lastc = nodep->firstc + ROUND_UP(nodep->size, BPC(bs)) / BPC(bs) - 1; 228 229 229 clst = lastc +1;230 clst = lastc + 1; 230 231 while (bitmap_is_free(bs, nodep->idx->service_id, clst) == EOK) { 231 if ( (clst - lastc)== count){232 if (clst - lastc == count){ 232 233 return bitmap_set_clusters(bs, nodep->idx->service_id, 233 lastc+1, count); 234 } 235 else 234 lastc + 1, count); 235 } else 236 236 clst++; 237 237 } … … 248 248 lastc -= count; 249 249 250 return bitmap_clear_clusters(bs, nodep->idx->service_id, lastc +1, count);250 return bitmap_clear_clusters(bs, nodep->idx->service_id, lastc + 1, count); 251 251 } 252 252 … … 260 260 261 261 for (clst = nodep->firstc; clst < lastc; clst++) { 262 rc = exfat_set_cluster(bs, service_id, clst, clst +1);262 rc = exfat_set_cluster(bs, service_id, clst, clst + 1); 263 263 if (rc != EOK) 264 264 return rc; -
uspace/srv/fs/exfat/exfat_bitmap.h
rabb7491c rff0c270 42 42 struct exfat_bs; 43 43 44 extern int bitmap_alloc_clusters(struct exfat_bs * bs, service_id_t service_id,45 exfat_cluster_t * firstc, exfat_cluster_t count);46 extern int bitmap_append_clusters(struct exfat_bs * bs, struct exfat_node *nodep,47 exfat_cluster_t count);48 extern int bitmap_free_clusters(struct exfat_bs * bs, struct exfat_node *nodep,49 exfat_cluster_t count);50 extern int bitmap_replicate_clusters(struct exfat_bs * bs, struct exfat_node *nodep);44 extern int bitmap_alloc_clusters(struct exfat_bs *, service_id_t, 45 exfat_cluster_t *, exfat_cluster_t); 46 extern int bitmap_append_clusters(struct exfat_bs *, struct exfat_node *, 47 exfat_cluster_t); 48 extern int bitmap_free_clusters(struct exfat_bs *, struct exfat_node *, 49 exfat_cluster_t); 50 extern int bitmap_replicate_clusters(struct exfat_bs *, struct exfat_node *); 51 51 52 extern int bitmap_is_free(struct exfat_bs *bs, service_id_t service_id, 53 exfat_cluster_t clst); 54 extern int bitmap_set_cluster(struct exfat_bs *bs, service_id_t service_id, 55 exfat_cluster_t clst); 56 extern int bitmap_clear_cluster(struct exfat_bs *bs, service_id_t service_id, 57 exfat_cluster_t clst); 52 extern int bitmap_is_free(struct exfat_bs *, service_id_t, exfat_cluster_t); 53 extern int bitmap_set_cluster(struct exfat_bs *, service_id_t, exfat_cluster_t); 54 extern int bitmap_clear_cluster(struct exfat_bs *, service_id_t, 55 exfat_cluster_t); 58 56 59 extern int bitmap_set_clusters(struct exfat_bs * bs, service_id_t service_id,60 exfat_cluster_t firstc, exfat_cluster_t count);61 extern int bitmap_clear_clusters(struct exfat_bs * bs, service_id_t service_id,62 exfat_cluster_t firstc, exfat_cluster_t count);57 extern int bitmap_set_clusters(struct exfat_bs *, service_id_t, 58 exfat_cluster_t, exfat_cluster_t); 59 extern int bitmap_clear_clusters(struct exfat_bs *, service_id_t, 60 exfat_cluster_t, exfat_cluster_t); 63 61 64 62 -
uspace/srv/fs/exfat/exfat_dentry.c
rabb7491c rff0c270 90 90 void exfat_dentry_get_name(const exfat_name_dentry_t *name, size_t size, uint16_t *dst, size_t *offset) 91 91 { 92 size_t i =0;93 while (i<EXFAT_NAME_PART_LEN && *offset < size) {92 size_t i = 0; 93 while (i < EXFAT_NAME_PART_LEN && *offset < size) { 94 94 dst[*offset] = uint16_t_le2host(name->name[i]); 95 95 i++; -
uspace/srv/fs/exfat/exfat_dentry.h
rabb7491c rff0c270 149 149 150 150 151 extern exfat_dentry_clsf_t exfat_classify_dentry(const exfat_dentry_t * d);151 extern exfat_dentry_clsf_t exfat_classify_dentry(const exfat_dentry_t *); 152 152 153 extern uint16_t exfat_name_hash(const uint16_t *name, const uint16_t *uctable, 154 size_t chars); 153 extern uint16_t exfat_name_hash(const uint16_t *, const uint16_t *, size_t); 155 154 156 extern void exfat_dentry_get_name(const exfat_name_dentry_t * name, size_t size,157 uint16_t * dst, size_t *offset);155 extern void exfat_dentry_get_name(const exfat_name_dentry_t *, size_t, 156 uint16_t *, size_t *); 158 157 159 158 160 extern bool exfat_valid_char(wchar_t ch);161 extern bool exfat_valid_name(const char * name);159 extern bool exfat_valid_char(wchar_t); 160 extern bool exfat_valid_name(const char *); 162 161 163 extern size_t utf16_length(const uint16_t * wstr);162 extern size_t utf16_length(const uint16_t *); 164 163 165 164 -
uspace/srv/fs/exfat/exfat_directory.c
rabb7491c rff0c270 72 72 di->bs = block_bb_get(di->service_id); 73 73 /* di->blocks = nodep->size / BPS(di->bs); */ 74 di->blocks = ROUND_UP(nodep->size, BPS(di->bs)) /BPS(di->bs);74 di->blocks = ROUND_UP(nodep->size, BPS(di->bs)) / BPS(di->bs); 75 75 return EOK; 76 76 } … … 90 90 int exfat_directory_close(exfat_directory_t *di) 91 91 { 92 int rc =EOK;92 int rc = EOK; 93 93 94 94 if (di->b) … … 113 113 if (!di->b) { 114 114 if (di->nodep) { 115 rc = exfat_block_get(&di->b, di->bs, di->nodep, i, BLOCK_FLAGS_NONE); 115 rc = exfat_block_get(&di->b, di->bs, di->nodep, i, 116 BLOCK_FLAGS_NONE); 116 117 } else { 117 rc = exfat_block_get_by_clst(&di->b, di->bs, di->service_id, 118 di->fragmented, di->firstc, NULL, i, BLOCK_FLAGS_NONE); 118 rc = exfat_block_get_by_clst(&di->b, di->bs, 119 di->service_id, di->fragmented, di->firstc, NULL, i, 120 BLOCK_FLAGS_NONE); 119 121 } 120 122 if (rc != EOK) { … … 133 135 di->pos += 1; 134 136 rc = exfat_directory_block_load(di); 135 if (rc !=EOK)137 if (rc != EOK) 136 138 di->pos -= 1; 137 139 … … 141 143 int exfat_directory_prev(exfat_directory_t *di) 142 144 { 143 int rc =EOK;145 int rc = EOK; 144 146 145 147 if (di->pos > 0) { … … 163 165 di->pos = pos; 164 166 rc = exfat_directory_block_load(di); 165 if (rc !=EOK)167 if (rc != EOK) 166 168 di->pos = _pos; 167 169 … … 182 184 } 183 185 184 int exfat_directory_find(exfat_directory_t *di, exfat_dentry_clsf_t type, exfat_dentry_t **d) 186 int exfat_directory_find(exfat_directory_t *di, exfat_dentry_clsf_t type, 187 exfat_dentry_t **d) 185 188 { 186 189 do { … … 195 198 } 196 199 197 int exfat_directory_find_continue(exfat_directory_t *di, exfat_dentry_clsf_t type, exfat_dentry_t **d) 200 int 201 exfat_directory_find_continue(exfat_directory_t *di, exfat_dentry_clsf_t type, 202 exfat_dentry_t **d) 198 203 { 199 204 int rc; … … 208 213 exfat_file_dentry_t *df, exfat_stream_dentry_t *ds) 209 214 { 210 uint16_t wname[EXFAT_FILENAME_LEN +1];215 uint16_t wname[EXFAT_FILENAME_LEN + 1]; 211 216 exfat_dentry_t *d = NULL; 212 217 int rc, i; … … 233 238 return EOVERFLOW; 234 239 235 for (i =0; i<df->count-1; i++) {240 for (i = 0; i < df->count - 1; i++) { 236 241 rc = exfat_directory_next(di); 237 242 if (rc != EOK) … … 269 274 { 270 275 int rc, i, count; 271 exfat_dentry_t *array =NULL, *de;276 exfat_dentry_t *array = NULL, *de; 272 277 aoff64_t pos = di->pos; 273 278 … … 275 280 if (rc != EOK) 276 281 return rc; 277 count = de->file.count +1;282 count = de->file.count + 1; 278 283 array = (exfat_dentry_t *) malloc(count*sizeof(exfat_dentry_t)); 279 284 if (!array) 280 285 return ENOMEM; 281 for (i =0; i<count; i++) {286 for (i = 0; i < count; i++) { 282 287 rc = exfat_directory_get(di, &de); 283 288 if (rc != EOK) … … 291 296 } 292 297 rc = exfat_directory_seek(di, pos); 293 if (rc !=EOK) {298 if (rc != EOK) { 294 299 free(array); 295 300 return rc; … … 303 308 array[1].stream.data_size = host2uint64_t_le(ds->data_size); 304 309 array[0].file.checksum = host2uint16_t_le(exfat_directory_set_checksum((uint8_t *)array, 305 count *sizeof(exfat_dentry_t)));310 count * sizeof(exfat_dentry_t))); 306 311 307 312 /* Store */ 308 for (i =0; i<count; i++) {313 for (i = 0; i < count; i++) { 309 314 rc = exfat_directory_get(di, &de); 310 315 if (rc != EOK) … … 313 318 di->b->dirty = true; 314 319 rc = exfat_directory_next(di); 315 if (rc !=EOK) {320 if (rc != EOK) { 316 321 free(array); 317 322 return rc; … … 329 334 uint16_t *uctable; 330 335 exfat_dentry_t df, ds, *de; 331 uint16_t wname[EXFAT_FILENAME_LEN +1];336 uint16_t wname[EXFAT_FILENAME_LEN + 1]; 332 337 int rc, i; 333 338 size_t uctable_chars, j; … … 399 404 uint16_t *sname = wname; 400 405 401 for (i =0; i<ds.stream.name_size; i++)406 for (i = 0; i < ds.stream.name_size; i++) 402 407 wname[i] = host2uint16_t_le(wname[i]); 403 408 404 for (i =0; i < df.file.count-1; i++) {409 for (i = 0; i < df.file.count - 1; i++) { 405 410 rc = exfat_directory_next(di); 406 411 if (rc != EOK) 407 412 return rc; 408 413 409 if (i == df.file.count -2)410 chars = ds.stream.name_size - EXFAT_NAME_PART_LEN*(df.file.count -2);414 if (i == df.file.count - 2) 415 chars = ds.stream.name_size - EXFAT_NAME_PART_LEN*(df.file.count - 2); 411 416 rc = exfat_directory_get(di, &de); 412 417 if (rc != EOK) … … 414 419 de->type = EXFAT_TYPE_NAME; 415 420 /* test */ 416 for (j =0; j<chars; j++){421 for (j = 0; j < chars; j++) { 417 422 de->name.name[j] = *sname; 418 423 sname++; … … 434 439 if (rc != EOK) 435 440 return rc; 436 count = de->file.count +1;441 count = de->file.count + 1; 437 442 438 443 while (count) { … … 440 445 if (rc != EOK) 441 446 return rc; 442 de->type &= (~EXFAT_TYPE_USED);447 de->type &= ~EXFAT_TYPE_USED; 443 448 di->b->dirty = true; 444 449 445 450 rc = exfat_directory_next(di); 446 if (rc !=EOK)451 if (rc != EOK) 447 452 return rc; 448 453 count--; … … 489 494 case EXFAT_DENTRY_LAST: 490 495 case EXFAT_DENTRY_FREE: 491 if (found==0) pos = di->pos; 496 if (found == 0) 497 pos = di->pos; 492 498 found++; 493 499 if (found == count) { -
uspace/srv/fs/exfat/exfat_directory.h
rabb7491c rff0c270 54 54 55 55 56 extern void exfat_directory_init(exfat_directory_t * di);57 extern int exfat_directory_open(exfat_node_t * nodep, exfat_directory_t *di);58 extern int exfat_directory_open_parent(exfat_directory_t * di,59 service_id_t service_id, exfat_cluster_t firstc, bool fragmented);60 extern int exfat_directory_close(exfat_directory_t * di);56 extern void exfat_directory_init(exfat_directory_t *); 57 extern int exfat_directory_open(exfat_node_t *, exfat_directory_t *); 58 extern int exfat_directory_open_parent(exfat_directory_t *, service_id_t, 59 exfat_cluster_t, bool); 60 extern int exfat_directory_close(exfat_directory_t *); 61 61 62 extern int exfat_directory_next(exfat_directory_t * di);63 extern int exfat_directory_prev(exfat_directory_t * di);64 extern int exfat_directory_seek(exfat_directory_t * di, aoff64_t pos);65 extern int exfat_directory_get(exfat_directory_t * di, exfat_dentry_t **de);66 extern int exfat_directory_find(exfat_directory_t * di,67 exfat_dentry_ clsf_t type, exfat_dentry_t **d);68 extern int exfat_directory_find_continue(exfat_directory_t * di,69 exfat_dentry_clsf_t type, exfat_dentry_t **d);62 extern int exfat_directory_next(exfat_directory_t *); 63 extern int exfat_directory_prev(exfat_directory_t *); 64 extern int exfat_directory_seek(exfat_directory_t *, aoff64_t); 65 extern int exfat_directory_get(exfat_directory_t *, exfat_dentry_t **); 66 extern int exfat_directory_find(exfat_directory_t *, exfat_dentry_clsf_t, 67 exfat_dentry_t **); 68 extern int exfat_directory_find_continue(exfat_directory_t *, 69 exfat_dentry_clsf_t, exfat_dentry_t **); 70 70 71 extern int exfat_directory_read_file(exfat_directory_t * di, char *name,72 size_t size, exfat_file_dentry_t *df, exfat_stream_dentry_t *ds);73 extern int exfat_directory_sync_file(exfat_directory_t * di,74 exfat_ file_dentry_t *df, exfat_stream_dentry_t *ds);75 extern int exfat_directory_write_file(exfat_directory_t * di, const char *name);76 extern int exfat_directory_erase_file(exfat_directory_t * di, aoff64_t pos);71 extern int exfat_directory_read_file(exfat_directory_t *, char *, size_t, 72 exfat_file_dentry_t *, exfat_stream_dentry_t *); 73 extern int exfat_directory_sync_file(exfat_directory_t *, exfat_file_dentry_t *, 74 exfat_stream_dentry_t *); 75 extern int exfat_directory_write_file(exfat_directory_t *, const char *); 76 extern int exfat_directory_erase_file(exfat_directory_t *, aoff64_t); 77 77 78 extern int exfat_directory_expand(exfat_directory_t * di);79 extern int exfat_directory_lookup_free(exfat_directory_t * di, size_t count);80 extern int exfat_directory_print(exfat_directory_t * di);78 extern int exfat_directory_expand(exfat_directory_t *); 79 extern int exfat_directory_lookup_free(exfat_directory_t *, size_t); 80 extern int exfat_directory_print(exfat_directory_t *); 81 81 82 82
Note:
See TracChangeset
for help on using the changeset viewer.