diff mbox

Patch to provide "btrfs subvolume last-gen".

Message ID 4CD12A16.4070802@support.tummy.com
State New, archived
Headers show

Commit Message

Sean Reifschneider Nov. 3, 2010, 9:23 a.m. UTC
None
diff mbox

Patch

diff --git a/btrfs-list.c b/btrfs-list.c
index 93766a8..7e4a282 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -310,7 +310,7 @@  static int lookup_ino_path(int fd, struct root_info *ri)
  * Then we use the tree search ioctl to scan all the root items for a
  * given root id and spit out the latest generation we can find
  */
-static u64 find_root_gen(int fd)
+u64 find_root_gen(int fd)
 {
 	struct btrfs_ioctl_ino_lookup_args ino_args;
 	int ret;
diff --git a/btrfs.c b/btrfs.c
index 46314cf..188b451 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -64,6 +64,9 @@  static struct Command commands[] = {
 	{ do_find_newer, 2, "subvolume find-new", "<path> <last_gen>\n"
 		"List the recently modified files in a filesystem."
 	},
+	{ do_get_latest_gen, 1, "subvolume last-gen", "<path>\n"
+		"Return the latest generation of a filesystem."
+	},
 	{ do_defrag, -1,
 	  "filesystem defragment", "[-vcf] [-s start] [-l len] [-t size] <file>|<dir> [<file>|<dir>...]\n"
 		"Defragment a file or a directory."
diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 8031c58..25eafb8 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -247,6 +247,35 @@  int do_defrag(int ac, char **av)
 	return errors + 20;
 }
 
+int do_get_latest_gen(int argc, char **argv)
+{
+	int fd;
+	int ret;
+	char *subvol;
+	u64 max_found = 0;
+
+	subvol = argv[1];
+
+	ret = test_issubvolume(subvol);
+	if (ret < 0) {
+		fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
+		return 12;
+	}
+	if (!ret) {
+		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
+		return 13;
+	}
+
+	fd = open_file_or_dir(subvol);
+	if (fd < 0) {
+		fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
+		return 12;
+	}
+	max_found = find_root_gen(fd);
+	printf("transid marker was %llu\n", (unsigned long long)max_found);
+	return 0;
+}
+
 int do_find_newer(int argc, char **argv)
 {
 	int fd;
diff --git a/btrfs_cmds.h b/btrfs_cmds.h
index 7bde191..ea4e18e 100644
--- a/btrfs_cmds.h
+++ b/btrfs_cmds.h
@@ -20,6 +20,7 @@  int do_delete_subvolume(int nargs, char **argv);
 int do_create_subvol(int nargs, char **argv);
 int do_fssync(int nargs, char **argv);
 int do_defrag(int argc, char **argv);
+int do_get_latest_gen(int argc, char **argv);
 int do_show_filesystem(int nargs, char **argv);
 int do_add_volume(int nargs, char **args);
 int do_balance(int nargs, char **argv);
@@ -32,3 +33,4 @@  int list_subvols(int fd);
 int do_df_filesystem(int nargs, char **argv);
 int find_updated_files(int fd, u64 root_id, u64 oldest_gen);
 int do_find_newer(int argc, char **argv);
+u64 find_root_gen(int fd);