sbin/fsck_msdosfs: Bring in freebsd/freebsd@d704245c (s/perror/perr/)
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 14 Sep 2019 03:23:31 +0000 (12:23 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 14 Sep 2019 17:10:59 +0000 (02:10 +0900)
Ignore most of sbin/fsck part (not in sync with FreeBSD at all).

sbin/fsck/fsutil.c
sbin/fsck/fsutil.h
sbin/fsck_msdosfs/boot.c
sbin/fsck_msdosfs/check.c
sbin/fsck_msdosfs/dir.c
sbin/fsck_msdosfs/fat.c

index b8630d9..4659f75 100644 (file)
@@ -125,6 +125,16 @@ pwarn(const char *fmt, ...)
        va_end(ap);
 }
 
+void
+perr(const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vmsg(1, fmt, ap);
+       va_end(ap);
+}
+
 void
 perror(const char *s)
 {
index ff7703f..3de4341 100644 (file)
@@ -35,6 +35,7 @@ void perror(const char *);
 void errexit(const char *, ...) __printflike(1, 2) __dead2;
 void pfatal(const char *, ...) __printflike(1, 2);
 void pwarn(const char *, ...) __printflike(1, 2);
+void perr(const char *, ...) __printflike(1, 2);
 void panic(const char *, ...) __printflike(1, 2) __dead2;
 const char *rawname(const char *);
 const char *unrawname(const char *);
index 67fde7b..5bf173d 100644 (file)
@@ -43,7 +43,7 @@ readboot(int dosfs, struct bootblock *boot)
        int ret = FSOK;
 
        if (read(dosfs, block, sizeof block) < sizeof block) {
-               perror("could not read boot block");
+               perr("could not read boot block");
                return FSFATAL;
        }
 
@@ -96,7 +96,7 @@ readboot(int dosfs, struct bootblock *boot)
                    != boot->bpbFSInfo * boot->bpbBytesPerSec
                    || read(dosfs, fsinfo, sizeof fsinfo)
                    != sizeof fsinfo) {
-                       perror("could not read fsinfo block");
+                       perr("could not read fsinfo block");
                        return FSFATAL;
                }
                if (memcmp(fsinfo, "RRaA", 4)
@@ -123,7 +123,7 @@ readboot(int dosfs, struct bootblock *boot)
                                    != boot->bpbFSInfo * boot->bpbBytesPerSec
                                    || write(dosfs, fsinfo, sizeof fsinfo)
                                    != sizeof fsinfo) {
-                                       perror("Unable to write bpbFSInfo");
+                                       perr("Unable to write bpbFSInfo");
                                        return FSFATAL;
                                }
                                ret = FSBOOTMOD;
@@ -142,7 +142,7 @@ readboot(int dosfs, struct bootblock *boot)
                if (lseek(dosfs, boot->bpbBackup * boot->bpbBytesPerSec, SEEK_SET)
                    != boot->bpbBackup * boot->bpbBytesPerSec
                    || read(dosfs, backup, sizeof backup) != sizeof  backup) {
-                       perror("could not read backup bootblock");
+                       perr("could not read backup bootblock");
                        return FSFATAL;
                }
                if (memcmp(block, backup, DOSBOOTBLOCKSIZE)) {
@@ -219,7 +219,7 @@ writefsinfo(int dosfs, struct bootblock *boot)
        if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
            != boot->bpbFSInfo * boot->bpbBytesPerSec
            || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
-               perror("could not read fsinfo block");
+               perr("could not read fsinfo block");
                return FSFATAL;
        }
        fsinfo[0x1e8] = (u_char)boot->FSFree;
