Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/fsck_msdos Avoid mixing cluster numbers and sector numb...



details:   https://anonhg.NetBSD.org/src/rev/1da537bfbe11
branches:  trunk
changeset: 335291:1da537bfbe11
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Fri Jan 02 06:21:28 2015 +0000

description:
Avoid mixing cluster numbers and sector numbers. Makes code more readable.

diffstat:

 sbin/fsck_msdos/boot.c  |  17 +++++++++--------
 sbin/fsck_msdos/dir.c   |  12 ++++++------
 sbin/fsck_msdos/dosfs.h |   4 ++--
 3 files changed, 17 insertions(+), 16 deletions(-)

diffs (112 lines):

diff -r 93f33da630c9 -r 1da537bfbe11 sbin/fsck_msdos/boot.c
--- a/sbin/fsck_msdos/boot.c    Fri Jan 02 02:00:15 2015 +0000
+++ b/sbin/fsck_msdos/boot.c    Fri Jan 02 06:21:28 2015 +0000
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: boot.c,v 1.18 2014/11/04 03:05:43 msaitoh Exp $");
+__RCSID("$NetBSD: boot.c,v 1.19 2015/01/02 06:21:28 mlelstv Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -185,11 +185,10 @@
                return FSFATAL;
        }
 
-       boot->ClusterOffset = (int)(boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
+       boot->FirstCluster = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
            / boot->BytesPerSec
            + boot->ResSectors
-           + boot->FATs * boot->FATsecs
-           - CLUST_FIRST * boot->SecPerClust;
+           + boot->FATs * boot->FATsecs;
 
        if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
                pfatal("Invalid sector size: %u", boot->BytesPerSec);
@@ -204,14 +203,16 @@
                boot->NumSectors = boot->Sectors;
        } else
                boot->NumSectors = boot->HugeSectors;
-       boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->SecPerClust;
 
-       if (boot->ClusterOffset > (intmax_t)boot->NumSectors) {
-               pfatal("Cluster offset too large (%d sectors)\n",
-                   boot->ClusterOffset);
+       if (boot->FirstCluster + boot->SecPerClust > boot->NumSectors) {
+               pfatal("Cluster offset too large (%u clusters)\n",
+                   boot->FirstCluster);
                return FSFATAL;
        }
 
+       boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->SecPerClust
+                           + CLUST_FIRST;
+
        if (boot->flags&FAT32)
                boot->ClustMask = CLUST32_MASK;
        else if (boot->NumClusters < (CLUST_RSRVD&CLUST12_MASK))
diff -r 93f33da630c9 -r 1da537bfbe11 sbin/fsck_msdos/dir.c
--- a/sbin/fsck_msdos/dir.c     Fri Jan 02 02:00:15 2015 +0000
+++ b/sbin/fsck_msdos/dir.c     Fri Jan 02 06:21:28 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $        */
+/*     $NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $");
+__RCSID("$NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -326,7 +326,7 @@
                                break;
                        e = delbuf + endoff;
                }
-               off = startcl * boot->SecPerClust + boot->ClusterOffset;
+               off = (startcl - CLUST_FIRST) * boot->SecPerClust + boot->FirstCluster;
                off *= boot->BytesPerSec;
                if (lseek(f, off, SEEK_SET) != off
                    || read(f, delbuf, clsz) != clsz) {
@@ -491,7 +491,7 @@
                        off = boot->ResSectors + boot->FATs * boot->FATsecs;
                } else {
                        last = boot->SecPerClust * boot->BytesPerSec;
-                       off = cl * boot->SecPerClust + boot->ClusterOffset;
+                       off = (cl - CLUST_FIRST) * boot->SecPerClust + boot->FirstCluster;
                }
 
                off *= boot->BytesPerSec;
@@ -967,8 +967,8 @@
                        pwarn("No space in %s\n", LOSTDIR);
                        return FSERROR;
                }
-               lfoff = lfcl * boot->ClusterSize
-                   + boot->ClusterOffset * boot->BytesPerSec;
+               lfoff = (lfcl - CLUST_FIRST) * boot->ClusterSize
+                   + boot->FirstCluster * boot->BytesPerSec;
                if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
                    || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
                        perr("could not read LOST.DIR");
diff -r 93f33da630c9 -r 1da537bfbe11 sbin/fsck_msdos/dosfs.h
--- a/sbin/fsck_msdos/dosfs.h   Fri Jan 02 02:00:15 2015 +0000
+++ b/sbin/fsck_msdos/dosfs.h   Fri Jan 02 06:21:28 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dosfs.h,v 1.7 2014/11/03 18:55:04 jakllsch Exp $       */
+/*     $NetBSD: dosfs.h,v 1.8 2015/01/02 06:21:28 mlelstv Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -70,7 +70,7 @@
        u_int32_t NumSectors;           /* how many sectors are there */
        u_int32_t FATsecs;              /* how many sectors are in FAT */
        u_int32_t NumFatEntries;        /* how many entries really are there */
-       int     ClusterOffset;          /* at what sector would sector 0 start */
+       u_int   FirstCluster;           /* at what sector is Cluster CLUST_FIRST */
        u_int   ClusterSize;            /* Cluster size in bytes */
 
        /* Now some statistics: */



Home | Main Index | Thread Index | Old Index