aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsck_msdosfs/dir.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2019-09-15 19:41:54 +0000
committerXin LI <delphij@FreeBSD.org>2019-09-15 19:41:54 +0000
commiteb1c42c1f072e7083e0055b479154afd68cbc629 (patch)
tree9bb1b6a0c0ba742eaa918ed668403514173ca48e /sbin/fsck_msdosfs/dir.c
parent7887a5a1407ac30cf13e5acfd1ce70e4ac27708f (diff)
Avoid mixing cluster numbers and sector numbers. Makes code more readable.
Obtained from: NetBSD MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=352364
Diffstat (limited to 'sbin/fsck_msdosfs/dir.c')
-rw-r--r--sbin/fsck_msdosfs/dir.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c
index 2163db049fac..7e459c75d4ff 100644
--- a/sbin/fsck_msdosfs/dir.c
+++ b/sbin/fsck_msdosfs/dir.c
@@ -317,7 +317,8 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
break;
e = delbuf + endoff;
}
- off = startcl * boot->bpbSecPerClust + boot->ClusterOffset;
+ off = (startcl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster;
+
off *= boot->bpbBytesPerSec;
if (lseek(f, off, SEEK_SET) != off) {
perr("Unable to lseek to %" PRId64, off);
@@ -457,7 +458,7 @@ check_subdirectory(int f, struct bootblock *boot, struct dosDirEntry *dir)
off = boot->bpbResSectors + boot->bpbFATs *
boot->FATsecs;
} else {
- off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
+ off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster;
}
/*
@@ -538,7 +539,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
boot->FATsecs;
} else {
last = boot->bpbSecPerClust * boot->bpbBytesPerSec;
- off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
+ off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster;
}
off *= boot->bpbBytesPerSec;
@@ -1069,8 +1070,9 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
lfcl = (lostDir->head < boot->NumClusters) ? lostDir->head : 0;
return FSERROR;
}
- lfoff = lfcl * boot->ClusterSize
- + boot->ClusterOffset * boot->bpbBytesPerSec;
+ lfoff = (lfcl - CLUST_FIRST) * boot->ClusterSize
+ + boot->FirstCluster * boot->bpbBytesPerSec;
+
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
perr("could not read LOST.DIR");