From 22fa27bbcdd46e12a382fdfa976a427f7a340baa Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Fri, 8 Mar 2024 19:55:25 -0700 Subject: [PATCH] [cmds] Cleanup fsck-dos messages and reduce memory requirement --- elkscmd/fsck_dos/boot.c | 1 - elkscmd/fsck_dos/check.c | 2 +- elkscmd/fsck_dos/dir.c | 6 ++---- elkscmd/fsck_dos/dosfs.h | 8 ++++---- elkscmd/fsck_dos/ext.h | 22 +++++++++++++++++----- elkscmd/fsck_dos/fat.c | 15 ++++++--------- elkscmd/fsck_dos/fsutil.h | 18 ------------------ elkscmd/fsck_dos/main.c | 6 +----- 8 files changed, 31 insertions(+), 47 deletions(-) delete mode 100644 elkscmd/fsck_dos/fsutil.h diff --git a/elkscmd/fsck_dos/boot.c b/elkscmd/fsck_dos/boot.c index 53bcc7207..fc8c9898c 100644 --- a/elkscmd/fsck_dos/boot.c +++ b/elkscmd/fsck_dos/boot.c @@ -44,7 +44,6 @@ static const char rcsid[] = #include #include -#include "fsutil.h" #include "ext.h" int diff --git a/elkscmd/fsck_dos/check.c b/elkscmd/fsck_dos/check.c index 83160be7d..bc2748c70 100644 --- a/elkscmd/fsck_dos/check.c +++ b/elkscmd/fsck_dos/check.c @@ -45,7 +45,6 @@ static const char rcsid[] = #include #include -#include "fsutil.h" #include "ext.h" /* @@ -174,6 +173,7 @@ checkfilesys(const char *fname) /* now write the FATs */ if (mod & FSFATMOD) { + printf("Rewriting FAT table\n"); if (ask(1, "Update FATs")) { mod |= writefat(dosfs, &boot, fat, mod & FSFIXFAT); if (mod & FSFATAL) { diff --git a/elkscmd/fsck_dos/dir.c b/elkscmd/fsck_dos/dir.c index d73f7023b..dbe570ecf 100644 --- a/elkscmd/fsck_dos/dir.c +++ b/elkscmd/fsck_dos/dir.c @@ -47,10 +47,8 @@ static const char rcsid[] = #include #include #include - #include -#include "fsutil.h" #include "ext.h" #define SLOT_EMPTY 0x00 /* slot has never been used */ @@ -210,7 +208,7 @@ calcShortSum(u_char *p) /* * Global variables temporarily used during a directory scan */ -static char longName[DOSLONGNAMELEN] = ""; +static char longName[DOSLONGNAMELEN+1] = ""; static u_char *buffer = NULL; static u_char *delbuf = NULL; @@ -659,7 +657,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, if (p[k + 1]) t[-1] = '?'; } - if (t >= longName + sizeof(longName)) { + if (t >= longName + sizeof(longName) - 1) { pwarn("long filename too long\n"); if (!invlfn) { invlfn = vallfn; diff --git a/elkscmd/fsck_dos/dosfs.h b/elkscmd/fsck_dos/dosfs.h index b1a66eaa4..d13a7eb4d 100644 --- a/elkscmd/fsck_dos/dosfs.h +++ b/elkscmd/fsck_dos/dosfs.h @@ -138,12 +138,12 @@ struct dosDirEntry { *parent, /* previous tree level */ *next, /* next brother */ *child; /* if this is a directory */ - char name[8+1+3+1]; /* alias name first part */ - char lname[DOSLONGNAMELEN]; /* real name */ - uint flags; /* attributes */ cl_t head; /* cluster no */ u_int32_t size; /* filesize in bytes */ - uint fsckflags; /* flags during fsck */ + char lname[DOSLONGNAMELEN+1]; /* real name */ + u_char flags; /* attributes */ + char name[8+1+3+1]; /* alias name first part */ + u_char fsckflags; /* flags during fsck */ }; /* Flags in fsckflags: */ #define DIREMPTY 1 diff --git a/elkscmd/fsck_dos/ext.h b/elkscmd/fsck_dos/ext.h index 6d183e95e..5a484f79c 100644 --- a/elkscmd/fsck_dos/ext.h +++ b/elkscmd/fsck_dos/ext.h @@ -1,3 +1,5 @@ +#ifndef EXT_H +#define EXT_H /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank * Copyright (c) 1995 Martin Husemann @@ -32,14 +34,24 @@ * $FreeBSD: src/sbin/fsck_msdosfs/ext.h,v 1.10.20.1 2009/04/15 03:14:26 kensmith Exp $ */ -#ifndef EXT_H -#define EXT_H - #include +#include -#include "dosfs.h" +#define MAXPATHLEN PATH_MAX +#define LOSTDIR "LOST.DIR" + +typedef unsigned int u_int; /* FIXME possibly change to 32-bit for ELKS */ +typedef unsigned char u_char; +typedef unsigned long u_int32_t; +typedef unsigned long U32; + +typedef off_t loff_t; +#define lseek64 lseek -#define LOSTDIR "LOST.DIR" +#define pwarn printf +#define pfatal printf + +#include "dosfs.h" /* * Options: diff --git a/elkscmd/fsck_dos/fat.c b/elkscmd/fsck_dos/fat.c index 538ca8424..5acc29fdf 100644 --- a/elkscmd/fsck_dos/fat.c +++ b/elkscmd/fsck_dos/fat.c @@ -44,7 +44,6 @@ static const char rcsid[] = #include #include -#include "fsutil.h" #include "ext.h" static int checkclnum(struct bootblock *, int, cl_t, cl_t *); @@ -85,7 +84,7 @@ checkdirty(int fs, struct bootblock *boot) buffer = malloc(boot->BytesPerSec); if (buffer == NULL) { - perror("No space for FAT (1)"); + perror("No space for FAT dirty check"); return 1; } @@ -170,12 +169,10 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer) { off_t off; - printf("Attempting to allocate %lu KB for FAT\n", - (boot->FATsecs * boot->BytesPerSec) / 1024); - *buffer = malloc(boot->FATsecs * boot->BytesPerSec); if (*buffer == NULL) { - perror("No space for FAT (2)"); + printf("Can't allocate %lu KB for FAT\n", + (boot->FATsecs * boot->BytesPerSec) / 1024); return 0; } @@ -218,7 +215,7 @@ 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 (3)"); + perror("No space for FAT entries"); free(buffer); return FSFATAL; } @@ -562,7 +559,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec); if (buffer == NULL) { - perror("No space for FAT (4)"); + perror("No space for FAT write"); return FSFATAL; } memset(buffer, 0, fatsz); @@ -685,7 +682,7 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) mod |= FSFATMOD; continue; } - if (ret == FSERROR && ask(1, "Clear")) { + if (ret == FSERROR && ask(1, "Clear lost chains")) { clearchain(boot, fat, head); mod |= FSFATMOD; } diff --git a/elkscmd/fsck_dos/fsutil.h b/elkscmd/fsck_dos/fsutil.h deleted file mode 100644 index 6009bb7c4..000000000 --- a/elkscmd/fsck_dos/fsutil.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _FS_UTIL_H -#define _FS_UTIL_H - -#define pwarn printf -#define pfatal printf - -typedef unsigned int u_int; /* FIXME possibly change to 32-bit for ELKS */ -typedef unsigned char u_char; -typedef unsigned int uint; -typedef unsigned long u_int32_t; -typedef unsigned long U32; - -#include -#define MAXPATHLEN PATH_MAX -typedef off_t loff_t; -#define lseek64 lseek - -#endif diff --git a/elkscmd/fsck_dos/main.c b/elkscmd/fsck_dos/main.c index 4938227a4..7242a129c 100644 --- a/elkscmd/fsck_dos/main.c +++ b/elkscmd/fsck_dos/main.c @@ -46,7 +46,6 @@ static const char rcsid[] = #include #include -#include "fsutil.h" #include "ext.h" int alwaysno; /* assume "no" for all questions */ @@ -60,10 +59,7 @@ static void usage(void); static void usage(void) { - - fprintf(stderr, "%s\n%s\n", - "usage: fsck_msdosfs -p [-f] filesystem ...", - " fsck_msdosfs [-ny] filesystem ..."); + fprintf(stderr, "usage: fsck-dos [-fpny] filesystem ...\n"); exit(1); }