@@ -234,7 +234,7 @@ writefsinfo(int dosfs, struct bootblock *boot)
            != boot->bpbFSInfo * boot->bpbBytesPerSec
            || write(dosfs, fsinfo, sizeof fsinfo)
            != sizeof fsinfo) {
-               perror("Unable to write bpbFSInfo");
+               perr("Unable to write bpbFSInfo");
                return FSFATAL;
        }
        /*
index 6254ebc..bf8c593 100644 (file)
@@ -61,7 +61,7 @@ checkfilesys(const char *fname)
                printf("\n");
 
        if (dosfs < 0) {
-               perror("Can't open");
+               perr("Can't open `%s'", fname);
                return 8;
        }
 
index f5d531d..4046096 100644 (file)
@@ -223,7 +223,7 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
        if (!(buffer = malloc(b1 > b2 ? b1 : b2))
            || !(delbuf = malloc(b2))
            || !(rootDir = newDosDirEntry())) {
-               perror("No space for directory");
+               perr("No space for directory buffer");
                return FSFATAL;
        }
        memset(rootDir, 0, sizeof *rootDir);
@@ -313,7 +313,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
                off *= boot->bpbBytesPerSec;
                if (lseek(f, off, SEEK_SET) != off
                    || read(f, delbuf, clsz) != clsz) {
-                       perror("Unable to read directory");
+                       perr("Unable to read directory");
                        return FSFATAL;
                }
                while (s < e) {
@@ -322,7 +322,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
                }
                if (lseek(f, off, SEEK_SET) != off
                    || write(f, delbuf, clsz) != clsz) {
-                       perror("Unable to write directory");
+                       perr("Unable to write directory");
                        return FSFATAL;
                }
                if (startcl == endcl)
@@ -457,7 +457,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
                off *= boot->bpbBytesPerSec;
                if (lseek(f, off, SEEK_SET) != off
                    || read(f, buffer, last) != last) {
-                       perror("Unable to read directory");
+                       perr("Unable to read directory");
                        return FSFATAL;
                }
                last /= 32;
@@ -810,7 +810,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
 
                                /* create directory tree node */
                                if (!(d = newDosDirEntry())) {
-                                       perror("No space for directory");
+                                       perr("No space for directory");
                                        return FSFATAL;
                                }
                                memcpy(d, &dirent, sizeof(struct dosDirEntry));
@@ -819,7 +819,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
 
                                /* Enter this directory into the todo list */
                                if (!(n = newDirTodo())) {
-                                       perror("No space for todo list");
+                                       perr("No space for todo list");
                                        return FSFATAL;
                                }
                                n->next = pendingDirectories;
@@ -836,7 +836,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
                        last *= 32;
                        if (lseek(f, off, SEEK_SET) != off
                            || write(f, buffer, last) != last) {
-                               perror("Unable to write directory");
+                               perr("Unable to write directory");
                                return FSFATAL;
                        }
                        mod &= ~THISMOD;
@@ -913,7 +913,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
        if (!lfbuf) {
                lfbuf = malloc(boot->ClusterSize);
                if (!lfbuf) {
-                       perror("No space for buffer");
+                       perr("No space for buffer");
                        return FSFATAL;
                }
                p = NULL;
@@ -937,7 +937,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
                    + boot->ClusterOffset * boot->bpbBytesPerSec;
                if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
                    || read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
-                       perror("could not read LOST.DIR");
+                       perr("could not read LOST.DIR");
                        return FSFATAL;
                }
                p = lfbuf;
@@ -967,7 +967,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
        fat[head].flags |= FAT_USED;
        if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
            || write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
-               perror("could not write LOST.DIR");
+               perr("could not write LOST.DIR");
                return FSFATAL;
        }
        return FSDIRMOD;
index be9dd39..43f393b 100644 (file)
@@ -80,7 +80,8 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
 
        *buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
        if (*buffer == NULL) {
-               perror("No space for FAT");
+               perr("No space for FAT sectors (%zu)",
+                   (size_t)boot->FATsecs);
                return 0;
        }
 
@@ -88,13 +89,13 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
        off *= boot->bpbBytesPerSec;
 
        if (lseek(fs, off, SEEK_SET) != off) {
-               perror("Unable to read FAT");
+               perr("Unable to read FAT");
                goto err;
        }
 
        if (read(fs, *buffer, boot->FATsecs * boot->bpbBytesPerSec)
            != boot->FATsecs * boot->bpbBytesPerSec) {
-               perror("Unable to read FAT");
+               perr("Unable to read FAT");
                goto err;
        }
 
@@ -123,7 +124,8 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp)
 
        fat = calloc(boot->NumClusters, sizeof(struct fatEntry));
        if (fat == NULL) {
-               perror("No space for FAT");
+               perr("No space for FAT clusters (%zu)",
+                   (size_t)boot->NumClusters);
                free(buffer);
                return FSFATAL;
        }
@@ -456,7 +458,8 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
        fatsz = boot->FATsecs * boot->bpbBytesPerSec;
        buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
        if (buffer == NULL) {
-               perror("No space for FAT");
+               perr("No space for FAT sectors (%zu)",
+                   (size_t)boot->FATsecs);
                return FSFATAL;
        }
        boot->NumFree = 0;
@@ -540,7 +543,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
                off *= boot->bpbBytesPerSec;
                if (lseek(fs, off, SEEK_SET) != off
                    || write(fs, buffer, fatsz) != fatsz) {
-                       perror("Unable to write FAT");
+                       perr("Unable to write FAT");
                        ret = FSFATAL; /* Return immediately?           XXX */
                }
        }