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); }
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); }