Changeset 5352d72 in mainline
- Timestamp:
- 2011-02-16T16:47:18Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2a1792
- Parents:
- ce13577
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ext2info/ext2info.c
rce13577 r5352d72 56 56 static void print_block_groups(ext2_filesystem_t *); 57 57 static void print_block_group(ext2_block_group_t *); 58 static void print_inode_by_number(ext2_filesystem_t *, uint32_t); 59 static void print_inode(ext2_inode_t *); 60 61 #define ARG_SUPERBLOCK 1 62 #define ARG_BLOCK_GROUPS 2 63 #define ARG_INODE 4 64 #define ARG_STRICT_CHECK 8 65 #define ARG_COMMON (ARG_SUPERBLOCK | ARG_BLOCK_GROUPS) 66 #define ARG_ALL (ARG_COMMON | ARG_INODE) 67 58 68 59 69 int main(int argc, char **argv) … … 61 71 62 72 int rc; 73 char *endptr; 63 74 char *dev_path; 64 75 devmap_handle_t handle; 65 76 ext2_filesystem_t filesystem; 66 bool strict_check; 77 int arg_flags; 78 uint32_t inode = 0; 79 80 arg_flags = 0; 67 81 68 82 if (argc < 2) { … … 72 86 } 73 87 74 strict_check = false; 88 // Skip program name 89 --argc; ++argv; 90 75 91 if (str_cmp(*argv, "--strict-check") == 0) { 76 92 --argc; ++argv; 77 strict_check = true; 78 } 79 80 --argc; ++argv; 93 arg_flags |= ARG_STRICT_CHECK; 94 } 95 96 if (str_cmp(*argv, "--superblock") == 0) { 97 --argc; ++argv; 98 arg_flags |= ARG_SUPERBLOCK; 99 } 100 101 if (str_cmp(*argv, "--block-groups") == 0) { 102 --argc; ++argv; 103 arg_flags |= ARG_BLOCK_GROUPS; 104 } 105 106 if (str_cmp(*argv, "--inode") == 0) { 107 --argc; ++argv; 108 if (argc == 0) { 109 printf(NAME ": Argument expected for --inode\n"); 110 return 2; 111 } 112 113 inode = strtol(*argv, &endptr, 10); 114 if (*endptr != '\0') { 115 printf(NAME ": Error, invalid argument for --inode.\n"); 116 syntax_print(); 117 return 1; 118 } 119 120 arg_flags |= ARG_INODE; 121 --argc; ++argv; 122 } 81 123 82 124 if (argc != 1) { … … 85 127 return 1; 86 128 } 129 130 // Display common things by default 131 if ((arg_flags & ARG_ALL) == 0) { 132 arg_flags = ARG_COMMON; 133 } 87 134 88 135 dev_path = *argv; … … 103 150 if (rc != EOK) { 104 151 printf(NAME ": Filesystem did not pass sanity check.\n"); 105 if ( strict_check) {152 if (arg_flags & ARG_STRICT_CHECK) { 106 153 return 3; 107 154 } 108 155 } 109 156 110 print_superblock(filesystem.superblock); 111 print_block_groups(&filesystem); 157 if (arg_flags & ARG_SUPERBLOCK) { 158 print_superblock(filesystem.superblock); 159 } 160 161 if (arg_flags & ARG_BLOCK_GROUPS) { 162 print_block_groups(&filesystem); 163 } 164 165 if (arg_flags & ARG_INODE) { 166 print_inode_by_number(&filesystem, inode); 167 } 112 168 113 169 ext2_filesystem_fini(&filesystem); … … 119 175 static void syntax_print(void) 120 176 { 121 printf("syntax: ext2info <device_name>\n");177 printf("syntax: ext2info --strict-check --superblock --block-groups --inode <i-number> <device_name>\n"); 122 178 } 123 179 … … 212 268 } 213 269 214 void print_block_groups(ext2_filesystem_t *filesystem) { 270 void print_block_groups(ext2_filesystem_t *filesystem) 271 { 215 272 uint32_t block_group_count; 216 273 uint32_t i; … … 241 298 } 242 299 243 void print_block_group(ext2_block_group_t *bg) { 300 void print_block_group(ext2_block_group_t *bg) 301 { 244 302 uint32_t block_bitmap_block; 245 303 uint32_t inode_bitmap_block; … … 264 322 } 265 323 324 void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode) 325 { 326 int rc; 327 ext2_inode_ref_t *inode_ref; 328 329 printf("Inode %u\n", inode); 330 331 rc = ext2_filesystem_get_inode_ref(fs, inode, &inode_ref); 332 if (rc != EOK) { 333 printf(" Failed getting inode ref\n"); 334 return; 335 } 336 337 print_inode(inode_ref->inode); 338 339 rc = ext2_filesystem_put_inode_ref(inode_ref); 340 if (rc != EOK) { 341 printf(" Failed putting inode ref\n"); 342 } 343 } 344 345 void print_inode(ext2_inode_t *inode) 346 { 347 uint16_t mode; 348 uint32_t user_id; 349 uint32_t group_id; 350 uint32_t size; 351 uint16_t usage_count; 352 uint32_t flags; 353 uint16_t access; 354 const char *type; 355 uint32_t block; 356 int i; 357 bool all_blocks = false; 358 359 mode = ext2_inode_get_mode(inode); 360 user_id = ext2_inode_get_user_id(inode); 361 group_id = ext2_inode_get_group_id(inode); 362 size = ext2_inode_get_size(inode); 363 usage_count = ext2_inode_get_usage_count(inode); 364 flags = ext2_inode_get_flags(inode); 365 366 type = "Unknown"; 367 if ((mode & EXT2_INODE_MODE_BLOCKDEV) == EXT2_INODE_MODE_BLOCKDEV) { 368 type = "Block device"; 369 } 370 else if (mode & EXT2_INODE_MODE_FIFO) { 371 type = "Fifo (pipe)"; 372 } 373 else if (mode & EXT2_INODE_MODE_CHARDEV) { 374 type = "Character device"; 375 } 376 else if (mode & EXT2_INODE_MODE_DIRECTORY) { 377 type = "Directory"; 378 } 379 else if (mode & EXT2_INODE_MODE_FILE) { 380 type = "File"; 381 } 382 else if (mode & EXT2_INODE_MODE_SOFTLINK) { 383 type = "Soft link"; 384 } 385 else if (mode & EXT2_INODE_MODE_SOCKET) { 386 type = "Socket"; 387 } 388 389 access = mode & EXT2_INODE_MODE_ACCESS_MASK; 390 391 printf(" Mode: %04x (Type: %s, Access bits: %04ho)\n", mode, type, access); 392 printf(" User ID: %u\n", user_id); 393 printf(" Group ID: %u\n", group_id); 394 printf(" Size: %u\n", size); 395 printf(" Usage (link) count: %u\n", usage_count); 396 printf(" Flags: %u\n", flags); 397 printf(" Block list: "); 398 for (i = 0; i < 12; i++) { 399 block = ext2_inode_get_direct_block(inode, i); 400 if (block == 0) { 401 all_blocks = true; 402 break; 403 } 404 printf("%u ", block); 405 } 406 if (!all_blocks) { 407 printf(" and more..."); 408 } 409 printf("\n"); 410 } 411 266 412 /** 267 413 * @} -
uspace/lib/ext2/libext2_filesystem.c
rce13577 r5352d72 225 225 } 226 226 227 newref->inode = newref->block->data + offset_in_group;227 newref->inode = newref->block->data + (offset_in_group*inode_size); 228 228 229 229 *ref = newref; -
uspace/lib/ext2/libext2_inode.c
rce13577 r5352d72 38 38 #include <byteorder.h> 39 39 40 /** 41 * Get mode stored in the inode 42 * 43 * @param inode pointer to inode 44 */ 45 inline uint16_t ext2_inode_get_mode(ext2_inode_t *inode) 46 { 47 return uint16_t_le2host(inode->mode); 48 } 49 50 /** 51 * Get uid this inode is belonging to 52 * 53 * @param inode pointer to inode 54 */ 55 inline uint32_t ext2_inode_get_user_id(ext2_inode_t *inode) 56 { 57 // TODO: use additional OS specific bits 58 return uint16_t_le2host(inode->user_id); 59 } 60 61 /** 62 * Get size of file 63 * 64 * @param inode pointer to inode 65 */ 66 inline uint32_t ext2_inode_get_size(ext2_inode_t *inode) 67 { 68 // TODO: Directory ACLS! 69 return uint16_t_le2host(inode->size); 70 } 71 72 /** 73 * Get gid this inode belongs to 74 * 75 * @param inode pointer to inode 76 */ 77 inline uint32_t ext2_inode_get_group_id(ext2_inode_t *inode) 78 { 79 // TODO: use additional OS specific bits 80 return uint16_t_le2host(inode->group_id); 81 } 82 83 /** 84 * Get usage count (i.e. hard link count) 85 * A value of 1 is common, while 0 means that the inode should be freed 86 * 87 * @param inode pointer to inode 88 */ 89 inline uint16_t ext2_inode_get_usage_count(ext2_inode_t *inode) 90 { 91 return uint16_t_le2host(inode->usage_count); 92 } 93 94 /** 95 * Get size of inode in 512 byte blocks 96 * TODO: clarify this 97 * 98 * @param inode pointer to inode 99 */ 100 inline uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *inode) 101 { 102 return uint32_t_le2host(inode->reserved_512_blocks); 103 } 104 105 /** 106 * Get inode flags 107 * 108 * @param inode pointer to inode 109 */ 110 111 inline uint32_t ext2_inode_get_flags(ext2_inode_t *inode) { 112 return uint32_t_le2host(inode->flags); 113 } 114 115 /** 116 * Get direct block ID 117 * 118 * @param inode pointer to inode 119 * @param idx Index to block. Valid values are 0 <= idx < 12 120 */ 121 inline uint32_t ext2_inode_get_direct_block(ext2_inode_t *inode, uint8_t idx) 122 { 123 return uint32_t_le2host(inode->direct_blocks[idx]); 124 } 125 126 /** 127 * Get indirect block ID 128 * 129 * @param inode pointer to inode 130 */ 131 inline uint32_t ext2_inode_get_single_indirect_block(ext2_inode_t *inode) 132 { 133 return uint32_t_le2host(inode->single_indirect_block); 134 } 135 136 /** 137 * Get double indirect block ID 138 * 139 * @param inode pointer to inode 140 */ 141 inline uint32_t ext2_inode_get_double_indirect_block(ext2_inode_t *inode) 142 { 143 return uint32_t_le2host(inode->double_indirect_block); 144 } 145 146 /** 147 * Get triple indirect block ID 148 * 149 * @param inode pointer to inode 150 */ 151 inline uint32_t ext2_inode_get_triple_indirect_block(ext2_inode_t *inode) 152 { 153 return uint32_t_le2host(inode->triple_indirect_block); 154 } 40 155 41 156 -
uspace/lib/ext2/libext2_inode.h
rce13577 r5352d72 55 55 } ext2_inode_t; 56 56 57 #define EXT2_INODE_MODE_FIFO 0x1000 58 #define EXT2_INODE_MODE_CHARDEV 0x2000 59 #define EXT2_INODE_MODE_DIRECTORY 0x4000 60 #define EXT2_INODE_MODE_BLOCKDEV 0x6000 61 #define EXT2_INODE_MODE_FILE 0x8000 62 #define EXT2_INODE_MODE_SOFTLINK 0xA000 63 #define EXT2_INODE_MODE_SOCKET 0xC000 64 #define EXT2_INODE_MODE_ACCESS_MASK 0x0FFF 65 57 66 typedef struct ext2_inode_ref { 58 67 block_t *block; // Reference to a block containing this inode 59 68 ext2_inode_t *inode; 60 69 } ext2_inode_ref_t; 70 71 inline uint16_t ext2_inode_get_mode(ext2_inode_t *); 72 inline uint32_t ext2_inode_get_user_id(ext2_inode_t *); 73 inline uint32_t ext2_inode_get_size(ext2_inode_t *); 74 inline uint32_t ext2_inode_get_group_id(ext2_inode_t *); 75 inline uint16_t ext2_inode_get_usage_count(ext2_inode_t *); 76 inline uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *); 77 inline uint32_t ext2_inode_get_flags(ext2_inode_t *); 78 inline uint32_t ext2_inode_get_direct_block(ext2_inode_t *, uint8_t); 79 inline uint32_t ext2_inode_get_single_indirect_block(ext2_inode_t *); 80 inline uint32_t ext2_inode_get_double_indirect_block(ext2_inode_t *); 81 inline uint32_t ext2_inode_get_triple_indirect_block(ext2_inode_t *); 61 82 62 83
Note:
See TracChangeset
for help on using the changeset viewer.