Don't cast to void* for the 2nd argument to read() and write().
Only cast to off_t for the 2nd argument to lseek() when it's just a value.
*Do* cast just one operand of * to make sure the math is done in the
bigger type.
ok?
Index: sbin/fsirand//fsirand.c
===================================================================
RCS file: /data/src/openbsd/src/sbin/fsirand/fsirand.c,v
retrieving revision 1.38
diff -u -p -r1.38 fsirand.c
--- sbin/fsirand//fsirand.c 28 May 2016 17:16:39 -0000 1.38
+++ sbin/fsirand//fsirand.c 14 Aug 2016 21:02:26 -0000
@@ -131,13 +131,13 @@ fsirand(char *device)
for (i = 0; sbtry[i] != -1; i++) {
sblockloc = sbtry[i];
- if (lseek(devfd, (off_t)sblockloc, SEEK_SET) == -1) {
- warn("Can't seek to superblock (%qd) on %s", sblockloc,
- devpath);
+ if (lseek(devfd, sblockloc, SEEK_SET) == -1) {
+ warn("Can't seek to superblock (%lld) on %s",
+ (long long)sblockloc, devpath);
return (1);
}
- if ((n = read(devfd, (void *)sblock, SBSIZE)) != SBSIZE) {
+ if ((n = read(devfd, sblock, SBSIZE)) != SBSIZE) {
warnx("Can't read superblock on %s: %s", devpath,
(n < SBSIZE) ? "short read" : strerror(errno));
return (1);
@@ -180,10 +180,10 @@ fsirand(char *device)
tmpsblock = (struct fs *)&sbuftmp;
for (cg = 0; cg < sblock->fs_ncg; cg++) {
dblk = fsbtodb(sblock, cgsblock(sblock, cg));
- if (lseek(devfd, (off_t)dblk * (off_t)bsize, SEEK_SET) < 0) {
- warn("Can't seek to %qd", (off_t)dblk * bsize);
+ if (lseek(devfd, (off_t)dblk * bsize, SEEK_SET) < 0) {
+ warn("Can't seek to %lld", (long long)dblk * bsize);
return (1);
- } else if ((n = read(devfd, (void *)tmpsblock, SBSIZE)) !=
SBSIZE) {
+ } else if ((n = read(devfd, tmpsblock, SBSIZE)) != SBSIZE) {
warn("Can't read backup superblock %d on %s: %s",
cg + 1, devpath, (n < SBSIZE) ? "short read"
: strerror(errno));
@@ -229,12 +229,12 @@ fsirand(char *device)
sblock->fs_id[0] = (u_int32_t)time(NULL);
sblock->fs_id[1] = arc4random();
- if (lseek(devfd, (off_t)SBOFF, SEEK_SET) == -1) {
- warn("Can't seek to superblock (%qd) on %s", SBOFF,
- devpath);
+ if (lseek(devfd, SBOFF, SEEK_SET) == -1) {
+ warn("Can't seek to superblock (%lld) on %s",
+ (long long)SBOFF, devpath);
return (1);
}
- if ((n = write(devfd, (void *)sblock, SBSIZE)) != SBSIZE) {
+ if ((n = write(devfd, sblock, SBSIZE)) != SBSIZE) {
warn("Can't write superblock on %s: %s", devpath,
(n < SBSIZE) ? "short write" : strerror(errno));
return (1);
@@ -246,11 +246,12 @@ fsirand(char *device)
/* Update superblock if appropriate */
if ((sblock->fs_inodefmt >= FS_44INODEFMT) && !printonly) {
dblk = fsbtodb(sblock, cgsblock(sblock, cg));
- if (lseek(devfd, (off_t)dblk * (off_t)bsize,
+ if (lseek(devfd, (off_t)dblk * bsize,
SEEK_SET) < 0) {
- warn("Can't seek to %qd", (off_t)dblk * bsize);
+ warn("Can't seek to %lld",
+ (long long)dblk * bsize);
return (1);
- } else if ((n = write(devfd, (void *)sblock, SBSIZE)) !=
+ } else if ((n = write(devfd, sblock, SBSIZE)) !=
SBSIZE) {
warn("Can't read backup superblock %d on %s:
%s",
cg + 1, devpath, (n < SBSIZE) ? "short
write"
@@ -261,8 +262,8 @@ fsirand(char *device)
/* Read in inodes, then print or randomize generation nums */
dblk = fsbtodb(sblock, ino_to_fsba(sblock, inumber));
- if (lseek(devfd, (off_t)dblk * (off_t)bsize, SEEK_SET) < 0) {
- warn("Can't seek to %qd", (off_t)dblk * bsize);
+ if (lseek(devfd, (off_t)dblk * bsize, SEEK_SET) < 0) {
+ warn("Can't seek to %lld", (long long)dblk * bsize);
return (1);
} else if ((n = read(devfd, inodebuf, ibufsize)) != ibufsize) {
warnx("Can't read inodes: %s",
@@ -290,9 +291,9 @@ fsirand(char *device)
/* Write out modified inodes */
if (!printonly) {
- if (lseek(devfd, (off_t)dblk * (off_t)bsize, SEEK_SET)
< 0) {
- warn("Can't seek to %qd",
- (off_t)dblk * bsize);
+ if (lseek(devfd, (off_t)dblk * bsize, SEEK_SET) < 0) {
+ warn("Can't seek to %lld",
+ (long long)dblk * bsize);
return (1);
} else if ((n = write(devfd, inodebuf, ibufsize)) !=
ibufsize) {