static int do_mount(const char *src, const char *mntpt, char *opts) { char *argv[8] = { "/bin/mount", "-t", MNTTYPE_ZFS, "-o", opts, (char *)src, (char *)mntpt, (char *)NULL }; int rc; /* Return only the most critical mount error */ rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE); if (rc) { if (rc & MOUNT_FILEIO) return EIO; if (rc & MOUNT_USER) return EINTR; if (rc & MOUNT_SOFTWARE) return EPIPE; if (rc & MOUNT_SYSERR) return EAGAIN; if (rc & MOUNT_USAGE) return EINVAL; return ENXIO; /* Generic error */ } return 0; }
static int do_unmount(const char *mntpt, int flags) { char force_opt[] = "-f"; char lazy_opt[] = "-l"; char *argv[7] = { "/bin/umount", "-t", MNTTYPE_ZFS, NULL, NULL, NULL, NULL }; int rc, count = 3; if (flags & MS_FORCE) { argv[count] = force_opt; count++; } if (flags & MS_DETACH) { argv[count] = lazy_opt; count++; } argv[count] = (char *)mntpt; rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE); return (rc ? EINVAL : 0); }
static int do_unmount_volume(const char *mntpt, int flags) { char force_opt[] = "force"; #ifdef __LINUX__ char lazy_opt[] = "-l"; #endif /* __LINUX__ */ char *argv[7] = { "/usr/sbin/diskutil", "unmountDisk", NULL, NULL, NULL, NULL }; int rc, count = 2; if (flags & MS_FORCE) { argv[count] = force_opt; count++; } #ifdef __LINUX__ if (flags & MS_DETACH) { argv[count] = lazy_opt; count++; } #endif /* __LINUX__ */ argv[count] = (char *)mntpt; rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE); return (rc ? EINVAL : 0); }
/** * Used internally by nfs_enable_share to enable sharing for a single host. */ static int nfs_enable_share_one(const char *sharepath, const char *host, const char *security, const char *access, void *pcookie) { int rc; char *linuxhost, *hostpath, *opts; const char *linux_opts = (const char *)pcookie; char *argv[6]; /* exportfs -i -o sec=XX,rX,<opts> <host>:<sharepath> */ rc = get_linux_hostspec(host, &linuxhost); if (rc < 0) exit(1); hostpath = malloc(strlen(linuxhost) + 1 + strlen(sharepath) + 1); if (hostpath == NULL) { free(linuxhost); exit(1); } sprintf(hostpath, "%s:%s", linuxhost, sharepath); free(linuxhost); if (linux_opts == NULL) linux_opts = ""; opts = malloc(4 + strlen(security) + 4 + strlen(linux_opts) + 1); if (opts == NULL) exit(1); sprintf(opts, "sec=%s,%s,%s", security, access, linux_opts); #ifdef DEBUG fprintf(stderr, "sharing %s with opts %s\n", hostpath, opts); #endif argv[0] = "/usr/sbin/exportfs"; argv[1] = "-i"; argv[2] = "-o"; argv[3] = opts; argv[4] = hostpath; argv[5] = NULL; rc = libzfs_run_process(argv[0], argv, 0); free(hostpath); free(opts); if (rc < 0) return SA_SYSTEM_ERR; else return SA_OK; }
/* * Used internally by smb_enable_share to enable sharing for a single host. */ static int smb_enable_share_one(const char *sharename, const char *sharepath) { char *argv[10], *pos; char name[SMB_NAME_MAX], comment[SMB_COMMENT_MAX]; int rc; /* Support ZFS share name regexp '[[:alnum:]_-.: ]' */ strncpy(name, sharename, sizeof (name)); name [sizeof (name)-1] = '\0'; pos = name; while (*pos != '\0') { switch (*pos) { case '/': case '-': case ':': case ' ': *pos = '_'; } ++pos; } /* * CMD: net -S NET_CMD_ARG_HOST usershare add Test1 /share/Test1 \ * "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); argv[0] = NET_CMD_PATH; argv[1] = (char *)"-S"; argv[2] = NET_CMD_ARG_HOST; argv[3] = (char *)"usershare"; argv[4] = (char *)"add"; argv[5] = (char *)name; argv[6] = (char *)sharepath; argv[7] = (char *)comment; argv[8] = "Everyone:F"; argv[9] = NULL; rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) return (SA_SYSTEM_ERR); /* Reload the share file */ (void) smb_retrieve_shares(); return (SA_OK); }
/** * Used internally by nfs_disable_share to disable sharing for a single host. */ static int nfs_disable_share_one(const char *sharepath, const char *host, const char *security, const char *access, void *cookie) { int rc; char *linuxhost, *hostpath; char *argv[4]; rc = get_linux_hostspec(host, &linuxhost); if (rc < 0) exit(1); hostpath = malloc(strlen(linuxhost) + 1 + strlen(sharepath) + 1); if (hostpath == NULL) { free(linuxhost); exit(1); } sprintf(hostpath, "%s:%s", linuxhost, sharepath); free(linuxhost); #ifdef DEBUG fprintf(stderr, "unsharing %s\n", hostpath); #endif argv[0] = "/usr/sbin/exportfs"; argv[1] = "-u"; argv[2] = hostpath; argv[3] = NULL; rc = libzfs_run_process(argv[0], argv, 0); free(hostpath); if (rc < 0) return SA_SYSTEM_ERR; else return SA_OK; }
/* * Used internally by smb_disable_share to disable sharing for a single host. */ static int smb_disable_share_one(const char *sharename) { int rc; char *argv[7]; /* CMD: net -S NET_CMD_ARG_HOST usershare delete Test1 */ argv[0] = NET_CMD_PATH; argv[1] = (char *)"-S"; argv[2] = NET_CMD_ARG_HOST; argv[3] = (char *)"usershare"; argv[4] = (char *)"delete"; argv[5] = strdup(sharename); argv[6] = NULL; rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) return (SA_SYSTEM_ERR); else return (SA_OK); }