calculate the 'offset' argument to lseek() in a prettier way, more

consistent with the way fsck(8) does it.  no functional change.
This commit is contained in:
cgd 1995-03-18 07:02:29 +00:00
parent ca3ff7bdd8
commit 909eb54fbb
2 changed files with 15 additions and 6 deletions

View File

@ -33,7 +33,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)mkfs.c 8.3 (Berkeley) 2/3/94";*/
static char *rcsid = "$Id: mkfs.c,v 1.17 1995/03/04 06:28:20 cgd Exp $";
static char *rcsid = "$Id: mkfs.c,v 1.18 1995/03/18 07:02:29 cgd Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -1090,12 +1090,15 @@ rdfs(bno, size, bf)
char *bf;
{
int n;
off_t offset;
if (mfs) {
memcpy(bf, membase + bno * sectorsize, size);
return;
}
if (lseek(fsi, (off_t)bno * sectorsize, SEEK_SET) < 0) {
offset = bno;
offset *= sectorsize;
if (lseek(fsi, offset, SEEK_SET) < 0) {
printf("seek error: %ld\n", bno);
perror("rdfs");
exit(33);
@ -1117,6 +1120,7 @@ wtfs(bno, size, bf)
char *bf;
{
int n;
off_t offset;
if (mfs) {
memcpy(membase + bno * sectorsize, bf, size);
@ -1124,7 +1128,9 @@ wtfs(bno, size, bf)
}
if (Nflag)
return;
if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) {
offset = bno;
offset *= sectorsize;
if (lseek(fso, offset, SEEK_SET) < 0) {
printf("seek error: %ld\n", bno);
perror("wtfs");
exit(35);

View File

@ -39,7 +39,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)newfs.c 8.8 (Berkeley) 4/18/94";*/
static char *rcsid = "$Id: newfs.c,v 1.16 1995/03/04 06:11:13 cgd Exp $";
static char *rcsid = "$Id: newfs.c,v 1.17 1995/03/18 07:02:38 cgd Exp $";
#endif /* not lint */
/*
@ -624,8 +624,11 @@ rewritelabel(s, fd, lp)
*(struct disklabel *)(blk + LABELOFFSET) = *lp;
alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
if (lseek(cfd, (off_t)(alt + i) * lp->d_secsize,
SEEK_SET) == -1)
off_t offset;
offset = alt + i;
offset *= lp->d_secsize;
if (lseek(cfd, offset, SEEK_SET) == -1)
fatal("lseek to badsector area: %s",
strerror(errno));
if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)