Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/zfs/zfsimpl.c
Show First 20 Lines • Show All 1,467 Lines • ▼ Show 20 Lines | zap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name, uint64_t *value) | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
/* | /* | ||||
* List a microzap directory. Assumes that the zap scratch buffer contains | * List a microzap directory. Assumes that the zap scratch buffer contains | ||||
* the directory contents. | * the directory contents. | ||||
*/ | */ | ||||
static int | static int | ||||
mzap_list(const dnode_phys_t *dnode) | mzap_list(const dnode_phys_t *dnode, int (*callback)(const char *)) | ||||
{ | { | ||||
const mzap_phys_t *mz; | const mzap_phys_t *mz; | ||||
const mzap_ent_phys_t *mze; | const mzap_ent_phys_t *mze; | ||||
size_t size; | size_t size; | ||||
int chunks, i; | int chunks, i; | ||||
/* | /* | ||||
* Microzap objects use exactly one block. Read the whole | * Microzap objects use exactly one block. Read the whole | ||||
* thing. | * thing. | ||||
*/ | */ | ||||
size = dnode->dn_datablkszsec * 512; | 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; | chunks = size / MZAP_ENT_LEN - 1; | ||||
for (i = 0; i < chunks; i++) { | for (i = 0; i < chunks; i++) { | ||||
mze = &mz->mz_chunk[i]; | mze = &mz->mz_chunk[i]; | ||||
if (mze->mze_name[0]) | if (mze->mze_name[0]) | ||||
//printf("%-32s 0x%jx\n", mze->mze_name, (uintmax_t)mze->mze_value); | //printf("%-32s 0x%jx\n", mze->mze_name, (uintmax_t)mze->mze_value); | ||||
printf("%s\n", mze->mze_name); | callback(mze->mze_name); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* List a fatzap directory. Assumes that the zap scratch buffer contains | * List a fatzap directory. Assumes that the zap scratch buffer contains | ||||
* the directory header. | * the directory header. | ||||
*/ | */ | ||||
static int | static int | ||||
fzap_list(const spa_t *spa, const dnode_phys_t *dnode) | fzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const char *)) | ||||
{ | { | ||||
int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; | 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; | fat_zap_t z; | ||||
int i, j; | int i, j; | ||||
if (zh.zap_magic != ZAP_MAGIC) | if (zh.zap_magic != ZAP_MAGIC) | ||||
return (EIO); | return (EIO); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) { | ||||
/* | /* | ||||
* Assume the first eight bytes of the value are | * Assume the first eight bytes of the value are | ||||
* a uint64_t. | * a uint64_t. | ||||
*/ | */ | ||||
value = fzap_leaf_value(&zl, zc); | value = fzap_leaf_value(&zl, zc); | ||||
//printf("%s 0x%jx\n", name, (uintmax_t)value); | //printf("%s 0x%jx\n", name, (uintmax_t)value); | ||||
printf("%s\n", name); | callback((const char *)name); | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int zfs_printf(const char *name) | |||||
{ | |||||
bapt: To respect style(9) your need a space before this line | |||||
printf("%s\n", name); | |||||
Done Inline ActionsTo respect style(9) your need a space before this line bapt: To respect style(9) your need a space before this line | |||||
Done Inline ActionsActually I was wrong here, I misread style(9) bapt: Actually I was wrong here, I misread style(9) | |||||
return (0); | |||||
} | |||||
/* | /* | ||||
* List a zap directory. | * List a zap directory. | ||||
*/ | */ | ||||
static int | static int | ||||
zap_list(const spa_t *spa, const dnode_phys_t *dnode) | zap_list(const spa_t *spa, const dnode_phys_t *dnode) | ||||
{ | { | ||||
uint64_t zap_type; | uint64_t zap_type; | ||||
size_t size = dnode->dn_datablkszsec * 512; | size_t size = dnode->dn_datablkszsec * 512; | ||||
if (dnode_read(spa, dnode, 0, zap_scratch, size)) | if (dnode_read(spa, dnode, 0, zap_scratch, size)) | ||||
return (EIO); | return (EIO); | ||||
zap_type = *(uint64_t *) zap_scratch; | zap_type = *(uint64_t *) zap_scratch; | ||||
if (zap_type == ZBT_MICRO) | if (zap_type == ZBT_MICRO) | ||||
return mzap_list(dnode); | return mzap_list(dnode, zfs_printf); | ||||
else | else | ||||
return fzap_list(spa, dnode); | return fzap_list(spa, dnode, zfs_printf); | ||||
Not Done Inline ActionsNot new but due to the fact the if does a return, there's no need for the else here. smh: Not new but due to the fact the if does a return, there's no need for the else here. | |||||
} | } | ||||
static int | 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; | off_t offset; | ||||
offset = objnum * sizeof(dnode_phys_t); | offset = objnum * sizeof(dnode_phys_t); | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | zfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/) | ||||
child_dir_zapobj = dd->dd_child_dir_zapobj; | 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); | printf("ZFS: can't find child zap %ju\n", (uintmax_t)dir_obj); | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
return (zap_list(spa, &child_dir_zap) != 0); | return (zap_list(spa, &child_dir_zap) != 0); | ||||
} | |||||
int | |||||
zfs_callback_dataset(const spa_t *spa, uint64_t objnum, int (*callback)(const char *name)) | |||||
{ | |||||
uint64_t dir_obj, child_dir_zapobj, zap_type; | |||||
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)) { | |||||
Done Inline ActionsAssign to err value and return what you go, so we don't loose info about the error + style(9) bool test fix e.g. err = objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset); if (err != 0) { printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum); return (err); } more below too and the same with dnode_read smh: Assign to err value and return what you go, so we don't loose info about the error + style(9)… | |||||
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); | |||||
} | |||||
if (dnode_read(spa, &child_dir_zap, 0, zap_scratch, child_dir_zap.dn_datablkszsec * 512)) | |||||
return (EIO); | |||||
zap_type = *(uint64_t *) zap_scratch; | |||||
if (zap_type == ZBT_MICRO) | |||||
return mzap_list(&child_dir_zap, callback); | |||||
else | |||||
Not Done Inline ActionsNo need for else here. smh: No need for else here. | |||||
return fzap_list(spa, &child_dir_zap, callback); | |||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* Find the object set given the object number of its dataset object | * Find the object set given the object number of its dataset object | ||||
* and return its details in *objset | * and return its details in *objset | ||||
*/ | */ | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines |
To respect style(9) your need a space before this line