#include <unistd.h>
#include <dirent.h>
#include <uuid/uuid.h>
+#include <getopt.h>
#include "kerncompat.h"
#include "ctree.h"
{
uuid_t new_fsid;
uuid_t new_chunk_id;
+ uuid_t old_fsid;
char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
int ret = 0;
fs_info->new_fsid = new_fsid;
fs_info->new_chunk_tree_uuid = new_chunk_id;
- uuid_unparse_upper(new_fsid, uuid_buf);
- printf("Changing fsid to %s\n", uuid_buf);
+ memcpy(old_fsid, (const char*)fs_info->fsid, BTRFS_UUID_SIZE);
+ uuid_unparse(old_fsid, uuid_buf);
+ printf("Current fsid: %s\n", uuid_buf);
+
+ uuid_unparse(new_fsid, uuid_buf);
+ printf("New fsid: %s\n", uuid_buf);
/* Now we can begin fsid change */
+ printf("Set superblock flag CHANGING_FSID\n");
ret = change_fsid_prepare(fs_info);
if (ret < 0)
goto out;
/* Change extents first */
+ printf("Change fsid in extents\n");
ret = change_extents_uuid(fs_info);
if (ret < 0) {
fprintf(stderr, "Failed to change UUID of metadata\n");
}
/* Then devices */
+ printf("Change fsid on devices\n");
ret = change_devices_uuid(fs_info);
if (ret < 0) {
fprintf(stderr, "Failed to change UUID of devices\n");
goto out;
/* Now fsid change is done */
+ printf("Clear superblock flag CHANGING_FSID\n");
ret = change_fsid_done(fs_info);
fs_info->new_fsid = NULL;
fs_info->new_chunk_tree_uuid = NULL;
- printf("Fsid changed to %s\n", uuid_buf);
+ printf("Fsid change finished\n");
out:
return ret;
}
optind = 1;
while(1) {
- int c = getopt(argc, argv, "S:rxfuU:n");
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, GETOPT_VAL_HELP},
+ { NULL, 0, NULL, 0 }
+ };
+ int c = getopt_long(argc, argv, "S:rxfuU:n", long_options, NULL);
+
if (c < 0)
break;
switch(c) {
ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH;
random_fsid = 1;
break;
+ case GETOPT_VAL_HELP:
default:
print_usage();
- return 1;
+ return c != GETOPT_VAL_HELP;
}
}