Changeset e80c2ff in mainline
- Timestamp:
- 2011-07-06T19:56:57Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b89281b
- Parents:
- 70ac0af
- Location:
- uspace/srv/fs/minixfs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/minixfs/mfs.h
r70ac0af re80c2ff 208 208 extern int 209 209 read_directory_entry(struct mfs_node *mnode, 210 struct mfs_dentry_info * *d_info, unsigned index);210 struct mfs_dentry_info *d_info, unsigned index); 211 211 212 212 extern int -
uspace/srv/fs/minixfs/mfs_dentry.c
r70ac0af re80c2ff 36 36 int 37 37 read_directory_entry(struct mfs_node *mnode, 38 struct mfs_dentry_info * *d_info, unsigned index)38 struct mfs_dentry_info *d_info, unsigned index) 39 39 { 40 40 const struct mfs_instance *inst = mnode->instance; … … 44 44 block_t *b; 45 45 46 *d_info = malloc(sizeof(**d_info));47 if (!*d_info)48 return ENOMEM;49 50 46 int r = read_map(&block, mnode, index * sbi->dirsize); 51 if (r != EOK) 52 goto out_err; 47 on_error(r, goto out_err); 53 48 54 49 if (block == 0) { … … 59 54 60 55 r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE); 61 if (r != EOK) 62 goto out_err; 56 on_error(r, goto out_err); 63 57 64 58 unsigned dentries_per_zone = sbi->block_size / sbi->dirsize; … … 70 64 d3 = b->data + (dentry_off * MFS3_DIRSIZE); 71 65 72 (*d_info)->d_inum = conv32(sbi->native, d3->d_inum);73 memcpy( (*d_info)->d_name, d3->d_name, MFS3_MAX_NAME_LEN);66 d_info->d_inum = conv32(sbi->native, d3->d_inum); 67 memcpy(d_info->d_name, d3->d_name, MFS3_MAX_NAME_LEN); 74 68 } else { 75 69 const int namelen = longnames ? MFS_L_MAX_NAME_LEN : … … 80 74 d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE : 81 75 MFS_DIRSIZE); 82 (*d_info)->d_inum = conv16(sbi->native, d->d_inum);83 memcpy( (*d_info)->d_name, d->d_name, namelen);76 d_info->d_inum = conv16(sbi->native, d->d_inum); 77 memcpy(d_info->d_name, d->d_name, namelen); 84 78 } 85 79 86 80 block_put(b); 87 81 88 (*d_info)->index = index; 89 (*d_info)->node = mnode; 82 d_info->index = index; 83 d_info->node = mnode; 84 85 out_err: 90 86 return EOK; 91 92 out_err:93 free(*d_info);94 *d_info = NULL;95 return r;96 87 } 97 88 … … 108 99 109 100 r = read_map(&block, mnode, d_off_bytes); 110 if (r != EOK) 111 goto out; 101 on_error(r, goto out); 112 102 113 103 r = block_get(&b, mnode->instance->handle, block, BLOCK_FLAGS_NONE); 114 if (r != EOK) 115 goto out; 104 on_error(r, goto out); 116 105 117 106 const size_t name_len = sbi->max_name_len; … … 144 133 { 145 134 struct mfs_sb_info *sbi = mnode->instance->sbi; 146 struct mfs_dentry_info *d_info;147 int i,r;135 struct mfs_dentry_info d_info; 136 int r; 148 137 149 138 const size_t name_len = str_size(d_name); … … 153 142 154 143 /*Search the directory entry to be removed*/ 155 for (i = 0; ; ++i) { 144 unsigned i; 145 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize ; ++i) { 156 146 r = read_directory_entry(mnode, &d_info, i); 157 147 on_error(r, return r); 158 148 159 if (!d_info) { 160 /*Reached the end of the dentries list*/ 161 break; 162 } 163 164 if (!bcmp(d_info->d_name, d_name, name_len)) { 165 d_info->d_inum = 0; 166 r = write_dentry(d_info); 167 free(d_info); 149 if (!bcmp(d_info.d_name, d_name, name_len)) { 150 d_info.d_inum = 0; 151 r = write_dentry(&d_info); 168 152 return r; 169 153 } 170 free(d_info);171 154 } 172 155 … … 177 160 insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum) 178 161 { 179 int i,r;162 int r; 180 163 struct mfs_sb_info *sbi = mnode->instance->sbi; 181 struct mfs_dentry_info *d_info;164 struct mfs_dentry_info d_info; 182 165 bool empty_dentry_found = false; 183 166 … … 188 171 189 172 /*Search for an empty dentry*/ 190 191 for (i = 0; ; ++i) {173 unsigned i; 174 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { 192 175 r = read_directory_entry(mnode, &d_info, i); 193 if (r != EOK) 194 return r; 195 196 if (!d_info) { 197 /*Reached the end of the dentries list*/ 198 break; 199 } 200 201 if (d_info->d_inum == 0) { 176 on_error(r, return r); 177 178 if (d_info.d_inum == 0) { 202 179 /*This entry is not used*/ 203 180 empty_dentry_found = true; 204 181 break; 205 182 } 206 free(d_info);207 183 } 208 184 … … 213 189 r = read_directory_entry(mnode, &d_info, i); 214 190 on_error(r, goto out); 215 216 assert(d_info != NULL); 217 } 218 219 d_info->d_inum = d_inum; 220 memcpy(d_info->d_name, d_name, name_len); 221 d_info->d_name[name_len] = 0; 222 223 r = write_dentry(d_info); 224 free(d_info); 191 } 192 193 d_info.d_inum = d_inum; 194 memcpy(d_info.d_name, d_name, name_len); 195 d_info.d_name[name_len] = 0; 196 197 r = write_dentry(&d_info); 225 198 out: 226 199 return r; -
uspace/srv/fs/minixfs/mfs_ops.c
r70ac0af re80c2ff 335 335 struct mfs_node *mnode = pfn->data; 336 336 struct mfs_ino_info *ino_i = mnode->ino_i; 337 struct mfs_dentry_info *d_info;337 struct mfs_dentry_info d_info; 338 338 int r; 339 339 … … 344 344 const size_t comp_size = str_size(component); 345 345 346 int i = 2;347 while (1) {348 r = read_directory_entry(mnode, &d_info, i ++);346 unsigned i; 347 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { 348 r = read_directory_entry(mnode, &d_info, i); 349 349 on_error(r, return r); 350 350 351 if (!d_info) { 352 /*Reached the end of the directory entry list*/ 353 break; 354 } 355 356 if (!d_info->d_inum) { 351 if (!d_info.d_inum) { 357 352 /*This entry is not used*/ 358 free(d_info);359 353 continue; 360 354 } 361 355 362 if (!bcmp(component, d_info ->d_name, min(sbi->max_name_len,356 if (!bcmp(component, d_info.d_name, min(sbi->max_name_len, 363 357 comp_size))) { 364 358 /*Hit!*/ 365 359 mfs_node_core_get(rfn, mnode->instance, 366 d_info->d_inum); 367 free(d_info); 360 d_info.d_inum); 368 361 goto found; 369 362 } 370 free(d_info);371 363 } 372 364 *rfn = NULL; … … 566 558 { 567 559 struct mfs_node *mnode = fsnode->data; 560 struct mfs_sb_info *sbi = mnode->instance->sbi; 568 561 int r; 569 562 … … 573 566 goto out; 574 567 575 struct mfs_dentry_info *d_info;568 struct mfs_dentry_info d_info; 576 569 577 570 /* The first two dentries are always . and .. */ 578 int i = 2;579 while (1) {580 r = read_directory_entry(mnode, &d_info, i ++);571 unsigned i; 572 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { 573 r = read_directory_entry(mnode, &d_info, i); 581 574 on_error(r, return r); 582 575 583 if (!d_info) { 584 /*Reached the end of the dentries list*/ 576 if (d_info.d_inum) { 577 /*A valid entry has been found*/ 578 *has_children = true; 585 579 break; 586 580 } 587 588 if (d_info->d_inum) { 589 /*A valid entry has been found*/ 590 *has_children = true; 591 free(d_info); 592 break; 593 } 594 595 free(d_info); 596 } 597 581 } 598 582 out: 599 583 … … 636 620 if (S_ISDIR(ino_i->i_mode)) { 637 621 aoff64_t spos = pos; 638 struct mfs_dentry_info *d_info; 639 640 while (1) { 622 struct mfs_dentry_info d_info; 623 struct mfs_sb_info *sbi = mnode->instance->sbi; 624 625 unsigned i; 626 for (i = pos; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { 641 627 rc = read_directory_entry(mnode, &d_info, pos); 642 628 on_error(rc, goto out_error); 643 629 644 if (!d_info) { 645 /*Reached the end of the dentries list*/ 646 break; 647 } 648 649 if (d_info->d_inum) { 630 if (d_info.d_inum) { 650 631 /*Dentry found!*/ 651 632 goto found; 652 633 } 653 654 free(d_info);655 634 pos++; 656 635 } … … 661 640 return; 662 641 found: 663 async_data_read_finalize(callid, d_info ->d_name,664 str_size(d_info ->d_name) + 1);642 async_data_read_finalize(callid, d_info.d_name, 643 str_size(d_info.d_name) + 1); 665 644 bytes = ((pos - spos) + 1); 666 645 } else {
Note:
See TracChangeset
for help on using the changeset viewer.