Changeset View
Changeset View
Standalone View
Standalone View
stand/libsa/zfs/zfs.c
Show First 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | |||||
zfs_mount(const char *dev, const char *path, void **data) | zfs_mount(const char *dev, const char *path, void **data) | ||||
{ | { | ||||
struct zfs_devdesc *zfsdev; | struct zfs_devdesc *zfsdev; | ||||
spa_t *spa; | spa_t *spa; | ||||
struct zfsmount *mnt; | struct zfsmount *mnt; | ||||
int rv; | int rv; | ||||
errno = 0; | errno = 0; | ||||
zfsdev = malloc(sizeof(*zfsdev)); | rv = zfs_parsedev((struct devdesc **)&zfsdev, dev + 3, NULL); | ||||
if (zfsdev == NULL) | |||||
return (errno); | |||||
rv = zfs_parsedev(zfsdev, dev + 3, NULL); | |||||
if (rv != 0) { | if (rv != 0) { | ||||
free(zfsdev); | |||||
return (rv); | return (rv); | ||||
} | } | ||||
spa = spa_find_by_dev(zfsdev); | spa = spa_find_by_dev(zfsdev); | ||||
if (spa == NULL) | if (spa == NULL) | ||||
return (ENXIO); | return (ENXIO); | ||||
mnt = calloc(1, sizeof(*mnt)); | mnt = calloc(1, sizeof(*mnt)); | ||||
▲ Show 20 Lines • Show All 1,229 Lines • ▼ Show 20 Lines | struct devsw zfs_dev = { | ||||
.dv_close = zfs_dev_close, | .dv_close = zfs_dev_close, | ||||
.dv_ioctl = noioctl, | .dv_ioctl = noioctl, | ||||
.dv_print = zfs_dev_print, | .dv_print = zfs_dev_print, | ||||
.dv_cleanup = nullsys, | .dv_cleanup = nullsys, | ||||
.dv_fmtdev = zfs_fmtdev, | .dv_fmtdev = zfs_fmtdev, | ||||
}; | }; | ||||
int | int | ||||
zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path) | zfs_parsedev(struct devdesc **idev, const char *devspec, const char **path) | ||||
{ | { | ||||
static char rootname[ZFS_MAXNAMELEN]; | static char rootname[ZFS_MAXNAMELEN]; | ||||
static char poolname[ZFS_MAXNAMELEN]; | static char poolname[ZFS_MAXNAMELEN]; | ||||
spa_t *spa; | spa_t *spa; | ||||
const char *end; | const char *end; | ||||
const char *np; | const char *np; | ||||
const char *sep; | const char *sep; | ||||
int rv; | int rv; | ||||
struct zfs_devdesc *dev; | |||||
np = devspec; | np = devspec; | ||||
if (*np != ':') | if (*np != ':') | ||||
return (EINVAL); | return (EINVAL); | ||||
np++; | np++; | ||||
end = strrchr(np, ':'); | end = strrchr(np, ':'); | ||||
if (end == NULL) | if (end == NULL) | ||||
return (EINVAL); | return (EINVAL); | ||||
sep = strchr(np, '/'); | sep = strchr(np, '/'); | ||||
if (sep == NULL || sep >= end) | if (sep == NULL || sep >= end) | ||||
sep = end; | sep = end; | ||||
memcpy(poolname, np, sep - np); | memcpy(poolname, np, sep - np); | ||||
poolname[sep - np] = '\0'; | poolname[sep - np] = '\0'; | ||||
if (sep < end) { | if (sep < end) { | ||||
sep++; | sep++; | ||||
memcpy(rootname, sep, end - sep); | memcpy(rootname, sep, end - sep); | ||||
rootname[end - sep] = '\0'; | rootname[end - sep] = '\0'; | ||||
} | } | ||||
else | else | ||||
rootname[0] = '\0'; | rootname[0] = '\0'; | ||||
spa = spa_find_by_name(poolname); | spa = spa_find_by_name(poolname); | ||||
if (!spa) | if (!spa) | ||||
return (ENXIO); | return (ENXIO); | ||||
dev = malloc(sizeof(*dev)); | |||||
if (dev == NULL) | |||||
return (ENOMEM); | |||||
dev->pool_guid = spa->spa_guid; | dev->pool_guid = spa->spa_guid; | ||||
rv = zfs_lookup_dataset(spa, rootname, &dev->root_guid); | rv = zfs_lookup_dataset(spa, rootname, &dev->root_guid); | ||||
if (rv != 0) | if (rv != 0) { | ||||
free(dev); | |||||
return (rv); | return (rv); | ||||
} | |||||
if (path != NULL) | if (path != NULL) | ||||
*path = (*end == '\0') ? end : end + 1; | *path = (*end == '\0') ? end : end + 1; | ||||
dev->dd.d_dev = &zfs_dev; | dev->dd.d_dev = &zfs_dev; | ||||
*idev = &dev->dd; | |||||
return (0); | return (0); | ||||
} | } | ||||
char * | char * | ||||
zfs_fmtdev(struct devdesc *vdev) | zfs_fmtdev(struct devdesc *vdev) | ||||
{ | { | ||||
static char rootname[ZFS_MAXNAMELEN]; | static char rootname[ZFS_MAXNAMELEN]; | ||||
static char buf[2 * ZFS_MAXNAMELEN + 8]; | static char buf[2 * ZFS_MAXNAMELEN + 8]; | ||||
▲ Show 20 Lines • Show All 355 Lines • Show Last 20 Lines |