int main(int argc, char **argv) { extern void zfs_prop_init(void); char *path[MAX_NUM_PATHS]; const char *subcommand; int rv = 0; char c; g_importargs.path = path; dprintf_setup(&argc, argv); zfs_prop_init(); while ((c = getopt(argc, argv, "c:d:")) != -1) { switch (c) { case 'c': g_importargs.cachefile = optarg; break; case 'd': assert(g_importargs.paths < MAX_NUM_PATHS); g_importargs.path[g_importargs.paths++] = optarg; break; default: usage(); break; } } argc -= optind; argv += optind; optind = 1; if (argc == 0) { (void) fprintf(stderr, "error: no command specified\n"); usage(); } subcommand = argv[0]; if (strcmp(subcommand, "feature") == 0) { rv = zhack_do_feature(argc, argv); } else { (void) fprintf(stderr, "error: unknown subcommand: %s\n", subcommand); usage(); } if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE) != 0) { fatal(NULL, FTAG, "pool export failed; " "changes may not be committed to disk\n"); } libzfs_fini(g_zfs); kernel_fini(); return (rv); }
libzfs_handle_t * libzfs_init(void) { libzfs_handle_t *hdl; #ifdef __APPLE__ struct vfsconf vfc; struct stat sb; int loaded; /* Attempt to load zfs kext if its not already loaded. */ if (getvfsbyname("zfs", &vfc) != 0) { int pick = 0; int i; /* Find all possible zfs kext versions. */ getkextvers(kextpaths[0], &kextvers[0]); /* Pick the newest one. */ for (i = 0; i < 1; ++i) { if (kextvers[i] > kextvers[pick]) pick = i; } loaded = load_zfs_kext(kextpaths[pick]); } /* Attempt to create "/etc/zfs" its not already there. */ if (getuid() == 0 && stat("/etc/zfs", &sb)!= 0 && errno == ENOENT) { (void) mkdir("/etc/zfs", 0755); } #endif if ((hdl = calloc(sizeof (libzfs_handle_t), 1)) == NULL) { return (NULL); } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { free(hdl); return (NULL); } #ifndef __APPLE__ if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { (void) close(hdl->libzfs_fd); free(hdl); return (NULL); } #endif /*!__APPLE__*/ hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "r"); zfs_prop_init(); return (hdl); }
void initioctl(void) { PyObject *zfs_ioctl = Py_InitModule("zfs.ioctl", zfsmethods); PyObject *zfs_util = PyImport_ImportModule("zfs.util"); PyObject *devfile; if (zfs_util == NULL) return; ZFSError = PyObject_GetAttrString(zfs_util, "ZFSError"); devfile = PyObject_GetAttrString(zfs_util, "dev"); zfsdevfd = PyObject_AsFileDescriptor(devfile); zfs_prop_init(); }
libzfs_handle_t * libzfs_init(void) { libzfs_handle_t *hdl; #ifdef __APPLE__ struct vfsconf vfc; struct stat sb; int loaded; /* Attempt to load zfs kext if its not already loaded. */ if (getvfsbyname("zfs", &vfc) != 0) { int pick = 0; int i; /* Find all possible zfs kext versions. */ getkextvers(kextpaths[0], &kextvers[0]); getkextvers(kextpaths[1], &kextvers[1]); /* Pick the newest one. */ for (i = 0; i < 2; ++i) { if (kextvers[i] > kextvers[pick]) pick = i; } loaded = load_zfs_kext(kextpaths[pick]); ASSERT(loaded == 0); } /* Attempt to create "/etc/zfs" its not already there. */ if (getuid() == 0 && stat("/etc/zfs", &sb)!= 0 && errno == ENOENT) { (void) mkdir("/etc/zfs", 0755); } #endif if ((hdl = calloc(sizeof (libzfs_handle_t), 1)) == NULL) { return (NULL); } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { free(hdl); return (NULL); } else { /* Perform special version ceck ioctl() to unlock user-kernel * interface. This serves as protection against using userland * tools of one implementation against kernel land of another * implementation. */ zfs_cmd_t vers_zc = {0}; strncpy(vers_zc.zc_name, __STRING(MACZFS_ID), sizeof(vers_zc.zc_name)-1); vers_zc.zc_value[0] = ZFS_IOC_NUM(ZFS_IOC__LAST_USED); vers_zc.zc_value[1] = MACZFS_VERS_MAJOR; vers_zc.zc_value[2] = MACZFS_VERS_MINOR; vers_zc.zc_value[3] = MACZFS_VERS_PATCH; hdl->libzfs_log_str = NULL; if (zfs_ioctl(hdl, ZFS_IOC__VERSION_CHECK, &vers_zc) != 0) { /* kernel - user version mismatch or kernel side not ready. */ free(hdl); return (NULL); } } #ifndef __APPLE__ if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { (void) close(hdl->libzfs_fd); free(hdl); return (NULL); } #endif /*!__APPLE__*/ hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "r"); zfs_prop_init(); return (hdl); }
libzfs_handle_t * libzfs_init(void) { libzfs_handle_t *hdl; #ifdef __APPLE__ struct vfsconf vfc; struct stat sb; int loaded; /* Attempt to load zfs kext if its not already loaded. */ if (getvfsbyname("zfs", &vfc) != 0) { int pick = 0; int i; /* Find all possible zfs kext versions. */ getkextvers(kextpaths[0], &kextvers[0]); getkextvers(kextpaths[1], &kextvers[1]); getkextvers(kextpaths[2], &kextvers[2]); /* Pick the newest one. */ for (i = 0; i < 3; ++i) { if (kextvers[i] > kextvers[pick]) pick = i; } loaded = load_zfs_kext(kextpaths[pick]); zfs_readonly_kext = (pick == 2); /* Make sure user knows they have loaded the readonly kext */ if(zfs_readonly_kext && (loaded != -1)) (void) fprintf(stderr, gettext("ZFS Readonly implemntation " "is loaded!\nTo download the full ZFS " "read/write kext with all functionality " "enabled, please go to " "http://developer.apple.com\n")); } else { zfs_readonly_kext = is_readonly_kext(vfc.vfc_typenum); } /* Attempt to create "/etc/zfs" its not already there. */ if (getuid() == 0 && stat("/etc/zfs", &sb)!= 0 && errno == ENOENT) { (void) mkdir("/etc/zfs", 0755); } #endif if ((hdl = calloc(sizeof (libzfs_handle_t), 1)) == NULL) { return (NULL); } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { free(hdl); return (NULL); } #ifndef __APPLE__ if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { (void) close(hdl->libzfs_fd); free(hdl); return (NULL); } #endif /*!__APPLE__*/ hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "r"); zfs_prop_init(); /* Make sure the user knows they have loaded the Read Only kext */ return (hdl); }