aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsirand/fsirand.c
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2018-11-13 21:40:56 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-11-13 21:40:56 +0000
commit9fc5d538fc57f438ca860e07db191b946b4768c9 (patch)
tree0f73178df156f836c4d9dde3af92b526b95c4e72 /sbin/fsirand/fsirand.c
parentf183fb162c1dbc58cc3f7e2c27891bd881db2bf2 (diff)
downloadsrc-9fc5d538fc57f438ca860e07db191b946b4768c9.tar.gz
src-9fc5d538fc57f438ca860e07db191b946b4768c9.zip
In preparation for adding inode check-hashes, clean up and
document the libufs interface for fetching and storing inodes. The undocumented getino / putino interface has been replaced with a new getinode / putinode interface. Convert the utilities that had been using the undocumented interface to use the new documented interface. No functional change (as for now the libufs library does not do inode check-hashes). Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=340411
Diffstat (limited to 'sbin/fsirand/fsirand.c')
-rw-r--r--sbin/fsirand/fsirand.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c
index bb0f27a59301..f5e26571f903 100644
--- a/sbin/fsirand/fsirand.c
+++ b/sbin/fsirand/fsirand.c
@@ -175,7 +175,7 @@ fsirand(char *device)
}
/* For each cylinder group, randomize inodes and update backup sblock */
- for (cg = 0, inumber = 0; cg < (int)sblock->fs_ncg; cg++) {
+ for (cg = 0, inumber = UFS_ROOTINO; cg < (int)sblock->fs_ncg; cg++) {
/* Read in inodes, then print or randomize generation nums */
dblk = fsbtodb(sblock, ino_to_fsba(sblock, inumber));
if (lseek(devfd, (off_t)dblk * bsize, SEEK_SET) < 0) {
@@ -187,21 +187,22 @@ fsirand(char *device)
return (1);
}
- for (n = 0; n < (int)sblock->fs_ipg; n++, inumber++) {
- if (sblock->fs_magic == FS_UFS1_MAGIC)
- dp1 = &((struct ufs1_dinode *)inodebuf)[n];
- else
- dp2 = &((struct ufs2_dinode *)inodebuf)[n];
- if (inumber >= UFS_ROOTINO) {
- if (printonly)
- (void)printf("ino %ju gen %08x\n",
- (uintmax_t)inumber,
- sblock->fs_magic == FS_UFS1_MAGIC ?
- dp1->di_gen : dp2->di_gen);
- else if (sblock->fs_magic == FS_UFS1_MAGIC)
- dp1->di_gen = random();
- else
- dp2->di_gen = random();
+ dp1 = (struct ufs1_dinode *)(void *)inodebuf;
+ dp2 = (struct ufs2_dinode *)(void *)inodebuf;
+ for (n = cg > 0 ? 0 : UFS_ROOTINO;
+ n < (int)sblock->fs_ipg;
+ n++, inumber++) {
+ if (printonly) {
+ (void)printf("ino %ju gen %08x\n",
+ (uintmax_t)inumber,
+ sblock->fs_magic == FS_UFS1_MAGIC ?
+ dp1->di_gen : dp2->di_gen);
+ } else if (sblock->fs_magic == FS_UFS1_MAGIC) {
+ dp1->di_gen = arc4random();
+ dp1++;
+ } else {
+ dp2->di_gen = arc4random();
+ dp2++;
}
}