#include <linux/magic.h>
#include <getopt.h>
#include <sys/utsname.h>
+#include <linux/version.h>
#include "kerncompat.h"
#include "radix-tree.h"
return ret;
}
+#define VERSION_TO_STRING3(a,b,c) #a "." #b "." #c, KERNEL_VERSION(a,b,c)
+#define VERSION_TO_STRING2(a,b) #a "." #b, KERNEL_VERSION(a,b,0)
+
+/*
+ * Feature stability status and versions: compat <= safe <= default
+ */
static const struct btrfs_fs_feature {
const char *name;
u64 flag;
+ const char *sysfs_name;
+ /*
+ * Compatibility with kernel of given version. Filesystem can be
+ * mounted.
+ */
+ const char *compat_str;
+ u32 compat_ver;
+ /*
+ * Considered safe for use, but is not on by default, even if the
+ * kernel supports the feature.
+ */
+ const char *safe_str;
+ u32 safe_ver;
+ /*
+ * Considered safe for use and will be turned on by default if
+ * supported by the running kernel.
+ */
+ const char *default_str;
+ u32 default_ver;
const char *desc;
} mkfs_features[] = {
{ "mixed-bg", BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS,
+ "mixed_groups",
+ VERSION_TO_STRING3(2,6,37),
+ VERSION_TO_STRING3(2,6,37),
+ NULL, 0,
"mixed data and metadata block groups" },
{ "extref", BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF,
+ "extended_iref",
+ VERSION_TO_STRING2(3,7),
+ VERSION_TO_STRING2(3,12),
+ VERSION_TO_STRING2(3,12),
"increased hardlink limit per file to 65536" },
{ "raid56", BTRFS_FEATURE_INCOMPAT_RAID56,
+ "raid56",
+ VERSION_TO_STRING2(3,9),
+ NULL, 0,
+ NULL, 0,
"raid56 extended format" },
{ "skinny-metadata", BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA,
+ "skinny_metadata",
+ VERSION_TO_STRING2(3,10),
+ VERSION_TO_STRING2(3,18),
+ VERSION_TO_STRING2(3,18),
"reduced-size metadata extent refs" },
{ "no-holes", BTRFS_FEATURE_INCOMPAT_NO_HOLES,
+ "no_holes",
+ VERSION_TO_STRING2(3,14),
+ VERSION_TO_STRING2(4,0),
+ NULL, 0,
"no explicit hole extents for files" },
/* Keep this one last */
{ "list-all", BTRFS_FEATURE_LIST_ALL, NULL }
fprintf(stderr, "Filesystem features available:\n");
for (i = 0; i < ARRAY_SIZE(mkfs_features) - 1; i++) {
- char *is_default = "";
+ const struct btrfs_fs_feature *feat = &mkfs_features[i];
- if (mkfs_features[i].flag & mask_disallowed)
+ if (feat->flag & mask_disallowed)
continue;
- if (mkfs_features[i].flag & BTRFS_MKFS_DEFAULT_FEATURES)
- is_default = ", default";
- fprintf(stderr, "%-20s- %s (0x%llx%s)\n",
- mkfs_features[i].name,
- mkfs_features[i].desc,
- mkfs_features[i].flag,
- is_default);
+ fprintf(stderr, "%-20s- %s (0x%llx", feat->name, feat->desc,
+ feat->flag);
+ if (feat->compat_ver)
+ fprintf(stderr, ", compat=%s", feat->compat_str);
+ if (feat->safe_ver)
+ fprintf(stderr, ", safe=%s", feat->safe_str);
+ if (feat->default_ver)
+ fprintf(stderr, ", default=%s", feat->default_str);
+ fprintf(stderr, ")\n");
}
}
int fd = -1;
int ret = 0;
int ndevs = 0;
- int i = 0;
+ u64 last_devid = 0;
int replacing = 0;
struct btrfs_fs_devices *fs_devices_mnt = NULL;
struct btrfs_ioctl_dev_info_args *di_args;
if (is_block_device(path) == 1) {
struct btrfs_super_block *disk_super;
char buf[BTRFS_SUPER_INFO_SIZE];
- u64 devid;
/* Ensure it's mounted, then set path to the mountpoint */
fd = open(path, O_RDONLY);
ret = -EIO;
goto out;
}
- devid = btrfs_stack_device_id(&disk_super->dev_item);
-
- fi_args->max_id = devid;
- i = devid;
+ last_devid = btrfs_stack_device_id(&disk_super->dev_item);
+ fi_args->max_id = last_devid;
memcpy(fi_args->fsid, fs_devices_mnt->fsid, BTRFS_FSID_SIZE);
close(fd);
fi_args->num_devices++;
ndevs++;
replacing = 1;
- if (i == 0)
- i++;
+ if (last_devid == 0)
+ last_devid++;
}
}
if (replacing)
memcpy(di_args, &tmp, sizeof(tmp));
- for (; i <= fi_args->max_id; ++i) {
- ret = get_device_info(fd, i, &di_args[ndevs]);
+ for (; last_devid <= fi_args->max_id; last_devid++) {
+ ret = get_device_info(fd, last_devid, &di_args[ndevs]);
if (ret == -ENODEV)
continue;
if (ret)
}
/*
- * For a given:
- * - file or directory return the containing tree root id
- * - subvolume return its own tree id
- * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is
- * undefined and function returns -1
- */
-int lookup_path_rootid(int fd, u64 *rootid)
-{
- struct btrfs_ioctl_ino_lookup_args args;
- int ret;
-
- memset(&args, 0, sizeof(args));
- args.treeid = 0;
- args.objectid = BTRFS_FIRST_FREE_OBJECTID;
-
- ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
- if (ret < 0)
- return -errno;
-
- *rootid = args.treeid;
-
- return 0;
-}
-
-/*
* return 0 if a btrfs mount point is found
* return 1 if a mount point is found but not btrfs
* return <0 if something goes wrong
int string_is_numerical(const char *str)
{
+ if (!str)
+ return 0;
if (!(*str >= '0' && *str <= '9'))
return 0;
while (*str >= '0' && *str <= '9')