Changeset 3958e315 in mainline for uspace/srv
- Timestamp:
- 2011-10-15T12:31:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e3f7418
- Parents:
- 03f4acf (diff), df3caec5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/srv/fs/mfs
- Files:
-
- 7 edited
-
mfs.c (modified) (1 diff)
-
mfs_balloc.c (modified) (8 diffs)
-
mfs_dentry.c (modified) (9 diffs)
-
mfs_inode.c (modified) (12 diffs)
-
mfs_ops.c (modified) (49 diffs)
-
mfs_rw.c (modified) (13 diffs)
-
mfs_utils.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs.c
r03f4acf r3958e315 74 74 75 75 async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 76 SERVICE_VFS, 0, 0);76 SERVICE_VFS, 0, 0); 77 77 78 78 if (!vfs_sess) { -
uspace/srv/fs/mfs/mfs_balloc.c
r03f4acf r3958e315 36 36 static int 37 37 find_free_bit_and_set(bitchunk_t *b, const int bsize, 38 const bool native, unsigned start_bit);38 const bool native, unsigned start_bit); 39 39 40 40 static int … … 129 129 if (idx > sbi->nzones) { 130 130 printf(NAME ": Error! Trying to free beyond the" \ 131 "bitmap max size\n");131 "bitmap max size\n"); 132 132 return -1; 133 133 } 134 134 } else { 135 /* bid == BMAP_INODE*/135 /* bid == BMAP_INODE */ 136 136 search = &sbi->isearch; 137 137 start_block = 2; 138 138 if (idx > sbi->ninodes) { 139 139 printf(NAME ": Error! Trying to free beyond the" \ 140 "bitmap max size\n");140 "bitmap max size\n"); 141 141 return -1; 142 142 } 143 143 } 144 144 145 /* Compute the bitmap block*/145 /* Compute the bitmap block */ 146 146 uint32_t block = idx / (sbi->block_size * 8) + start_block; 147 147 … … 150 150 goto out_err; 151 151 152 /* Compute the bit index in the block*/152 /* Compute the bit index in the block */ 153 153 idx %= (sbi->block_size * 8); 154 154 bitchunk_t *ptr = b->data; … … 220 220 221 221 freebit = find_free_bit_and_set(b->data, sbi->block_size, 222 sbi->native, tmp);222 sbi->native, tmp); 223 223 if (freebit == -1) { 224 /* No free bit in this block*/224 /* No free bit in this block */ 225 225 r = block_put(b); 226 226 if (r != EOK) … … 229 229 } 230 230 231 /* Free bit found in this block, compute the real index*/231 /* Free bit found in this block, compute the real index */ 232 232 *idx = freebit + bits_per_block * i; 233 233 if (*idx > limit) { 234 /* Index is beyond the limit, it is invalid*/234 /* Index is beyond the limit, it is invalid */ 235 235 r = block_put(b); 236 236 if (r != EOK) … … 246 246 247 247 if (*search > 0) { 248 /* Repeat the search from the first bitmap block*/248 /* Repeat the search from the first bitmap block */ 249 249 *search = 0; 250 250 goto retry; 251 251 } 252 252 253 /* Free bit not found, return error*/253 /* Free bit not found, return error */ 254 254 return ENOSPC; 255 255 … … 260 260 static int 261 261 find_free_bit_and_set(bitchunk_t *b, const int bsize, 262 const bool native, unsigned start_bit)262 const bool native, unsigned start_bit) 263 263 { 264 264 int r = -1; … … 268 268 269 269 for (i = start_bit / chunk_bits; 270 i < bsize / sizeof(bitchunk_t); ++i) { 270 i < bsize / sizeof(bitchunk_t); ++i) { 271 271 272 if (!(~b[i])) { 272 /* No free bit in this chunk*/273 /* No free bit in this chunk */ 273 274 continue; 274 275 } -
uspace/srv/fs/mfs/mfs_dentry.c
r03f4acf r3958e315 44 44 int 45 45 mfs_read_dentry(struct mfs_node *mnode, 46 struct mfs_dentry_info *d_info, unsigned index)46 struct mfs_dentry_info *d_info, unsigned index) 47 47 { 48 48 const struct mfs_instance *inst = mnode->instance; … … 57 57 58 58 if (block == 0) { 59 /* End of the dentries list*/59 /* End of the dentries list */ 60 60 r = EOK; 61 61 goto out_err; … … 79 79 } else { 80 80 const int namelen = longnames ? MFS_L_MAX_NAME_LEN : 81 MFS_MAX_NAME_LEN;81 MFS_MAX_NAME_LEN; 82 82 83 83 struct mfs_dentry *d; 84 84 85 85 d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE : 86 MFS_DIRSIZE);86 MFS_DIRSIZE); 87 87 d_info->d_inum = conv16(sbi->native, d->d_inum); 88 88 memcpy(d_info->d_name, d->d_name, namelen); … … 101 101 /**Write a directory entry on disk. 102 102 * 103 * @param d_info Pointer to the directory entry structure to write on disk.104 * 105 * @return EOK on success or a negative error code.103 * @param d_info Pointer to the directory entry structure to write on disk. 104 * 105 * @return EOK on success or a negative error code. 106 106 */ 107 107 int … … 178 178 179 179 if (name_len == d_name_len && 180 !bcmp(d_info.d_name, d_name, name_len)) { 180 !bcmp(d_info.d_name, d_name, name_len)) { 181 181 182 d_info.d_inum = 0; 182 183 r = mfs_write_dentry(&d_info); … … 197 198 */ 198 199 int 199 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum) 200 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, 201 fs_index_t d_inum) 200 202 { 201 203 int r; … … 209 211 return ENAMETOOLONG; 210 212 211 /* Search for an empty dentry*/213 /* Search for an empty dentry */ 212 214 unsigned i; 213 215 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { … … 217 219 218 220 if (d_info.d_inum == 0) { 219 /* This entry is not used*/221 /* This entry is not used */ 220 222 empty_dentry_found = true; 221 223 break; … … 231 233 232 234 if (b == 0) { 233 /* Increase the inode size*/235 /* Increase the inode size */ 234 236 235 237 uint32_t dummy; -
uspace/srv/fs/mfs/mfs_inode.c
r03f4acf r3958e315 42 42 static int 43 43 mfs_read_inode_raw(const struct mfs_instance *instance, 44 struct mfs_ino_info **ino_ptr, uint16_t inum);44 struct mfs_ino_info **ino_ptr, uint16_t inum); 45 45 46 46 static int 47 47 mfs2_read_inode_raw(const struct mfs_instance *instance, 48 struct mfs_ino_info **ino_ptr, uint32_t inum);48 struct mfs_ino_info **ino_ptr, uint32_t inum); 49 49 50 50 /**Read a MINIX inode from disk … … 59 59 int 60 60 mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i, 61 fs_index_t index)61 fs_index_t index) 62 62 { 63 63 struct mfs_sb_info *sbi = inst->sbi; … … 65 65 66 66 if (sbi->fs_version == MFS_VERSION_V1) { 67 /* Read a MFS V1 inode*/67 /* Read a MFS V1 inode */ 68 68 r = mfs_read_inode_raw(inst, ino_i, index); 69 69 } else { 70 /* Read a MFS V2/V3 inode*/70 /* Read a MFS V2/V3 inode */ 71 71 r = mfs2_read_inode_raw(inst, ino_i, index); 72 72 } … … 77 77 static int 78 78 mfs_read_inode_raw(const struct mfs_instance *instance, 79 struct mfs_ino_info **ino_ptr, uint16_t inum) { 79 struct mfs_ino_info **ino_ptr, uint16_t inum) 80 { 80 81 struct mfs_inode *ino; 81 82 struct mfs_ino_info *ino_i = NULL; … … 86 87 sbi = instance->sbi; 87 88 88 /* inode 0 does not exist*/89 /* inode 0 does not exist */ 89 90 inum -= 1; 90 91 … … 101 102 102 103 r = block_get(&b, instance->service_id, 103 itable_off + inum / sbi->ino_per_block, 104 BLOCK_FLAGS_NONE); 104 itable_off + inum / sbi->ino_per_block, 105 BLOCK_FLAGS_NONE); 106 105 107 if (r != EOK) 106 108 goto out_err; … … 134 136 static int 135 137 mfs2_read_inode_raw(const struct mfs_instance *instance, 136 struct mfs_ino_info **ino_ptr, uint32_t inum) { 138 struct mfs_ino_info **ino_ptr, uint32_t inum) 139 { 137 140 struct mfs2_inode *ino; 138 141 struct mfs_ino_info *ino_i = NULL; … … 150 153 sbi = instance->sbi; 151 154 152 /* inode 0 does not exist*/155 /* inode 0 does not exist */ 153 156 inum -= 1; 154 157 … … 157 160 158 161 r = block_get(&b, instance->service_id, 159 itable_off + inum / sbi->ino_per_block, 160 BLOCK_FLAGS_NONE); 162 itable_off + inum / sbi->ino_per_block, 163 BLOCK_FLAGS_NONE); 164 161 165 if (r != EOK) 162 166 goto out_err; … … 322 326 323 327 if (size_shrink == 0) { 324 /* File is empty*/328 /* Nothing to be done */ 325 329 return EOK; 326 330 } … … 333 337 ino_i->dirty = true; 334 338 335 /* Compute the number of zones to free*/339 /* Compute the number of zones to free */ 336 340 unsigned zones_to_free; 337 341 … … 354 358 355 359 if (old_zone == 0) 356 continue; /* Sparse block*/360 continue; /* Sparse block */ 357 361 358 362 r = mfs_free_zone(mnode->instance, old_zone); -
uspace/srv/fs/mfs/mfs_ops.c
r03f4acf r3958e315 43 43 44 44 static bool check_magic_number(uint16_t magic, bool *native, 45 mfs_version_t *version, bool *longfilenames);45 mfs_version_t *version, bool *longfilenames); 46 46 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 47 fs_index_t index); 48 47 fs_index_t index); 49 48 static int mfs_node_put(fs_node_t *fsnode); 50 49 static int mfs_node_open(fs_node_t *fsnode); … … 64 63 static hash_index_t open_nodes_hash(unsigned long key[]); 65 64 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 66 link_t *item);65 link_t *item); 67 66 static void open_nodes_remove_cb(link_t *link); 68 69 67 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 70 fs_index_t index); 71 static int 72 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance); 73 68 fs_index_t index); 69 static int mfs_instance_get(service_id_t service_id, 70 struct mfs_instance **instance); 71 static int mfs_check_sanity(struct mfs_sb_info *sbi); 72 static bool is_power_of_two(uint32_t n); 74 73 75 74 static hash_table_t open_nodes; … … 96 95 97 96 /* Hash table interface for open nodes hash table */ 98 static hash_index_t open_nodes_hash(unsigned long key[]) 97 static hash_index_t 98 open_nodes_hash(unsigned long key[]) 99 99 { 100 100 /* TODO: This is very simple and probably can be improved */ … … 102 102 } 103 103 104 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 104 static int 105 open_nodes_compare(unsigned long key[], hash_count_t keys, 106 link_t *item) 106 107 { 107 108 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); … … 118 119 } 119 120 120 static void open_nodes_remove_cb(link_t *link) 121 static void 122 open_nodes_remove_cb(link_t *link) 121 123 { 122 124 /* We don't use remove callback for this hash table */ … … 129 131 }; 130 132 131 int mfs_global_init(void) 133 int 134 mfs_global_init(void) 132 135 { 133 136 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 134 OPEN_NODES_KEYS, &open_nodes_ops)) {137 OPEN_NODES_KEYS, &open_nodes_ops)) { 135 138 return ENOMEM; 136 139 } … … 140 143 static int 141 144 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index, 142 aoff64_t *size, unsigned *linkcnt)145 aoff64_t *size, unsigned *linkcnt) 143 146 { 144 147 enum cache_mode cmode; … … 163 166 return rc; 164 167 165 /* Allocate space for generic MFS superblock*/168 /* Allocate space for generic MFS superblock */ 166 169 sbi = malloc(sizeof(*sbi)); 167 170 if (!sbi) { … … 170 173 } 171 174 172 /* Allocate space for filesystem instance*/175 /* Allocate space for filesystem instance */ 173 176 instance = malloc(sizeof(*instance)); 174 177 if (!instance) { … … 191 194 192 195 if (check_magic_number(sb->s_magic, &native, &version, &longnames)) { 193 /* This is a V1 or V2 Minix filesystem*/196 /* This is a V1 or V2 Minix filesystem */ 194 197 magic = sb->s_magic; 195 198 } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) { 196 /* This is a V3 Minix filesystem*/199 /* This is a V3 Minix filesystem */ 197 200 magic = sb3->s_magic; 198 201 } else { 199 /* Not recognized*/202 /* Not recognized */ 200 203 mfsdebug("magic number not recognized\n"); 201 204 rc = ENOTSUP; … … 205 208 mfsdebug("magic number recognized = %04x\n", magic); 206 209 207 /* Fill superblock info structure*/210 /* Fill superblock info structure */ 208 211 209 212 sbi->fs_version = version; … … 243 246 sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE; 244 247 sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN : 245 MFS_MAX_NAME_LEN;248 MFS_MAX_NAME_LEN; 246 249 } 247 250 … … 259 262 260 263 sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks; 264 if ((rc = mfs_check_sanity(sbi)) != EOK) { 265 fprintf(stderr, "Filesystem corrupted, invalid superblock"); 266 goto out_error; 267 } 261 268 262 269 rc = block_cache_init(service_id, sbi->block_size, 0, cmode); … … 267 274 } 268 275 269 /* Initialize the instance structure and remember it*/276 /* Initialize the instance structure and remember it */ 270 277 instance->service_id = service_id; 271 278 instance->sbi = sbi; … … 273 280 rc = fs_instance_create(service_id, instance); 274 281 if (rc != EOK) { 275 free(instance);276 free(sbi);277 282 block_cache_fini(service_id); 278 block_fini(service_id);279 283 mfsdebug("fs instance creation failed\n"); 280 return rc;284 goto out_error; 281 285 } 282 286 … … 331 335 } 332 336 333 service_id_t mfs_service_get(fs_node_t *fsnode) 337 service_id_t 338 mfs_service_get(fs_node_t *fsnode) 334 339 { 335 340 struct mfs_node *node = fsnode->data; … … 337 342 } 338 343 339 static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 344 static int 345 mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 340 346 { 341 347 int r; … … 351 357 return r; 352 358 353 /* Alloc a new inode*/359 /* Alloc a new inode */ 354 360 r = mfs_alloc_inode(inst, &inum); 355 361 if (r != EOK) … … 378 384 if (flags & L_DIRECTORY) { 379 385 ino_i->i_mode = S_IFDIR; 380 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry*/386 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry */ 381 387 } else { 382 388 ino_i->i_mode = S_IFREG; … … 431 437 } 432 438 433 static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 439 static int 440 mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 434 441 { 435 442 struct mfs_node *mnode = pfn->data; … … 453 460 454 461 if (!d_info.d_inum) { 455 /* This entry is not used*/462 /* This entry is not used */ 456 463 continue; 457 464 } … … 460 467 461 468 if (comp_size == dentry_name_size && 462 !bcmp(component, d_info.d_name, dentry_name_size)) {463 /* Hit!*/469 !bcmp(component, d_info.d_name, dentry_name_size)) { 470 /* Hit! */ 464 471 mfs_node_core_get(rfn, mnode->instance, 465 d_info.d_inum);472 d_info.d_inum); 466 473 goto found; 467 474 } … … 472 479 } 473 480 474 static aoff64_t mfs_size_get(fs_node_t *node) 481 static aoff64_t 482 mfs_size_get(fs_node_t *node) 475 483 { 476 484 const struct mfs_node *mnode = node->data; … … 480 488 static int 481 489 mfs_node_get(fs_node_t **rfn, service_id_t service_id, 482 fs_index_t index)490 fs_index_t index) 483 491 { 484 492 int rc; … … 524 532 } 525 533 526 static int mfs_node_open(fs_node_t *fsnode) 534 static int 535 mfs_node_open(fs_node_t *fsnode) 527 536 { 528 537 /* … … 533 542 } 534 543 535 static fs_index_t mfs_index_get(fs_node_t *fsnode) 544 static fs_index_t 545 mfs_index_get(fs_node_t *fsnode) 536 546 { 537 547 struct mfs_node *mnode = fsnode->data; … … 539 549 } 540 550 541 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode) 551 static unsigned 552 mfs_lnkcnt_get(fs_node_t *fsnode) 542 553 { 543 554 struct mfs_node *mnode = fsnode->data; … … 554 565 } 555 566 556 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 557 fs_index_t index) 567 static int 568 mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 569 fs_index_t index) 558 570 { 559 571 fs_node_t *node = NULL; … … 627 639 } 628 640 629 static bool mfs_is_directory(fs_node_t *fsnode) 641 static bool 642 mfs_is_directory(fs_node_t *fsnode) 630 643 { 631 644 const struct mfs_node *node = fsnode->data; … … 633 646 } 634 647 635 static bool mfs_is_file(fs_node_t *fsnode) 648 static bool 649 mfs_is_file(fs_node_t *fsnode) 636 650 { 637 651 struct mfs_node *node = fsnode->data; … … 639 653 } 640 654 641 static int mfs_root_get(fs_node_t **rfn, service_id_t service_id) 655 static int 656 mfs_root_get(fs_node_t **rfn, service_id_t service_id) 642 657 { 643 658 int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO); … … 645 660 } 646 661 647 static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 662 static int 663 mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 648 664 { 649 665 struct mfs_node *parent = pfn->data; … … 720 736 } 721 737 722 static int mfs_has_children(bool *has_children, fs_node_t *fsnode) 738 static int 739 mfs_has_children(bool *has_children, fs_node_t *fsnode) 723 740 { 724 741 struct mfs_node *mnode = fsnode->data; … … 741 758 742 759 if (d_info.d_inum) { 743 /* A valid entry has been found*/760 /* A valid entry has been found */ 744 761 *has_children = true; 745 762 break; … … 753 770 static int 754 771 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 755 size_t *rbytes)772 size_t *rbytes) 756 773 { 757 774 int rc; … … 783 800 784 801 if (pos < 2) { 785 /* Skip the first two dentries ('.' and '..')*/802 /* Skip the first two dentries ('.' and '..') */ 786 803 pos = 2; 787 804 } … … 793 810 794 811 if (d_info.d_inum) { 795 /* Dentry found!*/812 /* Dentry found! */ 796 813 goto found; 797 814 } … … 809 826 810 827 if (pos >= (size_t) ino_i->i_size) { 811 /* Trying to read beyond the end of file*/828 /* Trying to read beyond the end of file */ 812 829 bytes = 0; 813 830 (void) async_data_read_finalize(callid, NULL, 0); … … 826 843 827 844 if (zone == 0) { 828 /* sparse file*/845 /* sparse file */ 829 846 uint8_t *buf = malloc(sbi->block_size); 830 847 if (!buf) { … … 834 851 memset(buf, 0, sizeof(sbi->block_size)); 835 852 async_data_read_finalize(callid, 836 buf + pos % sbi->block_size, bytes);853 buf + pos % sbi->block_size, bytes); 837 854 free(buf); 838 855 goto out_success; … … 844 861 845 862 async_data_read_finalize(callid, b->data + 846 pos % sbi->block_size, bytes);863 pos % sbi->block_size, bytes); 847 864 848 865 rc = block_put(b); … … 865 882 static int 866 883 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 867 size_t *wbytes, aoff64_t *nsize)884 size_t *wbytes, aoff64_t *nsize) 868 885 { 869 886 fs_node_t *fn; … … 900 917 901 918 if (block == 0) { 902 /*Writing in a sparse block*/903 919 uint32_t dummy; 904 920 … … 958 974 return ENOENT; 959 975 960 /* Destroy the inode*/976 /* Destroy the inode */ 961 977 return mfs_destroy_node(fn); 962 978 } … … 977 993 assert(!has_children); 978 994 979 /* Free the entire inode content*/995 /* Free the entire inode content */ 980 996 r = mfs_inode_shrink(mnode, mnode->ino_i->i_size); 981 997 if (r != EOK) 982 998 goto out; 983 999 984 /* Mark the inode as free in the bitmap*/1000 /* Mark the inode as free in the bitmap */ 985 1001 r = mfs_free_inode(mnode->instance, mnode->ino_i->index); 986 1002 … … 1021 1037 1022 1038 rc = fs_instance_get(service_id, &data); 1023 if (rc == EOK) {1039 if (rc == EOK) 1024 1040 *instance = (struct mfs_instance *) data; 1025 }else {1041 else { 1026 1042 mfsdebug("instance not found\n"); 1027 1043 } … … 1030 1046 } 1031 1047 1032 static bool check_magic_number(uint16_t magic, bool *native, 1033 mfs_version_t *version, bool *longfilenames) 1048 static bool 1049 check_magic_number(uint16_t magic, bool *native, 1050 mfs_version_t *version, bool *longfilenames) 1034 1051 { 1035 1052 bool rc = true; … … 1059 1076 } 1060 1077 1078 /** Filesystem sanity check 1079 * 1080 * @param Pointer to the MFS superblock. 1081 * 1082 * @return EOK on success, ENOTSUP otherwise. 1083 */ 1084 static int 1085 mfs_check_sanity(struct mfs_sb_info *sbi) 1086 { 1087 if (!is_power_of_two(sbi->block_size) || 1088 sbi->block_size < MFS_MIN_BLOCKSIZE || 1089 sbi->block_size > MFS_MAX_BLOCKSIZE) 1090 return ENOTSUP; 1091 else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0) 1092 return ENOTSUP; 1093 else if (sbi->ninodes == 0 || sbi->nzones == 0) 1094 return ENOTSUP; 1095 else if (sbi->firstdatazone == 0) 1096 return ENOTSUP; 1097 1098 return EOK; 1099 } 1100 1061 1101 static int 1062 1102 mfs_close(service_id_t service_id, fs_index_t index) … … 1079 1119 1080 1120 return mfs_node_put(fn); 1121 } 1122 1123 /** Check if a given number is a power of two. 1124 * 1125 * @param n The number to check. 1126 * 1127 * @return true if it is a power of two, false otherwise. 1128 */ 1129 static bool 1130 is_power_of_two(uint32_t n) 1131 { 1132 if (n == 0) 1133 return false; 1134 1135 return (n & (n - 1)) == 0; 1081 1136 } 1082 1137 -
uspace/srv/fs/mfs/mfs_rw.c
r03f4acf r3958e315 36 36 static int 37 37 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock, 38 bool write_mode, uint32_t w_block);38 bool write_mode, uint32_t w_block); 39 39 40 40 static int … … 68 68 const int block_size = sbi->block_size; 69 69 70 /* Compute relative block number in file*/70 /* Compute relative block number in file */ 71 71 int rblock = pos / block_size; 72 72 73 73 if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) { 74 /* Trying to read beyond the end of file*/74 /* Trying to read beyond the end of file */ 75 75 r = EOK; 76 76 *b = 0; … … 85 85 int 86 86 mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone, 87 uint32_t *old_zone)87 uint32_t *old_zone) 88 88 { 89 89 const struct mfs_sb_info *sbi = mnode->instance->sbi; 90 90 91 91 if (pos >= sbi->max_file_size) { 92 /* Can't write beyond the maximum file size*/92 /* Can't write beyond the maximum file size */ 93 93 return EINVAL; 94 94 } 95 95 96 /* Compute the relative block number in file*/96 /* Compute the relative block number in file */ 97 97 int rblock = pos / sbi->block_size; 98 98 … … 102 102 static int 103 103 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock, 104 bool write_mode, uint32_t w_block)104 bool write_mode, uint32_t w_block) 105 105 { 106 106 int r, nr_direct; … … 123 123 } 124 124 125 /* Check if the wanted block is in the direct zones*/125 /* Check if the wanted block is in the direct zones */ 126 126 if (rblock < nr_direct) { 127 127 *b = ino_i->i_dzone[rblock]; … … 136 136 137 137 if (rblock < ptrs_per_block) { 138 /* The wanted block is in the single indirect zone chain*/138 /* The wanted block is in the single indirect zone chain */ 139 139 if (ino_i->i_izone[0] == 0) { 140 140 if (write_mode && !deleting) { … … 168 168 rblock -= ptrs_per_block; 169 169 170 /* The wanted block is in the double indirect zone chain*/171 172 /* read the first indirect zone of the chain*/170 /* The wanted block is in the double indirect zone chain */ 171 172 /* Read the first indirect zone of the chain */ 173 173 if (ino_i->i_izone[1] == 0) { 174 174 if (write_mode && !deleting) { … … 181 181 ino_i->dirty = true; 182 182 } else { 183 /* Sparse block*/183 /* Sparse block */ 184 184 *b = 0; 185 185 return EOK; … … 192 192 193 193 /* 194 * Compute the position of the second indirect195 * zone pointer in the chain.194 * Compute the position of the second indirect 195 * zone pointer in the chain. 196 196 */ 197 197 uint32_t ind2_off = rblock / ptrs_per_block; 198 198 199 /* read the second indirect zone of the chain*/199 /* read the second indirect zone of the chain */ 200 200 if (ind_zone[ind2_off] == 0) { 201 201 if (write_mode && !deleting) { … … 208 208 write_ind_zone(inst, ino_i->i_izone[1], ind_zone); 209 209 } else { 210 /* Sparse block*/210 /* Sparse block */ 211 211 r = EOK; 212 212 *b = 0; … … 264 264 265 265 if (rblock < nr_direct) { 266 /* free the single indirect zone*/266 /* Free the single indirect zone */ 267 267 if (ino_i->i_izone[0]) { 268 268 r = mfs_free_zone(inst, ino_i->i_izone[0]); … … 282 282 ++fzone_to_free; 283 283 284 /* free the entire double indirect zone*/284 /* Free the entire double indirect zone */ 285 285 uint32_t *dbl_zone; 286 286 287 287 if (ino_i->i_izone[1] == 0) { 288 /* Nothing to be done*/288 /* Nothing to be done */ 289 289 return EOK; 290 290 } … … 350 350 block_t *b; 351 351 const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) * 352 sizeof(uint32_t);352 sizeof(uint32_t); 353 353 354 354 *ind_zone = malloc(max_ind_zone_ptrs); -
uspace/srv/fs/mfs/mfs_utils.c
r03f4acf r3958e315 34 34 #include "mfs.h" 35 35 36 uint16_t conv16(bool native, uint16_t n) 36 uint16_t 37 conv16(bool native, uint16_t n) 37 38 { 38 39 if (native) … … 42 43 } 43 44 44 uint32_t conv32(bool native, uint32_t n) 45 uint32_t 46 conv32(bool native, uint32_t n) 45 47 { 46 48 if (native) … … 50 52 } 51 53 52 uint64_t conv64(bool native, uint64_t n) 54 uint64_t 55 conv64(bool native, uint64_t n) 53 56 { 54 57 if (native)
Note:
See TracChangeset
for help on using the changeset viewer.
