Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmds] Cleanup fsck-dos messages and reduce memory requirement #1823

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion elkscmd/fsck_dos/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static const char rcsid[] =
#include <stdio.h>
#include <unistd.h>

#include "fsutil.h"
#include "ext.h"

int
Expand Down
2 changes: 1 addition & 1 deletion elkscmd/fsck_dos/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static const char rcsid[] =
#include <unistd.h>
#include <fcntl.h>

#include "fsutil.h"
#include "ext.h"

/*
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions elkscmd/fsck_dos/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ static const char rcsid[] =
#include <stdio.h>
#include <unistd.h>
#include <time.h>

#include <sys/param.h>

#include "fsutil.h"
#include "ext.h"

#define SLOT_EMPTY 0x00 /* slot has never been used */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions elkscmd/fsck_dos/dosfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions elkscmd/fsck_dos/ext.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef EXT_H
#define EXT_H
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
* Copyright (c) 1995 Martin Husemann
Expand Down Expand Up @@ -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 <sys/types.h>
#include <limits.h>

#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:
Expand Down
15 changes: 6 additions & 9 deletions elkscmd/fsck_dos/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static const char rcsid[] =
#include <stdio.h>
#include <unistd.h>

#include "fsutil.h"
#include "ext.h"

static int checkclnum(struct bootblock *, int, cl_t, cl_t *);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 0 additions & 18 deletions elkscmd/fsck_dos/fsutil.h

This file was deleted.

6 changes: 1 addition & 5 deletions elkscmd/fsck_dos/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static const char rcsid[] =
#include <errno.h>
#include <stdarg.h>

#include "fsutil.h"
#include "ext.h"

int alwaysno; /* assume "no" for all questions */
Expand All @@ -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);
}

Expand Down
Loading