@@ -253,6 +253,7 @@ static int set_defaults(enum device_action action)
break;
case NDCTL_NS_MODE_FSDAX:
case NDCTL_NS_MODE_DEVDAX:
+ case NDCTL_NS_MODE_SECTOR:
break;
default:
if (action == ACTION_WRITE_INFOBLOCK) {
@@ -2014,6 +2015,48 @@ static int write_pfn_sb(int fd, unsigned long long size, const char *sig,
return 0;
}
+static int write_btt_sb(const int fd, unsigned long long size, struct ns_info *ns_info)
+{
+ int rc = 0;
+ uuid_t uuid, parent_uuid;
+
+ // updating the original values which are asked to change,
+ // rest will be unchanged
+ if (param.uuid) {
+ rc = uuid_parse(param.uuid, uuid);
+ if (rc) {
+ error("Failed to parse UUID");
+ return rc;
+ }
+ memcpy(((struct btt_sb *)(ns_info->ns_sb_buf + ns_info->offset))->uuid,
+ uuid, sizeof(uuid_t));
+ }
+ if (param.parent_uuid) {
+ rc = uuid_parse(param.parent_uuid, parent_uuid);
+ if (rc) {
+ error("Failed to parse UUID");
+ return rc;
+ }
+ memcpy(((struct btt_sb *)(ns_info->ns_sb_buf + ns_info->offset))->parent_uuid,
+ parent_uuid, sizeof(uuid_t));
+ }
+
+ if (pwrite(fd, ns_info->ns_sb_buf + ns_info->offset, sizeof(struct btt_sb),
+ ns_info->offset) < 0) {
+ pr_verbose("Unable to write the info block: %s\n",
+ strerror(errno));
+ rc = -errno;
+ }
+
+ if (pwrite(fd, ns_info->ns_sb_buf + ns_info->offset, sizeof(struct btt_sb),
+ size - sizeof(struct btt_sb)) < 0) {
+ pr_verbose("Unable to write the info block: %s\n",
+ strerror(errno));
+ rc = -errno;
+ }
+ return rc;
+}
+
static int file_write_infoblock(const char *path, struct ns_info *ns_info)
{
unsigned long long size = parse_size64(param.size);
@@ -2061,6 +2104,14 @@ static int file_write_infoblock(const char *path, struct ns_info *ns_info)
case NDCTL_NS_MODE_DEVDAX:
rc = write_pfn_sb(fd, size, DAX_SIG, ns_info);
break;
+ case NDCTL_NS_MODE_SECTOR:
+ if (ns_info->mode == NDCTL_NS_MODE_SECTOR)
+ rc = write_btt_sb(fd, size, ns_info);
+ else {
+ pr_verbose("Non-sector mode namespaces can't be converted to sector mode namespaces");
+ rc = -EPERM;
+ }
+ break;
case NDCTL_NS_MODE_UNKNOWN:
switch (ns_info->mode) {
case NDCTL_NS_MODE_FSDAX:
@@ -2069,6 +2120,9 @@ static int file_write_infoblock(const char *path, struct ns_info *ns_info)
case NDCTL_NS_MODE_DEVDAX:
rc = write_pfn_sb(fd, size, DAX_SIG, ns_info);
break;
+ case NDCTL_NS_MODE_SECTOR:
+ rc = write_btt_sb(fd, size, ns_info);
+ break;
default:
rc = -EINVAL;
break;