#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
static char *program_version = "1.2 - 11/11/96";
-static char *device_name = NULL;
+static char *device_name;
static int IN;
-static int repair = 0, automatic = 0, verbose = 0, list = 0, show =
- 0, warn_mode = 0, force = 0;
-static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links =
- 0, symlinks = 0, total = 0;
+static int repair, automatic, verbose, list, show, warn_mode, force;
+static int directory, regular, blockdev, chardev, links, symlinks, total;
-static int changed = 0; /* flags if the filesystem has been changed */
-static int errors_uncorrected = 0; /* flag if some error was not corrected */
+static int changed; /* flags if the filesystem has been changed */
+static int errors_uncorrected; /* flag if some error was not corrected */
static int dirsize = 16;
static int namelen = 14;
-static int version2 = 0;
+static int version2;
static struct termios termios;
-static int termios_set = 0;
+static int termios_set;
/* File-name data */
enum { MAX_DEPTH = 32 };
-static int name_depth = 0;
+static int name_depth;
// static char name_list[MAX_DEPTH][BUFSIZ + 1];
-static char **name_list = NULL;
+static char **name_list;
-static char *inode_buffer = NULL;
+static char *inode_buffer;
#define Inode (((struct minix_inode *) inode_buffer)-1)
#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
static char *inode_map;
static char *zone_map;
-static unsigned char *inode_count = NULL;
-static unsigned char *zone_count = NULL;
+static unsigned char *inode_count;
+static unsigned char *zone_count;
static void recursive_check(unsigned int ino);
#ifdef CONFIG_FEATURE_MINIX2
close(fd);
printf("%s is mounted. ", device_name);
+ cont = 0;
if (isatty(0) && isatty(1))
cont = ask("Do you really want to continue", 0);
- else
- cont = 0;
if (!cont) {
- printf("check aborted.\n");
+ printf("Check aborted\n");
exit(0);
}
return;
* if an error was corrected, and returns the zone (0 for no zone
* or a bad zone-number).
*/
-static int check_zone_nr(unsigned short *nr, int *corrected)
+static int check_zone_nr2(uint32_t *nr, int *corrected)
{
if (!*nr)
return 0;
return 0;
}
-#ifdef CONFIG_FEATURE_MINIX2
-static int check_zone_nr2(unsigned int *nr, int *corrected)
+static int check_zone_nr(uint16_t *nr, int *corrected)
{
- if (!*nr)
- return 0;
- if (*nr < FIRSTZONE)
- printf("Zone nr < FIRSTZONE in file `");
- else if (*nr >= ZONES)
- printf("Zone nr >= ZONES in file `");
- else
- return *nr;
- print_current_name();
- printf("'.");
- if (ask("Remove block", 1)) {
- *nr = 0;
- *corrected = 1;
- }
- return 0;
+ uint32_t nr32 = *nr;
+ int r = check_zone_nr2(&nr32, corrected);
+ *nr = (uint16_t)nr32;
+ return r;
}
-#endif
/*
* read-block reads block nr into the buffer at addr.
printf("Read error: unable to seek to block in file '");
print_current_name();
printf("'\n");
- memset(addr, 0, BLOCK_SIZE);
errors_uncorrected = 1;
+ memset(addr, 0, BLOCK_SIZE);
} else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) {
printf("Read error: bad block in file '");
print_current_name();
printf("'\n");
- memset(addr, 0, BLOCK_SIZE);
errors_uncorrected = 1;
+ memset(addr, 0, BLOCK_SIZE);
}
}
}
/*
- * map-block calculates the absolute block nr of a block in a file.
+ * map_block calculates the absolute block nr of a block in a file.
* It sets 'changed' if the inode has needed changing, and re-writes
* any indirect blocks with errors.
*/
static int map_block(struct minix_inode *inode, unsigned int blknr)
{
- unsigned short ind[BLOCK_SIZE >> 1];
- unsigned short dind[BLOCK_SIZE >> 1];
+ uint16_t ind[BLOCK_SIZE >> 1];
+ uint16_t dind[BLOCK_SIZE >> 1];
int blk_chg, block, result;
if (blknr < 7)
#ifdef CONFIG_FEATURE_MINIX2
static int map_block2(struct minix2_inode *inode, unsigned int blknr)
{
- unsigned int ind[BLOCK_SIZE >> 2];
- unsigned int dind[BLOCK_SIZE >> 2];
- unsigned int tind[BLOCK_SIZE >> 2];
+ uint32_t ind[BLOCK_SIZE >> 2];
+ uint32_t dind[BLOCK_SIZE >> 2];
+ uint32_t tind[BLOCK_SIZE >> 2];
int blk_chg, block, result;
if (blknr < 7)
die("seek failed in write_super_block");
if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE))
die("unable to write super-block");
-
- return;
}
static void write_tables(void)
die("seek failed");
if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE))
die("unable to read super block");
+ namelen = 14;
+ dirsize = 16;
+ version2 = 0;
if (MAGIC == MINIX_SUPER_MAGIC) {
- namelen = 14;
- dirsize = 16;
- version2 = 0;
} else if (MAGIC == MINIX_SUPER_MAGIC2) {
namelen = 30;
dirsize = 32;
- version2 = 0;
#ifdef CONFIG_FEATURE_MINIX2
} else if (MAGIC == MINIX2_SUPER_MAGIC) {
- namelen = 14;
- dirsize = 16;
version2 = 1;
} else if (MAGIC == MINIX2_SUPER_MAGIC2) {
namelen = 30;
}
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("Filesystem state=%d\n", Super.s_state);
- printf("namelen=%d\n\n", namelen);
+ printf("%ld inodes\n"
+ "%ld blocks\n"
+ "Firstdatazone=%ld (%ld)\n"
+ "Zonesize=%d\n"
+ "Maxsize=%ld\n"
+ "Filesystem state=%d\n"
+ "namelen=%d\n\n",
+ INODES,
+ ZONES,
+ FIRSTZONE, NORM_FIRSTZONE,
+ BLOCK_SIZE << ZONESIZE,
+ MAXSIZE,
+ Super.s_state,
+ namelen);
}
}
} else
links++;
if (!++inode_count[nr]) {
- printf("Warning: inode count too big.\n");
+ printf("Warning: inode count too big\n");
inode_count[nr]--;
errors_uncorrected = 1;
}
} else
links++;
if (!++inode_count[nr]) {
- printf("Warning: inode count too big.\n");
+ printf("Warning: inode count too big\n");
inode_count[nr]--;
errors_uncorrected = 1;
}
}
#endif
-static int add_zone(unsigned short *znr, int *corrected)
+static int add_zone(uint16_t *znr, int *corrected)
{
int result;
int block;
*znr = 0;
block = 0;
*corrected = 1;
+ return 0;
}
}
- if (!block)
- return 0;
if (!zone_in_use(block)) {
printf("Block %d in file `", block);
print_current_name();
}
#ifdef CONFIG_FEATURE_MINIX2
-static int add_zone2(unsigned int *znr, int *corrected)
+static int add_zone2(uint32_t *znr, int *corrected)
{
int result;
int block;
*znr = 0;
block = 0;
*corrected = 1;
+ return 0;
}
}
- if (!block)
- return 0;
if (!zone_in_use(block)) {
printf("Block %d in file `", block);
print_current_name();
}
#endif
-static void add_zone_ind(unsigned short *znr, int *corrected)
+static void add_zone_ind(uint16_t *znr, int *corrected)
{
static char blk[BLOCK_SIZE];
int i, chg_blk = 0;
return;
read_block(block, blk);
for (i = 0; i < (BLOCK_SIZE >> 1); i++)
- add_zone(i + (unsigned short *) blk, &chg_blk);
+ add_zone(i + (uint16_t *) blk, &chg_blk);
if (chg_blk)
write_block(block, blk);
}
#ifdef CONFIG_FEATURE_MINIX2
-static void add_zone_ind2(unsigned int *znr, int *corrected)
+static void add_zone_ind2(uint32_t *znr, int *corrected)
{
static char blk[BLOCK_SIZE];
int i, chg_blk = 0;
return;
read_block(block, blk);
for (i = 0; i < BLOCK_SIZE >> 2; i++)
- add_zone2(i + (unsigned int *) blk, &chg_blk);
+ add_zone2(i + (uint32_t *) blk, &chg_blk);
if (chg_blk)
write_block(block, blk);
}
#endif
-static void add_zone_dind(unsigned short *znr, int *corrected)
+static void add_zone_dind(uint16_t *znr, int *corrected)
{
static char blk[BLOCK_SIZE];
int i, blk_chg = 0;
return;
read_block(block, blk);
for (i = 0; i < (BLOCK_SIZE >> 1); i++)
- add_zone_ind(i + (unsigned short *) blk, &blk_chg);
+ add_zone_ind(i + (uint16_t *) blk, &blk_chg);
if (blk_chg)
write_block(block, blk);
}
#ifdef CONFIG_FEATURE_MINIX2
-static void add_zone_dind2(unsigned int *znr, int *corrected)
+static void add_zone_dind2(uint32_t *znr, int *corrected)
{
static char blk[BLOCK_SIZE];
int i, blk_chg = 0;
return;
read_block(block, blk);
for (i = 0; i < BLOCK_SIZE >> 2; i++)
- add_zone_ind2(i + (unsigned int *) blk, &blk_chg);
+ add_zone_ind2(i + (uint32_t *) blk, &blk_chg);
if (blk_chg)
write_block(block, blk);
}
-static void add_zone_tind2(unsigned int *znr, int *corrected)
+static void add_zone_tind2(uint32_t *znr, int *corrected)
{
static char blk[BLOCK_SIZE];
int i, blk_chg = 0;
return;
read_block(block, blk);
for (i = 0; i < BLOCK_SIZE >> 2; i++)
- add_zone_dind2(i + (unsigned int *) blk, &blk_chg);
+ add_zone_dind2(i + (uint32_t *) blk, &blk_chg);
if (blk_chg)
write_block(block, blk);
}
block = map_block(dir, offset / BLOCK_SIZE);
read_block(block, blk);
name = blk + (offset % BLOCK_SIZE) + 2;
- ino = *(unsigned short *) (name - 2);
+ ino = *(uint16_t *) (name - 2);
if (ino > INODES) {
print_current_name();
printf(" contains a bad inode number for file '");
printf("%.*s'.", namelen, name);
if (ask(" Remove", 1)) {
- *(unsigned short *) (name - 2) = 0;
+ *(uint16_t *) (name - 2) = 0;
write_block(block, blk);
}
ino = 0;
block = map_block2(dir, offset / BLOCK_SIZE);
read_block(block, blk);
name = blk + (offset % BLOCK_SIZE) + 2;
- ino = *(unsigned short *) (name - 2);
+ ino = *(uint16_t *) (name - 2);
if (ino > INODES) {
print_current_name();
printf(" contains a bad inode number for file '");
printf("%.*s'.", namelen, name);
if (ask(" Remove", 1)) {
- *(unsigned short *) (name - 2) = 0;
+ *(uint16_t *) (name - 2) = 0;
write_block(block, blk);
}
ino = 0;
int i;
for (i = 1; i <= INODES; i++) {
- if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) {
+ if (warn_mode && Inode[i].i_mode && !inode_in_use(i)) {
printf("Inode %d mode not cleared.", i);
if (ask("Clear", 1)) {
Inode[i].i_mode = 0;
int i;
for (i = 1; i <= INODES; i++) {
- if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) {
+ if (warn_mode && Inode2[i].i_mode && !inode_in_use(i)) {
printf("Inode %d mode not cleared.", i);
if (ask("Clear", 1)) {
Inode2[i].i_mode = 0;
name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
for (i = 0; i < MAX_DEPTH; i++)
- name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1);
+ name_list[i] = xmalloc(sizeof(char) * (BUFSIZ + 1));
}
#ifdef CONFIG_FEATURE_CLEAN_UP
int fsck_minix_main(int argc, char **argv)
{
struct termios tmp;
- int count;
int retcode = 0;
alloc_name_list();
}
IN = open(device_name, repair ? O_RDWR : O_RDONLY);
if (IN < 0){
- fprintf(stderr,"unable to open device '%s'.\n",device_name);
+ fprintf(stderr,"unable to open device '%s'\n",device_name);
leave(8);
}
- for (count = 0; count < 3; count++)
- sync();
+ sync(); /* paranoia? */
read_superblock();
/*
if (!(Super.s_state & MINIX_ERROR_FS) &&
(Super.s_state & MINIX_VALID_FS) && !force) {
if (repair)
- printf("%s is clean, no check.\n", device_name);
+ printf("%s is clean, no check\n", device_name);
return retcode;
} else if (force)
- printf("Forcing filesystem check on %s.\n", device_name);
+ printf("Forcing filesystem check on %s\n", device_name);
else if (repair)
- printf("Filesystem on %s is dirty, needs checking.\n",
+ printf("Filesystem on %s is dirty, needs checking\n",
device_name);
read_tables();
printf("----------------------------\n"
"FILE SYSTEM HAS BEEN CHANGED\n"
"----------------------------\n");
- for (count = 0; count < 3; count++)
- sync();
+ sync();
} else if (repair)
write_super_block();