#define ROOT_INO 1
-#define UPPER(size,n) ((size+((n)-1))/(n))
-#define INODE_SIZE (sizeof(struct minix_inode))
-#define INODE_SIZE2 (sizeof(struct minix2_inode))
-#define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
- : MINIX_INODES_PER_BLOCK))
-#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
-
-#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
-
static char * program_name = "fsck.minix";
static char * device_name = NULL;
static int IN;
static int errors_uncorrected = 0; /* flag if some error was not corrected */
static int dirsize = 16;
static int namelen = 14;
-static int version2 = 0;
static struct termios termios;
static volatile sig_atomic_t termios_set = 0;
/* This is a waste of 12kB or so. */
static char current_name[MAX_DEPTH*(NAME_MAX+1)+1];
-static char * inode_buffer = NULL;
-#define Inode (((struct minix_inode *) inode_buffer)-1)
-#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
-
-static char *super_block_buffer;
-#define Super (*(struct minix_super_block *)super_block_buffer)
-#define INODES ((unsigned long)Super.s_ninodes)
-#define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones))
-#define IMAPS ((unsigned long)Super.s_imap_blocks)
-#define ZMAPS ((unsigned long)Super.s_zmap_blocks)
-#define FIRSTZONE ((unsigned long)Super.s_firstdatazone)
-#define ZONESIZE ((unsigned long)Super.s_log_zone_size)
-#define MAXSIZE ((unsigned long)Super.s_max_size)
#define MAGIC (Super.s_magic)
-#define NORM_FIRSTZONE (2+IMAPS+ZMAPS+INODE_BLOCKS)
-
-static char *inode_map;
-static char *zone_map;
static unsigned char * inode_count = NULL;
static unsigned char * zone_count = NULL;
static void recursive_check2(unsigned int ino);
#define inode_in_use(x) (isset(inode_map,(x)) != 0)
-#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1) != 0)
+#define zone_in_use(x) (isset(zone_map,(x)-get_first_zone()+1) != 0)
#define mark_inode(x) (setbit(inode_map,(x)),changed=1)
#define unmark_inode(x) (clrbit(inode_map,(x)),changed=1)
-#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),changed=1)
-#define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1)
+#define mark_zone(x) (setbit(zone_map,(x)-get_first_zone()+1),changed=1)
+#define unmark_zone(x) (clrbit(zone_map,(x)-get_first_zone()+1),changed=1)
static void
reset(void) {
if (!*nr)
return 0;
- if (*nr < FIRSTZONE) {
+ if (*nr < get_first_zone()) {
get_current_name();
printf(_("Zone nr < FIRSTZONE in file `%s'."),
current_name);
- } else if (*nr >= ZONES) {
+ } else if (*nr >= get_nzones()) {
get_current_name();
printf(_("Zone nr >= ZONES in file `%s'."),
current_name);
if (!*nr)
return 0;
- if (*nr < FIRSTZONE) {
+ if (*nr < get_first_zone()) {
get_current_name();
printf (_("Zone nr < FIRSTZONE in file `%s'."),
current_name);
- } else if (*nr >= ZONES) {
+ } else if (*nr >= get_nzones()) {
get_current_name();
printf (_("Zone nr >= ZONES in file `%s'."),
current_name);
write_block(unsigned int nr, char * addr) {
if (!nr)
return;
- if (nr < FIRSTZONE || nr >= ZONES) {
+ if (nr < get_first_zone() || nr >= get_nzones()) {
printf(_("Internal error: trying to write bad block\n"
"Write request ignored\n"));
errors_uncorrected = 1;
static void
write_tables(void) {
write_super_block();
+ unsigned long buffsz = get_inode_buffer_size();
+ unsigned long imaps = get_nimaps();
+ unsigned long zmaps = get_nzmaps();
- if (IMAPS*BLOCK_SIZE != write(IN,inode_map,IMAPS*BLOCK_SIZE))
+ if (imaps*BLOCK_SIZE != write(IN,inode_map, imaps*BLOCK_SIZE))
die(_("Unable to write inode map"));
- if (ZMAPS*BLOCK_SIZE != write(IN,zone_map,ZMAPS*BLOCK_SIZE))
+ if (zmaps*BLOCK_SIZE != write(IN,zone_map, zmaps*BLOCK_SIZE))
die(_("Unable to write zone map"));
- if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE))
+ if (buffsz != write(IN,inode_buffer, buffsz))
die(_("Unable to write inodes"));
}
char blk[BLOCK_SIZE];
int size;
- if (version2)
+ if (fs_version == 2)
block = Inode2[ROOT_INO].i_zone[0];
else
block = Inode[ROOT_INO].i_zone[0];
if (MAGIC == MINIX_SUPER_MAGIC) {
namelen = 14;
dirsize = 16;
- version2 = 0;
+ fs_version = 1;
} else if (MAGIC == MINIX_SUPER_MAGIC2) {
namelen = 30;
dirsize = 32;
- version2 = 0;
+ fs_version = 1;
} else if (MAGIC == MINIX2_SUPER_MAGIC) {
namelen = 14;
dirsize = 16;
- version2 = 1;
+ fs_version = 2;
} else if (MAGIC == MINIX2_SUPER_MAGIC2) {
namelen = 30;
dirsize = 32;
- version2 = 1;
+ fs_version = 2;
} else
die(_("bad magic number in super-block"));
- if (ZONESIZE != 0 || BLOCK_SIZE != 1024)
+ if (get_zone_size() != 0 || BLOCK_SIZE != 1024)
die(_("Only 1k blocks/zones supported"));
- if (IMAPS * BLOCK_SIZE * 8 < INODES + 1)
+ if (get_nimaps() * BLOCK_SIZE * 8 < get_ninodes() + 1)
die(_("bad s_imap_blocks field in super-block"));
- if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1)
+ if (get_nzmaps() * BLOCK_SIZE * 8 < get_nzones() - get_first_zone() + 1)
die(_("bad s_zmap_blocks field in super-block"));
}
static void
read_tables(void) {
- inode_map = malloc(IMAPS * BLOCK_SIZE);
+ unsigned long inodes = get_ninodes();
+ unsigned long buffsz = get_inode_buffer_size();
+ unsigned long norm_first_zone = first_zone_data();
+ unsigned long first_zone = get_first_zone();
+ unsigned long zones = get_nzones();
+ unsigned long imaps = get_nimaps();
+ unsigned long zmaps = get_nzmaps();
+
+ inode_map = malloc(imaps * BLOCK_SIZE);
if (!inode_map)
die(_("Unable to allocate buffer for inode map"));
- zone_map = malloc(ZMAPS * BLOCK_SIZE);
+ zone_map = malloc(zmaps * BLOCK_SIZE);
if (!inode_map)
die(_("Unable to allocate buffer for zone map"));
memset(inode_map,0,sizeof(inode_map));
memset(zone_map,0,sizeof(zone_map));
- inode_buffer = malloc(INODE_BUFFER_SIZE);
+ inode_buffer = malloc(buffsz);
if (!inode_buffer)
die(_("Unable to allocate buffer for inodes"));
- inode_count = malloc(INODES + 1);
+ inode_count = malloc(inodes + 1);
if (!inode_count)
die(_("Unable to allocate buffer for inode count"));
- zone_count = malloc(ZONES);
+ zone_count = malloc(zones);
if (!zone_count)
die(_("Unable to allocate buffer for zone count"));
- if (IMAPS*BLOCK_SIZE != read(IN,inode_map,IMAPS*BLOCK_SIZE))
+ if (imaps*BLOCK_SIZE != read(IN,inode_map,imaps*BLOCK_SIZE))
die(_("Unable to read inode map"));
- if (ZMAPS*BLOCK_SIZE != read(IN,zone_map,ZMAPS*BLOCK_SIZE))
+ if (zmaps*BLOCK_SIZE != read(IN,zone_map, zmaps*BLOCK_SIZE))
die(_("Unable to read zone map"));
- if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE))
+ if (buffsz != read(IN,inode_buffer, buffsz))
die(_("Unable to read inodes"));
- if (NORM_FIRSTZONE != FIRSTZONE) {
+ if (norm_first_zone != first_zone) {
printf(_("Warning: Firstzone != Norm_firstzone\n"));
errors_uncorrected = 1;
}
get_dirsize ();
if (show) {
- printf(_("%ld inodes\n"),INODES);
- printf(_("%ld blocks\n"),ZONES);
- printf(_("Firstdatazone=%ld (%ld)\n"),FIRSTZONE,NORM_FIRSTZONE);
- printf(_("Zonesize=%d\n"),BLOCK_SIZE<<ZONESIZE);
- printf(_("Maxsize=%ld\n"),MAXSIZE);
+ printf(_("%ld inodes\n"), inodes);
+ printf(_("%ld blocks\n"), zones);
+ printf(_("Firstdatazone=%ld (%ld)\n"), first_zone, norm_first_zone);
+ printf(_("Zonesize=%d\n"),BLOCK_SIZE<<get_zone_size());
+ printf(_("Maxsize=%ld\n"), get_max_size());
printf(_("Filesystem state=%d\n"), Super.s_state);
printf(_("namelen=%d\n\n"),namelen);
}
get_inode(unsigned int nr) {
struct minix_inode * inode;
- if (!nr || nr > INODES)
+ if (!nr || nr > get_ninodes())
return NULL;
total++;
inode = Inode + nr;
get_inode2 (unsigned int nr) {
struct minix2_inode *inode;
- if (!nr || nr > INODES)
+ if (!nr || nr > get_ninodes())
return NULL;
total++;
inode = Inode2 + nr;
static void
check_zones(unsigned int i) {
- struct minix_inode * inode;
+ struct minix_inode *inode;
- if (!i || i > INODES)
+ if (!i || i > get_ninodes())
return;
if (inode_count[i] > 1) /* have we counted this file already? */
return;
check_zones2 (unsigned int i) {
struct minix2_inode *inode;
- if (!i || i > INODES)
+ if (!i || i > get_ninodes())
return;
if (inode_count[i] > 1) /* have we counted this file already? */
return;
read_block(block, blk);
name = blk + (offset % BLOCK_SIZE) + 2;
ino = * (unsigned short *) (name-2);
- if (ino > INODES) {
+ if (ino > get_ninodes()) {
get_current_name();
printf(_("The directory '%s' contains a bad inode number "
"for file '%.*s'."),
read_block (block, blk);
name = blk + (offset % BLOCK_SIZE) + 2;
ino = *(unsigned short *) (name - 2);
- if (ino > INODES) {
+ if (ino > get_ninodes()) {
get_current_name();
printf(_("The directory '%s' contains a bad inode number "
"for file '%.*s'."),
check_counts(void) {
int i;
- for (i=1 ; i <= INODES ; i++) {
+ for (i=1 ; i <= get_ninodes(); i++) {
if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) {
printf(_("Inode %d mode not cleared."),i);
if (ask(_("Clear"),1)) {
}
}
}
- for (i=FIRSTZONE ; i < ZONES ; i++) {
+ for (i=get_first_zone() ; i < get_nzones() ; i++) {
if (zone_in_use(i) == zone_count[i])
continue;
if (!zone_count[i]) {
check_counts2 (void) {
int i;
- for (i = 1; i <= INODES; i++) {
+ for (i = 1; i <= get_ninodes(); i++) {
if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) {
printf (_("Inode %d mode not cleared."), i);
if (ask (_("Clear"), 1)) {
}
}
}
- for (i = FIRSTZONE; i < ZONES; i++) {
+ for (i = get_first_zone(); i < get_nzones(); i++) {
if (zone_in_use (i) == zone_count[i])
continue;
if (!zone_count[i]) {
static void
check(void) {
- memset(inode_count,0,(INODES + 1) * sizeof(*inode_count));
- memset(zone_count,0,ZONES*sizeof(*zone_count));
+ memset(inode_count,0,(get_ninodes() + 1) * sizeof(*inode_count));
+ memset(zone_count,0, get_nzones()*sizeof(*zone_count));
check_zones(ROOT_INO);
recursive_check(ROOT_INO);
check_counts();
static void
check2 (void) {
- memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count));
- memset (zone_count, 0, ZONES * sizeof (*zone_count));
+ memset (inode_count, 0, (get_ninodes() + 1) * sizeof (*inode_count));
+ memset (zone_count, 0, get_nzones() * sizeof (*zone_count));
check_zones2 (ROOT_INO);
recursive_check2 (ROOT_INO);
check_counts2 ();
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size"));
- if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
+ if (INODE2_SIZE * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad v2 inode size"));
while (argc-- > 1) {
termios_set = 1;
}
- if (version2) {
+ if (fs_version == 2) {
check_root2 ();
check2 ();
} else {
if (verbose) {
int i, free;
- for (i=1,free=0 ; i <= INODES ; i++)
+ for (i=1,free=0 ; i <= get_ninodes() ; i++)
if (!inode_in_use(i))
free++;
- printf(_("\n%6ld inodes used (%ld%%)\n"),(INODES-free),
- 100*(INODES-free)/INODES);
- for (i=FIRSTZONE,free=0 ; i < ZONES ; i++)
+ printf(_("\n%6ld inodes used (%ld%%)\n"),(get_ninodes()-free),
+ 100*(get_ninodes()-free)/get_ninodes());
+ for (i=get_first_zone(),free=0 ; i < get_nzones(); i++)
if (!zone_in_use(i))
free++;
- printf(_("%6ld zones used (%ld%%)\n"),(ZONES-free),
- 100*(ZONES-free)/ZONES);
+ printf(_("%6ld zones used (%ld%%)\n"),(get_nzones()-free),
+ 100*(get_nzones()-free)/get_nzones());
printf(_("\n%6d regular files\n"
"%6d directories\n"
"%6d character device files\n"