@@ -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;
@@ -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."
@@ -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;
@@ -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);