[Midnightbsd-cvs] src [8291] trunk/sys/boot/zfs: zfs boot: add code for listing child datasets
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Sep 17 18:09:15 EDT 2016
Revision: 8291
http://svnweb.midnightbsd.org/src/?rev=8291
Author: laffer1
Date: 2016-09-17 18:09:15 -0400 (Sat, 17 Sep 2016)
Log Message:
-----------
zfs boot: add code for listing child datasets
Modified Paths:
--------------
trunk/sys/boot/zfs/libzfs.h
trunk/sys/boot/zfs/zfs.c
trunk/sys/boot/zfs/zfsimpl.c
Modified: trunk/sys/boot/zfs/libzfs.h
===================================================================
--- trunk/sys/boot/zfs/libzfs.h 2016-09-17 22:08:46 UTC (rev 8290)
+++ trunk/sys/boot/zfs/libzfs.h 2016-09-17 22:09:15 UTC (rev 8291)
@@ -59,6 +59,7 @@
const char **path);
char *zfs_fmtdev(void *vdev);
int zfs_probe_dev(const char *devname, uint64_t *pool_guid);
+int zfs_list(const char *name);
extern struct devsw zfs_dev;
extern struct fs_ops zfs_fsops;
Modified: trunk/sys/boot/zfs/zfs.c
===================================================================
--- trunk/sys/boot/zfs/zfs.c 2016-09-17 22:08:46 UTC (rev 8290)
+++ trunk/sys/boot/zfs/zfs.c 2016-09-17 22:09:15 UTC (rev 8291)
@@ -574,3 +574,38 @@
rootname);
return (buf);
}
+
+int
+zfs_list(const char *name)
+{
+ static char poolname[ZFS_MAXNAMELEN];
+ uint64_t objid;
+ spa_t *spa;
+ const char *dsname;
+ int len;
+ int rv;
+
+ len = strlen(name);
+ dsname = strchr(name, '/');
+ if (dsname != NULL) {
+ len = dsname - name;
+ dsname++;
+ }
+ memcpy(poolname, name, len);
+ poolname[len] = '\0';
+
+ spa = spa_find_by_name(poolname);
+ if (!spa)
+ return (ENXIO);
+ rv = zfs_spa_init(spa);
+ if (rv != 0)
+ return (rv);
+ if (dsname != NULL)
+ rv = zfs_lookup_dataset(spa, dsname, &objid);
+ else
+ rv = zfs_get_root(spa, &objid);
+ if (rv != 0)
+ return (rv);
+ rv = zfs_list_dataset(spa, objid);
+ return (0);
+}
Modified: trunk/sys/boot/zfs/zfsimpl.c
===================================================================
--- trunk/sys/boot/zfs/zfsimpl.c 2016-09-17 22:08:46 UTC (rev 8290)
+++ trunk/sys/boot/zfs/zfsimpl.c 2016-09-17 22:09:15 UTC (rev 8291)
@@ -1332,8 +1332,6 @@
return (EIO);
}
-#ifdef BOOT2
-
/*
* List a microzap directory. Assumes that the zap scratch buffer contains
* the directory contents.
@@ -1458,8 +1456,6 @@
return fzap_list(spa, dnode);
}
-#endif
-
static int
objset_get_dnode(const spa_t *spa, const objset_phys_t *os, uint64_t objnum, dnode_phys_t *dnode)
{
@@ -1696,6 +1692,38 @@
return (0);
}
+#ifndef BOOT2
+static int
+zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
+{
+ uint64_t dir_obj, child_dir_zapobj;
+ dnode_phys_t child_dir_zap, dir, dataset;
+ dsl_dataset_phys_t *ds;
+ dsl_dir_phys_t *dd;
+
+ if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
+ printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
+ return (EIO);
+ }
+ ds = (dsl_dataset_phys_t *) &dataset.dn_bonus;
+ dir_obj = ds->ds_dir_obj;
+
+ if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir)) {
+ printf("ZFS: can't find dirobj %ju\n", (uintmax_t)dir_obj);
+ return (EIO);
+ }
+ dd = (dsl_dir_phys_t *)&dir.dn_bonus;
+
+ child_dir_zapobj = dd->dd_child_dir_zapobj;
+ if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0) {
+ printf("ZFS: can't find child zap %ju\n", (uintmax_t)dir_obj);
+ return (EIO);
+ }
+
+ return (zap_list(spa, &child_dir_zap) != 0);
+}
+#endif
+
/*
* Find the object set given the object number of its dataset object
* and return its details in *objset
More information about the Midnightbsd-cvs
mailing list