Changes in / [2ac7af3:3a5506a] in mainline
- Location:
- uspace
- Files:
-
- 10 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkmfs/mkmfs.c
r2ac7af3 r3a5506a 1 1 /* 2 * Copyright (c) 2010 Jiri Svoboda 2 3 * Copyright (c) 2011 Maurizio Lombardi 3 4 * All rights reserved. … … 55 56 #define USED 1 56 57 57 #define UPPER(n, size) (((n) / (size)) + (((n) % (size)) != 0))58 #define NEXT_DENTRY(p, dirsize) (p += (dirsize))58 #define UPPER(n, size) (((n) / (size)) + (((n) % (size)) != 0)) 59 #define NEXT_DENTRY(p, dirsize) (p += (dirsize)) 59 60 60 61 typedef enum { … … 63 64 } help_level_t; 64 65 65 /* Generic MFS superblock*/66 /*Generic MFS superblock*/ 66 67 struct mfs_sb_info { 67 68 uint64_t n_inodes; … … 83 84 84 85 static void help_cmd_mkmfs(help_level_t level); 85 static bool is_power_of_two(uint32_t n);86 static int num_of_set_bits(uint32_t n); 86 87 static int init_superblock(struct mfs_sb_info *sb); 87 88 static int write_superblock(const struct mfs_sb_info *sbi); … … 117 118 struct mfs_sb_info sb; 118 119 119 /* Default is MinixFS V3*/120 /*Default is MinixFS V3*/ 120 121 sb.magic = MFS_MAGIC_V3; 121 122 sb.fs_version = 3; 122 123 123 /* Default block size is 4Kb*/124 /*Default block size is 4Kb*/ 124 125 sb.block_size = MFS_MAX_BLOCKSIZE; 125 126 sb.dirsize = MFS3_DIRSIZE; … … 135 136 136 137 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 137 c = getopt_long(argc, argv, "lh12b:i:", 138 long_options, &opt_ind); 138 c = getopt_long(argc, argv, "lh12b:i:", long_options, &opt_ind); 139 139 switch (c) { 140 140 case 'h': … … 169 169 170 170 if (sb.block_size < MFS_MIN_BLOCKSIZE || 171 171 sb.block_size > MFS_MAX_BLOCKSIZE) { 172 172 printf(NAME ":Error! Invalid block size.\n"); 173 173 exit(0); 174 } else if ( !is_power_of_two(sb.block_size)) {175 /* Block size must be a power of 2.*/174 } else if (num_of_set_bits(sb.block_size) != 1) { 175 /*Block size must be a power of 2.*/ 176 176 printf(NAME ":Error! Invalid block size.\n"); 177 177 exit(0); 178 178 } else if (sb.block_size > MFS_BLOCKSIZE && 179 sb.fs_version != 3) { 180 printf(NAME ":Error! Block size > 1024 is " 181 "supported by V3 filesystem only.\n"); 179 sb.fs_version != 3) { 180 printf(NAME ":Error! Block size > 1024 is supported by V3 filesystem only.\n"); 182 181 exit(0); 183 182 } else if (sb.fs_version == 3 && sb.longnames) { 184 printf(NAME ":Error! Long filenames are supported " 185 "by V1/V2 filesystem only.\n"); 183 printf(NAME ":Error! Long filenames are supported by V1/V2 filesystem only.\n"); 186 184 exit(0); 187 185 } … … 223 221 rc = block_get_nblocks(service_id, &sb.dev_nblocks); 224 222 if (rc != EOK) { 225 printf(NAME ": Warning, failed to obtain " 226 "block device size.\n"); 223 printf(NAME ": Warning, failed to obtain block device size.\n"); 227 224 } else { 228 225 printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n", 229 226 sb.dev_nblocks); 230 227 } 231 228 … … 235 232 } 236 233 237 /* Minimum block size is 1 Kb*/234 /*Minimum block size is 1 Kb*/ 238 235 sb.dev_nblocks /= 2; 239 236 240 237 printf(NAME ": Creating Minix file system on device\n"); 241 printf(NAME ": Writing superblock\n"); 242 243 /* Initialize superblock */ 238 239 /*Initialize superblock*/ 244 240 if (init_superblock(&sb) != EOK) { 245 241 printf(NAME ": Error. Superblock initialization failed\n"); … … 247 243 } 248 244 249 printf(NAME ": Initializing bitmaps\n"); 250 251 /* Initialize bitmaps */ 245 /*Initialize bitmaps*/ 252 246 if (init_bitmaps(&sb) != EOK) { 253 247 printf(NAME ": Error. Bitmaps initialization failed\n"); … … 255 249 } 256 250 257 printf(NAME ": Initializing the inode table\n"); 258 259 /* Init inode table */ 251 /*Init inode table*/ 260 252 if (init_inode_table(&sb) != EOK) { 261 253 printf(NAME ": Error. Inode table initialization failed\n"); … … 263 255 } 264 256 265 printf(NAME ": Creating the root directory inode\n"); 266 267 /* Make the root inode */ 257 /*Make the root inode*/ 268 258 if (sb.fs_version == 1) 269 259 rc = make_root_ino(&sb); … … 276 266 } 277 267 278 /* Insert directory entries . and ..*/268 /*Insert directory entries . and ..*/ 279 269 if (insert_dentries(&sb) != EOK) { 280 270 printf(NAME ": Error. Root directory initialization failed\n"); … … 309 299 310 300 if (sb->fs_version != 3) { 311 /* Directory entries for V1/V2 filesystem*/301 /*Directory entries for V1/V2 filesystem*/ 312 302 struct mfs_dentry *dentry = root_block; 313 303 … … 316 306 317 307 dentry = (struct mfs_dentry *) NEXT_DENTRY(dentry_ptr, 318 308 sb->dirsize); 319 309 320 310 dentry->d_inum = MFS_ROOT_INO; 321 311 memcpy(dentry->d_name, "..\0", 3); 322 312 } else { 323 /* Directory entries for V3 filesystem*/313 /*Directory entries for V3 filesystem*/ 324 314 struct mfs3_dentry *dentry = root_block; 325 315 … … 328 318 329 319 dentry = (struct mfs3_dentry *) NEXT_DENTRY(dentry_ptr, 330 320 sb->dirsize); 331 321 332 322 dentry->d_inum = MFS_ROOT_INO; … … 399 389 ino_buf[MFS_ROOT_INO - 1].i_gid = 0; 400 390 ino_buf[MFS_ROOT_INO - 1].i_size = (sb->longnames ? MFSL_DIRSIZE : 401 391 MFS_DIRSIZE) * 2; 402 392 ino_buf[MFS_ROOT_INO - 1].i_mtime = sec; 403 393 ino_buf[MFS_ROOT_INO - 1].i_nlinks = 2; … … 421 411 int rc; 422 412 423 /* Compute offset of the first inode table block*/413 /*Compute offset of the first inode table block*/ 424 414 const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2; 425 415 … … 464 454 465 455 if (sb->longnames) 466 sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L : 467 MFS_MAGIC_V2L; 468 469 /* Compute the number of zones on disk */ 456 sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L : MFS_MAGIC_V2L; 457 458 /*Compute the number of zones on disk*/ 470 459 471 460 if (sb->fs_version == 1) { 472 /* Valid only for MFS V1*/461 /*Valid only for MFS V1*/ 473 462 sb->n_zones = sb->dev_nblocks > UINT16_MAX ? 474 463 UINT16_MAX : sb->dev_nblocks; 475 464 ind = MFS_BLOCKSIZE / sizeof(uint16_t); 476 465 ind2 = ind * ind; 477 sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) * 478 MFS_BLOCKSIZE; 466 sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) * MFS_BLOCKSIZE; 479 467 } else { 480 468 /*Valid for MFS V2/V3*/ … … 484 472 else 485 473 ptrsize = sizeof(uint32_t); 486 487 474 ind = sb->block_size / ptrsize; 488 475 ind2 = ind * ind; … … 490 477 sb->max_file_size = zones * sb->block_size; 491 478 sb->n_zones = sb->dev_nblocks > UINT32_MAX ? 492 479 UINT32_MAX : sb->dev_nblocks; 493 480 494 481 if (sb->fs_version == 3) { … … 500 487 } 501 488 502 /* Round up the number of inodes to fill block size*/489 /*Round up the number of inodes to fill block size*/ 503 490 if (sb->n_inodes == 0) 504 491 inodes = sb->dev_nblocks / 3; … … 507 494 508 495 if (inodes % sb->ino_per_block) 509 inodes = ((inodes / sb->ino_per_block) + 1) * 510 sb->ino_per_block; 496 inodes = ((inodes / sb->ino_per_block) + 1) * sb->ino_per_block; 511 497 512 498 if (sb->fs_version < 3) … … 515 501 sb->n_inodes = inodes > UINT32_MAX ? UINT32_MAX : inodes; 516 502 517 /* Compute inode bitmap size in blocks*/503 /*Compute inode bitmap size in blocks*/ 518 504 sb->ibmap_blocks = UPPER(sb->n_inodes, sb->block_size * 8); 519 505 520 /* Compute inode table size*/506 /*Compute inode table size*/ 521 507 sb->itable_size = sb->n_inodes / sb->ino_per_block; 522 508 523 /* Compute zone bitmap size in blocks*/509 /*Compute zone bitmap size in blocks*/ 524 510 sb->zbmap_blocks = UPPER(sb->n_zones, sb->block_size * 8); 525 511 526 /* Compute first data zone position*/512 /*Compute first data zone position*/ 527 513 sb->first_data_zone = 2 + sb->itable_size + 528 529 530 /* Set log2 of zone to block ratio to zero*/514 sb->zbmap_blocks + sb->ibmap_blocks; 515 516 /*Set log2 of zone to block ratio to zero*/ 531 517 sb->log2_zone_size = 0; 532 518 533 /* Check for errors*/519 /*Check for errors*/ 534 520 if (sb->first_data_zone >= sb->n_zones) { 535 521 printf(NAME ": Error! Insufficient disk space"); … … 537 523 } 538 524 539 /* Superblock is now ready to be written on disk*/525 /*Superblock is now ready to be written on disk*/ 540 526 printf(NAME ": %d block size\n", sb->block_size); 541 527 printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes); … … 544 530 printf(NAME ": inode bitmap blocks = %ld\n", sb->ibmap_blocks); 545 531 printf(NAME ": zone bitmap blocks = %ld\n", sb->zbmap_blocks); 546 printf(NAME ": first data zone = %d\n", (uint32_t) sb->first_data_zone);532 printf(NAME ": first data zone = %d\n", (uint32_t) sb->first_data_zone); 547 533 printf(NAME ": max file size = %u\n", sb->max_file_size); 548 534 printf(NAME ": long fnames = %s\n", sb->longnames ? "Yes" : "No"); … … 659 645 for (i = 0; i < ibmap_nblocks; ++i) { 660 646 if ((rc = write_block(start_block + i, 661 647 1, (ibmap_buf8 + i * sb->block_size))) != EOK) 662 648 return rc; 663 649 } … … 667 653 for (i = 0; i < zbmap_nblocks; ++i) { 668 654 if ((rc = write_block(start_block + i, 669 655 1, (zbmap_buf8 + i * sb->block_size))) != EOK) 670 656 return rc; 671 657 } … … 706 692 uint8_t *data_ptr = (uint8_t *) data; 707 693 708 rc = block_write_direct(service_id, tmp_off << 2, 709 size << 2, data_ptr); 694 rc = block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr); 710 695 711 696 if (rc != EOK) … … 715 700 tmp_off++; 716 701 717 return block_write_direct(service_id, tmp_off << 2, 718 size << 2, data_ptr); 719 } 720 return block_write_direct(service_id, off << shift, 721 size << shift, data); 702 return block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr); 703 } 704 return block_write_direct(service_id, off << shift, size << shift, data); 722 705 } 723 706 … … 728 711 } else { 729 712 printf("Usage: [options] device\n" 730 "-1 Make a Minix version 1 filesystem\n" 731 "-2 Make a Minix version 2 filesystem\n" 732 "-b ## Specify the block size in bytes (V3 only),\n" 733 " valid block size values are 1024, 2048 and" 734 " 4096 bytes per block\n" 735 "-i ## Specify the number of inodes" 736 " for the filesystem\n" 737 "-l Use 30-char long filenames (V1/V2 only)\n"); 738 } 739 } 740 741 /** Check if a given number is a power of two. 742 * 743 * @param n The number to check. 744 * 745 * @return true if it is a power of two, false otherwise. 746 */ 747 static bool is_power_of_two(uint32_t n) 748 { 749 if (n == 0) 750 return false; 751 752 return (n & (n - 1)) == 0; 713 "-1 Make a Minix version 1 filesystem\n" 714 "-2 Make a Minix version 2 filesystem\n" 715 "-b ## Specify the block size in bytes (V3 only),\n" 716 " valid block size values are 1024, 2048 and 4096 bytes per block\n" 717 "-i ## Specify the number of inodes for the filesystem\n" 718 "-l Use 30-char long filenames (V1/V2 only)\n"); 719 } 720 } 721 722 static int num_of_set_bits(uint32_t n) 723 { 724 n = n - ((n >> 1) & 0x55555555); 725 n = (n & 0x33333333) + ((n >> 2) & 0x33333333); 726 return (((n + (n >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; 753 727 } 754 728 -
uspace/srv/fs/mfs/mfs.c
r2ac7af3 r3a5506a 74 74 75 75 async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 76 76 SERVICE_VFS, 0, 0); 77 77 78 78 if (!vfs_sess) { -
uspace/srv/fs/mfs/mfs_balloc.c
r2ac7af3 r3a5506a 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 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) { 271 270 i < bsize / sizeof(bitchunk_t); ++i) { 272 271 if (!(~b[i])) { 273 /* No free bit in this chunk*/272 /*No free bit in this chunk*/ 274 273 continue; 275 274 } -
uspace/srv/fs/mfs/mfs_dentry.c
r2ac7af3 r3a5506a 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 104 * 105 * @return 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)) { 181 180 !bcmp(d_info.d_name, d_name, name_len)) { 182 181 d_info.d_inum = 0; 183 182 r = mfs_write_dentry(&d_info); … … 198 197 */ 199 198 int 200 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, 201 fs_index_t d_inum) 199 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum) 202 200 { 203 201 int r; … … 211 209 return ENAMETOOLONG; 212 210 213 /* Search for an empty dentry*/211 /*Search for an empty dentry*/ 214 212 unsigned i; 215 213 for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) { … … 219 217 220 218 if (d_info.d_inum == 0) { 221 /* This entry is not used*/219 /*This entry is not used*/ 222 220 empty_dentry_found = true; 223 221 break; … … 233 231 234 232 if (b == 0) { 235 /* Increase the inode size*/233 /*Increase the inode size*/ 236 234 237 235 uint32_t dummy; -
uspace/srv/fs/mfs/mfs_inode.c
r2ac7af3 r3a5506a 42 42 static int 43 43 mfs_read_inode_raw(const struct mfs_instance *instance, 44 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 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 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) 80 { 79 struct mfs_ino_info **ino_ptr, uint16_t inum) { 81 80 struct mfs_inode *ino; 82 81 struct mfs_ino_info *ino_i = NULL; … … 87 86 sbi = instance->sbi; 88 87 89 /* inode 0 does not exist*/88 /*inode 0 does not exist*/ 90 89 inum -= 1; 91 90 … … 102 101 103 102 r = block_get(&b, instance->service_id, 104 itable_off + inum / sbi->ino_per_block, 105 BLOCK_FLAGS_NONE); 106 103 itable_off + inum / sbi->ino_per_block, 104 BLOCK_FLAGS_NONE); 107 105 if (r != EOK) 108 106 goto out_err; … … 136 134 static int 137 135 mfs2_read_inode_raw(const struct mfs_instance *instance, 138 struct mfs_ino_info **ino_ptr, uint32_t inum) 139 { 136 struct mfs_ino_info **ino_ptr, uint32_t inum) { 140 137 struct mfs2_inode *ino; 141 138 struct mfs_ino_info *ino_i = NULL; … … 153 150 sbi = instance->sbi; 154 151 155 /* inode 0 does not exist*/152 /*inode 0 does not exist*/ 156 153 inum -= 1; 157 154 … … 160 157 161 158 r = block_get(&b, instance->service_id, 162 itable_off + inum / sbi->ino_per_block, 163 BLOCK_FLAGS_NONE); 164 159 itable_off + inum / sbi->ino_per_block, 160 BLOCK_FLAGS_NONE); 165 161 if (r != EOK) 166 162 goto out_err; … … 326 322 327 323 if (size_shrink == 0) { 328 /* Nothing to be done*/324 /*File is empty*/ 329 325 return EOK; 330 326 } … … 337 333 ino_i->dirty = true; 338 334 339 /* Compute the number of zones to free*/335 /*Compute the number of zones to free*/ 340 336 unsigned zones_to_free; 341 337 … … 358 354 359 355 if (old_zone == 0) 360 continue; /* Sparse block*/356 continue; /*Sparse block*/ 361 357 362 358 r = mfs_free_zone(mnode->instance, old_zone); -
uspace/srv/fs/mfs/mfs_ops.c
r2ac7af3 r3a5506a 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); 47 fs_index_t index); 48 48 49 static int mfs_node_put(fs_node_t *fsnode); 49 50 static int mfs_node_open(fs_node_t *fsnode); … … 63 64 static hash_index_t open_nodes_hash(unsigned long key[]); 64 65 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 65 66 link_t *item); 66 67 static void open_nodes_remove_cb(link_t *link); 68 67 69 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 68 69 static int mfs_instance_get(service_id_t service_id,70 70 fs_index_t index); 71 static int 72 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance); 71 73 72 74 … … 94 96 95 97 /* Hash table interface for open nodes hash table */ 96 static hash_index_t 97 open_nodes_hash(unsigned long key[]) 98 static hash_index_t open_nodes_hash(unsigned long key[]) 98 99 { 99 100 /* TODO: This is very simple and probably can be improved */ … … 101 102 } 102 103 103 static int 104 open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 104 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 106 106 { 107 107 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); … … 118 118 } 119 119 120 static void 121 open_nodes_remove_cb(link_t *link) 120 static void open_nodes_remove_cb(link_t *link) 122 121 { 123 122 /* We don't use remove callback for this hash table */ … … 130 129 }; 131 130 132 int 133 mfs_global_init(void) 131 int mfs_global_init(void) 134 132 { 135 133 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 136 134 OPEN_NODES_KEYS, &open_nodes_ops)) { 137 135 return ENOMEM; 138 136 } … … 142 140 static int 143 141 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index, 144 142 aoff64_t *size, unsigned *linkcnt) 145 143 { 146 144 enum cache_mode cmode; … … 165 163 return rc; 166 164 167 /* Allocate space for generic MFS superblock*/165 /*Allocate space for generic MFS superblock*/ 168 166 sbi = malloc(sizeof(*sbi)); 169 167 if (!sbi) { … … 172 170 } 173 171 174 /* Allocate space for filesystem instance*/172 /*Allocate space for filesystem instance*/ 175 173 instance = malloc(sizeof(*instance)); 176 174 if (!instance) { … … 193 191 194 192 if (check_magic_number(sb->s_magic, &native, &version, &longnames)) { 195 /* This is a V1 or V2 Minix filesystem*/193 /*This is a V1 or V2 Minix filesystem*/ 196 194 magic = sb->s_magic; 197 195 } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) { 198 /* This is a V3 Minix filesystem*/196 /*This is a V3 Minix filesystem*/ 199 197 magic = sb3->s_magic; 200 198 } else { 201 /* Not recognized*/199 /*Not recognized*/ 202 200 mfsdebug("magic number not recognized\n"); 203 201 rc = ENOTSUP; … … 207 205 mfsdebug("magic number recognized = %04x\n", magic); 208 206 209 /* Fill superblock info structure*/207 /*Fill superblock info structure*/ 210 208 211 209 sbi->fs_version = version; … … 245 243 sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE; 246 244 sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN : 247 MFS_MAX_NAME_LEN;245 MFS_MAX_NAME_LEN; 248 246 } 249 247 … … 269 267 } 270 268 271 /* Initialize the instance structure and remember it*/269 /*Initialize the instance structure and remember it*/ 272 270 instance->service_id = service_id; 273 271 instance->sbi = sbi; … … 275 273 rc = fs_instance_create(service_id, instance); 276 274 if (rc != EOK) { 275 free(instance); 276 free(sbi); 277 277 block_cache_fini(service_id); 278 block_fini(service_id); 278 279 mfsdebug("fs instance creation failed\n"); 279 goto out_error;280 return rc; 280 281 } 281 282 … … 330 331 } 331 332 332 service_id_t 333 mfs_service_get(fs_node_t *fsnode) 333 service_id_t mfs_service_get(fs_node_t *fsnode) 334 334 { 335 335 struct mfs_node *node = fsnode->data; … … 337 337 } 338 338 339 static int 340 mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 339 static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 341 340 { 342 341 int r; … … 352 351 return r; 353 352 354 /* Alloc a new inode*/353 /*Alloc a new inode*/ 355 354 r = mfs_alloc_inode(inst, &inum); 356 355 if (r != EOK) … … 379 378 if (flags & L_DIRECTORY) { 380 379 ino_i->i_mode = S_IFDIR; 381 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry*/380 ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/ 382 381 } else { 383 382 ino_i->i_mode = S_IFREG; … … 432 431 } 433 432 434 static int 435 mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 433 static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 436 434 { 437 435 struct mfs_node *mnode = pfn->data; … … 455 453 456 454 if (!d_info.d_inum) { 457 /* This entry is not used*/455 /*This entry is not used*/ 458 456 continue; 459 457 } … … 462 460 463 461 if (comp_size == dentry_name_size && 464 465 /* Hit!*/462 !bcmp(component, d_info.d_name, dentry_name_size)) { 463 /*Hit!*/ 466 464 mfs_node_core_get(rfn, mnode->instance, 467 465 d_info.d_inum); 468 466 goto found; 469 467 } … … 474 472 } 475 473 476 static aoff64_t 477 mfs_size_get(fs_node_t *node) 474 static aoff64_t mfs_size_get(fs_node_t *node) 478 475 { 479 476 const struct mfs_node *mnode = node->data; … … 483 480 static int 484 481 mfs_node_get(fs_node_t **rfn, service_id_t service_id, 485 482 fs_index_t index) 486 483 { 487 484 int rc; … … 527 524 } 528 525 529 static int 530 mfs_node_open(fs_node_t *fsnode) 526 static int mfs_node_open(fs_node_t *fsnode) 531 527 { 532 528 /* … … 537 533 } 538 534 539 static fs_index_t 540 mfs_index_get(fs_node_t *fsnode) 535 static fs_index_t mfs_index_get(fs_node_t *fsnode) 541 536 { 542 537 struct mfs_node *mnode = fsnode->data; … … 544 539 } 545 540 546 static unsigned 547 mfs_lnkcnt_get(fs_node_t *fsnode) 541 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode) 548 542 { 549 543 struct mfs_node *mnode = fsnode->data; … … 560 554 } 561 555 562 static int 563 mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 564 fs_index_t index) 556 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 557 fs_index_t index) 565 558 { 566 559 fs_node_t *node = NULL; … … 634 627 } 635 628 636 static bool 637 mfs_is_directory(fs_node_t *fsnode) 629 static bool mfs_is_directory(fs_node_t *fsnode) 638 630 { 639 631 const struct mfs_node *node = fsnode->data; … … 641 633 } 642 634 643 static bool 644 mfs_is_file(fs_node_t *fsnode) 635 static bool mfs_is_file(fs_node_t *fsnode) 645 636 { 646 637 struct mfs_node *node = fsnode->data; … … 648 639 } 649 640 650 static int 651 mfs_root_get(fs_node_t **rfn, service_id_t service_id) 641 static int mfs_root_get(fs_node_t **rfn, service_id_t service_id) 652 642 { 653 643 int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO); … … 655 645 } 656 646 657 static int 658 mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 647 static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 659 648 { 660 649 struct mfs_node *parent = pfn->data; … … 731 720 } 732 721 733 static int 734 mfs_has_children(bool *has_children, fs_node_t *fsnode) 722 static int mfs_has_children(bool *has_children, fs_node_t *fsnode) 735 723 { 736 724 struct mfs_node *mnode = fsnode->data; … … 753 741 754 742 if (d_info.d_inum) { 755 /* A valid entry has been found*/743 /*A valid entry has been found*/ 756 744 *has_children = true; 757 745 break; … … 765 753 static int 766 754 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 767 755 size_t *rbytes) 768 756 { 769 757 int rc; … … 795 783 796 784 if (pos < 2) { 797 /* Skip the first two dentries ('.' and '..')*/785 /*Skip the first two dentries ('.' and '..')*/ 798 786 pos = 2; 799 787 } … … 805 793 806 794 if (d_info.d_inum) { 807 /* Dentry found!*/795 /*Dentry found!*/ 808 796 goto found; 809 797 } … … 821 809 822 810 if (pos >= (size_t) ino_i->i_size) { 823 /* Trying to read beyond the end of file*/811 /*Trying to read beyond the end of file*/ 824 812 bytes = 0; 825 813 (void) async_data_read_finalize(callid, NULL, 0); … … 838 826 839 827 if (zone == 0) { 840 /* sparse file*/828 /*sparse file*/ 841 829 uint8_t *buf = malloc(sbi->block_size); 842 830 if (!buf) { … … 846 834 memset(buf, 0, sizeof(sbi->block_size)); 847 835 async_data_read_finalize(callid, 848 836 buf + pos % sbi->block_size, bytes); 849 837 free(buf); 850 838 goto out_success; … … 856 844 857 845 async_data_read_finalize(callid, b->data + 858 846 pos % sbi->block_size, bytes); 859 847 860 848 rc = block_put(b); … … 877 865 static int 878 866 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 879 867 size_t *wbytes, aoff64_t *nsize) 880 868 { 881 869 fs_node_t *fn; … … 912 900 913 901 if (block == 0) { 902 /*Writing in a sparse block*/ 914 903 uint32_t dummy; 915 904 … … 969 958 return ENOENT; 970 959 971 /* Destroy the inode*/960 /*Destroy the inode*/ 972 961 return mfs_destroy_node(fn); 973 962 } … … 988 977 assert(!has_children); 989 978 990 /* Free the entire inode content*/979 /*Free the entire inode content*/ 991 980 r = mfs_inode_shrink(mnode, mnode->ino_i->i_size); 992 981 if (r != EOK) 993 982 goto out; 994 983 995 /* Mark the inode as free in the bitmap*/984 /*Mark the inode as free in the bitmap*/ 996 985 r = mfs_free_inode(mnode->instance, mnode->ino_i->index); 997 986 … … 1032 1021 1033 1022 rc = fs_instance_get(service_id, &data); 1034 if (rc == EOK) 1023 if (rc == EOK) { 1035 1024 *instance = (struct mfs_instance *) data; 1036 else {1025 } else { 1037 1026 mfsdebug("instance not found\n"); 1038 1027 } … … 1041 1030 } 1042 1031 1043 static bool 1044 check_magic_number(uint16_t magic, bool *native, 1045 mfs_version_t *version, bool *longfilenames) 1032 static bool check_magic_number(uint16_t magic, bool *native, 1033 mfs_version_t *version, bool *longfilenames) 1046 1034 { 1047 1035 bool rc = true; -
uspace/srv/fs/mfs/mfs_rw.c
r2ac7af3 r3a5506a 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 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 * 195 * 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
r2ac7af3 r3a5506a 34 34 #include "mfs.h" 35 35 36 uint16_t 37 conv16(bool native, uint16_t n) 36 uint16_t conv16(bool native, uint16_t n) 38 37 { 39 38 if (native) … … 43 42 } 44 43 45 uint32_t 46 conv32(bool native, uint32_t n) 44 uint32_t conv32(bool native, uint32_t n) 47 45 { 48 46 if (native) … … 52 50 } 53 51 54 uint64_t 55 conv64(bool native, uint64_t n) 52 uint64_t conv64(bool native, uint64_t n) 56 53 { 57 54 if (native)
Note:
See TracChangeset
for help on using the changeset viewer.