@@ -18,6 +18,11 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ctree.h"
+#include "disk-io.h"
#include "debug_btrfs.h"
void do_show_debugfs_params(int argc, char *argv[])
@@ -25,3 +30,21 @@ void do_show_debugfs_params(int argc, char *argv[])
FILE *out = stdout;
fprintf(out, "Filesystem in use: %s\n", current_device);
}
+
+void do_open_filesys(int argc, char *argv[])
+{
+ if (argc != 1) {
+ free((void *)current_device);
+ current_device = strdup(argv[1]);
+ }
+
+ if (current_fs_root)
+ close_ctree(current_fs_root);
+
+ radix_tree_init();
+ current_fs_root = open_ctree(current_device, 0, 0);
+ if (!current_fs_root) {
+ fprintf(stderr, "unable to open %s\n", current_device);
+ return;
+ }
+}
@@ -19,27 +19,25 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ss/ss.h>
#include "debug_btrfs.h"
extern ss_request_table btrfs_debug_cmds;
const char *current_device;
-
-void usage(char *prg)
-{
- fprintf(stderr, "Usage: %s device\n", prg);
- exit(1);
-}
+struct btrfs_root *current_fs_root;
+extern void do_open_filesys(int argc, char *argv[]);
int main(int argc, char *argv[])
{
int sci_idx;
int retval;
- if (argc < 2)
- usage(argv[0]);
+ if (argc != 1) {
+ /* open the file system */
+ do_open_filesys(argc, argv);
+ }
- current_device = argv[1];
sci_idx = ss_create_invocation("debug-btrfs", "0.0", NULL,
&btrfs_debug_cmds, &retval);
if (retval) {
@@ -22,6 +22,7 @@
#include <getopt.h>
extern const char *current_device;
+extern struct btrfs_root *current_fs_root;
static inline void reset_getopt(void)
{
optind = 0;
@@ -20,5 +20,8 @@ command_table btrfs_debug_cmds;
request do_show_debugfs_params, "Show btrfs_debug parameters",
show_debugfs_params, params;
+request do_open_filesys, "Open the file system",
+ open_filesys, open;
+
end;