On 02/08/2013 01:37 AM, Ian Kumlien wrote: > the btrfs command now lists: > btrfs rescue select-super -s <number> <device> > Select a superblock > btrfs rescue dump-super <device> > Dump a superblock to disk > btrfs rescue debug-tree [options] <device> > Debug the filesystem > > btrfs-dump-super.c was imported in to cmds-rescue-super-ops.c > > This patch integrates all the functionality... > > cmds-rescue.c is used to glue cmds-rescue-debug-tree.c, > cmds-rescue-restore.c and cmds-rescue-super-ops.c together to > make the source files more managable. [...] > -int main(int ac, char **av) > +const char * const cmd_dump_super_usage[] = { > + "btrfs rescue dump-super <device>", > + "Dump a superblock to disk", > + NULL > +}; [...] > +int cmd_dump_super(int argc, char **argv) > +{ > + int i; > + > + if (argc != 2) > + usage(cmd_dump_super_usage); > + > + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { > + u64 bytenr = btrfs_sb_offset(i); > + int fd; > + struct btrfs_super_block sb; > + int block_size = sizeof(struct btrfs_super_block); > + char filename[1024]; > + int bytes_read = read_block(argv[optind], bytenr, &sb); > + if (bytes_read < block_size) > + continue; I think that we should also implement a check of the superblock checksum.
> + > + sprintf(filename, "/tmp/block.%s.%llu", > + strrchr(argv[optind], '/') + 1, bytenr); > + fd = open(filename, O_CREAT|O_WRONLY, 0644); This is the part that I don't like. The output file name should be passed via the command line. It should not be defined by some obscure logic. The user is able to understand where the sb is written only after. > + if (block_size != pwrite(fd, &sb, block_size, 0)) { > + fprintf(stderr, "Failed to dump superblock %d", i); > + continue; > + } > + fprintf(stderr, "Dumped superblock %s:%d, gen %llu to %s.\n", > + argv[optind], i, sb.generation, filename); > + close(fd); > + } [...] -- gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it> Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html