int osd_init(void) { int ret = 0; #ifdef HAVE_LDISKFS_OSD ret = ldiskfs_init(); if (ret) return ret; #endif /* HAVE_LDISKFS_OSD */ #ifdef HAVE_ZFS_OSD ret = zfs_init(); /* we want to be able to set up a ldiskfs-based filesystem w/o * the ZFS modules installed, see ORI-425 */ if (ret) ret = 0; #endif /* HAVE_ZFS_OSD */ return ret; }
int main(int argc, char** argv) { int i, n, off; int fd[99]; spa_t *spa; dnode_phys_t dn; char buf[512]; zfs_init(); if (argc == 1) { static char *av[] = { "zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", NULL, }; argc = 4; argv = av; } for (i = 1; i < argc; i++) { fd[i] = open(argv[i], O_RDONLY); if (fd[i] < 0) continue; if (vdev_probe(vdev_read, &fd[i], NULL) != 0) close(fd[i]); } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (!spa || zfs_mount_pool(spa)) exit(1); if (zfs_lookup(spa, "zfs.c", &dn)) exit(1); off = 0; do { n = zfs_read(spa, &dn, buf, 512, off); write(1, buf, n); off += n; } while (n == 512); }
int zfs_module_start(__unused kmod_info_t *ki, __unused void *data) { struct vfs_fsentry vfe; zfs_init(); printf("zfs_module_start: memory footprint %d (kalloc %d, kernel %d)\n", zfs_footprint.current, zfs_kallocmap_size, zfs_kernelmap_size); vfe.vfe_vfsops = &zfs_vfsops_template; vfe.vfe_vopcnt = ZFS_VNOP_TBL_CNT; vfe.vfe_opvdescs = zfs_vnodeop_opv_desc_list; #if 1 strcpy(vfe.vfe_fsname, "zfs"); #else strlcpy(vfe.vfe_fsname, "zfs", sizeof(vfe.vfe_fsname)); #endif /* * Note: must set VFS_TBLGENERICMNTARGS with VFS_TBLLOCALVOL * to suppress local mount argument handling. */ vfe.vfe_flags = VFS_TBLTHREADSAFE | VFS_TBLNOTYPENUM | VFS_TBLLOCALVOL | VFS_TBL64BITREADY | VFS_TBLNATIVEXATTR | VFS_TBLGENERICMNTARGS| VFS_TBLREADDIR_EXTENDED; vfe.vfe_reserv[0] = 0; vfe.vfe_reserv[1] = 0; if (vfs_fsadd(&vfe, &zfs_vfsconf) != 0) return KERN_FAILURE; else return KERN_SUCCESS; }
static void init() { zfs_init(); }
int main(int argc, char** argv) { char buf[512], hash[33]; MD5_CTX ctx; struct stat sb; struct zfsmount zfsmnt; dnode_phys_t dn; #if 0 uint64_t rootobj; #endif spa_t *spa; off_t off; ssize_t n; int i, failures, *fd; zfs_init(); if (argc == 1) { static char *av[] = { "zfsboottest", "/dev/gpt/system0", "/dev/gpt/system1", "-", "/boot/zfsloader", "/boot/support.4th", "/boot/kernel/kernel", NULL, }; argc = sizeof(av) / sizeof(av[0]) - 1; argv = av; } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-") == 0) break; } fd = malloc(sizeof(fd[0]) * (i - 1)); if (fd == NULL) errx(1, "Unable to allocate memory."); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-") == 0) break; fd[i - 1] = open(argv[i], O_RDONLY); if (fd[i - 1] == -1) { warn("open(%s) failed", argv[i]); continue; } if (vdev_probe(vdev_read, &fd[i - 1], NULL) != 0) { warnx("vdev_probe(%s) failed", argv[i]); close(fd[i - 1]); } } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (spa == NULL) { fprintf(stderr, "no pools\n"); exit(1); } if (zfs_spa_init(spa)) { fprintf(stderr, "can't init pool\n"); exit(1); } #if 0 if (zfs_get_root(spa, &rootobj)) { fprintf(stderr, "can't get root\n"); exit(1); } if (zfs_mount(spa, rootobj, &zfsmnt)) { #else if (zfs_mount(spa, 0, &zfsmnt)) { fprintf(stderr, "can't mount\n"); exit(1); } #endif printf("\n"); for (++i, failures = 0; i < argc; i++) { if (zfs_lookup(&zfsmnt, argv[i], &dn)) { fprintf(stderr, "%s: can't lookup\n", argv[i]); failures++; continue; } if (zfs_dnode_stat(spa, &dn, &sb)) { fprintf(stderr, "%s: can't stat\n", argv[i]); failures++; continue; } off = 0; MD5Init(&ctx); do { n = sb.st_size - off; n = n > sizeof(buf) ? sizeof(buf) : n; n = zfs_read(spa, &dn, buf, n, off); if (n < 0) { fprintf(stderr, "%s: zfs_read failed\n", argv[i]); failures++; break; } MD5Update(&ctx, buf, n); off += n; } while (off < sb.st_size); if (off < sb.st_size) continue; MD5End(&ctx, hash); printf("%s %s\n", hash, argv[i]); } return (failures == 0 ? 0 : 1); }
int main(int argc, char** argv) { char buf[512]; int fd[100]; struct stat sb; dnode_phys_t dn; spa_t *spa; off_t off; ssize_t n; int i; zfs_init(); if (argc == 1) { static char *av[] = { "zfstest", "COPYRIGHT", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", NULL, }; argc = 5; argv = av; } for (i = 2; i < argc; i++) { fd[i] = open(argv[i], O_RDONLY); if (fd[i] < 0) continue; if (vdev_probe(vdev_read, &fd[i], NULL) != 0) close(fd[i]); } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (spa == NULL) { fprintf(stderr, "no pools\n"); exit(1); } if (zfs_mount_pool(spa)) { fprintf(stderr, "can't mount pool\n"); exit(1); } if (zfs_lookup(spa, argv[1], &dn)) { fprintf(stderr, "can't lookup\n"); exit(1); } if (zfs_dnode_stat(spa, &dn, &sb)) { fprintf(stderr, "can't stat\n"); exit(1); } off = 0; do { n = sb.st_size - off; n = n > sizeof(buf) ? sizeof(buf) : n; n = zfs_read(spa, &dn, buf, n, off); if (n < 0) { fprintf(stderr, "zfs_read failed\n"); exit(1); } write(1, buf, n); off += n; } while (off < sb.st_size); return (0); }