From 377b6539a81a24c69d498b87c97027db1fce1f04 Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 23 Oct 1998 01:27:51 +0000 Subject: [PATCH] Use DINODE_SIZE instead of sizeof(struct dinode) and/or pointer arithmetic. --- sbin/fsirand/fsirand.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c index 66b65d70012b..4a13e301ca0e 100644 --- a/sbin/fsirand/fsirand.c +++ b/sbin/fsirand/fsirand.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsirand.c,v 1.9 1998/08/25 19:18:16 ross Exp $ */ +/* $NetBSD: fsirand.c,v 1.10 1998/10/23 01:27:51 thorpej Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fsirand.c,v 1.9 1998/08/25 19:18:16 ross Exp $"); +__RCSID("$NetBSD: fsirand.c,v 1.10 1998/10/23 01:27:51 thorpej Exp $"); #endif /* lint */ #include @@ -139,11 +139,12 @@ fixinodes(fd, fs, lab, pflag, xorval) long xorval; { int inopb = INOPB(fs); - int size = inopb * sizeof(struct dinode); - struct dinode *dibuf, *dip; - int ino, imax; + int size = inopb * DINODE_SIZE; + caddr_t buf; + struct dinode *dip; + int i, ino, imax; - if ((dibuf = malloc(size)) == NULL) + if ((buf = malloc(size)) == NULL) err(1, "Out of memory"); for (ino = 0, imax = fs->fs_ipg * fs->fs_ncg; ino < imax;) { @@ -157,10 +158,11 @@ fixinodes(fd, fs, lab, pflag, xorval) if (lseek(fd, sp, SEEK_SET) == (off_t) -1) err(1, "Seeking to inode %d failed", ino); - if (read(fd, dibuf, size) != size) + if (read(fd, buf, size) != size) err(1, "Reading inodes %d+%d failed", ino, inopb); - for (dip = dibuf; dip < &dibuf[inopb]; dip++) { + for (i = 0; i < inopb; i++) { + dip = (struct dinode *)(buf + (i * DINODE_SIZE)); if (pflag) printf("ino %d gen 0x%x\n", ino, ufs_rw32(dip->di_gen, needswap)); @@ -176,10 +178,10 @@ fixinodes(fd, fs, lab, pflag, xorval) if (lseek(fd, sp, SEEK_SET) == (off_t) -1) err(1, "Seeking to inode %d failed", ino); - if (write(fd, dibuf, size) != size) + if (write(fd, buf, size) != size) err(1, "Writing inodes %d+%d failed", ino, inopb); } - free(dibuf); + free(buf); } int