return ioctl(fd, NVME_IOCTL_RESCAN);
}
-int nvme_get_nsid(int fd)
+int nvme_get_nsid(int fd, __u32 *nsid)
{
- static struct stat nvme_stat;
- int err = fstat(fd, &nvme_stat);
-
- if (err < 0)
- return -1;
-
- if (!S_ISBLK(nvme_stat.st_mode)) {
- errno = ENOTBLK;
- return -1;
- }
- return ioctl(fd, NVME_IOCTL_ID);
+ errno = 0;
+ *nsid = ioctl(fd, NVME_IOCTL_ID);
+ return -1 * (errno != 0);
}
static int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
/**
* nvme_get_nsid() - Retrieve the NSID from a namespace file descriptor
* @fd: File descriptor of nvme namespace
+ * @nsid: User pointer to namespace id
*
* This should only be sent to namespace handles, not to controllers.
*
- * Return: The namespace identifier if a succecssful or -1 with errno set
- * otherwise.
+ * Return: 0 if @nsid was set succecssfully or -1 with errno set otherwise.
*/
-int nvme_get_nsid(int fd);
+int nvme_get_nsid(int fd, __u32 *nsid);
/**
* enum nvme_admin_opcode - Known NVMe admin opcodes
struct nvme_ctrl *c;
int fd;
- int nsid;
+ __u32 nsid;
char *name;
char *sysfs_dir;
if (n->fd < 0)
goto free_ns;
- n->nsid = nvme_get_nsid(n->fd);
- if (n->nsid < 0)
+ if (nvme_get_nsid(n->fd, &n->nsid) < 0)
goto close_fd;
list_head_init(&n->paths);