summaryrefslogtreecommitdiff
path: root/usr/src/boot/lib/libstand/zfs/zfsimpl.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/boot/lib/libstand/zfs/zfsimpl.c')
-rw-r--r--usr/src/boot/lib/libstand/zfs/zfsimpl.c294
1 files changed, 157 insertions, 137 deletions
diff --git a/usr/src/boot/lib/libstand/zfs/zfsimpl.c b/usr/src/boot/lib/libstand/zfs/zfsimpl.c
index 7d0d79b922..a85f6f5721 100644
--- a/usr/src/boot/lib/libstand/zfs/zfsimpl.c
+++ b/usr/src/boot/lib/libstand/zfs/zfsimpl.c
@@ -103,7 +103,7 @@ typedef struct indirect_vsd {
*/
static vdev_list_t zfs_vdevs;
- /*
+/*
* List of ZFS features supported for read
*/
static const char *features_for_read[] = {
@@ -140,7 +140,7 @@ static char *dnode_cache_buf;
static char *zap_scratch;
static char *zfs_temp_buf, *zfs_temp_end, *zfs_temp_ptr;
-#define TEMP_SIZE (1024 * 1024)
+#define TEMP_SIZE (1024 * 1024)
static int zio_read(const spa_t *spa, const blkptr_t *bp, void *buf);
static int zfs_get_root(const spa_t *spa, uint64_t *objid);
@@ -205,7 +205,7 @@ xdr_int(const unsigned char **xdr, int *ip)
}
static int
-xdr_u_int(const unsigned char **xdr, u_int *ip)
+xdr_u_int(const unsigned char **xdr, uint_t *ip)
{
*ip = be32dec(*xdr);
(*xdr) += 4;
@@ -215,17 +215,17 @@ xdr_u_int(const unsigned char **xdr, u_int *ip)
static int
xdr_uint64_t(const unsigned char **xdr, uint64_t *lp)
{
- u_int hi, lo;
+ uint_t hi, lo;
xdr_u_int(xdr, &hi);
xdr_u_int(xdr, &lo);
- *lp = (((uint64_t) hi) << 32) | lo;
+ *lp = (((uint64_t)hi) << 32) | lo;
return (0);
}
static int
nvlist_find(const unsigned char *nvlist, const char *name, int type,
- int *elementsp, void *valuep)
+ int *elementsp, void *valuep)
{
const unsigned char *p, *pair;
int junk;
@@ -243,33 +243,34 @@ nvlist_find(const unsigned char *nvlist, const char *name, int type,
const char *pairname;
xdr_int(&p, &namelen);
- pairname = (const char*) p;
+ pairname = (const char *)p;
p += roundup(namelen, 4);
xdr_int(&p, &pairtype);
- if (!memcmp(name, pairname, namelen) && type == pairtype) {
+ if (memcmp(name, pairname, namelen) == 0 && type == pairtype) {
xdr_int(&p, &elements);
if (elementsp)
*elementsp = elements;
if (type == DATA_TYPE_UINT64) {
- xdr_uint64_t(&p, (uint64_t *) valuep);
+ xdr_uint64_t(&p, (uint64_t *)valuep);
return (0);
} else if (type == DATA_TYPE_STRING) {
int len;
xdr_int(&p, &len);
- (*(const char**) valuep) = (const char*) p;
+ (*(const char **)valuep) = (const char *)p;
return (0);
- } else if (type == DATA_TYPE_NVLIST
- || type == DATA_TYPE_NVLIST_ARRAY) {
- (*(const unsigned char**) valuep) =
- (const unsigned char*) p;
+ } else if (type == DATA_TYPE_NVLIST ||
+ type == DATA_TYPE_NVLIST_ARRAY) {
+ (*(const unsigned char **)valuep) =
+ (const unsigned char *)p;
return (0);
} else {
return (EIO);
}
} else {
/*
- * Not the pair we are looking for, skip to the next one.
+ * Not the pair we are looking for, skip to the
+ * next one.
*/
p = pair + encoded_size;
}
@@ -307,12 +308,13 @@ nvlist_check_features_for_read(const unsigned char *nvlist)
found = 0;
xdr_int(&p, &namelen);
- pairname = (const char*) p;
+ pairname = (const char *)p;
p += roundup(namelen, 4);
xdr_int(&p, &pairtype);
for (i = 0; features_for_read[i] != NULL; i++) {
- if (!memcmp(pairname, features_for_read[i], namelen)) {
+ if (memcmp(pairname, features_for_read[i],
+ namelen) == 0) {
found = 1;
break;
}
@@ -358,7 +360,7 @@ nvlist_next(const unsigned char *nvlist)
xdr_int(&p, &decoded_size);
}
- return p;
+ return (p);
}
#ifdef TEST
@@ -366,7 +368,7 @@ nvlist_next(const unsigned char *nvlist)
static const unsigned char *
nvlist_print(const unsigned char *nvlist, unsigned int indent)
{
- static const char* typenames[] = {
+ static const char *typenames[] = {
"DATA_TYPE_UNKNOWN",
"DATA_TYPE_BOOLEAN",
"DATA_TYPE_BYTE",
@@ -413,7 +415,7 @@ nvlist_print(const unsigned char *nvlist, unsigned int indent)
const char *pairname;
xdr_int(&p, &namelen);
- pairname = (const char*) p;
+ pairname = (const char *)p;
p += roundup(namelen, 4);
xdr_int(&p, &pairtype);
@@ -449,7 +451,8 @@ nvlist_print(const unsigned char *nvlist, unsigned int indent)
if (j != elements - 1) {
for (i = 0; i < indent; i++)
printf(" ");
- printf("%s %s", typenames[pairtype], pairname);
+ printf("%s %s", typenames[pairtype],
+ pairname);
}
}
break;
@@ -465,7 +468,7 @@ nvlist_print(const unsigned char *nvlist, unsigned int indent)
xdr_int(&p, &decoded_size);
}
- return p;
+ return (p);
}
#endif
@@ -486,7 +489,6 @@ vdev_read_phys(vdev_t *vdev, const blkptr_t *bp, void *buf,
psize = size;
}
- /*printf("ZFS: reading %zu bytes at 0x%jx to %p\n", psize, (uintmax_t)offset, buf);*/
rc = vdev->v_phys_read(vdev, vdev->v_read_priv, offset, buf, psize);
if (rc)
return (rc);
@@ -848,7 +850,7 @@ vdev_indirect_remap(vdev_t *vd, uint64_t offset, uint64_t asize, void *arg)
printf("vdev_indirect_remap: out of memory.\n");
zio->io_error = ENOMEM;
}
- for ( ; rs != NULL; rs = list_remove_head(&stack)) {
+ for (; rs != NULL; rs = list_remove_head(&stack)) {
vdev_t *v = rs->rs_vd;
uint64_t num_entries = 0;
/* vdev_indirect_mapping_t *vim = v->v_mapping; */
@@ -1018,7 +1020,7 @@ vdev_disk_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
{
return (vdev_read_phys(vdev, bp, buf,
- offset + VDEV_LABEL_START_SIZE, bytes));
+ offset + VDEV_LABEL_START_SIZE, bytes));
}
@@ -1080,8 +1082,8 @@ vdev_create(uint64_t guid, vdev_read_t *vdev_read)
vdev_t *vdev;
vdev_indirect_config_t *vic;
- vdev = malloc(sizeof(vdev_t));
- memset(vdev, 0, sizeof(vdev_t));
+ vdev = malloc(sizeof (vdev_t));
+ memset(vdev, 0, sizeof (vdev_t));
STAILQ_INIT(&vdev->v_children);
vdev->v_guid = guid;
vdev->v_state = VDEV_STATE_OFFLINE;
@@ -1117,15 +1119,16 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
return (ENOENT);
}
- if (strcmp(type, VDEV_TYPE_MIRROR)
- && strcmp(type, VDEV_TYPE_DISK)
+ if (strcmp(type, VDEV_TYPE_MIRROR) != 0 &&
+ strcmp(type, VDEV_TYPE_DISK) != 0 &&
#ifdef ZFS_TEST
- && strcmp(type, VDEV_TYPE_FILE)
+ strcmp(type, VDEV_TYPE_FILE) != 0 &&
#endif
- && strcmp(type, VDEV_TYPE_RAIDZ)
- && strcmp(type, VDEV_TYPE_INDIRECT)
- && strcmp(type, VDEV_TYPE_REPLACING)) {
- printf("ZFS: can only boot from disk, mirror, raidz1, raidz2 and raidz3 vdevs\n");
+ strcmp(type, VDEV_TYPE_RAIDZ) != 0 &&
+ strcmp(type, VDEV_TYPE_INDIRECT) != 0 &&
+ strcmp(type, VDEV_TYPE_REPLACING) != 0) {
+ printf("ZFS: can only boot from disk, mirror, raidz1, "
+ "raidz2 and raidz3 vdevs\n");
return (EIO);
}
@@ -1149,13 +1152,13 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
if (!vdev) {
is_new = 1;
- if (!strcmp(type, VDEV_TYPE_MIRROR))
+ if (strcmp(type, VDEV_TYPE_MIRROR) == 0)
vdev = vdev_create(guid, vdev_mirror_read);
- else if (!strcmp(type, VDEV_TYPE_RAIDZ))
+ else if (strcmp(type, VDEV_TYPE_RAIDZ) == 0)
vdev = vdev_create(guid, vdev_raidz_read);
- else if (!strcmp(type, VDEV_TYPE_REPLACING))
+ else if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
vdev = vdev_create(guid, vdev_replacing_read);
- else if (!strcmp(type, VDEV_TYPE_INDIRECT)) {
+ else if (strcmp(type, VDEV_TYPE_INDIRECT) == 0) {
vdev_indirect_config_t *vic;
vdev = vdev_create(guid, vdev_indirect_read);
@@ -1213,7 +1216,7 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
} else {
char *name;
- if (!strcmp(type, "raidz")) {
+ if (strcmp(type, "raidz") == 0) {
if (vdev->v_nparity < 1 ||
vdev->v_nparity > 3) {
printf("ZFS: can only boot from disk, "
@@ -1221,12 +1224,12 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
"vdevs\n");
return (EIO);
}
- asprintf(&name, "%s%d-%" PRIu64, type,
+ rc = asprintf(&name, "%s%d-%" PRIu64, type,
vdev->v_nparity, id);
} else {
- asprintf(&name, "%s-%" PRIu64, type, id);
+ rc = asprintf(&name, "%s-%" PRIu64, type, id);
}
- if (name == NULL)
+ if (rc < 0)
return (ENOMEM);
vdev->v_name = name;
}
@@ -1266,7 +1269,7 @@ vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
return (rc);
if (is_new)
STAILQ_INSERT_TAIL(&vdev->v_children, kid,
- v_childlink);
+ v_childlink);
kids = nvlist_next(kids);
}
} else {
@@ -1328,7 +1331,7 @@ spa_find_by_guid(uint64_t guid)
if (spa->spa_guid == guid)
return (spa);
- return (0);
+ return (NULL);
}
static spa_t *
@@ -1337,10 +1340,10 @@ spa_find_by_name(const char *name)
spa_t *spa;
STAILQ_FOREACH(spa, &zfs_pools, spa_link)
- if (!strcmp(spa->spa_name, name))
+ if (strcmp(spa->spa_name, name) == 0)
return (spa);
- return (0);
+ return (NULL);
}
spa_t *
@@ -1363,7 +1366,7 @@ spa_get_primary_vdev(const spa_t *spa)
if (vdev == NULL)
return (NULL);
for (kid = STAILQ_FIRST(&vdev->v_children); kid != NULL;
- kid = STAILQ_FIRST(&vdev->v_children))
+ kid = STAILQ_FIRST(&vdev->v_children))
vdev = kid;
return (vdev);
}
@@ -1389,7 +1392,7 @@ spa_create(uint64_t guid, const char *name)
static const char *
state_name(vdev_state_t state)
{
- static const char* names[] = {
+ static const char *names[] = {
"UNKNOWN",
"CLOSED",
"OFFLINE",
@@ -1399,7 +1402,7 @@ state_name(vdev_state_t state)
"DEGRADED",
"ONLINE"
};
- return names[state];
+ return (names[state]);
}
static int
@@ -1414,7 +1417,7 @@ pager_printf(const char *fmt, ...)
return (pager_output(line));
}
-#define STATUS_FORMAT " %s %s\n"
+#define STATUS_FORMAT " %s %s\n"
static int
print_state(int indent, const char *name, vdev_state_t state)
@@ -1436,7 +1439,7 @@ vdev_status(vdev_t *vdev, int indent)
int ret;
if (vdev->v_islog) {
- (void)pager_output(" logs\n");
+ (void) pager_output(" logs\n");
indent++;
}
@@ -1731,7 +1734,7 @@ vdev_probe(vdev_phys_read_t *phys_read, void *read_priv, spa_t **spap)
if (!SPA_VERSION_IS_SUPPORTED(val)) {
printf("ZFS: unsupported ZFS version %u (should be %u)\n",
- (unsigned) val, (unsigned) SPA_VERSION);
+ (unsigned)val, (unsigned)SPA_VERSION);
free(nvlist);
return (EIO);
}
@@ -1876,8 +1879,8 @@ ilog2(int n)
for (v = 0; v < 32; v++)
if (n == (1 << v))
- return v;
- return -1;
+ return (v);
+ return (-1);
}
static int
@@ -1948,8 +1951,8 @@ zio_read(const spa_t *spa, const blkptr_t *bp, void *buf)
zfs_free(pbuf, size);
}
if (error != 0)
- printf("ZFS: i/o error - unable to decompress block pointer data, error %d\n",
- error);
+ printf("ZFS: i/o error - unable to decompress "
+ "block pointer data, error %d\n", error);
return (error);
}
@@ -2006,7 +2009,8 @@ zio_read(const spa_t *spa, const blkptr_t *bp, void *buf)
}
static int
-dnode_read(const spa_t *spa, const dnode_phys_t *dnode, off_t offset, void *buf, size_t buflen)
+dnode_read(const spa_t *spa, const dnode_phys_t *dnode, off_t offset,
+ void *buf, size_t buflen)
{
int ibshift = dnode->dn_indblkshift - SPA_BLKPTRSHIFT;
int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
@@ -2073,7 +2077,7 @@ dnode_read(const spa_t *spa, const dnode_phys_t *dnode, off_t offset, void *buf,
i = bsize - boff;
if (i > buflen) i = buflen;
memcpy(buf, &dnode_cache_buf[boff], i);
- buf = ((char*) buf) + i;
+ buf = ((char *)buf) + i;
offset += i;
buflen -= i;
}
@@ -2104,7 +2108,7 @@ mzap_lookup(const dnode_phys_t *dnode, const char *name, uint64_t *value)
for (i = 0; i < chunks; i++) {
mze = &mz->mz_chunk[i];
- if (!strcmp(mze->mze_name, name)) {
+ if (strcmp(mze->mze_name, name) == 0) {
*value = mze->mze_value;
return (0);
}
@@ -2118,7 +2122,8 @@ mzap_lookup(const dnode_phys_t *dnode, const char *name, uint64_t *value)
* matches.
*/
static int
-fzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, const char *name)
+fzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc,
+ const char *name)
{
size_t namelen;
const zap_leaf_chunk_t *nc;
@@ -2130,6 +2135,7 @@ fzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, const char *na
p = name;
while (namelen > 0) {
size_t len;
+
len = namelen;
if (len > ZAP_LEAF_ARRAY_BYTES)
len = ZAP_LEAF_ARRAY_BYTES;
@@ -2140,7 +2146,7 @@ fzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, const char *na
nc = &ZAP_LEAF_CHUNK(zl, nc->l_array.la_next);
}
- return 1;
+ return (1);
}
/*
@@ -2159,7 +2165,7 @@ fzap_leaf_value(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc)
value = (value << 8) | p[i];
}
- return value;
+ return (value);
}
static void
@@ -2251,7 +2257,7 @@ fzap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name,
uint64_t integer_size, uint64_t num_integers, void *value)
{
int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
- zap_phys_t zh = *(zap_phys_t *) zap_scratch;
+ zap_phys_t zh = *(zap_phys_t *)zap_scratch;
fat_zap_t z;
uint64_t *ptrtbl;
uint64_t hash;
@@ -2264,17 +2270,17 @@ fzap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name,
return (rc);
z.zap_block_shift = ilog2(bsize);
- z.zap_phys = (zap_phys_t *) zap_scratch;
+ z.zap_phys = (zap_phys_t *)zap_scratch;
/*
* Figure out where the pointer table is and read it in if necessary.
*/
if (zh.zap_ptrtbl.zt_blk) {
rc = dnode_read(spa, dnode, zh.zap_ptrtbl.zt_blk * bsize,
- zap_scratch, bsize);
+ zap_scratch, bsize);
if (rc)
return (rc);
- ptrtbl = (uint64_t *) zap_scratch;
+ ptrtbl = (uint64_t *)zap_scratch;
} else {
ptrtbl = &ZAP_EMBEDDED_PTRTBL_ENT(&z, 0);
}
@@ -2291,20 +2297,21 @@ fzap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name,
if (rc)
return (rc);
- zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
+ zl.l_phys = (zap_leaf_phys_t *)zap_scratch;
/*
* Make sure this chunk matches our hash.
*/
- if (zl.l_phys->l_hdr.lh_prefix_len > 0
- && zl.l_phys->l_hdr.lh_prefix
- != hash >> (64 - zl.l_phys->l_hdr.lh_prefix_len))
+ if (zl.l_phys->l_hdr.lh_prefix_len > 0 &&
+ zl.l_phys->l_hdr.lh_prefix !=
+ hash >> (64 - zl.l_phys->l_hdr.lh_prefix_len))
return (ENOENT);
/*
* Hash within the chunk to find our entry.
*/
- int shift = (64 - ZAP_LEAF_HASH_SHIFT(&zl) - zl.l_phys->l_hdr.lh_prefix_len);
+ int shift = (64 - ZAP_LEAF_HASH_SHIFT(&zl) -
+ zl.l_phys->l_hdr.lh_prefix_len);
int h = (hash >> shift) & ((1 << ZAP_LEAF_HASH_SHIFT(&zl)) - 1);
h = zl.l_phys->l_hash[h];
if (h == 0xffff)
@@ -2343,12 +2350,12 @@ zap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name,
if (rc)
return (rc);
- zap_type = *(uint64_t *) zap_scratch;
+ zap_type = *(uint64_t *)zap_scratch;
if (zap_type == ZBT_MICRO)
- return mzap_lookup(dnode, name, value);
+ return (mzap_lookup(dnode, name, value));
else if (zap_type == ZBT_HEADER) {
- return fzap_lookup(spa, dnode, name, integer_size,
- num_integers, value);
+ return (fzap_lookup(spa, dnode, name, integer_size,
+ num_integers, value));
}
printf("ZFS: invalid zap_type=%d\n", (int)zap_type);
return (EIO);
@@ -2391,10 +2398,11 @@ mzap_list(const dnode_phys_t *dnode, int (*callback)(const char *, uint64_t))
* the directory header.
*/
static int
-fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const char *, uint64_t))
+fzap_list(const spa_t *spa, const dnode_phys_t *dnode,
+ int (*callback)(const char *, uint64_t))
{
int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
- zap_phys_t zh = *(zap_phys_t *) zap_scratch;
+ zap_phys_t zh = *(zap_phys_t *)zap_scratch;
fat_zap_t z;
int i, j, rc;
@@ -2402,7 +2410,7 @@ fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const cha
return (EIO);
z.zap_block_shift = ilog2(bsize);
- z.zap_phys = (zap_phys_t *) zap_scratch;
+ z.zap_phys = (zap_phys_t *)zap_scratch;
/*
* This assumes that the leaf blocks start at block 1. The
@@ -2418,7 +2426,7 @@ fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const cha
if (dnode_read(spa, dnode, off, zap_scratch, bsize))
return (EIO);
- zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
+ zl.l_phys = (zap_leaf_phys_t *)zap_scratch;
for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
zap_leaf_chunk_t *zc, *nc;
@@ -2428,8 +2436,8 @@ fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const cha
if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY)
continue;
namelen = zc->l_entry.le_name_numints;
- if (namelen > sizeof(name))
- namelen = sizeof(name);
+ if (namelen > sizeof (name))
+ namelen = sizeof (name);
/*
* Paste the name back together.
@@ -2453,7 +2461,7 @@ fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const cha
*/
value = fzap_leaf_value(&zl, zc);
- //printf("%s 0x%jx\n", name, (uintmax_t)value);
+ /* printf("%s 0x%jx\n", name, (uintmax_t)value); */
rc = callback((const char *)name, value);
if (rc != 0)
return (rc);
@@ -2483,21 +2491,22 @@ zap_list(const spa_t *spa, const dnode_phys_t *dnode)
if (dnode_read(spa, dnode, 0, zap_scratch, size))
return (EIO);
- zap_type = *(uint64_t *) zap_scratch;
+ zap_type = *(uint64_t *)zap_scratch;
if (zap_type == ZBT_MICRO)
- return mzap_list(dnode, zfs_printf);
+ return (mzap_list(dnode, zfs_printf));
else
- return fzap_list(spa, dnode, zfs_printf);
+ return (fzap_list(spa, dnode, zfs_printf));
}
static int
-objset_get_dnode(const spa_t *spa, const objset_phys_t *os, uint64_t objnum, dnode_phys_t *dnode)
+objset_get_dnode(const spa_t *spa, const objset_phys_t *os, uint64_t objnum,
+ dnode_phys_t *dnode)
{
off_t offset;
- offset = objnum * sizeof(dnode_phys_t);
- return dnode_read(spa, &os->os_meta_dnode, offset,
- dnode, sizeof(dnode_phys_t));
+ offset = objnum * sizeof (dnode_phys_t);
+ return (dnode_read(spa, &os->os_meta_dnode, offset,
+ dnode, sizeof (dnode_phys_t)));
}
static int
@@ -2515,7 +2524,7 @@ mzap_rlookup(const spa_t *spa __unused, const dnode_phys_t *dnode, char *name,
*/
size = dnode->dn_datablkszsec * 512;
- mz = (const mzap_phys_t *) zap_scratch;
+ mz = (const mzap_phys_t *)zap_scratch;
chunks = size / MZAP_ENT_LEN - 1;
for (i = 0; i < chunks; i++) {
@@ -2555,10 +2564,11 @@ fzap_name_copy(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, char *name)
}
static int
-fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
+fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name,
+ uint64_t value)
{
int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
- zap_phys_t zh = *(zap_phys_t *) zap_scratch;
+ zap_phys_t zh = *(zap_phys_t *)zap_scratch;
fat_zap_t z;
int i, j;
@@ -2566,7 +2576,7 @@ fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t v
return (EIO);
z.zap_block_shift = ilog2(bsize);
- z.zap_phys = (zap_phys_t *) zap_scratch;
+ z.zap_phys = (zap_phys_t *)zap_scratch;
/*
* This assumes that the leaf blocks start at block 1. The
@@ -2580,7 +2590,7 @@ fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t v
if (dnode_read(spa, dnode, off, zap_scratch, bsize))
return (EIO);
- zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
+ zl.l_phys = (zap_leaf_phys_t *)zap_scratch;
for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
zap_leaf_chunk_t *zc;
@@ -2603,7 +2613,8 @@ fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t v
}
static int
-zap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
+zap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name,
+ uint64_t value)
{
int rc;
uint64_t zap_type;
@@ -2613,11 +2624,11 @@ zap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t va
if (rc)
return (rc);
- zap_type = *(uint64_t *) zap_scratch;
+ zap_type = *(uint64_t *)zap_scratch;
if (zap_type == ZBT_MICRO)
- return mzap_rlookup(spa, dnode, name, value);
+ return (mzap_rlookup(spa, dnode, name, value));
else
- return fzap_rlookup(spa, dnode, name, value);
+ return (fzap_rlookup(spa, dnode, name, value));
}
static int
@@ -2632,7 +2643,7 @@ zfs_rlookup(const spa_t *spa, uint64_t objnum, char *result)
char *p;
int len;
- p = &name[sizeof(name) - 1];
+ p = &name[sizeof (name) - 1];
*p = '\0';
if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
@@ -2648,15 +2659,17 @@ zfs_rlookup(const spa_t *spa, uint64_t objnum, char *result)
dd = (dsl_dir_phys_t *)&dir.dn_bonus;
/* Actual loop condition. */
- parent_obj = dd->dd_parent_obj;
+ parent_obj = dd->dd_parent_obj;
if (parent_obj == 0)
break;
- if (objset_get_dnode(spa, &spa->spa_mos, parent_obj, &parent) != 0)
+ if (objset_get_dnode(spa, &spa->spa_mos, parent_obj,
+ &parent) != 0)
return (EIO);
dd = (dsl_dir_phys_t *)&parent.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)
+ if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj,
+ &child_dir_zap) != 0)
return (EIO);
if (zap_rlookup(spa, &child_dir_zap, component, dir_obj) != 0)
return (EIO);
@@ -2687,7 +2700,8 @@ zfs_lookup_dataset(const spa_t *spa, const char *name, uint64_t *objnum)
dsl_dir_phys_t *dd;
const char *p, *q;
- if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir))
+ if (objset_get_dnode(spa, &spa->spa_mos,
+ DMU_POOL_DIRECTORY_OBJECT, &dir))
return (EIO);
if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, sizeof (dir_obj),
1, &dir_obj))
@@ -2716,7 +2730,8 @@ zfs_lookup_dataset(const spa_t *spa, const char *name, uint64_t *objnum)
}
child_dir_zapobj = dd->dd_child_dir_zapobj;
- if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0)
+ if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj,
+ &child_dir_zap) != 0)
return (EIO);
/* Actual loop condition #2. */
@@ -2731,7 +2746,7 @@ zfs_lookup_dataset(const spa_t *spa, const char *name, uint64_t *objnum)
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
static int
-zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
+zfs_list_dataset(const spa_t *spa, uint64_t objnum)
{
uint64_t dir_obj, child_dir_zapobj;
dnode_phys_t child_dir_zap, dir, dataset;
@@ -2742,7 +2757,7 @@ zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
return (EIO);
}
- ds = (dsl_dataset_phys_t *) &dataset.dn_bonus;
+ 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)) {
@@ -2752,7 +2767,8 @@ zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
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) {
+ 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);
}
@@ -2761,7 +2777,8 @@ zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
}
int
-zfs_callback_dataset(const spa_t *spa, uint64_t objnum, int (*callback)(const char *, uint64_t))
+zfs_callback_dataset(const spa_t *spa, uint64_t objnum,
+ int (*callback)(const char *, uint64_t))
{
uint64_t dir_obj, child_dir_zapobj, zap_type;
dnode_phys_t child_dir_zap, dir, dataset;
@@ -2774,7 +2791,7 @@ zfs_callback_dataset(const spa_t *spa, uint64_t objnum, int (*callback)(const ch
printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
return (err);
}
- ds = (dsl_dataset_phys_t *) &dataset.dn_bonus;
+ ds = (dsl_dataset_phys_t *)&dataset.dn_bonus;
dir_obj = ds->ds_dir_obj;
err = objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir);
@@ -2785,21 +2802,23 @@ zfs_callback_dataset(const spa_t *spa, uint64_t objnum, int (*callback)(const ch
dd = (dsl_dir_phys_t *)&dir.dn_bonus;
child_dir_zapobj = dd->dd_child_dir_zapobj;
- err = objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap);
+ err = objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj,
+ &child_dir_zap);
if (err != 0) {
printf("ZFS: can't find child zap %ju\n", (uintmax_t)dir_obj);
return (err);
}
- err = dnode_read(spa, &child_dir_zap, 0, zap_scratch, child_dir_zap.dn_datablkszsec * 512);
+ err = dnode_read(spa, &child_dir_zap, 0, zap_scratch,
+ child_dir_zap.dn_datablkszsec * 512);
if (err != 0)
return (err);
- zap_type = *(uint64_t *) zap_scratch;
+ zap_type = *(uint64_t *)zap_scratch;
if (zap_type == ZBT_MICRO)
- return mzap_list(&child_dir_zap, callback);
+ return (mzap_list(&child_dir_zap, callback));
else
- return fzap_list(spa, &child_dir_zap, callback);
+ return (fzap_list(spa, &child_dir_zap, callback));
}
/*
@@ -2817,7 +2836,7 @@ zfs_mount_dataset(const spa_t *spa, uint64_t objnum, objset_phys_t *objset)
return (EIO);
}
- ds = (dsl_dataset_phys_t *) &dataset.dn_bonus;
+ ds = (dsl_dataset_phys_t *)&dataset.dn_bonus;
if (zio_read(spa, &ds->ds_bp, objset)) {
printf("ZFS: can't read object set for dataset %ju\n",
(uintmax_t)objnum);
@@ -2842,7 +2861,8 @@ zfs_get_root(const spa_t *spa, uint64_t *objid)
/*
* Start with the MOS directory object.
*/
- if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir)) {
+ if (objset_get_dnode(spa, &spa->spa_mos,
+ DMU_POOL_DIRECTORY_OBJECT, &dir)) {
printf("ZFS: can't read MOS object directory\n");
return (EIO);
}
@@ -2850,19 +2870,20 @@ zfs_get_root(const spa_t *spa, uint64_t *objid)
/*
* Lookup the pool_props and see if we can find a bootfs.
*/
- if (zap_lookup(spa, &dir, DMU_POOL_PROPS, sizeof (props), 1, &props) == 0
- && objset_get_dnode(spa, &spa->spa_mos, props, &propdir) == 0
- && zap_lookup(spa, &propdir, "bootfs", sizeof (bootfs), 1, &bootfs) == 0
- && bootfs != 0)
- {
+ if (zap_lookup(spa, &dir, DMU_POOL_PROPS,
+ sizeof (props), 1, &props) == 0 &&
+ objset_get_dnode(spa, &spa->spa_mos, props, &propdir) == 0 &&
+ zap_lookup(spa, &propdir, "bootfs",
+ sizeof (bootfs), 1, &bootfs) == 0 && bootfs != 0) {
*objid = bootfs;
return (0);
}
/*
* Lookup the root dataset directory
*/
- if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, sizeof (root), 1, &root)
- || objset_get_dnode(spa, &spa->spa_mos, root, &dir)) {
+ if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET,
+ sizeof (root), 1, &root) ||
+ objset_get_dnode(spa, &spa->spa_mos, root, &dir)) {
printf("ZFS: can't find root dsl_dir\n");
return (EIO);
}
@@ -2871,7 +2892,7 @@ zfs_get_root(const spa_t *spa, uint64_t *objid)
* Use the information from the dataset directory's bonus buffer
* to find the dataset object and from that the object set itself.
*/
- dsl_dir_phys_t *dd = (dsl_dir_phys_t *) &dir.dn_bonus;
+ dsl_dir_phys_t *dd = (dsl_dir_phys_t *)&dir.dn_bonus;
*objid = dd->dd_head_dataset_obj;
return (0);
}
@@ -2956,7 +2977,7 @@ check_mos_features(const spa_t *spa)
if (dnode_read(spa, &dir, 0, zap_scratch, size))
return (EIO);
- zap_type = *(uint64_t *) zap_scratch;
+ zap_type = *(uint64_t *)zap_scratch;
if (zap_type == ZBT_MICRO)
rc = mzap_list(&dir, check_feature);
else
@@ -3052,8 +3073,7 @@ zfs_spa_init(spa_t *spa)
goto done;
}
- if (nvlist_find(nv, ZPOOL_CONFIG_TYPE, DATA_TYPE_STRING,
- NULL, &type)) {
+ if (nvlist_find(nv, ZPOOL_CONFIG_TYPE, DATA_TYPE_STRING, NULL, &type)) {
printf("ZFS: can't find vdev details\n");
rc = ENOENT;
goto done;
@@ -3064,7 +3084,7 @@ zfs_spa_init(spa_t *spa)
}
rc = nvlist_find(nv, ZPOOL_CONFIG_CHILDREN, DATA_TYPE_NVLIST_ARRAY,
- &nkids, &nv);
+ &nkids, &nv);
if (rc != 0)
goto done;
@@ -3199,9 +3219,9 @@ zfs_dnode_readlink(const spa_t *spa, dnode_phys_t *dn, char *path, size_t psize)
* Second test is purely to silence bogus compiler
* warning about accessing past the end of dn_bonus.
*/
- if (psize + sizeof(znode_phys_t) <= dn->dn_bonuslen &&
- sizeof(znode_phys_t) <= sizeof(dn->dn_bonus)) {
- memcpy(path, &dn->dn_bonus[sizeof(znode_phys_t)], psize);
+ if (psize + sizeof (znode_phys_t) <= dn->dn_bonuslen &&
+ sizeof (znode_phys_t) <= sizeof (dn->dn_bonus)) {
+ memcpy(path, &dn->dn_bonus[sizeof (znode_phys_t)], psize);
} else {
rc = dnode_read(spa, dn, 0, path, psize);
}
@@ -3238,7 +3258,7 @@ zfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
return (EIO);
}
- if ((entry = malloc(sizeof(struct obj_list))) == NULL)
+ if ((entry = malloc(sizeof (struct obj_list))) == NULL)
return (ENOMEM);
/*
@@ -3250,7 +3270,7 @@ zfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
return (rc);
}
- rc = zap_lookup(spa, &dn, ZFS_ROOT_OBJ, sizeof(objnum), 1, &objnum);
+ rc = zap_lookup(spa, &dn, ZFS_ROOT_OBJ, sizeof (objnum), 1, &objnum);
if (rc) {
free(entry);
return (rc);
@@ -3295,7 +3315,7 @@ zfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
objnum = (STAILQ_FIRST(&on_cache))->objnum;
continue;
}
- if (q - p + 1 > sizeof(element)) {
+ if (q - p + 1 > sizeof (element)) {
rc = ENAMETOOLONG;
goto done;
}
@@ -3310,12 +3330,12 @@ zfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
goto done;
}
- rc = zap_lookup(spa, &dn, element, sizeof(objnum), 1, &objnum);
+ rc = zap_lookup(spa, &dn, element, sizeof (objnum), 1, &objnum);
if (rc)
goto done;
objnum = ZFS_DIRENT_OBJ(objnum);
- if ((entry = malloc(sizeof(struct obj_list))) == NULL) {
+ if ((entry = malloc(sizeof (struct obj_list))) == NULL) {
rc = ENOMEM;
goto done;
}
@@ -3342,7 +3362,7 @@ zfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
* Read the link value and copy the tail of our
* current path onto the end.
*/
- if (sb.st_size + strlen(p) + 1 > sizeof(path)) {
+ if (sb.st_size + strlen(p) + 1 > sizeof (path)) {
rc = ENAMETOOLONG;
goto done;
}