void do_cleari(int argc, char *argv[]) { unsigned int inode; int err; int test_result, op_result; if (check_fs_open(argv[0])) return; if (argc != 2) { com_err(argv[0], 0, "Usage: clearb <inode>"); return; } inode = parse_ulong(argv[1], argv[0], "inode", &err); if (err) return; test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); op_result = ext2fs_unmark_inode_bitmap2(test_fs->inode_map, inode); printf("Clearing inode %u, was %s before\n", inode, op_result ? "set" : "clear"); if (!test_result != !op_result) { com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", test_result, op_result); exit_status++; } }
void do_testb(int argc, char *argv[]) { unsigned int block, num; int err; int test_result; if (check_fs_open(argv[0])) return; if (argc != 2 && argc != 3) { com_err(argv[0], 0, "Usage: testb <block> [num]"); return; } block = parse_ulong(argv[1], argv[0], "block", &err); if (err) return; if (argc == 3) { num = parse_ulong(argv[2], argv[0], "num", &err); if (err) return; test_result = ext2fs_test_block_bitmap_range2(test_fs->block_map, block, num); printf("Blocks %u to %u are %sall clear.\n", block, block + num - 1, test_result ? "" : "NOT "); return; } test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); printf("Block %u is %s\n", block, test_result ? "set" : "clear"); }
void close_cmd(int argc, char **argv) { if (check_fs_open(argv[0])) return; ext2fs_close_free(&test_fs); }
void do_ffsi(int argc, char *argv[]) { unsigned int start, end; int err; errcode_t retval; ext2_ino_t out; if (check_fs_open(argv[0])) return; if (argc != 3 && argc != 3) { com_err(argv[0], 0, "Usage: ffsi <start> <end>"); return; } start = parse_ulong(argv[1], argv[0], "start", &err); if (err) return; end = parse_ulong(argv[2], argv[0], "end", &err); if (err) return; retval = ext2fs_find_first_set_inode_bitmap2(test_fs->inode_map, start, end, &out); if (retval) { printf("ext2fs_find_first_set_inode_bitmap2() returned %s\n", error_message(retval)); return; } printf("First marked inode is %u\n", out); }
void do_dirsearch(int argc, char *argv[]) { ext2_ino_t inode; struct process_block_struct pb; if (check_fs_open(argv[0])) return; if (argc != 3) { com_err(0, 0, "Usage: dirsearch dir filename"); return; } inode = string_to_inode(argv[1]); if (!inode) return; pb.buf = malloc(current_fs->blocksize); if (!pb.buf) { com_err("dirsearch", 0, "Couldn't allocate buffer"); return; } pb.search_name = argv[2]; pb.len = strlen(pb.search_name); ext2fs_block_iterate2(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0, search_dir_block, &pb); free(pb.buf); }
void do_zerob(int argc, char *argv[]) { if (check_fs_open(argv[0])) return; printf("Clearing block bitmap.\n"); ext2fs_clear_block_bitmap(test_fs->block_map); }
void do_zeroi(int argc, char *argv[]) { if (check_fs_open(argv[0])) return; printf("Clearing inode bitmap.\n"); ext2fs_clear_inode_bitmap(test_fs->inode_map); }
void dump_inode_bitmap_cmd(int argc, char **argv) { if (check_fs_open(argv[0])) return; printf("inode bitmap: "); dump_bitmap(test_fs->inode_map, 1, test_fs->super->s_inodes_count); }
void dump_block_bitmap_cmd(int argc, char **argv) { if (check_fs_open(argv[0])) return; printf("block bitmap: "); dump_bitmap(test_fs->block_map, test_fs->super->s_first_data_block, test_fs->super->s_blocks_count); }
void do_show_super_stats(int argc, char *argv[]) { dgrp_t i; FILE *out; struct ext2_group_desc *gdp; int c, header_only = 0; int numdirs = 0; const char *usage = "Usage: show_super [-h]"; reset_getopt(); while ((c = getopt (argc, argv, "h")) != EOF) { switch (c) { case 'h': header_only++; break; default: com_err(argv[0], 0, usage); return; } } if (optind != argc) { com_err(argv[0], 0, usage); return; } if (check_fs_open(argv[0])) return; out = open_pager(); list_super2(current_fs->super, out); for (i=0; i < current_fs->group_desc_count; i++) numdirs += current_fs->group_desc[i].bg_used_dirs_count; fprintf(out, "Directories: %d\n", numdirs); if (header_only) { close_pager(out); return; } gdp = ¤t_fs->group_desc[0]; for (i = 0; i < current_fs->group_desc_count; i++, gdp++) fprintf(out, " Group %2d: block bitmap at %d, " "inode bitmap at %d, " "inode table at %d\n" " %d free %s, " "%d free %s, " "%d used %s\n", i, gdp->bg_block_bitmap, gdp->bg_inode_bitmap, gdp->bg_inode_table, gdp->bg_free_blocks_count, gdp->bg_free_blocks_count != 1 ? "blocks" : "block", gdp->bg_free_inodes_count, gdp->bg_free_inodes_count != 1 ? "inodes" : "inode", gdp->bg_used_dirs_count, gdp->bg_used_dirs_count != 1 ? "directories" : "directory"); close_pager(out); }
void do_dump(int argc, char **argv) { ext2_ino_t inode; int fd; int c; int preserve = 0; char *in_fn, *out_fn; reset_getopt(); while ((c = getopt (argc, argv, "p")) != EOF) { switch (c) { case 'p': preserve++; break; default: print_usage: com_err(argv[0], 0, "Usage: dump_inode [-p] " "<file> <output_file>"); return; } } if (optind != argc-2) goto print_usage; if (check_fs_open(argv[0])) return; in_fn = argv[optind]; out_fn = argv[optind+1]; inode = string_to_inode(in_fn); if (!inode) return; fd = open(out_fn, O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE, 0666); if (fd < 0) { com_err(argv[0], errno, "while opening %s for dump_inode", out_fn); return; } dump_file(argv[0], inode, fd, preserve, out_fn); if (close(fd) != 0) { com_err(argv[0], errno, "while closing %s for dump_inode", out_fn); return; } return; }
void do_rm_xattr(int argc, char **argv) { ext2_ino_t ino; struct ext2_xattr_handle *h; int i; errcode_t err; if (argc < 3) { printf("%s: Usage: %s <file> <attrs>...\n", argv[0], argv[0]); return; } if (check_fs_open(argv[0])) return; if (check_fs_read_write(argv[0])) return; if (check_fs_bitmaps(argv[0])) return; ino = string_to_inode(argv[1]); if (!ino) return; err = ext2fs_xattrs_open(current_fs, ino, &h); if (err) return; err = ext2fs_xattrs_read(h); if (err) goto out; for (i = 2; i < argc; i++) { size_t buflen; char *buf; err = ext2fs_xattr_remove(h, argv[i]); if (err) goto out; } err = ext2fs_xattrs_write(h); if (err) goto out; out: ext2fs_xattrs_close(&h); if (err) com_err(argv[0], err, "while removing extended attribute"); }
void do_extent_open(int argc, char *argv[]) { ext2_ino_t inode; int ret; errcode_t retval; char *cp; if (check_fs_open(argv[0])) return; if (argc == 1) { if (current_ino) printf("Current inode is %d\n", current_ino); else printf("No current inode\n"); return; } if (common_inode_args_process(argc, argv, &inode, 0)) return; current_ino = 0; retval = ext2fs_extent_open(current_fs, inode, ¤t_handle); if (retval) { com_err(argv[1], retval, "while opening extent handle"); return; } current_ino = inode; orig_prompt = ss_get_prompt(sci_idx); extent_prompt = malloc(strlen(orig_prompt) + 32); strcpy(extent_prompt, orig_prompt); cp = strchr(extent_prompt, ':'); if (cp) *cp = 0; sprintf(extent_prompt + strlen(extent_prompt), " (extent ino %d): ", current_ino); ss_add_request_table(sci_idx, &extent_cmds, 1, &ret); ss_set_prompt(sci_idx, extent_prompt); return; }
void do_list_xattr(int argc, char **argv) { ext2_ino_t ino; if (argc != 2) { printf("%s: Usage: %s <file>\n", argv[0], argv[0]); return; } if (check_fs_open(argv[0])) return; ino = string_to_inode(argv[1]); if (!ino) return; dump_inode_attributes(stdout, ino); }
/* * This is a common helper function used by the command processing * routines */ int common_args_process(int argc, char *argv[], int min_argc, int max_argc, const char *cmd, const char *usage, int flags) { if (argc < min_argc || argc > max_argc) { com_err(argv[0], 0, "Usage: %s %s", cmd, usage); return 1; } if (flags & CHECK_FS_NOTOPEN) { if (check_fs_not_open(argv[0])) return 1; } else { if (check_fs_open(argv[0])) return 1; } if ((flags & CHECK_FS_RW) && check_fs_read_write(argv[0])) return 1; if ((flags & CHECK_FS_BITMAPS) && check_fs_bitmaps(argv[0])) return 1; return 0; }
void do_testi(int argc, char *argv[]) { unsigned int inode; int err; int test_result; if (check_fs_open(argv[0])) return; if (argc != 2) { com_err(argv[0], 0, "Usage: testb <inode>"); return; } inode = parse_ulong(argv[1], argv[0], "inode", &err); if (err) return; test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); printf("Inode %u is %s\n", inode, test_result ? "set" : "clear"); }
static int load_quota_ctx(char *progname) { errcode_t retval; if (check_fs_open(progname)) return 1; if (!ext2fs_has_feature_quota(current_fs->super)) { com_err(progname, 0, "quota feature not enabled"); return 1; } if (current_qctx) return 0; retval = quota_init_context(¤t_qctx, current_fs, QUOTA_ALL_BIT); if (retval) { com_err(current_fs->device_name, retval, "while trying to load quota information"); return 1; } return 0; }
void do_clearb(int argc, char *argv[]) { unsigned int block, num; int err; int test_result, op_result; if (check_fs_open(argv[0])) return; if (argc != 2 && argc != 3) { com_err(argv[0], 0, "Usage: clearb <block> [num]"); return; } block = parse_ulong(argv[1], argv[0], "block", &err); if (err) return; if (argc == 3) { num = parse_ulong(argv[2], argv[0], "num", &err); if (err) return; ext2fs_unmark_block_bitmap_range2(test_fs->block_map, block, num); printf("Clearing blocks %u to %u\n", block, block + num - 1); return; } test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); op_result = ext2fs_unmark_block_bitmap2(test_fs->block_map, block); printf("Clearing block %u, was %s before\n", block, op_result ? "set" : "clear"); if (!test_result != !op_result) com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", test_result, op_result); }
void do_journal_run(int argc, char *argv[]) { errcode_t err; if (check_fs_open(argv[0])) return; if (check_fs_read_write(argv[0])) return; if (check_fs_bitmaps(argv[0])) return; if (current_journal) { printf("Please close the journal before recovering it.\n"); return; } err = ext2fs_run_ext3_journal(¤t_fs); if (err) com_err("journal_run", err, "while recovering journal"); else { current_fs->super->s_feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER; ext2fs_mark_super_dirty(current_fs); } }
static int load_quota_ctx(char *progname) { errcode_t retval; if (check_fs_open(progname)) return 1; if (!EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super, EXT4_FEATURE_RO_COMPAT_QUOTA)) { com_err(progname, 0, "quota feature not enabled"); return 1; } if (current_qctx) return 0; retval = quota_init_context(¤t_qctx, current_fs, -1); if (retval) { com_err(current_fs->device_name, retval, "while trying to load quota information"); return 1; } return 0; }
void do_htree_dump(int argc, char *argv[]) { ext2_ino_t ino; struct ext2_inode inode; int c; int long_opt = 0; blk_t blk; char *buf = NULL; struct ext2_dx_root_info *rootnode; struct ext2_dx_entry *ent; struct ext2_dx_countlimit *limit; errcode_t errcode; if (check_fs_open(argv[0])) return; pager = open_pager(); reset_getopt(); while ((c = getopt (argc, argv, "l")) != EOF) { switch (c) { case 'l': long_opt++; break; default: goto print_usage; } } if (argc > optind+1) { print_usage: com_err(0, 0, "Usage: htree_dump [-l] file"); goto errout; } if (argc == optind) ino = cwd; else ino = string_to_inode(argv[optind]); if (!ino) goto errout; if (debugfs_read_inode(ino, &inode, argv[1])) goto errout; if (!LINUX_S_ISDIR(inode.i_mode)) { com_err(argv[0], 0, "Not a directory"); goto errout; } if ((inode.i_flags & EXT2_BTREE_FL) == 0) { com_err(argv[0], 0, "Not a hash-indexed directory"); goto errout; } buf = malloc(2*current_fs->blocksize); if (!buf) { com_err(argv[0], 0, "Couldn't allocate htree buffer"); goto errout; } errcode = ext2fs_bmap(current_fs, ino, &inode, buf, 0, 0, &blk); if (errcode) { com_err("do_htree_block", errcode, "while mapping logical block 0\n"); goto errout; } errcode = io_channel_read_blk(current_fs->io, blk, 1, buf); if (errcode) { com_err(argv[0], errcode, "Error reading root node"); goto errout; } rootnode = (struct ext2_dx_root_info *) (buf + 24); fprintf(pager, "Root node dump:\n"); fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero); fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version); fprintf(pager, "\t Info length: %d\n", rootnode->info_length); fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels); fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags); ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length); limit = (struct ext2_dx_countlimit *) ent; htree_dump_int_node(current_fs, ino, &inode, rootnode, ent, buf + current_fs->blocksize, rootnode->indirect_levels); errout: free(buf); close_pager(pager); }
void do_journal_open(int argc, char *argv[]) { int opt, enable_csum = 0, csum_ver = 3; journal_t *journal; errcode_t err; if (check_fs_open(argv[0])) return; if (check_fs_read_write(argv[0])) return; if (check_fs_bitmaps(argv[0])) return; if (current_journal) { printf("Journal is already open.\n"); return; } if (!EXT2_HAS_COMPAT_FEATURE(current_fs->super, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { printf("Journalling is not enabled on this filesystem.\n"); return; } reset_getopt(); while ((opt = getopt(argc, argv, "cv:f:")) != -1) { switch (opt) { case 'c': enable_csum = 1; break; case 'f': if (current_fs->journal_name) free(current_fs->journal_name); current_fs->journal_name = strdup(optarg); break; case 'v': csum_ver = atoi(optarg); if (csum_ver != 2 && csum_ver != 3) { printf("Unknown journal csum v%d\n", csum_ver); csum_ver = 3; } break; default: printf("%s: [-c] [-v ver] [-f ext_jnl]\n", argv[0]); printf("-c: Enable journal checksumming.\n"); printf("-v: Use this version checksum format.\n"); printf("-j: Load this external journal.\n"); } } err = ext2fs_open_journal(current_fs, ¤t_journal); if (err) { com_err(argv[0], err, "while opening journal"); return; } journal = current_journal; dbg_printf("JOURNAL: seq=%d tailseq=%d start=%lu first=%lu " "maxlen=%lu\n", journal->j_tail_sequence, journal->j_transaction_sequence, journal->j_tail, journal->j_first, journal->j_last); update_uuid(journal); update_64bit_flag(journal); if (enable_csum) update_journal_csum(journal, csum_ver); err = journal_find_head(journal); if (err) com_err(argv[0], err, "while examining journal"); }
void do_logdump(int argc, char **argv) { int c; int retval; char *out_fn; FILE *out_file; char *inode_spec = NULL; char *journal_fn = NULL; int journal_fd = 0; int use_sb = 0; ext2_ino_t journal_inum; struct ext2_inode journal_inode; ext2_file_t journal_file; char *tmp; struct journal_source journal_source; struct ext2_super_block *es = NULL; journal_source.where = 0; journal_source.fd = 0; journal_source.file = 0; dump_all = 0; dump_contents = 0; dump_descriptors = 1; block_to_dump = ANY_BLOCK; bitmap_to_dump = -1; inode_block_to_dump = ANY_BLOCK; inode_to_dump = -1; reset_getopt(); while ((c = getopt (argc, argv, "ab:ci:f:s")) != EOF) { switch (c) { case 'a': dump_all++; break; case 'b': block_to_dump = strtoul(optarg, &tmp, 0); if (*tmp) { com_err(argv[0], 0, "Bad block number - %s", optarg); return; } dump_descriptors = 0; break; case 'c': dump_contents++; break; case 'f': journal_fn = optarg; break; case 'i': inode_spec = optarg; dump_descriptors = 0; break; case 's': use_sb++; break; default: goto print_usage; } } if (optind != argc && optind != argc-1) { goto print_usage; } if (current_fs) es = current_fs->super; if (inode_spec) { int inode_group, group_offset, inodes_per_block; if (check_fs_open(argv[0])) return; inode_to_dump = string_to_inode(inode_spec); if (!inode_to_dump) return; inode_group = ((inode_to_dump - 1) / es->s_inodes_per_group); group_offset = ((inode_to_dump - 1) % es->s_inodes_per_group); inodes_per_block = (current_fs->blocksize / sizeof(struct ext2_inode)); inode_block_to_dump = current_fs->group_desc[inode_group].bg_inode_table + (group_offset / inodes_per_block); inode_offset_to_dump = ((group_offset % inodes_per_block) * sizeof(struct ext2_inode)); printf("Inode %u is at group %u, block %u, offset %u\n", inode_to_dump, inode_group, inode_block_to_dump, inode_offset_to_dump); } if (optind == argc) { out_file = stdout; } else { out_fn = argv[optind]; out_file = fopen(out_fn, "w"); if (!out_file < 0) { com_err(argv[0], errno, "while opening %s for logdump", out_fn); return; } } if (block_to_dump != ANY_BLOCK && current_fs != NULL) { group_to_dump = ((block_to_dump - es->s_first_data_block) / es->s_blocks_per_group); bitmap_to_dump = current_fs->group_desc[group_to_dump].bg_block_bitmap; } if (!journal_fn && check_fs_open(argv[0])) return; if (journal_fn) { /* Set up to read journal from a regular file somewhere */ journal_fd = open(journal_fn, O_RDONLY, 0); if (journal_fd < 0) { com_err(argv[0], errno, "while opening %s for logdump", journal_fn); return; } journal_source.where = JOURNAL_IS_EXTERNAL; journal_source.fd = journal_fd; } else if ((journal_inum = es->s_journal_inum)) { if (use_sb) { if (es->s_jnl_backup_type != EXT3_JNL_BACKUP_BLOCKS) { com_err(argv[0], 0, "no journal backup in super block\n"); return; } memset(&journal_inode, 0, sizeof(struct ext2_inode)); memcpy(&journal_inode.i_block[0], es->s_jnl_blocks, EXT2_N_BLOCKS*4); journal_inode.i_size = es->s_jnl_blocks[16]; journal_inode.i_links_count = 1; journal_inode.i_mode = LINUX_S_IFREG | 0600; } else { if (debugfs_read_inode(journal_inum, &journal_inode, argv[0])) return; } retval = ext2fs_file_open2(current_fs, journal_inum, &journal_inode, 0, &journal_file); if (retval) { com_err(argv[0], retval, "while opening ext2 file"); return; } journal_source.where = JOURNAL_IS_INTERNAL; journal_source.file = journal_file; } else { char uuid[37]; uuid_unparse(es->s_journal_uuid, uuid); journal_fn = blkid_get_devname(NULL, "UUID", uuid); if (!journal_fn) journal_fn = blkid_devno_to_devname(es->s_journal_dev); if (!journal_fn) { com_err(argv[0], 0, "filesystem has no journal"); return; } journal_fd = open(journal_fn, O_RDONLY, 0); if (journal_fd < 0) { com_err(argv[0], errno, "while opening %s for logdump", journal_fn); free(journal_fn); return; } fprintf(out_file, "Using external journal found at %s\n", journal_fn); free(journal_fn); journal_source.where = JOURNAL_IS_EXTERNAL; journal_source.fd = journal_fd; } dump_journal(argv[0], out_file, &journal_source); if (journal_source.where == JOURNAL_IS_INTERNAL) ext2fs_file_close(journal_file); else close(journal_fd); if (out_file != stdout) fclose(out_file); return; print_usage: fprintf(stderr, "%s: Usage: logdump [-ac] [-b<block>] [-i<inode>]\n\t" "[-f<journal_file>] [output_file]\n", argv[0]); }
void do_show_super_stats(int argc, char *argv[]) { dgrp_t i; FILE *out; struct ext2_group_desc *gdp; int c, header_only = 0; int numdirs = 0, first, gdt_csum; reset_getopt(); while ((c = getopt (argc, argv, "h")) != EOF) { switch (c) { case 'h': header_only++; break; default: goto print_usage; } } if (optind != argc) { goto print_usage; } if (check_fs_open(argv[0])) return; out = open_pager(); list_super2(current_fs->super, out); for (i=0; i < current_fs->group_desc_count; i++) numdirs += current_fs->group_desc[i].bg_used_dirs_count; fprintf(out, "Directories: %d\n", numdirs); if (header_only) { close_pager(out); return; } gdt_csum = EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM); gdp = ¤t_fs->group_desc[0]; for (i = 0; i < current_fs->group_desc_count; i++, gdp++) { fprintf(out, " Group %2d: block bitmap at %u, " "inode bitmap at %u, " "inode table at %u\n" " %d free %s, " "%d free %s, " "%d used %s%s", i, gdp->bg_block_bitmap, gdp->bg_inode_bitmap, gdp->bg_inode_table, gdp->bg_free_blocks_count, gdp->bg_free_blocks_count != 1 ? "blocks" : "block", gdp->bg_free_inodes_count, gdp->bg_free_inodes_count != 1 ? "inodes" : "inode", gdp->bg_used_dirs_count, gdp->bg_used_dirs_count != 1 ? "directories" : "directory", gdt_csum ? ", " : "\n"); if (gdt_csum) fprintf(out, "%d unused %s\n", gdp->bg_itable_unused, gdp->bg_itable_unused != 1 ? "inodes":"inode"); first = 1; print_bg_opts(gdp, EXT2_BG_INODE_UNINIT, "Inode not init", &first, out); print_bg_opts(gdp, EXT2_BG_BLOCK_UNINIT, "Block not init", &first, out); if (gdt_csum) { fprintf(out, "%sChecksum 0x%04x", first ? " [":", ", gdp->bg_checksum); first = 0; } if (!first) fputs("]\n", out); } close_pager(out); return; print_usage: fprintf(stderr, "%s: Usage: show_super [-h]\n", argv[0]); }
void do_htree_dump(int argc, char *argv[]) { ext2_ino_t ino; struct ext2_inode inode; blk64_t blk; char *buf = NULL; struct ext2_dx_root_info *rootnode; struct ext2_dx_entry *ent; errcode_t errcode; if (check_fs_open(argv[0])) return; pager = open_pager(); if (common_inode_args_process(argc, argv, &ino, 0)) goto errout; if (debugfs_read_inode(ino, &inode, argv[1])) goto errout; if (!LINUX_S_ISDIR(inode.i_mode)) { com_err(argv[0], 0, "Not a directory"); goto errout; } if ((inode.i_flags & EXT2_BTREE_FL) == 0) { com_err(argv[0], 0, "Not a hash-indexed directory"); goto errout; } buf = malloc(2*current_fs->blocksize); if (!buf) { com_err(argv[0], 0, "Couldn't allocate htree buffer"); goto errout; } errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk); if (errcode) { com_err("do_htree_block", errcode, "while mapping logical block 0\n"); goto errout; } errcode = io_channel_read_blk64(current_fs->io, blk, 1, buf); if (errcode) { com_err(argv[0], errcode, "Error reading root node"); goto errout; } rootnode = (struct ext2_dx_root_info *) (buf + 24); fprintf(pager, "Root node dump:\n"); fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero); fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version); fprintf(pager, "\t Info length: %d\n", rootnode->info_length); fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels); fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags); ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length); htree_dump_int_node(current_fs, ino, &inode, rootnode, ent, buf + current_fs->blocksize, rootnode->indirect_levels); errout: free(buf); close_pager(pager); }
void do_set_xattr(int argc, char **argv) { ext2_ino_t ino; struct ext2_xattr_handle *h; FILE *fp = NULL; char *buf = NULL; size_t buflen; unsigned int handle_flags = 0; int i; errcode_t err; reset_getopt(); while ((i = getopt(argc, argv, "f:r")) != -1) { switch (i) { case 'f': if (fp) fclose(fp); fp = fopen(optarg, "r"); if (fp == NULL) { perror(optarg); return; } break; case 'r': handle_flags |= XATTR_HANDLE_FLAG_RAW; break; default: goto print_usage; } } if (!(fp && optind == argc - 2) && !(!fp && optind == argc - 3)) { print_usage: printf("Usage:\t%s [-r] <file> <attr> <value>\n", argv[0]); printf("\t%s -f <value_file> [-r] <file> <attr>\n", argv[0]); goto out2; } if (check_fs_open(argv[0])) goto out2; if (check_fs_read_write(argv[0])) goto out2; if (check_fs_bitmaps(argv[0])) goto out2; ino = string_to_inode(argv[optind]); if (!ino) goto out2; err = ext2fs_xattrs_open(current_fs, ino, &h); if (err) goto out2; err = ext2fs_xattrs_flags(h, &handle_flags, NULL); if (err) goto out; err = ext2fs_xattrs_read(h); if (err) goto out; if (fp) { err = ext2fs_get_mem(current_fs->blocksize, &buf); if (err) goto out; buflen = fread(buf, 1, current_fs->blocksize, fp); } else { buf = argv[optind + 2]; buflen = parse_c_string(buf); } err = ext2fs_xattr_set(h, argv[optind + 1], buf, buflen); out: ext2fs_xattrs_close(&h); if (err) com_err(argv[0], err, "while setting extended attribute"); out2: if (fp) { fclose(fp); ext2fs_free_mem(&buf); } }
void do_get_xattr(int argc, char **argv) { ext2_ino_t ino; struct ext2_xattr_handle *h; FILE *fp = NULL; char *buf = NULL; size_t buflen; int i; int print_flags = 0; unsigned int handle_flags = 0; errcode_t err; reset_getopt(); while ((i = getopt(argc, argv, "Cf:rxV")) != -1) { switch (i) { case 'f': if (fp) fclose(fp); fp = fopen(optarg, "w"); if (fp == NULL) { perror(optarg); return; } break; case 'r': handle_flags |= XATTR_HANDLE_FLAG_RAW; break; case 'x': print_flags |= PRINT_XATTR_HEX; break; case 'V': print_flags |= PRINT_XATTR_RAW| PRINT_XATTR_NOQUOTES; break; case 'C': print_flags |= PRINT_XATTR_C; break; default: goto usage; } } if (optind != argc - 2) { usage: printf("%s: Usage: %s [-f outfile]|[-xVC] [-r] <file> <attr>\n", argv[0], argv[0]); goto out2; } if (check_fs_open(argv[0])) goto out2; ino = string_to_inode(argv[optind]); if (!ino) goto out2; err = ext2fs_xattrs_open(current_fs, ino, &h); if (err) goto out2; err = ext2fs_xattrs_flags(h, &handle_flags, NULL); if (err) goto out; err = ext2fs_xattrs_read(h); if (err) goto out; err = ext2fs_xattr_get(h, argv[optind + 1], (void **)&buf, &buflen); if (err) goto out; if (fp) { fwrite(buf, buflen, 1, fp); } else { if (print_flags & PRINT_XATTR_RAW) { if (print_flags & (PRINT_XATTR_HEX|PRINT_XATTR_C)) print_flags &= ~PRINT_XATTR_RAW; print_xattr_string(stdout, buf, buflen, print_flags); } else { print_xattr(stdout, argv[optind + 1], buf, buflen, print_flags); } printf("\n"); } ext2fs_free_mem(&buf); out: ext2fs_xattrs_close(&h); if (err) com_err(argv[0], err, "while getting extended attribute"); out2: if (fp) fclose(fp); }
void do_set_xattr(int argc, char **argv) { ext2_ino_t ino; struct ext2_xattr_handle *h; FILE *fp = NULL; char *buf = NULL; size_t buflen; int i; errcode_t err; reset_getopt(); while ((i = getopt(argc, argv, "f:")) != -1) { switch (i) { case 'f': fp = fopen(optarg, "r"); if (fp == NULL) { perror(optarg); return; } break; default: printf("%s: Usage: %s <file> <attr> [-f infile | " "value]\n", argv[0], argv[0]); return; } } if (optind != argc - 2 && optind != argc - 3) { printf("%s: Usage: %s <file> <attr> [-f infile | value>]\n", argv[0], argv[0]); return; } if (check_fs_open(argv[0])) return; if (check_fs_read_write(argv[0])) return; if (check_fs_bitmaps(argv[0])) return; ino = string_to_inode(argv[optind]); if (!ino) return; err = ext2fs_xattrs_open(current_fs, ino, &h); if (err) return; err = ext2fs_xattrs_read(h); if (err) goto out; if (fp) { err = ext2fs_get_mem(current_fs->blocksize, &buf); if (err) goto out; buflen = fread(buf, 1, current_fs->blocksize, fp); } else { buf = argv[optind + 2]; buflen = strlen(argv[optind + 2]); } err = ext2fs_xattr_set(h, argv[optind + 1], buf, buflen); if (err) goto out; err = ext2fs_xattrs_write(h); if (err) goto out; out: if (fp) { fclose(fp); ext2fs_free_mem(&buf); } ext2fs_xattrs_close(&h); if (err) com_err(argv[0], err, "while setting extended attribute"); }
void do_get_xattr(int argc, char **argv) { ext2_ino_t ino; struct ext2_xattr_handle *h; FILE *fp = NULL; char *buf = NULL; size_t buflen; int i; errcode_t err; reset_getopt(); while ((i = getopt(argc, argv, "f:")) != -1) { switch (i) { case 'f': fp = fopen(optarg, "w"); if (fp == NULL) { perror(optarg); return; } break; default: printf("%s: Usage: %s <file> <attr> [-f outfile]\n", argv[0], argv[0]); return; } } if (optind != argc - 2) { printf("%s: Usage: %s <file> <attr> [-f outfile]\n", argv[0], argv[0]); return; } if (check_fs_open(argv[0])) return; ino = string_to_inode(argv[optind]); if (!ino) return; err = ext2fs_xattrs_open(current_fs, ino, &h); if (err) return; err = ext2fs_xattrs_read(h); if (err) goto out; err = ext2fs_xattr_get(h, argv[optind + 1], (void **)&buf, &buflen); if (err) goto out; if (fp) { fwrite(buf, buflen, 1, fp); fclose(fp); } else { dump_xattr_string(stdout, buf, buflen); printf("\n"); } if (buf) ext2fs_free_mem(&buf); out: ext2fs_xattrs_close(&h); if (err) com_err(argv[0], err, "while getting extended attribute"); }