Made em work.

This commit is contained in:
Eric Andersen 1999-10-19 20:52:57 +00:00
parent e494fdd2c7
commit e674eb78e4
6 changed files with 439 additions and 450 deletions

View File

@ -85,6 +85,7 @@
* enforced (but it's not much fun on a character device :-). * enforced (but it's not much fun on a character device :-).
*/ */
#include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@ -98,8 +99,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/minix_fs.h> #include <linux/minix_fs.h>
#include "../version.h"
#include "nls.h"
#ifdef MINIX2_SUPER_MAGIC2 #ifdef MINIX2_SUPER_MAGIC2
#define HAVE_MINIX2 1 #define HAVE_MINIX2 1
@ -171,10 +170,8 @@ static char *zone_map;
static unsigned char * inode_count = NULL; static unsigned char * inode_count = NULL;
static unsigned char * zone_count = NULL; static unsigned char * zone_count = NULL;
void recursive_check(unsigned int ino); static void recursive_check(unsigned int ino);
void recursive_check2(unsigned int ino); static void recursive_check2(unsigned int ino);
#include "bitops.h"
#define inode_in_use(x) (bit(inode_map,(x))) #define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
@ -185,22 +182,22 @@ void recursive_check2(unsigned int ino);
#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),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 unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1)
void leave(int) __attribute__ ((noreturn)); static void leave(int) __attribute__ ((noreturn));
void leave(int status) static void leave(int status)
{ {
if (termios_set) if (termios_set)
tcsetattr(0, TCSANOW, &termios); tcsetattr(0, TCSANOW, &termios);
exit(status); exit(status);
} }
void usage(void) { static void show_usage(void) {
fprintf(stderr, fprintf(stderr,
_("Usage: %s [-larvsmf] /dev/name\n"), "Usage: %s [-larvsmf] /dev/name\n",
program_name); program_name);
leave(16); leave(16);
} }
void die(const char *str) { static void die(const char *str) {
fprintf(stderr, "%s: %s\n", program_name, str); fprintf(stderr, "%s: %s\n", program_name, str);
leave(8); leave(8);
} }
@ -209,7 +206,7 @@ void die(const char *str) {
* This simply goes through the file-name data and prints out the * This simply goes through the file-name data and prints out the
* current file. * current file.
*/ */
void print_current_name(void) static void print_current_name(void)
{ {
int i=0; int i=0;
@ -219,7 +216,7 @@ void print_current_name(void)
printf ("/"); printf ("/");
} }
int ask(const char * string, int def) static int ask(const char * string, int def)
{ {
int c; int c;
@ -293,13 +290,13 @@ static void check_mount(void)
else else
close(fd); close(fd);
printf (_("%s is mounted. "), device_name); printf ("%s is mounted. ", device_name);
if (isatty(0) && isatty(1)) if (isatty(0) && isatty(1))
cont = ask(_("Do you really want to continue"), 0); cont = ask("Do you really want to continue", 0);
else else
cont = 0; cont = 0;
if (!cont) { if (!cont) {
printf (_("check aborted.\n")); printf ("check aborted.\n");
exit (0); exit (0);
} }
return; return;
@ -311,19 +308,19 @@ static void check_mount(void)
* if an error was corrected, and returns the zone (0 for no zone * if an error was corrected, and returns the zone (0 for no zone
* or a bad zone-number). * or a bad zone-number).
*/ */
int check_zone_nr(unsigned short * nr, int * corrected) static int check_zone_nr(unsigned short * nr, int * corrected)
{ {
if (!*nr) if (!*nr)
return 0; return 0;
if (*nr < FIRSTZONE) if (*nr < FIRSTZONE)
printf(_("Zone nr < FIRSTZONE in file `")); printf("Zone nr < FIRSTZONE in file `");
else if (*nr >= ZONES) else if (*nr >= ZONES)
printf(_("Zone nr >= ZONES in file `")); printf("Zone nr >= ZONES in file `");
else else
return *nr; return *nr;
print_current_name(); print_current_name();
printf("'."); printf("'.");
if (ask(_("Remove block"),1)) { if (ask("Remove block",1)) {
*nr = 0; *nr = 0;
*corrected = 1; *corrected = 1;
} }
@ -331,19 +328,19 @@ int check_zone_nr(unsigned short * nr, int * corrected)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
int check_zone_nr2 (unsigned int *nr, int *corrected) static int check_zone_nr2 (unsigned int *nr, int *corrected)
{ {
if (!*nr) if (!*nr)
return 0; return 0;
if (*nr < FIRSTZONE) if (*nr < FIRSTZONE)
printf (_("Zone nr < FIRSTZONE in file `")); printf ("Zone nr < FIRSTZONE in file `");
else if (*nr >= ZONES) else if (*nr >= ZONES)
printf (_("Zone nr >= ZONES in file `")); printf ("Zone nr >= ZONES in file `");
else else
return *nr; return *nr;
print_current_name (); print_current_name ();
printf ("'."); printf ("'.");
if (ask (_("Remove block"), 1)) { if (ask ("Remove block", 1)) {
*nr = 0; *nr = 0;
*corrected = 1; *corrected = 1;
} }
@ -354,20 +351,20 @@ int check_zone_nr2 (unsigned int *nr, int *corrected)
/* /*
* read-block reads block nr into the buffer at addr. * read-block reads block nr into the buffer at addr.
*/ */
void read_block(unsigned int nr, char * addr) static void read_block(unsigned int nr, char * addr)
{ {
if (!nr) { if (!nr) {
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
return; return;
} }
if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) { if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) {
printf(_("Read error: unable to seek to block in file '")); printf("Read error: unable to seek to block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
errors_uncorrected = 1; errors_uncorrected = 1;
} else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) {
printf(_("Read error: bad block in file '")); printf("Read error: bad block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
@ -378,20 +375,20 @@ void read_block(unsigned int nr, char * addr)
/* /*
* write_block writes block nr to disk. * write_block writes block nr to disk.
*/ */
void write_block(unsigned int nr, char * addr) static void write_block(unsigned int nr, char * addr)
{ {
if (!nr) if (!nr)
return; return;
if (nr < FIRSTZONE || nr >= ZONES) { if (nr < FIRSTZONE || nr >= ZONES) {
printf(_("Internal error: trying to write bad block\n" printf("Internal error: trying to write bad block\n"
"Write request ignored\n")); "Write request ignored\n");
errors_uncorrected = 1; errors_uncorrected = 1;
return; return;
} }
if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET))
die(_("seek failed in write_block")); die("seek failed in write_block");
if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) {
printf(_("Write error: bad block in file '")); printf("Write error: bad block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
errors_uncorrected = 1; errors_uncorrected = 1;
@ -403,7 +400,7 @@ void write_block(unsigned int nr, char * addr)
* It sets 'changed' if the inode has needed changing, and re-writes * It sets 'changed' if the inode has needed changing, and re-writes
* any indirect blocks with errors. * any indirect blocks with errors.
*/ */
int map_block(struct minix_inode * inode, unsigned int blknr) static int map_block(struct minix_inode * inode, unsigned int blknr)
{ {
unsigned short ind[BLOCK_SIZE>>1]; unsigned short ind[BLOCK_SIZE>>1];
unsigned short dind[BLOCK_SIZE>>1]; unsigned short dind[BLOCK_SIZE>>1];
@ -438,7 +435,7 @@ int map_block(struct minix_inode * inode, unsigned int blknr)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
int map_block2 (struct minix2_inode *inode, unsigned int blknr) static int map_block2 (struct minix2_inode *inode, unsigned int blknr)
{ {
unsigned int ind[BLOCK_SIZE >> 2]; unsigned int ind[BLOCK_SIZE >> 2];
unsigned int dind[BLOCK_SIZE >> 2]; unsigned int dind[BLOCK_SIZE >> 2];
@ -496,7 +493,7 @@ int map_block2 (struct minix2_inode *inode, unsigned int blknr)
} }
#endif #endif
void write_super_block(void) static void write_super_block(void)
{ {
/* /*
* Set the state of the filesystem based on whether or not there * Set the state of the filesystem based on whether or not there
@ -510,26 +507,26 @@ void write_super_block(void)
Super.s_state &= ~MINIX_ERROR_FS; Super.s_state &= ~MINIX_ERROR_FS;
if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_super_block")); die("seek failed in write_super_block");
if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE))
die(_("unable to write super-block")); die("unable to write super-block");
return; return;
} }
void write_tables(void) static void write_tables(void)
{ {
write_super_block(); write_super_block();
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")); 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")); die("Unable to write zone map");
if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE))
die(_("Unable to write inodes")); die("Unable to write inodes");
} }
void get_dirsize (void) static void get_dirsize (void)
{ {
int block; int block;
char blk[BLOCK_SIZE]; char blk[BLOCK_SIZE];
@ -552,12 +549,12 @@ void get_dirsize (void)
/* use defaults */ /* use defaults */
} }
void read_superblock(void) static void read_superblock(void)
{ {
if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
die(_("seek failed")); die("seek failed");
if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE))
die(_("unable to read super block")); die("unable to read super block");
if (MAGIC == MINIX_SUPER_MAGIC) { if (MAGIC == MINIX_SUPER_MAGIC) {
namelen = 14; namelen = 14;
dirsize = 16; dirsize = 16;
@ -577,20 +574,20 @@ void read_superblock(void)
version2 = 1; version2 = 1;
#endif #endif
} else } else
die(_("bad magic number in super-block")); die("bad magic number in super-block");
if (ZONESIZE != 0 || BLOCK_SIZE != 1024) if (ZONESIZE != 0 || BLOCK_SIZE != 1024)
die(_("Only 1k blocks/zones supported")); die("Only 1k blocks/zones supported");
if (IMAPS * BLOCK_SIZE * 8 < INODES + 1) if (IMAPS * BLOCK_SIZE * 8 < INODES + 1)
die(_("bad s_imap_blocks field in super-block")); die("bad s_imap_blocks field in super-block");
if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1) if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1)
die(_("bad s_zmap_blocks field in super-block")); die("bad s_zmap_blocks field in super-block");
} }
void read_tables(void) static void read_tables(void)
{ {
inode_map = malloc(IMAPS * BLOCK_SIZE); inode_map = malloc(IMAPS * BLOCK_SIZE);
if (!inode_map) if (!inode_map)
die(_("Unable to allocate buffer for 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) if (!inode_map)
die("Unable to allocate buffer for zone map"); die("Unable to allocate buffer for zone map");
@ -598,32 +595,32 @@ void read_tables(void)
memset(zone_map,0,sizeof(zone_map)); memset(zone_map,0,sizeof(zone_map));
inode_buffer = malloc(INODE_BUFFER_SIZE); inode_buffer = malloc(INODE_BUFFER_SIZE);
if (!inode_buffer) if (!inode_buffer)
die(_("Unable to allocate buffer for inodes")); die("Unable to allocate buffer for inodes");
inode_count = malloc(INODES + 1); inode_count = malloc(INODES + 1);
if (!inode_count) if (!inode_count)
die(_("Unable to allocate buffer for inode count")); die("Unable to allocate buffer for inode count");
zone_count = malloc(ZONES); zone_count = malloc(ZONES);
if (!zone_count) if (!zone_count)
die(_("Unable to allocate buffer for 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")); 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")); die("Unable to read zone map");
if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE))
die(_("Unable to read inodes")); die("Unable to read inodes");
if (NORM_FIRSTZONE != FIRSTZONE) { if (NORM_FIRSTZONE != FIRSTZONE) {
printf(_("Warning: Firstzone != Norm_firstzone\n")); printf("Warning: Firstzone != Norm_firstzone\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
get_dirsize (); get_dirsize ();
if (show) { if (show) {
printf(_("%ld inodes\n"),INODES); printf("%ld inodes\n",INODES);
printf(_("%ld blocks\n"),ZONES); printf("%ld blocks\n",ZONES);
printf(_("Firstdatazone=%ld (%ld)\n"),FIRSTZONE,NORM_FIRSTZONE); printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE);
printf(_("Zonesize=%d\n"),BLOCK_SIZE<<ZONESIZE); printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE);
printf(_("Maxsize=%ld\n"),MAXSIZE); printf("Maxsize=%ld\n",MAXSIZE);
printf(_("Filesystem state=%d\n"), Super.s_state); printf("Filesystem state=%d\n", Super.s_state);
printf(_("namelen=%d\n\n"),namelen); printf("namelen=%d\n\n",namelen);
} }
} }
@ -637,12 +634,12 @@ struct minix_inode * get_inode(unsigned int nr)
inode = Inode + nr; inode = Inode + nr;
if (!inode_count[nr]) { if (!inode_count[nr]) {
if (!inode_in_use(nr)) { if (!inode_in_use(nr)) {
printf(_("Inode %d marked not used, but used for file '"), printf("Inode %d marked not used, but used for file '",
nr); nr);
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
if (repair) { if (repair) {
if (ask(_("Mark in use"),1)) if (ask("Mark in use",1))
mark_inode(nr); mark_inode(nr);
} else { } else {
errors_uncorrected = 1; errors_uncorrected = 1;
@ -664,13 +661,13 @@ struct minix_inode * get_inode(unsigned int nr)
; ;
else { else {
print_current_name(); print_current_name();
printf(_(" has mode %05o\n"),inode->i_mode); printf(" has mode %05o\n",inode->i_mode);
} }
} else } else
links++; links++;
if (!++inode_count[nr]) { if (!++inode_count[nr]) {
printf(_("Warning: inode count too big.\n")); printf("Warning: inode count too big.\n");
inode_count[nr]--; inode_count[nr]--;
errors_uncorrected = 1; errors_uncorrected = 1;
} }
@ -689,11 +686,11 @@ get_inode2 (unsigned int nr)
inode = Inode2 + nr; inode = Inode2 + nr;
if (!inode_count[nr]) { if (!inode_count[nr]) {
if (!inode_in_use (nr)) { if (!inode_in_use (nr)) {
printf (_("Inode %d marked not used, but used for file '"), nr); printf ("Inode %d marked not used, but used for file '", nr);
print_current_name (); print_current_name ();
printf ("'\n"); printf ("'\n");
if (repair) { if (repair) {
if (ask (_("Mark in use"), 1)) if (ask ("Mark in use", 1))
mark_inode (nr); mark_inode (nr);
else else
errors_uncorrected = 1; errors_uncorrected = 1;
@ -713,12 +710,12 @@ get_inode2 (unsigned int nr)
else if (S_ISFIFO (inode->i_mode)); else if (S_ISFIFO (inode->i_mode));
else { else {
print_current_name (); print_current_name ();
printf (_(" has mode %05o\n"), inode->i_mode); printf (" has mode %05o\n", inode->i_mode);
} }
} else } else
links++; links++;
if (!++inode_count[nr]) { if (!++inode_count[nr]) {
printf (_("Warning: inode count too big.\n")); printf ("Warning: inode count too big.\n");
inode_count[nr]--; inode_count[nr]--;
errors_uncorrected = 1; errors_uncorrected = 1;
} }
@ -726,16 +723,16 @@ get_inode2 (unsigned int nr)
} }
#endif #endif
void check_root(void) static void check_root(void)
{ {
struct minix_inode * inode = Inode + ROOT_INO; struct minix_inode * inode = Inode + ROOT_INO;
if (!inode || !S_ISDIR(inode->i_mode)) if (!inode || !S_ISDIR(inode->i_mode))
die(_("root inode isn't a directory")); die("root inode isn't a directory");
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void check_root2 (void) static void check_root2 (void)
{ {
struct minix2_inode *inode = Inode2 + ROOT_INO; struct minix2_inode *inode = Inode2 + ROOT_INO;
@ -754,10 +751,10 @@ static int add_zone(unsigned short * znr, int * corrected)
if (!block) if (!block)
return 0; return 0;
if (zone_count[block]) { if (zone_count[block]) {
printf(_("Block has been used before. Now in file `")); printf("Block has been used before. Now in file `");
print_current_name(); print_current_name();
printf("'."); printf("'.");
if (ask(_("Clear"),1)) { if (ask("Clear",1)) {
*znr = 0; *znr = 0;
block = 0; block = 0;
*corrected = 1; *corrected = 1;
@ -766,10 +763,10 @@ static int add_zone(unsigned short * znr, int * corrected)
if (!block) if (!block)
return 0; return 0;
if (!zone_in_use(block)) { if (!zone_in_use(block)) {
printf(_("Block %d in file `"),block); printf("Block %d in file `",block);
print_current_name(); print_current_name();
printf(_("' is marked not in use.")); printf("' is marked not in use.");
if (ask(_("Correct"),1)) if (ask("Correct",1))
mark_zone(block); mark_zone(block);
} }
if (!++zone_count[block]) if (!++zone_count[block])
@ -788,10 +785,10 @@ static int add_zone2 (unsigned int *znr, int *corrected)
if (!block) if (!block)
return 0; return 0;
if (zone_count[block]) { if (zone_count[block]) {
printf (_("Block has been used before. Now in file `")); printf ("Block has been used before. Now in file `");
print_current_name (); print_current_name ();
printf ("'."); printf ("'.");
if (ask (_("Clear"), 1)) { if (ask ("Clear", 1)) {
*znr = 0; *znr = 0;
block = 0; block = 0;
*corrected = 1; *corrected = 1;
@ -800,10 +797,10 @@ static int add_zone2 (unsigned int *znr, int *corrected)
if (!block) if (!block)
return 0; return 0;
if (!zone_in_use (block)) { if (!zone_in_use (block)) {
printf (_("Block %d in file `"), block); printf ("Block %d in file `", block);
print_current_name (); print_current_name ();
printf (_("' is marked not in use.")); printf ("' is marked not in use.");
if (ask (_("Correct"), 1)) if (ask ("Correct", 1))
mark_zone (block); mark_zone (block);
} }
if (!++zone_count[block]) if (!++zone_count[block])
@ -899,7 +896,7 @@ add_zone_tind2 (unsigned int *znr, int *corrected)
} }
#endif #endif
void check_zones(unsigned int i) static void check_zones(unsigned int i)
{ {
struct minix_inode * inode; struct minix_inode * inode;
@ -918,7 +915,7 @@ void check_zones(unsigned int i)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_zones2 (unsigned int i) check_zones2 (unsigned int i)
{ {
struct minix2_inode *inode; struct minix2_inode *inode;
@ -939,7 +936,7 @@ check_zones2 (unsigned int i)
} }
#endif #endif
void check_file(struct minix_inode * dir, unsigned int offset) static void check_file(struct minix_inode * dir, unsigned int offset)
{ {
static char blk[BLOCK_SIZE]; static char blk[BLOCK_SIZE];
struct minix_inode * inode; struct minix_inode * inode;
@ -953,9 +950,9 @@ void check_file(struct minix_inode * dir, unsigned int offset)
ino = * (unsigned short *) (name-2); ino = * (unsigned short *) (name-2);
if (ino > INODES) { if (ino > INODES) {
print_current_name(); print_current_name();
printf(_(" contains a bad inode number for file '")); printf(" contains a bad inode number for file '");
printf("%.*s'.",namelen,name); printf("%.*s'.",namelen,name);
if (ask(_(" Remove"),1)) { if (ask(" Remove",1)) {
*(unsigned short *)(name-2) = 0; *(unsigned short *)(name-2) = 0;
write_block(block, blk); write_block(block, blk);
} }
@ -969,14 +966,14 @@ void check_file(struct minix_inode * dir, unsigned int offset)
if (!offset) { if (!offset) {
if (!inode || strcmp(".",name)) { if (!inode || strcmp(".",name)) {
print_current_name(); print_current_name();
printf(_(": bad directory: '.' isn't first\n")); printf(": bad directory: '.' isn't first\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else return; } else return;
} }
if (offset == dirsize) { if (offset == dirsize) {
if (!inode || strcmp("..",name)) { if (!inode || strcmp("..",name)) {
print_current_name(); print_current_name();
printf(_(": bad directory: '..' isn't second\n")); printf(": bad directory: '..' isn't second\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else return; } else return;
} }
@ -1002,7 +999,7 @@ void check_file(struct minix_inode * dir, unsigned int offset)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_file2 (struct minix2_inode *dir, unsigned int offset) check_file2 (struct minix2_inode *dir, unsigned int offset)
{ {
static char blk[BLOCK_SIZE]; static char blk[BLOCK_SIZE];
@ -1017,9 +1014,9 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
ino = *(unsigned short *) (name - 2); ino = *(unsigned short *) (name - 2);
if (ino > INODES) { if (ino > INODES) {
print_current_name (); print_current_name ();
printf (_(" contains a bad inode number for file '")); printf (" contains a bad inode number for file '");
printf ("%.*s'.", namelen, name); printf ("%.*s'.", namelen, name);
if (ask (_(" Remove"), 1)) { if (ask (" Remove", 1)) {
*(unsigned short *) (name - 2) = 0; *(unsigned short *) (name - 2) = 0;
write_block (block, blk); write_block (block, blk);
} }
@ -1033,7 +1030,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
if (!offset) { if (!offset) {
if (!inode || strcmp (".", name)) { if (!inode || strcmp (".", name)) {
print_current_name (); print_current_name ();
printf (_(": bad directory: '.' isn't first\n")); printf (": bad directory: '.' isn't first\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else } else
return; return;
@ -1041,7 +1038,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
if (offset == dirsize) { if (offset == dirsize) {
if (!inode || strcmp ("..", name)) { if (!inode || strcmp ("..", name)) {
print_current_name (); print_current_name ();
printf (_(": bad directory: '..' isn't second\n")); printf (": bad directory: '..' isn't second\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else } else
return; return;
@ -1066,17 +1063,17 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
} }
#endif #endif
void recursive_check(unsigned int ino) static void recursive_check(unsigned int ino)
{ {
struct minix_inode * dir; struct minix_inode * dir;
unsigned int offset; unsigned int offset;
dir = Inode + ino; dir = Inode + ino;
if (!S_ISDIR(dir->i_mode)) if (!S_ISDIR(dir->i_mode))
die(_("internal error")); die("internal error");
if (dir->i_size < 2 * dirsize) { if (dir->i_size < 2 * dirsize) {
print_current_name(); print_current_name();
printf(_(": bad directory: size<32")); printf(": bad directory: size<32");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
for (offset = 0 ; offset < dir->i_size ; offset += dirsize) for (offset = 0 ; offset < dir->i_size ; offset += dirsize)
@ -1084,7 +1081,7 @@ void recursive_check(unsigned int ino)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
recursive_check2 (unsigned int ino) recursive_check2 (unsigned int ino)
{ {
struct minix2_inode *dir; struct minix2_inode *dir;
@ -1095,7 +1092,7 @@ recursive_check2 (unsigned int ino)
die ("internal error"); die ("internal error");
if (dir->i_size < 2 * dirsize) { if (dir->i_size < 2 * dirsize) {
print_current_name (); print_current_name ();
printf (_(": bad directory: size < 32")); printf (": bad directory: size < 32");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
for (offset = 0; offset < dir->i_size; offset += dirsize) for (offset = 0; offset < dir->i_size; offset += dirsize)
@ -1103,23 +1100,23 @@ recursive_check2 (unsigned int ino)
} }
#endif #endif
int bad_zone(int i) static int bad_zone(int i)
{ {
char buffer[1024]; char buffer[1024];
if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET)) if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET))
die(_("seek failed in bad_zone")); die("seek failed in bad_zone");
return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE));
} }
void check_counts(void) static void check_counts(void)
{ {
int i; int i;
for (i=1 ; i <= INODES ; i++) { for (i=1 ; i <= INODES ; i++) {
if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) {
printf(_("Inode %d mode not cleared."),i); printf("Inode %d mode not cleared.",i);
if (ask(_("Clear"),1)) { if (ask("Clear",1)) {
Inode[i].i_mode = 0; Inode[i].i_mode = 0;
changed = 1; changed = 1;
} }
@ -1127,21 +1124,20 @@ void check_counts(void)
if (!inode_count[i]) { if (!inode_count[i]) {
if (!inode_in_use(i)) if (!inode_in_use(i))
continue; continue;
printf(_("Inode %d not used, marked used in the bitmap."),i); printf("Inode %d not used, marked used in the bitmap.",i);
if (ask(_("Clear"),1)) if (ask("Clear",1))
unmark_inode(i); unmark_inode(i);
continue; continue;
} }
if (!inode_in_use(i)) { if (!inode_in_use(i)) {
printf(_("Inode %d used, marked unused in the bitmap."), printf("Inode %d used, marked unused in the bitmap.", i);
i);
if (ask("Set",1)) if (ask("Set",1))
mark_inode(i); mark_inode(i);
} }
if (Inode[i].i_nlinks != inode_count[i]) { if (Inode[i].i_nlinks != inode_count[i]) {
printf(_("Inode %d (mode = %07o), i_nlinks=%d, counted=%d."), printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]); i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]);
if (ask(_("Set i_nlinks to count"),1)) { if (ask("Set i_nlinks to count",1)) {
Inode[i].i_nlinks=inode_count[i]; Inode[i].i_nlinks=inode_count[i];
changed=1; changed=1;
} }
@ -1153,26 +1149,26 @@ void check_counts(void)
if (!zone_count[i]) { if (!zone_count[i]) {
if (bad_zone(i)) if (bad_zone(i))
continue; continue;
printf(_("Zone %d: marked in use, no file uses it."),i); printf("Zone %d: marked in use, no file uses it.",i);
if (ask(_("Unmark"),1)) if (ask("Unmark",1))
unmark_zone(i); unmark_zone(i);
continue; continue;
} }
printf(_("Zone %d: %sin use, counted=%d\n"), printf("Zone %d: %sin use, counted=%d\n",
i,zone_in_use(i)?"":_("not "),zone_count[i]); i,zone_in_use(i)?"":"not ",zone_count[i]);
} }
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_counts2 (void) check_counts2 (void)
{ {
int i; int i;
for (i = 1; i <= INODES; i++) { for (i = 1; i <= INODES; i++) {
if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) { if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) {
printf (_("Inode %d mode not cleared."), i); printf ("Inode %d mode not cleared.", i);
if (ask (_("Clear"), 1)) { if (ask ("Clear", 1)) {
Inode2[i].i_mode = 0; Inode2[i].i_mode = 0;
changed = 1; changed = 1;
} }
@ -1180,20 +1176,20 @@ check_counts2 (void)
if (!inode_count[i]) { if (!inode_count[i]) {
if (!inode_in_use (i)) if (!inode_in_use (i))
continue; continue;
printf (_("Inode %d not used, marked used in the bitmap."), i); printf ("Inode %d not used, marked used in the bitmap.", i);
if (ask (_("Clear"), 1)) if (ask ("Clear", 1))
unmark_inode (i); unmark_inode (i);
continue; continue;
} }
if (!inode_in_use (i)) { if (!inode_in_use (i)) {
printf (_("Inode %d used, marked unused in the bitmap."), i); printf ("Inode %d used, marked unused in the bitmap.", i);
if (ask (_("Set"), 1)) if (ask ("Set", 1))
mark_inode (i); mark_inode (i);
} }
if (Inode2[i].i_nlinks != inode_count[i]) { if (Inode2[i].i_nlinks != inode_count[i]) {
printf (_("Inode %d (mode = %07o), i_nlinks=%d, counted=%d."), printf ("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]); i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]);
if (ask (_("Set i_nlinks to count"), 1)) { if (ask ("Set i_nlinks to count", 1)) {
Inode2[i].i_nlinks = inode_count[i]; Inode2[i].i_nlinks = inode_count[i];
changed = 1; changed = 1;
} }
@ -1205,18 +1201,18 @@ check_counts2 (void)
if (!zone_count[i]) { if (!zone_count[i]) {
if (bad_zone (i)) if (bad_zone (i))
continue; continue;
printf (_("Zone %d: marked in use, no file uses it."), i); printf ("Zone %d: marked in use, no file uses it.", i);
if (ask (_("Unmark"), 1)) if (ask ("Unmark", 1))
unmark_zone (i); unmark_zone (i);
continue; continue;
} }
printf (_("Zone %d: %sin use, counted=%d\n"), printf ("Zone %d: %sin use, counted=%d\n",
i, zone_in_use (i) ? "" : _("not "), zone_count[i]); i, zone_in_use (i) ? "" : "not ", zone_count[i]);
} }
} }
#endif #endif
void check(void) static void check(void)
{ {
memset(inode_count,0,(INODES + 1) * sizeof(*inode_count)); memset(inode_count,0,(INODES + 1) * sizeof(*inode_count));
memset(zone_count,0,ZONES*sizeof(*zone_count)); memset(zone_count,0,ZONES*sizeof(*zone_count));
@ -1226,7 +1222,7 @@ void check(void)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check2 (void) check2 (void)
{ {
memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count));
@ -1244,24 +1240,19 @@ fsck_minix_main(int argc, char ** argv)
int count; int count;
int retcode = 0; int retcode = 0;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if (argc && *argv) if (argc && *argv)
program_name = *argv; program_name = *argv;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad v2 inode size")); die("bad v2 inode size");
#endif #endif
while (argc-- > 1) { while (argc-- > 1) {
argv++; argv++;
if (argv[0][0] != '-') { if (argv[0][0] != '-') {
if (device_name) if (device_name)
usage(); show_usage();
else else
device_name = argv[0]; device_name = argv[0];
} else while (*++argv[0]) } else while (*++argv[0])
@ -1273,19 +1264,19 @@ fsck_minix_main(int argc, char ** argv)
case 's': show=1; break; case 's': show=1; break;
case 'm': warn_mode=1; break; case 'm': warn_mode=1; break;
case 'f': force=1; break; case 'f': force=1; break;
default: usage(); default: show_usage();
} }
} }
if (!device_name) if (!device_name)
usage(); show_usage();
check_mount(); /* trying to check a mounted filesystem? */ check_mount(); /* trying to check a mounted filesystem? */
if (repair && !automatic) { if (repair && !automatic) {
if (!isatty(0) || !isatty(1)) if (!isatty(0) || !isatty(1))
die(_("need terminal for interactive repairs")); die("need terminal for interactive repairs");
} }
IN = open(device_name,repair?O_RDWR:O_RDONLY); IN = open(device_name,repair?O_RDWR:O_RDONLY);
if (IN < 0) if (IN < 0)
die(_("unable to open '%s'")); die("unable to open '%s'");
for (count=0 ; count<3 ; count++) for (count=0 ; count<3 ; count++)
sync(); sync();
read_superblock(); read_superblock();
@ -1296,19 +1287,18 @@ fsck_minix_main(int argc, char ** argv)
* flags and whether or not the -f switch was specified on the * flags and whether or not the -f switch was specified on the
* command line. * command line.
*/ */
printf("%s, %s / %s\n", program_name, program_version, printf("%s, %s\n", program_name, program_version);
util_linux_version);
if ( !(Super.s_state & MINIX_ERROR_FS) && if ( !(Super.s_state & MINIX_ERROR_FS) &&
(Super.s_state & MINIX_VALID_FS) && (Super.s_state & MINIX_VALID_FS) &&
!force ) { !force ) {
if (repair) if (repair)
printf(_("%s is clean, no check.\n"), device_name); printf("%s is clean, no check.\n", device_name);
return retcode; return retcode;
} }
else if (force) else if (force)
printf(_("Forcing filesystem check on %s.\n"), device_name); printf("Forcing filesystem check on %s.\n", device_name);
else if (repair) else if (repair)
printf(_("Filesystem on %s is dirty, needs checking.\n"),\ printf("Filesystem on %s is dirty, needs checking.\n",\
device_name); device_name);
read_tables(); read_tables();
@ -1337,29 +1327,29 @@ fsck_minix_main(int argc, char ** argv)
for (i=1,free=0 ; i <= INODES ; i++) for (i=1,free=0 ; i <= INODES ; i++)
if (!inode_in_use(i)) if (!inode_in_use(i))
free++; free++;
printf(_("\n%6ld inodes used (%ld%%)\n"),(INODES-free), printf("\n%6ld inodes used (%ld%%)\n",(INODES-free),
100*(INODES-free)/INODES); 100*(INODES-free)/INODES);
for (i=FIRSTZONE,free=0 ; i < ZONES ; i++) for (i=FIRSTZONE,free=0 ; i < ZONES ; i++)
if (!zone_in_use(i)) if (!zone_in_use(i))
free++; free++;
printf(_("%6ld zones used (%ld%%)\n"),(ZONES-free), printf("%6ld zones used (%ld%%)\n",(ZONES-free),
100*(ZONES-free)/ZONES); 100*(ZONES-free)/ZONES);
printf(_("\n%6d regular files\n" printf("\n%6d regular files\n"
"%6d directories\n" "%6d directories\n"
"%6d character device files\n" "%6d character device files\n"
"%6d block device files\n" "%6d block device files\n"
"%6d links\n" "%6d links\n"
"%6d symbolic links\n" "%6d symbolic links\n"
"------\n" "------\n"
"%6d files\n"), "%6d files\n",
regular,directory,chardev,blockdev, regular,directory,chardev,blockdev,
links-2*directory+1,symlinks,total-2*directory+1); links-2*directory+1,symlinks,total-2*directory+1);
} }
if (changed) { if (changed) {
write_tables(); write_tables();
printf(_( "----------------------------\n" printf( "----------------------------\n"
"FILE SYSTEM HAS BEEN CHANGED\n" "FILE SYSTEM HAS BEEN CHANGED\n"
"----------------------------\n")); "----------------------------\n");
for (count=0 ; count<3 ; count++) for (count=0 ; count<3 ; count++)
sync(); sync();
} }

View File

@ -138,5 +138,30 @@ extern int parse_mode( const char* s, mode_t* theMode);
extern volatile void usage(const char *usage); extern volatile void usage(const char *usage);
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
static inline int bit(char * addr,unsigned int nr)
{
return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
}
static inline int setbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] |= (1<<(nr & 7));
return __res != 0; \
}
static inline int clrbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] &= ~(1<<(nr & 7));
return __res != 0;
}
#endif
#endif #endif

View File

@ -58,6 +58,7 @@
* enforced (but it's not much fun on a character device :-). * enforced (but it's not much fun on a character device :-).
*/ */
#include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@ -75,9 +76,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/minix_fs.h> #include <linux/minix_fs.h>
#include "nls.h"
#include "../version.h"
#ifdef MINIX2_SUPER_MAGIC2 #ifdef MINIX2_SUPER_MAGIC2
#define HAVE_MINIX2 1 #define HAVE_MINIX2 1
#endif #endif
@ -152,8 +150,6 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks = 0; static int used_good_blocks = 0;
static unsigned long req_nr_inodes = 0; static unsigned long req_nr_inodes = 0;
#include "bitops.h"
#define inode_in_use(x) (bit(inode_map,(x))) #define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
@ -168,22 +164,16 @@ static unsigned long req_nr_inodes = 0;
* to compile this under minix, volatile gives a warning, as * to compile this under minix, volatile gives a warning, as
* exit() isn't defined as volatile under minix. * exit() isn't defined as volatile under minix.
*/ */
volatile void fatal_error(const char * fmt_string,int status) static volatile void die(char *str) {
{
fprintf(stderr,fmt_string,program_name,device_name);
exit(status);
}
volatile void die(char *str) {
fprintf(stderr, "%s: %s\n", program_name, str); fprintf(stderr, "%s: %s\n", program_name, str);
exit(8); exit(8);
} }
volatile void usage() static volatile void show_usage()
{ {
fprintf(stderr, "%s (%s)\n", program_name, util_linux_version); fprintf(stderr, "%s\n", program_name);
fprintf(stderr, fprintf(stderr,
_("Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n"), "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n",
program_name); program_name);
exit(16); exit(16);
} }
@ -207,7 +197,7 @@ static void check_mount(void)
if (!mnt) if (!mnt)
return; return;
die(_("%s is mounted; will not make a filesystem here!")); die("%s is mounted; will not make a filesystem here!");
} }
static long valid_offset (int fd, int offset) static long valid_offset (int fd, int offset)
@ -261,43 +251,43 @@ static int get_size(const char *file)
return size; return size;
} }
void write_tables(void) static void write_tables(void)
{ {
/* Mark the super block valid. */ /* Mark the super block valid. */
Super.s_state |= MINIX_VALID_FS; Super.s_state |= MINIX_VALID_FS;
Super.s_state &= ~MINIX_ERROR_FS; Super.s_state &= ~MINIX_ERROR_FS;
if (lseek(DEV, 0, SEEK_SET)) if (lseek(DEV, 0, SEEK_SET))
die(_("seek to boot block failed in write_tables")); die("seek to boot block failed in write_tables");
if (512 != write(DEV, boot_block_buffer, 512)) if (512 != write(DEV, boot_block_buffer, 512))
die(_("unable to clear boot sector")); die("unable to clear boot sector");
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_tables")); die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
die(_("unable to write super-block")); die("unable to write super-block");
if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE)) if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE))
die(_("unable to write inode map")); die("unable to write inode map");
if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE)) if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE))
die(_("unable to write zone map")); die("unable to write zone map");
if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE))
die(_("unable to write inodes")); die("unable to write inodes");
} }
void write_block(int blk, char * buffer) static void write_block(int blk, char * buffer)
{ {
if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET)) if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_block")); die("seek failed in write_block");
if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE))
die(_("write failed in write_block")); die("write failed in write_block");
} }
int get_free_block(void) static int get_free_block(void)
{ {
int blk; int blk;
if (used_good_blocks+1 >= MAX_GOOD_BLOCKS) if (used_good_blocks+1 >= MAX_GOOD_BLOCKS)
die(_("too many bad blocks")); die("too many bad blocks");
if (used_good_blocks) if (used_good_blocks)
blk = good_blocks_table[used_good_blocks-1]+1; blk = good_blocks_table[used_good_blocks-1]+1;
else else
@ -305,13 +295,13 @@ int get_free_block(void)
while (blk < ZONES && zone_in_use(blk)) while (blk < ZONES && zone_in_use(blk))
blk++; blk++;
if (blk >= ZONES) if (blk >= ZONES)
die(_("not enough good blocks")); die("not enough good blocks");
good_blocks_table[used_good_blocks] = blk; good_blocks_table[used_good_blocks] = blk;
used_good_blocks++; used_good_blocks++;
return blk; return blk;
} }
void mark_good_blocks(void) static void mark_good_blocks(void)
{ {
int blk; int blk;
@ -329,7 +319,7 @@ inline int next(int zone)
return 0; return 0;
} }
void make_bad_inode(void) static void make_bad_inode(void)
{ {
struct minix_inode * inode = &Inode[MINIX_BAD_INO]; struct minix_inode * inode = &Inode[MINIX_BAD_INO];
int i,j,zone; int i,j,zone;
@ -371,7 +361,7 @@ void make_bad_inode(void)
goto end_bad; goto end_bad;
} }
} }
die(_("too many bad blocks")); die("too many bad blocks");
end_bad: end_bad:
if (ind) if (ind)
write_block(ind, (char *) ind_block); write_block(ind, (char *) ind_block);
@ -380,7 +370,7 @@ end_bad:
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
make_bad_inode2 (void) make_bad_inode2 (void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
@ -422,7 +412,7 @@ make_bad_inode2 (void)
} }
} }
/* Could make triple indirect block here */ /* Could make triple indirect block here */
die (_("too many bad blocks")); die ("too many bad blocks");
end_bad: end_bad:
if (ind) if (ind)
write_block (ind, (char *) ind_block); write_block (ind, (char *) ind_block);
@ -431,7 +421,7 @@ make_bad_inode2 (void)
} }
#endif #endif
void make_root_inode(void) static void make_root_inode(void)
{ {
struct minix_inode * inode = &Inode[MINIX_ROOT_INO]; struct minix_inode * inode = &Inode[MINIX_ROOT_INO];
@ -454,7 +444,7 @@ void make_root_inode(void)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
make_root_inode2 (void) make_root_inode2 (void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
@ -478,7 +468,7 @@ make_root_inode2 (void)
} }
#endif #endif
void setup_tables(void) static void setup_tables(void)
{ {
int i; int i;
unsigned long inodes; unsigned long inodes;
@ -526,7 +516,7 @@ void setup_tables(void)
inode_map = malloc(IMAPS * BLOCK_SIZE); inode_map = malloc(IMAPS * BLOCK_SIZE);
zone_map = malloc(ZMAPS * BLOCK_SIZE); zone_map = malloc(ZMAPS * BLOCK_SIZE);
if (!inode_map || !zone_map) if (!inode_map || !zone_map)
die(_("unable to allocate buffers for maps")); die("unable to allocate buffers for maps");
memset(inode_map,0xff,IMAPS * BLOCK_SIZE); memset(inode_map,0xff,IMAPS * BLOCK_SIZE);
memset(zone_map,0xff,ZMAPS * BLOCK_SIZE); memset(zone_map,0xff,ZMAPS * BLOCK_SIZE);
for (i = FIRSTZONE ; i<ZONES ; i++) for (i = FIRSTZONE ; i<ZONES ; i++)
@ -535,13 +525,13 @@ void setup_tables(void)
unmark_inode(i); unmark_inode(i);
inode_buffer = malloc(INODE_BUFFER_SIZE); inode_buffer = malloc(INODE_BUFFER_SIZE);
if (!inode_buffer) if (!inode_buffer)
die(_("unable to allocate buffer for inodes")); die("unable to allocate buffer for inodes");
memset(inode_buffer,0,INODE_BUFFER_SIZE); memset(inode_buffer,0,INODE_BUFFER_SIZE);
printf(_("%ld inodes\n"),INODES); printf("%ld inodes\n",INODES);
printf(_("%ld blocks\n"),ZONES); printf("%ld blocks\n",ZONES);
printf(_("Firstdatazone=%ld (%ld)\n"),FIRSTZONE,NORM_FIRSTZONE); printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE);
printf(_("Zonesize=%d\n"),BLOCK_SIZE<<ZONESIZE); printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE);
printf(_("Maxsize=%ld\n\n"),MAXSIZE); printf("Maxsize=%ld\n\n",MAXSIZE);
} }
/* /*
@ -555,7 +545,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
/* Seek to the correct loc. */ /* Seek to the correct loc. */
if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) !=
current_block * BLOCK_SIZE ) { current_block * BLOCK_SIZE ) {
die(_("seek failed during testing of blocks")); die("seek failed during testing of blocks");
} }
@ -563,7 +553,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
got = read(DEV, buffer, try * BLOCK_SIZE); got = read(DEV, buffer, try * BLOCK_SIZE);
if (got < 0) got = 0; if (got < 0) got = 0;
if (got & (BLOCK_SIZE - 1 )) { if (got & (BLOCK_SIZE - 1 )) {
printf(_("Weird values in do_check: probably bugs\n")); printf("Weird values in do_check: probably bugs\n");
} }
got /= BLOCK_SIZE; got /= BLOCK_SIZE;
return got; return got;
@ -571,7 +561,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
static unsigned int currently_testing = 0; static unsigned int currently_testing = 0;
void alarm_intr(int alnum) static void alarm_intr(int alnum)
{ {
if (currently_testing >= ZONES) if (currently_testing >= ZONES)
return; return;
@ -583,7 +573,7 @@ void alarm_intr(int alnum)
fflush(stdout); fflush(stdout);
} }
void check_blocks(void) static void check_blocks(void)
{ {
int try,got; int try,got;
static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS]; static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
@ -594,7 +584,7 @@ void check_blocks(void)
while (currently_testing < ZONES) { while (currently_testing < ZONES) {
if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) != if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) !=
currently_testing*BLOCK_SIZE) currently_testing*BLOCK_SIZE)
die(_("seek failed in check_blocks")); die("seek failed in check_blocks");
try = TEST_BUFFER_BLOCKS; try = TEST_BUFFER_BLOCKS;
if (currently_testing + try > ZONES) if (currently_testing + try > ZONES)
try = ZONES-currently_testing; try = ZONES-currently_testing;
@ -603,18 +593,18 @@ void check_blocks(void)
if (got == try) if (got == try)
continue; continue;
if (currently_testing < FIRSTZONE) if (currently_testing < FIRSTZONE)
die(_("bad blocks before data-area: cannot make fs")); die("bad blocks before data-area: cannot make fs");
mark_zone(currently_testing); mark_zone(currently_testing);
badblocks++; badblocks++;
currently_testing++; currently_testing++;
} }
if (badblocks > 1) if (badblocks > 1)
printf(_("%d bad blocks\n"), badblocks); printf("%d bad blocks\n", badblocks);
else if (badblocks == 1) else if (badblocks == 1)
printf(_("one bad block\n")); printf("one bad block\n");
} }
void get_list_blocks(filename) static void get_list_blocks(filename)
char *filename; char *filename;
{ {
@ -623,7 +613,7 @@ char *filename;
listfile=fopen(filename,"r"); listfile=fopen(filename,"r");
if(listfile == (FILE *)NULL) { if(listfile == (FILE *)NULL) {
die(_("can't open file of bad blocks")); die("can't open file of bad blocks");
} }
while(!feof(listfile)) { while(!feof(listfile)) {
fscanf(listfile,"%ld\n", &blockno); fscanf(listfile,"%ld\n", &blockno);
@ -631,9 +621,9 @@ char *filename;
badblocks++; badblocks++;
} }
if(badblocks > 1) if(badblocks > 1)
printf(_("%d bad blocks\n"), badblocks); printf("%d bad blocks\n", badblocks);
else if (badblocks == 1) else if (badblocks == 1)
printf(_("one bad block\n")); printf("one bad block\n");
} }
extern int extern int
@ -647,10 +637,10 @@ mkfs_minix_main(int argc, char ** argv)
if (argc && *argv) if (argc && *argv)
program_name = *argv; program_name = *argv;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#endif #endif
opterr = 0; opterr = 0;
while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF) while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF)
@ -665,13 +655,13 @@ mkfs_minix_main(int argc, char ** argv)
case 'n': case 'n':
i = strtoul(optarg,&tmp,0); i = strtoul(optarg,&tmp,0);
if (*tmp) if (*tmp)
usage(); show_usage();
if (i == 14) if (i == 14)
magic = MINIX_SUPER_MAGIC; magic = MINIX_SUPER_MAGIC;
else if (i == 30) else if (i == 30)
magic = MINIX_SUPER_MAGIC2; magic = MINIX_SUPER_MAGIC2;
else else
usage(); show_usage();
namelen = i; namelen = i;
dirsize = i+2; dirsize = i+2;
break; break;
@ -679,11 +669,12 @@ mkfs_minix_main(int argc, char ** argv)
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
version2 = 1; version2 = 1;
#else #else
fatal_error(_("%s: not compiled with minix v2 support\n"),-1); fprintf(stderr,"%s: not compiled with minix v2 support\n",program_name,device_name);
exit(-1);
#endif #endif
break; break;
default: default:
usage(); show_usage();
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -695,15 +686,15 @@ mkfs_minix_main(int argc, char ** argv)
if (argc > 0) { if (argc > 0) {
BLOCKS = strtol(argv[0],&tmp,0); BLOCKS = strtol(argv[0],&tmp,0);
if (*tmp) { if (*tmp) {
printf(_("strtol error: number of blocks not specified")); printf("strtol error: number of blocks not specified");
usage(); show_usage();
} }
} }
if (device_name && !BLOCKS) if (device_name && !BLOCKS)
BLOCKS = get_size (device_name) / 1024; BLOCKS = get_size (device_name) / 1024;
if (!device_name || BLOCKS<10) { if (!device_name || BLOCKS<10) {
usage(); show_usage();
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (version2) { if (version2) {
@ -727,13 +718,13 @@ mkfs_minix_main(int argc, char ** argv)
strcpy(tmp+2,".badblocks"); strcpy(tmp+2,".badblocks");
DEV = open(device_name,O_RDWR ); DEV = open(device_name,O_RDWR );
if (DEV<0) if (DEV<0)
die(_("unable to open %s")); die("unable to open %s");
if (fstat(DEV,&statbuf)<0) if (fstat(DEV,&statbuf)<0)
die(_("unable to stat %s")); die("unable to stat %s");
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))
check=0; check=0;
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
die(_("will not try to make filesystem on '%s'")); die("will not try to make filesystem on '%s'");
setup_tables(); setup_tables();
if (check) if (check)
check_blocks(); check_blocks();

View File

@ -85,6 +85,7 @@
* enforced (but it's not much fun on a character device :-). * enforced (but it's not much fun on a character device :-).
*/ */
#include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@ -98,8 +99,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/minix_fs.h> #include <linux/minix_fs.h>
#include "../version.h"
#include "nls.h"
#ifdef MINIX2_SUPER_MAGIC2 #ifdef MINIX2_SUPER_MAGIC2
#define HAVE_MINIX2 1 #define HAVE_MINIX2 1
@ -171,10 +170,8 @@ static char *zone_map;
static unsigned char * inode_count = NULL; static unsigned char * inode_count = NULL;
static unsigned char * zone_count = NULL; static unsigned char * zone_count = NULL;
void recursive_check(unsigned int ino); static void recursive_check(unsigned int ino);
void recursive_check2(unsigned int ino); static void recursive_check2(unsigned int ino);
#include "bitops.h"
#define inode_in_use(x) (bit(inode_map,(x))) #define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
@ -185,22 +182,22 @@ void recursive_check2(unsigned int ino);
#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),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 unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1)
void leave(int) __attribute__ ((noreturn)); static void leave(int) __attribute__ ((noreturn));
void leave(int status) static void leave(int status)
{ {
if (termios_set) if (termios_set)
tcsetattr(0, TCSANOW, &termios); tcsetattr(0, TCSANOW, &termios);
exit(status); exit(status);
} }
void usage(void) { static void show_usage(void) {
fprintf(stderr, fprintf(stderr,
_("Usage: %s [-larvsmf] /dev/name\n"), "Usage: %s [-larvsmf] /dev/name\n",
program_name); program_name);
leave(16); leave(16);
} }
void die(const char *str) { static void die(const char *str) {
fprintf(stderr, "%s: %s\n", program_name, str); fprintf(stderr, "%s: %s\n", program_name, str);
leave(8); leave(8);
} }
@ -209,7 +206,7 @@ void die(const char *str) {
* This simply goes through the file-name data and prints out the * This simply goes through the file-name data and prints out the
* current file. * current file.
*/ */
void print_current_name(void) static void print_current_name(void)
{ {
int i=0; int i=0;
@ -219,7 +216,7 @@ void print_current_name(void)
printf ("/"); printf ("/");
} }
int ask(const char * string, int def) static int ask(const char * string, int def)
{ {
int c; int c;
@ -293,13 +290,13 @@ static void check_mount(void)
else else
close(fd); close(fd);
printf (_("%s is mounted. "), device_name); printf ("%s is mounted. ", device_name);
if (isatty(0) && isatty(1)) if (isatty(0) && isatty(1))
cont = ask(_("Do you really want to continue"), 0); cont = ask("Do you really want to continue", 0);
else else
cont = 0; cont = 0;
if (!cont) { if (!cont) {
printf (_("check aborted.\n")); printf ("check aborted.\n");
exit (0); exit (0);
} }
return; return;
@ -311,19 +308,19 @@ static void check_mount(void)
* if an error was corrected, and returns the zone (0 for no zone * if an error was corrected, and returns the zone (0 for no zone
* or a bad zone-number). * or a bad zone-number).
*/ */
int check_zone_nr(unsigned short * nr, int * corrected) static int check_zone_nr(unsigned short * nr, int * corrected)
{ {
if (!*nr) if (!*nr)
return 0; return 0;
if (*nr < FIRSTZONE) if (*nr < FIRSTZONE)
printf(_("Zone nr < FIRSTZONE in file `")); printf("Zone nr < FIRSTZONE in file `");
else if (*nr >= ZONES) else if (*nr >= ZONES)
printf(_("Zone nr >= ZONES in file `")); printf("Zone nr >= ZONES in file `");
else else
return *nr; return *nr;
print_current_name(); print_current_name();
printf("'."); printf("'.");
if (ask(_("Remove block"),1)) { if (ask("Remove block",1)) {
*nr = 0; *nr = 0;
*corrected = 1; *corrected = 1;
} }
@ -331,19 +328,19 @@ int check_zone_nr(unsigned short * nr, int * corrected)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
int check_zone_nr2 (unsigned int *nr, int *corrected) static int check_zone_nr2 (unsigned int *nr, int *corrected)
{ {
if (!*nr) if (!*nr)
return 0; return 0;
if (*nr < FIRSTZONE) if (*nr < FIRSTZONE)
printf (_("Zone nr < FIRSTZONE in file `")); printf ("Zone nr < FIRSTZONE in file `");
else if (*nr >= ZONES) else if (*nr >= ZONES)
printf (_("Zone nr >= ZONES in file `")); printf ("Zone nr >= ZONES in file `");
else else
return *nr; return *nr;
print_current_name (); print_current_name ();
printf ("'."); printf ("'.");
if (ask (_("Remove block"), 1)) { if (ask ("Remove block", 1)) {
*nr = 0; *nr = 0;
*corrected = 1; *corrected = 1;
} }
@ -354,20 +351,20 @@ int check_zone_nr2 (unsigned int *nr, int *corrected)
/* /*
* read-block reads block nr into the buffer at addr. * read-block reads block nr into the buffer at addr.
*/ */
void read_block(unsigned int nr, char * addr) static void read_block(unsigned int nr, char * addr)
{ {
if (!nr) { if (!nr) {
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
return; return;
} }
if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) { if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) {
printf(_("Read error: unable to seek to block in file '")); printf("Read error: unable to seek to block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
errors_uncorrected = 1; errors_uncorrected = 1;
} else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) {
printf(_("Read error: bad block in file '")); printf("Read error: bad block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
memset(addr,0,BLOCK_SIZE); memset(addr,0,BLOCK_SIZE);
@ -378,20 +375,20 @@ void read_block(unsigned int nr, char * addr)
/* /*
* write_block writes block nr to disk. * write_block writes block nr to disk.
*/ */
void write_block(unsigned int nr, char * addr) static void write_block(unsigned int nr, char * addr)
{ {
if (!nr) if (!nr)
return; return;
if (nr < FIRSTZONE || nr >= ZONES) { if (nr < FIRSTZONE || nr >= ZONES) {
printf(_("Internal error: trying to write bad block\n" printf("Internal error: trying to write bad block\n"
"Write request ignored\n")); "Write request ignored\n");
errors_uncorrected = 1; errors_uncorrected = 1;
return; return;
} }
if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET))
die(_("seek failed in write_block")); die("seek failed in write_block");
if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) {
printf(_("Write error: bad block in file '")); printf("Write error: bad block in file '");
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
errors_uncorrected = 1; errors_uncorrected = 1;
@ -403,7 +400,7 @@ void write_block(unsigned int nr, char * addr)
* It sets 'changed' if the inode has needed changing, and re-writes * It sets 'changed' if the inode has needed changing, and re-writes
* any indirect blocks with errors. * any indirect blocks with errors.
*/ */
int map_block(struct minix_inode * inode, unsigned int blknr) static int map_block(struct minix_inode * inode, unsigned int blknr)
{ {
unsigned short ind[BLOCK_SIZE>>1]; unsigned short ind[BLOCK_SIZE>>1];
unsigned short dind[BLOCK_SIZE>>1]; unsigned short dind[BLOCK_SIZE>>1];
@ -438,7 +435,7 @@ int map_block(struct minix_inode * inode, unsigned int blknr)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
int map_block2 (struct minix2_inode *inode, unsigned int blknr) static int map_block2 (struct minix2_inode *inode, unsigned int blknr)
{ {
unsigned int ind[BLOCK_SIZE >> 2]; unsigned int ind[BLOCK_SIZE >> 2];
unsigned int dind[BLOCK_SIZE >> 2]; unsigned int dind[BLOCK_SIZE >> 2];
@ -496,7 +493,7 @@ int map_block2 (struct minix2_inode *inode, unsigned int blknr)
} }
#endif #endif
void write_super_block(void) static void write_super_block(void)
{ {
/* /*
* Set the state of the filesystem based on whether or not there * Set the state of the filesystem based on whether or not there
@ -510,26 +507,26 @@ void write_super_block(void)
Super.s_state &= ~MINIX_ERROR_FS; Super.s_state &= ~MINIX_ERROR_FS;
if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_super_block")); die("seek failed in write_super_block");
if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE))
die(_("unable to write super-block")); die("unable to write super-block");
return; return;
} }
void write_tables(void) static void write_tables(void)
{ {
write_super_block(); write_super_block();
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")); 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")); die("Unable to write zone map");
if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE))
die(_("Unable to write inodes")); die("Unable to write inodes");
} }
void get_dirsize (void) static void get_dirsize (void)
{ {
int block; int block;
char blk[BLOCK_SIZE]; char blk[BLOCK_SIZE];
@ -552,12 +549,12 @@ void get_dirsize (void)
/* use defaults */ /* use defaults */
} }
void read_superblock(void) static void read_superblock(void)
{ {
if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
die(_("seek failed")); die("seek failed");
if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE))
die(_("unable to read super block")); die("unable to read super block");
if (MAGIC == MINIX_SUPER_MAGIC) { if (MAGIC == MINIX_SUPER_MAGIC) {
namelen = 14; namelen = 14;
dirsize = 16; dirsize = 16;
@ -577,20 +574,20 @@ void read_superblock(void)
version2 = 1; version2 = 1;
#endif #endif
} else } else
die(_("bad magic number in super-block")); die("bad magic number in super-block");
if (ZONESIZE != 0 || BLOCK_SIZE != 1024) if (ZONESIZE != 0 || BLOCK_SIZE != 1024)
die(_("Only 1k blocks/zones supported")); die("Only 1k blocks/zones supported");
if (IMAPS * BLOCK_SIZE * 8 < INODES + 1) if (IMAPS * BLOCK_SIZE * 8 < INODES + 1)
die(_("bad s_imap_blocks field in super-block")); die("bad s_imap_blocks field in super-block");
if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1) if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1)
die(_("bad s_zmap_blocks field in super-block")); die("bad s_zmap_blocks field in super-block");
} }
void read_tables(void) static void read_tables(void)
{ {
inode_map = malloc(IMAPS * BLOCK_SIZE); inode_map = malloc(IMAPS * BLOCK_SIZE);
if (!inode_map) if (!inode_map)
die(_("Unable to allocate buffer for 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) if (!inode_map)
die("Unable to allocate buffer for zone map"); die("Unable to allocate buffer for zone map");
@ -598,32 +595,32 @@ void read_tables(void)
memset(zone_map,0,sizeof(zone_map)); memset(zone_map,0,sizeof(zone_map));
inode_buffer = malloc(INODE_BUFFER_SIZE); inode_buffer = malloc(INODE_BUFFER_SIZE);
if (!inode_buffer) if (!inode_buffer)
die(_("Unable to allocate buffer for inodes")); die("Unable to allocate buffer for inodes");
inode_count = malloc(INODES + 1); inode_count = malloc(INODES + 1);
if (!inode_count) if (!inode_count)
die(_("Unable to allocate buffer for inode count")); die("Unable to allocate buffer for inode count");
zone_count = malloc(ZONES); zone_count = malloc(ZONES);
if (!zone_count) if (!zone_count)
die(_("Unable to allocate buffer for 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")); 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")); die("Unable to read zone map");
if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE))
die(_("Unable to read inodes")); die("Unable to read inodes");
if (NORM_FIRSTZONE != FIRSTZONE) { if (NORM_FIRSTZONE != FIRSTZONE) {
printf(_("Warning: Firstzone != Norm_firstzone\n")); printf("Warning: Firstzone != Norm_firstzone\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
get_dirsize (); get_dirsize ();
if (show) { if (show) {
printf(_("%ld inodes\n"),INODES); printf("%ld inodes\n",INODES);
printf(_("%ld blocks\n"),ZONES); printf("%ld blocks\n",ZONES);
printf(_("Firstdatazone=%ld (%ld)\n"),FIRSTZONE,NORM_FIRSTZONE); printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE);
printf(_("Zonesize=%d\n"),BLOCK_SIZE<<ZONESIZE); printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE);
printf(_("Maxsize=%ld\n"),MAXSIZE); printf("Maxsize=%ld\n",MAXSIZE);
printf(_("Filesystem state=%d\n"), Super.s_state); printf("Filesystem state=%d\n", Super.s_state);
printf(_("namelen=%d\n\n"),namelen); printf("namelen=%d\n\n",namelen);
} }
} }
@ -637,12 +634,12 @@ struct minix_inode * get_inode(unsigned int nr)
inode = Inode + nr; inode = Inode + nr;
if (!inode_count[nr]) { if (!inode_count[nr]) {
if (!inode_in_use(nr)) { if (!inode_in_use(nr)) {
printf(_("Inode %d marked not used, but used for file '"), printf("Inode %d marked not used, but used for file '",
nr); nr);
print_current_name(); print_current_name();
printf("'\n"); printf("'\n");
if (repair) { if (repair) {
if (ask(_("Mark in use"),1)) if (ask("Mark in use",1))
mark_inode(nr); mark_inode(nr);
} else { } else {
errors_uncorrected = 1; errors_uncorrected = 1;
@ -664,13 +661,13 @@ struct minix_inode * get_inode(unsigned int nr)
; ;
else { else {
print_current_name(); print_current_name();
printf(_(" has mode %05o\n"),inode->i_mode); printf(" has mode %05o\n",inode->i_mode);
} }
} else } else
links++; links++;
if (!++inode_count[nr]) { if (!++inode_count[nr]) {
printf(_("Warning: inode count too big.\n")); printf("Warning: inode count too big.\n");
inode_count[nr]--; inode_count[nr]--;
errors_uncorrected = 1; errors_uncorrected = 1;
} }
@ -689,11 +686,11 @@ get_inode2 (unsigned int nr)
inode = Inode2 + nr; inode = Inode2 + nr;
if (!inode_count[nr]) { if (!inode_count[nr]) {
if (!inode_in_use (nr)) { if (!inode_in_use (nr)) {
printf (_("Inode %d marked not used, but used for file '"), nr); printf ("Inode %d marked not used, but used for file '", nr);
print_current_name (); print_current_name ();
printf ("'\n"); printf ("'\n");
if (repair) { if (repair) {
if (ask (_("Mark in use"), 1)) if (ask ("Mark in use", 1))
mark_inode (nr); mark_inode (nr);
else else
errors_uncorrected = 1; errors_uncorrected = 1;
@ -713,12 +710,12 @@ get_inode2 (unsigned int nr)
else if (S_ISFIFO (inode->i_mode)); else if (S_ISFIFO (inode->i_mode));
else { else {
print_current_name (); print_current_name ();
printf (_(" has mode %05o\n"), inode->i_mode); printf (" has mode %05o\n", inode->i_mode);
} }
} else } else
links++; links++;
if (!++inode_count[nr]) { if (!++inode_count[nr]) {
printf (_("Warning: inode count too big.\n")); printf ("Warning: inode count too big.\n");
inode_count[nr]--; inode_count[nr]--;
errors_uncorrected = 1; errors_uncorrected = 1;
} }
@ -726,16 +723,16 @@ get_inode2 (unsigned int nr)
} }
#endif #endif
void check_root(void) static void check_root(void)
{ {
struct minix_inode * inode = Inode + ROOT_INO; struct minix_inode * inode = Inode + ROOT_INO;
if (!inode || !S_ISDIR(inode->i_mode)) if (!inode || !S_ISDIR(inode->i_mode))
die(_("root inode isn't a directory")); die("root inode isn't a directory");
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void check_root2 (void) static void check_root2 (void)
{ {
struct minix2_inode *inode = Inode2 + ROOT_INO; struct minix2_inode *inode = Inode2 + ROOT_INO;
@ -754,10 +751,10 @@ static int add_zone(unsigned short * znr, int * corrected)
if (!block) if (!block)
return 0; return 0;
if (zone_count[block]) { if (zone_count[block]) {
printf(_("Block has been used before. Now in file `")); printf("Block has been used before. Now in file `");
print_current_name(); print_current_name();
printf("'."); printf("'.");
if (ask(_("Clear"),1)) { if (ask("Clear",1)) {
*znr = 0; *znr = 0;
block = 0; block = 0;
*corrected = 1; *corrected = 1;
@ -766,10 +763,10 @@ static int add_zone(unsigned short * znr, int * corrected)
if (!block) if (!block)
return 0; return 0;
if (!zone_in_use(block)) { if (!zone_in_use(block)) {
printf(_("Block %d in file `"),block); printf("Block %d in file `",block);
print_current_name(); print_current_name();
printf(_("' is marked not in use.")); printf("' is marked not in use.");
if (ask(_("Correct"),1)) if (ask("Correct",1))
mark_zone(block); mark_zone(block);
} }
if (!++zone_count[block]) if (!++zone_count[block])
@ -788,10 +785,10 @@ static int add_zone2 (unsigned int *znr, int *corrected)
if (!block) if (!block)
return 0; return 0;
if (zone_count[block]) { if (zone_count[block]) {
printf (_("Block has been used before. Now in file `")); printf ("Block has been used before. Now in file `");
print_current_name (); print_current_name ();
printf ("'."); printf ("'.");
if (ask (_("Clear"), 1)) { if (ask ("Clear", 1)) {
*znr = 0; *znr = 0;
block = 0; block = 0;
*corrected = 1; *corrected = 1;
@ -800,10 +797,10 @@ static int add_zone2 (unsigned int *znr, int *corrected)
if (!block) if (!block)
return 0; return 0;
if (!zone_in_use (block)) { if (!zone_in_use (block)) {
printf (_("Block %d in file `"), block); printf ("Block %d in file `", block);
print_current_name (); print_current_name ();
printf (_("' is marked not in use.")); printf ("' is marked not in use.");
if (ask (_("Correct"), 1)) if (ask ("Correct", 1))
mark_zone (block); mark_zone (block);
} }
if (!++zone_count[block]) if (!++zone_count[block])
@ -899,7 +896,7 @@ add_zone_tind2 (unsigned int *znr, int *corrected)
} }
#endif #endif
void check_zones(unsigned int i) static void check_zones(unsigned int i)
{ {
struct minix_inode * inode; struct minix_inode * inode;
@ -918,7 +915,7 @@ void check_zones(unsigned int i)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_zones2 (unsigned int i) check_zones2 (unsigned int i)
{ {
struct minix2_inode *inode; struct minix2_inode *inode;
@ -939,7 +936,7 @@ check_zones2 (unsigned int i)
} }
#endif #endif
void check_file(struct minix_inode * dir, unsigned int offset) static void check_file(struct minix_inode * dir, unsigned int offset)
{ {
static char blk[BLOCK_SIZE]; static char blk[BLOCK_SIZE];
struct minix_inode * inode; struct minix_inode * inode;
@ -953,9 +950,9 @@ void check_file(struct minix_inode * dir, unsigned int offset)
ino = * (unsigned short *) (name-2); ino = * (unsigned short *) (name-2);
if (ino > INODES) { if (ino > INODES) {
print_current_name(); print_current_name();
printf(_(" contains a bad inode number for file '")); printf(" contains a bad inode number for file '");
printf("%.*s'.",namelen,name); printf("%.*s'.",namelen,name);
if (ask(_(" Remove"),1)) { if (ask(" Remove",1)) {
*(unsigned short *)(name-2) = 0; *(unsigned short *)(name-2) = 0;
write_block(block, blk); write_block(block, blk);
} }
@ -969,14 +966,14 @@ void check_file(struct minix_inode * dir, unsigned int offset)
if (!offset) { if (!offset) {
if (!inode || strcmp(".",name)) { if (!inode || strcmp(".",name)) {
print_current_name(); print_current_name();
printf(_(": bad directory: '.' isn't first\n")); printf(": bad directory: '.' isn't first\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else return; } else return;
} }
if (offset == dirsize) { if (offset == dirsize) {
if (!inode || strcmp("..",name)) { if (!inode || strcmp("..",name)) {
print_current_name(); print_current_name();
printf(_(": bad directory: '..' isn't second\n")); printf(": bad directory: '..' isn't second\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else return; } else return;
} }
@ -1002,7 +999,7 @@ void check_file(struct minix_inode * dir, unsigned int offset)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_file2 (struct minix2_inode *dir, unsigned int offset) check_file2 (struct minix2_inode *dir, unsigned int offset)
{ {
static char blk[BLOCK_SIZE]; static char blk[BLOCK_SIZE];
@ -1017,9 +1014,9 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
ino = *(unsigned short *) (name - 2); ino = *(unsigned short *) (name - 2);
if (ino > INODES) { if (ino > INODES) {
print_current_name (); print_current_name ();
printf (_(" contains a bad inode number for file '")); printf (" contains a bad inode number for file '");
printf ("%.*s'.", namelen, name); printf ("%.*s'.", namelen, name);
if (ask (_(" Remove"), 1)) { if (ask (" Remove", 1)) {
*(unsigned short *) (name - 2) = 0; *(unsigned short *) (name - 2) = 0;
write_block (block, blk); write_block (block, blk);
} }
@ -1033,7 +1030,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
if (!offset) { if (!offset) {
if (!inode || strcmp (".", name)) { if (!inode || strcmp (".", name)) {
print_current_name (); print_current_name ();
printf (_(": bad directory: '.' isn't first\n")); printf (": bad directory: '.' isn't first\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else } else
return; return;
@ -1041,7 +1038,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
if (offset == dirsize) { if (offset == dirsize) {
if (!inode || strcmp ("..", name)) { if (!inode || strcmp ("..", name)) {
print_current_name (); print_current_name ();
printf (_(": bad directory: '..' isn't second\n")); printf (": bad directory: '..' isn't second\n");
errors_uncorrected = 1; errors_uncorrected = 1;
} else } else
return; return;
@ -1066,17 +1063,17 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
} }
#endif #endif
void recursive_check(unsigned int ino) static void recursive_check(unsigned int ino)
{ {
struct minix_inode * dir; struct minix_inode * dir;
unsigned int offset; unsigned int offset;
dir = Inode + ino; dir = Inode + ino;
if (!S_ISDIR(dir->i_mode)) if (!S_ISDIR(dir->i_mode))
die(_("internal error")); die("internal error");
if (dir->i_size < 2 * dirsize) { if (dir->i_size < 2 * dirsize) {
print_current_name(); print_current_name();
printf(_(": bad directory: size<32")); printf(": bad directory: size<32");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
for (offset = 0 ; offset < dir->i_size ; offset += dirsize) for (offset = 0 ; offset < dir->i_size ; offset += dirsize)
@ -1084,7 +1081,7 @@ void recursive_check(unsigned int ino)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
recursive_check2 (unsigned int ino) recursive_check2 (unsigned int ino)
{ {
struct minix2_inode *dir; struct minix2_inode *dir;
@ -1095,7 +1092,7 @@ recursive_check2 (unsigned int ino)
die ("internal error"); die ("internal error");
if (dir->i_size < 2 * dirsize) { if (dir->i_size < 2 * dirsize) {
print_current_name (); print_current_name ();
printf (_(": bad directory: size < 32")); printf (": bad directory: size < 32");
errors_uncorrected = 1; errors_uncorrected = 1;
} }
for (offset = 0; offset < dir->i_size; offset += dirsize) for (offset = 0; offset < dir->i_size; offset += dirsize)
@ -1103,23 +1100,23 @@ recursive_check2 (unsigned int ino)
} }
#endif #endif
int bad_zone(int i) static int bad_zone(int i)
{ {
char buffer[1024]; char buffer[1024];
if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET)) if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET))
die(_("seek failed in bad_zone")); die("seek failed in bad_zone");
return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE));
} }
void check_counts(void) static void check_counts(void)
{ {
int i; int i;
for (i=1 ; i <= INODES ; i++) { for (i=1 ; i <= INODES ; i++) {
if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) {
printf(_("Inode %d mode not cleared."),i); printf("Inode %d mode not cleared.",i);
if (ask(_("Clear"),1)) { if (ask("Clear",1)) {
Inode[i].i_mode = 0; Inode[i].i_mode = 0;
changed = 1; changed = 1;
} }
@ -1127,21 +1124,20 @@ void check_counts(void)
if (!inode_count[i]) { if (!inode_count[i]) {
if (!inode_in_use(i)) if (!inode_in_use(i))
continue; continue;
printf(_("Inode %d not used, marked used in the bitmap."),i); printf("Inode %d not used, marked used in the bitmap.",i);
if (ask(_("Clear"),1)) if (ask("Clear",1))
unmark_inode(i); unmark_inode(i);
continue; continue;
} }
if (!inode_in_use(i)) { if (!inode_in_use(i)) {
printf(_("Inode %d used, marked unused in the bitmap."), printf("Inode %d used, marked unused in the bitmap.", i);
i);
if (ask("Set",1)) if (ask("Set",1))
mark_inode(i); mark_inode(i);
} }
if (Inode[i].i_nlinks != inode_count[i]) { if (Inode[i].i_nlinks != inode_count[i]) {
printf(_("Inode %d (mode = %07o), i_nlinks=%d, counted=%d."), printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]); i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]);
if (ask(_("Set i_nlinks to count"),1)) { if (ask("Set i_nlinks to count",1)) {
Inode[i].i_nlinks=inode_count[i]; Inode[i].i_nlinks=inode_count[i];
changed=1; changed=1;
} }
@ -1153,26 +1149,26 @@ void check_counts(void)
if (!zone_count[i]) { if (!zone_count[i]) {
if (bad_zone(i)) if (bad_zone(i))
continue; continue;
printf(_("Zone %d: marked in use, no file uses it."),i); printf("Zone %d: marked in use, no file uses it.",i);
if (ask(_("Unmark"),1)) if (ask("Unmark",1))
unmark_zone(i); unmark_zone(i);
continue; continue;
} }
printf(_("Zone %d: %sin use, counted=%d\n"), printf("Zone %d: %sin use, counted=%d\n",
i,zone_in_use(i)?"":_("not "),zone_count[i]); i,zone_in_use(i)?"":"not ",zone_count[i]);
} }
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check_counts2 (void) check_counts2 (void)
{ {
int i; int i;
for (i = 1; i <= INODES; i++) { for (i = 1; i <= INODES; i++) {
if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) { if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) {
printf (_("Inode %d mode not cleared."), i); printf ("Inode %d mode not cleared.", i);
if (ask (_("Clear"), 1)) { if (ask ("Clear", 1)) {
Inode2[i].i_mode = 0; Inode2[i].i_mode = 0;
changed = 1; changed = 1;
} }
@ -1180,20 +1176,20 @@ check_counts2 (void)
if (!inode_count[i]) { if (!inode_count[i]) {
if (!inode_in_use (i)) if (!inode_in_use (i))
continue; continue;
printf (_("Inode %d not used, marked used in the bitmap."), i); printf ("Inode %d not used, marked used in the bitmap.", i);
if (ask (_("Clear"), 1)) if (ask ("Clear", 1))
unmark_inode (i); unmark_inode (i);
continue; continue;
} }
if (!inode_in_use (i)) { if (!inode_in_use (i)) {
printf (_("Inode %d used, marked unused in the bitmap."), i); printf ("Inode %d used, marked unused in the bitmap.", i);
if (ask (_("Set"), 1)) if (ask ("Set", 1))
mark_inode (i); mark_inode (i);
} }
if (Inode2[i].i_nlinks != inode_count[i]) { if (Inode2[i].i_nlinks != inode_count[i]) {
printf (_("Inode %d (mode = %07o), i_nlinks=%d, counted=%d."), printf ("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]); i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]);
if (ask (_("Set i_nlinks to count"), 1)) { if (ask ("Set i_nlinks to count", 1)) {
Inode2[i].i_nlinks = inode_count[i]; Inode2[i].i_nlinks = inode_count[i];
changed = 1; changed = 1;
} }
@ -1205,18 +1201,18 @@ check_counts2 (void)
if (!zone_count[i]) { if (!zone_count[i]) {
if (bad_zone (i)) if (bad_zone (i))
continue; continue;
printf (_("Zone %d: marked in use, no file uses it."), i); printf ("Zone %d: marked in use, no file uses it.", i);
if (ask (_("Unmark"), 1)) if (ask ("Unmark", 1))
unmark_zone (i); unmark_zone (i);
continue; continue;
} }
printf (_("Zone %d: %sin use, counted=%d\n"), printf ("Zone %d: %sin use, counted=%d\n",
i, zone_in_use (i) ? "" : _("not "), zone_count[i]); i, zone_in_use (i) ? "" : "not ", zone_count[i]);
} }
} }
#endif #endif
void check(void) static void check(void)
{ {
memset(inode_count,0,(INODES + 1) * sizeof(*inode_count)); memset(inode_count,0,(INODES + 1) * sizeof(*inode_count));
memset(zone_count,0,ZONES*sizeof(*zone_count)); memset(zone_count,0,ZONES*sizeof(*zone_count));
@ -1226,7 +1222,7 @@ void check(void)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
check2 (void) check2 (void)
{ {
memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count));
@ -1244,24 +1240,19 @@ fsck_minix_main(int argc, char ** argv)
int count; int count;
int retcode = 0; int retcode = 0;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if (argc && *argv) if (argc && *argv)
program_name = *argv; program_name = *argv;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad v2 inode size")); die("bad v2 inode size");
#endif #endif
while (argc-- > 1) { while (argc-- > 1) {
argv++; argv++;
if (argv[0][0] != '-') { if (argv[0][0] != '-') {
if (device_name) if (device_name)
usage(); show_usage();
else else
device_name = argv[0]; device_name = argv[0];
} else while (*++argv[0]) } else while (*++argv[0])
@ -1273,19 +1264,19 @@ fsck_minix_main(int argc, char ** argv)
case 's': show=1; break; case 's': show=1; break;
case 'm': warn_mode=1; break; case 'm': warn_mode=1; break;
case 'f': force=1; break; case 'f': force=1; break;
default: usage(); default: show_usage();
} }
} }
if (!device_name) if (!device_name)
usage(); show_usage();
check_mount(); /* trying to check a mounted filesystem? */ check_mount(); /* trying to check a mounted filesystem? */
if (repair && !automatic) { if (repair && !automatic) {
if (!isatty(0) || !isatty(1)) if (!isatty(0) || !isatty(1))
die(_("need terminal for interactive repairs")); die("need terminal for interactive repairs");
} }
IN = open(device_name,repair?O_RDWR:O_RDONLY); IN = open(device_name,repair?O_RDWR:O_RDONLY);
if (IN < 0) if (IN < 0)
die(_("unable to open '%s'")); die("unable to open '%s'");
for (count=0 ; count<3 ; count++) for (count=0 ; count<3 ; count++)
sync(); sync();
read_superblock(); read_superblock();
@ -1296,19 +1287,18 @@ fsck_minix_main(int argc, char ** argv)
* flags and whether or not the -f switch was specified on the * flags and whether or not the -f switch was specified on the
* command line. * command line.
*/ */
printf("%s, %s / %s\n", program_name, program_version, printf("%s, %s\n", program_name, program_version);
util_linux_version);
if ( !(Super.s_state & MINIX_ERROR_FS) && if ( !(Super.s_state & MINIX_ERROR_FS) &&
(Super.s_state & MINIX_VALID_FS) && (Super.s_state & MINIX_VALID_FS) &&
!force ) { !force ) {
if (repair) if (repair)
printf(_("%s is clean, no check.\n"), device_name); printf("%s is clean, no check.\n", device_name);
return retcode; return retcode;
} }
else if (force) else if (force)
printf(_("Forcing filesystem check on %s.\n"), device_name); printf("Forcing filesystem check on %s.\n", device_name);
else if (repair) else if (repair)
printf(_("Filesystem on %s is dirty, needs checking.\n"),\ printf("Filesystem on %s is dirty, needs checking.\n",\
device_name); device_name);
read_tables(); read_tables();
@ -1337,29 +1327,29 @@ fsck_minix_main(int argc, char ** argv)
for (i=1,free=0 ; i <= INODES ; i++) for (i=1,free=0 ; i <= INODES ; i++)
if (!inode_in_use(i)) if (!inode_in_use(i))
free++; free++;
printf(_("\n%6ld inodes used (%ld%%)\n"),(INODES-free), printf("\n%6ld inodes used (%ld%%)\n",(INODES-free),
100*(INODES-free)/INODES); 100*(INODES-free)/INODES);
for (i=FIRSTZONE,free=0 ; i < ZONES ; i++) for (i=FIRSTZONE,free=0 ; i < ZONES ; i++)
if (!zone_in_use(i)) if (!zone_in_use(i))
free++; free++;
printf(_("%6ld zones used (%ld%%)\n"),(ZONES-free), printf("%6ld zones used (%ld%%)\n",(ZONES-free),
100*(ZONES-free)/ZONES); 100*(ZONES-free)/ZONES);
printf(_("\n%6d regular files\n" printf("\n%6d regular files\n"
"%6d directories\n" "%6d directories\n"
"%6d character device files\n" "%6d character device files\n"
"%6d block device files\n" "%6d block device files\n"
"%6d links\n" "%6d links\n"
"%6d symbolic links\n" "%6d symbolic links\n"
"------\n" "------\n"
"%6d files\n"), "%6d files\n",
regular,directory,chardev,blockdev, regular,directory,chardev,blockdev,
links-2*directory+1,symlinks,total-2*directory+1); links-2*directory+1,symlinks,total-2*directory+1);
} }
if (changed) { if (changed) {
write_tables(); write_tables();
printf(_( "----------------------------\n" printf( "----------------------------\n"
"FILE SYSTEM HAS BEEN CHANGED\n" "FILE SYSTEM HAS BEEN CHANGED\n"
"----------------------------\n")); "----------------------------\n");
for (count=0 ; count<3 ; count++) for (count=0 ; count<3 ; count++)
sync(); sync();
} }

View File

@ -58,6 +58,7 @@
* enforced (but it's not much fun on a character device :-). * enforced (but it's not much fun on a character device :-).
*/ */
#include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@ -75,9 +76,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/minix_fs.h> #include <linux/minix_fs.h>
#include "nls.h"
#include "../version.h"
#ifdef MINIX2_SUPER_MAGIC2 #ifdef MINIX2_SUPER_MAGIC2
#define HAVE_MINIX2 1 #define HAVE_MINIX2 1
#endif #endif
@ -152,8 +150,6 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks = 0; static int used_good_blocks = 0;
static unsigned long req_nr_inodes = 0; static unsigned long req_nr_inodes = 0;
#include "bitops.h"
#define inode_in_use(x) (bit(inode_map,(x))) #define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
@ -168,22 +164,16 @@ static unsigned long req_nr_inodes = 0;
* to compile this under minix, volatile gives a warning, as * to compile this under minix, volatile gives a warning, as
* exit() isn't defined as volatile under minix. * exit() isn't defined as volatile under minix.
*/ */
volatile void fatal_error(const char * fmt_string,int status) static volatile void die(char *str) {
{
fprintf(stderr,fmt_string,program_name,device_name);
exit(status);
}
volatile void die(char *str) {
fprintf(stderr, "%s: %s\n", program_name, str); fprintf(stderr, "%s: %s\n", program_name, str);
exit(8); exit(8);
} }
volatile void usage() static volatile void show_usage()
{ {
fprintf(stderr, "%s (%s)\n", program_name, util_linux_version); fprintf(stderr, "%s\n", program_name);
fprintf(stderr, fprintf(stderr,
_("Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n"), "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n",
program_name); program_name);
exit(16); exit(16);
} }
@ -207,7 +197,7 @@ static void check_mount(void)
if (!mnt) if (!mnt)
return; return;
die(_("%s is mounted; will not make a filesystem here!")); die("%s is mounted; will not make a filesystem here!");
} }
static long valid_offset (int fd, int offset) static long valid_offset (int fd, int offset)
@ -261,43 +251,43 @@ static int get_size(const char *file)
return size; return size;
} }
void write_tables(void) static void write_tables(void)
{ {
/* Mark the super block valid. */ /* Mark the super block valid. */
Super.s_state |= MINIX_VALID_FS; Super.s_state |= MINIX_VALID_FS;
Super.s_state &= ~MINIX_ERROR_FS; Super.s_state &= ~MINIX_ERROR_FS;
if (lseek(DEV, 0, SEEK_SET)) if (lseek(DEV, 0, SEEK_SET))
die(_("seek to boot block failed in write_tables")); die("seek to boot block failed in write_tables");
if (512 != write(DEV, boot_block_buffer, 512)) if (512 != write(DEV, boot_block_buffer, 512))
die(_("unable to clear boot sector")); die("unable to clear boot sector");
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_tables")); die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
die(_("unable to write super-block")); die("unable to write super-block");
if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE)) if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE))
die(_("unable to write inode map")); die("unable to write inode map");
if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE)) if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE))
die(_("unable to write zone map")); die("unable to write zone map");
if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE)) if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE))
die(_("unable to write inodes")); die("unable to write inodes");
} }
void write_block(int blk, char * buffer) static void write_block(int blk, char * buffer)
{ {
if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET)) if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET))
die(_("seek failed in write_block")); die("seek failed in write_block");
if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE))
die(_("write failed in write_block")); die("write failed in write_block");
} }
int get_free_block(void) static int get_free_block(void)
{ {
int blk; int blk;
if (used_good_blocks+1 >= MAX_GOOD_BLOCKS) if (used_good_blocks+1 >= MAX_GOOD_BLOCKS)
die(_("too many bad blocks")); die("too many bad blocks");
if (used_good_blocks) if (used_good_blocks)
blk = good_blocks_table[used_good_blocks-1]+1; blk = good_blocks_table[used_good_blocks-1]+1;
else else
@ -305,13 +295,13 @@ int get_free_block(void)
while (blk < ZONES && zone_in_use(blk)) while (blk < ZONES && zone_in_use(blk))
blk++; blk++;
if (blk >= ZONES) if (blk >= ZONES)
die(_("not enough good blocks")); die("not enough good blocks");
good_blocks_table[used_good_blocks] = blk; good_blocks_table[used_good_blocks] = blk;
used_good_blocks++; used_good_blocks++;
return blk; return blk;
} }
void mark_good_blocks(void) static void mark_good_blocks(void)
{ {
int blk; int blk;
@ -329,7 +319,7 @@ inline int next(int zone)
return 0; return 0;
} }
void make_bad_inode(void) static void make_bad_inode(void)
{ {
struct minix_inode * inode = &Inode[MINIX_BAD_INO]; struct minix_inode * inode = &Inode[MINIX_BAD_INO];
int i,j,zone; int i,j,zone;
@ -371,7 +361,7 @@ void make_bad_inode(void)
goto end_bad; goto end_bad;
} }
} }
die(_("too many bad blocks")); die("too many bad blocks");
end_bad: end_bad:
if (ind) if (ind)
write_block(ind, (char *) ind_block); write_block(ind, (char *) ind_block);
@ -380,7 +370,7 @@ end_bad:
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
make_bad_inode2 (void) make_bad_inode2 (void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
@ -422,7 +412,7 @@ make_bad_inode2 (void)
} }
} }
/* Could make triple indirect block here */ /* Could make triple indirect block here */
die (_("too many bad blocks")); die ("too many bad blocks");
end_bad: end_bad:
if (ind) if (ind)
write_block (ind, (char *) ind_block); write_block (ind, (char *) ind_block);
@ -431,7 +421,7 @@ make_bad_inode2 (void)
} }
#endif #endif
void make_root_inode(void) static void make_root_inode(void)
{ {
struct minix_inode * inode = &Inode[MINIX_ROOT_INO]; struct minix_inode * inode = &Inode[MINIX_ROOT_INO];
@ -454,7 +444,7 @@ void make_root_inode(void)
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
void static void
make_root_inode2 (void) make_root_inode2 (void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
@ -478,7 +468,7 @@ make_root_inode2 (void)
} }
#endif #endif
void setup_tables(void) static void setup_tables(void)
{ {
int i; int i;
unsigned long inodes; unsigned long inodes;
@ -526,7 +516,7 @@ void setup_tables(void)
inode_map = malloc(IMAPS * BLOCK_SIZE); inode_map = malloc(IMAPS * BLOCK_SIZE);
zone_map = malloc(ZMAPS * BLOCK_SIZE); zone_map = malloc(ZMAPS * BLOCK_SIZE);
if (!inode_map || !zone_map) if (!inode_map || !zone_map)
die(_("unable to allocate buffers for maps")); die("unable to allocate buffers for maps");
memset(inode_map,0xff,IMAPS * BLOCK_SIZE); memset(inode_map,0xff,IMAPS * BLOCK_SIZE);
memset(zone_map,0xff,ZMAPS * BLOCK_SIZE); memset(zone_map,0xff,ZMAPS * BLOCK_SIZE);
for (i = FIRSTZONE ; i<ZONES ; i++) for (i = FIRSTZONE ; i<ZONES ; i++)
@ -535,13 +525,13 @@ void setup_tables(void)
unmark_inode(i); unmark_inode(i);
inode_buffer = malloc(INODE_BUFFER_SIZE); inode_buffer = malloc(INODE_BUFFER_SIZE);
if (!inode_buffer) if (!inode_buffer)
die(_("unable to allocate buffer for inodes")); die("unable to allocate buffer for inodes");
memset(inode_buffer,0,INODE_BUFFER_SIZE); memset(inode_buffer,0,INODE_BUFFER_SIZE);
printf(_("%ld inodes\n"),INODES); printf("%ld inodes\n",INODES);
printf(_("%ld blocks\n"),ZONES); printf("%ld blocks\n",ZONES);
printf(_("Firstdatazone=%ld (%ld)\n"),FIRSTZONE,NORM_FIRSTZONE); printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE);
printf(_("Zonesize=%d\n"),BLOCK_SIZE<<ZONESIZE); printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE);
printf(_("Maxsize=%ld\n\n"),MAXSIZE); printf("Maxsize=%ld\n\n",MAXSIZE);
} }
/* /*
@ -555,7 +545,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
/* Seek to the correct loc. */ /* Seek to the correct loc. */
if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) !=
current_block * BLOCK_SIZE ) { current_block * BLOCK_SIZE ) {
die(_("seek failed during testing of blocks")); die("seek failed during testing of blocks");
} }
@ -563,7 +553,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
got = read(DEV, buffer, try * BLOCK_SIZE); got = read(DEV, buffer, try * BLOCK_SIZE);
if (got < 0) got = 0; if (got < 0) got = 0;
if (got & (BLOCK_SIZE - 1 )) { if (got & (BLOCK_SIZE - 1 )) {
printf(_("Weird values in do_check: probably bugs\n")); printf("Weird values in do_check: probably bugs\n");
} }
got /= BLOCK_SIZE; got /= BLOCK_SIZE;
return got; return got;
@ -571,7 +561,7 @@ long do_check(char * buffer, int try, unsigned int current_block)
static unsigned int currently_testing = 0; static unsigned int currently_testing = 0;
void alarm_intr(int alnum) static void alarm_intr(int alnum)
{ {
if (currently_testing >= ZONES) if (currently_testing >= ZONES)
return; return;
@ -583,7 +573,7 @@ void alarm_intr(int alnum)
fflush(stdout); fflush(stdout);
} }
void check_blocks(void) static void check_blocks(void)
{ {
int try,got; int try,got;
static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS]; static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
@ -594,7 +584,7 @@ void check_blocks(void)
while (currently_testing < ZONES) { while (currently_testing < ZONES) {
if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) != if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) !=
currently_testing*BLOCK_SIZE) currently_testing*BLOCK_SIZE)
die(_("seek failed in check_blocks")); die("seek failed in check_blocks");
try = TEST_BUFFER_BLOCKS; try = TEST_BUFFER_BLOCKS;
if (currently_testing + try > ZONES) if (currently_testing + try > ZONES)
try = ZONES-currently_testing; try = ZONES-currently_testing;
@ -603,18 +593,18 @@ void check_blocks(void)
if (got == try) if (got == try)
continue; continue;
if (currently_testing < FIRSTZONE) if (currently_testing < FIRSTZONE)
die(_("bad blocks before data-area: cannot make fs")); die("bad blocks before data-area: cannot make fs");
mark_zone(currently_testing); mark_zone(currently_testing);
badblocks++; badblocks++;
currently_testing++; currently_testing++;
} }
if (badblocks > 1) if (badblocks > 1)
printf(_("%d bad blocks\n"), badblocks); printf("%d bad blocks\n", badblocks);
else if (badblocks == 1) else if (badblocks == 1)
printf(_("one bad block\n")); printf("one bad block\n");
} }
void get_list_blocks(filename) static void get_list_blocks(filename)
char *filename; char *filename;
{ {
@ -623,7 +613,7 @@ char *filename;
listfile=fopen(filename,"r"); listfile=fopen(filename,"r");
if(listfile == (FILE *)NULL) { if(listfile == (FILE *)NULL) {
die(_("can't open file of bad blocks")); die("can't open file of bad blocks");
} }
while(!feof(listfile)) { while(!feof(listfile)) {
fscanf(listfile,"%ld\n", &blockno); fscanf(listfile,"%ld\n", &blockno);
@ -631,9 +621,9 @@ char *filename;
badblocks++; badblocks++;
} }
if(badblocks > 1) if(badblocks > 1)
printf(_("%d bad blocks\n"), badblocks); printf("%d bad blocks\n", badblocks);
else if (badblocks == 1) else if (badblocks == 1)
printf(_("one bad block\n")); printf("one bad block\n");
} }
extern int extern int
@ -647,10 +637,10 @@ mkfs_minix_main(int argc, char ** argv)
if (argc && *argv) if (argc && *argv)
program_name = *argv; program_name = *argv;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die(_("bad inode size")); die("bad inode size");
#endif #endif
opterr = 0; opterr = 0;
while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF) while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF)
@ -665,13 +655,13 @@ mkfs_minix_main(int argc, char ** argv)
case 'n': case 'n':
i = strtoul(optarg,&tmp,0); i = strtoul(optarg,&tmp,0);
if (*tmp) if (*tmp)
usage(); show_usage();
if (i == 14) if (i == 14)
magic = MINIX_SUPER_MAGIC; magic = MINIX_SUPER_MAGIC;
else if (i == 30) else if (i == 30)
magic = MINIX_SUPER_MAGIC2; magic = MINIX_SUPER_MAGIC2;
else else
usage(); show_usage();
namelen = i; namelen = i;
dirsize = i+2; dirsize = i+2;
break; break;
@ -679,11 +669,12 @@ mkfs_minix_main(int argc, char ** argv)
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
version2 = 1; version2 = 1;
#else #else
fatal_error(_("%s: not compiled with minix v2 support\n"),-1); fprintf(stderr,"%s: not compiled with minix v2 support\n",program_name,device_name);
exit(-1);
#endif #endif
break; break;
default: default:
usage(); show_usage();
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -695,15 +686,15 @@ mkfs_minix_main(int argc, char ** argv)
if (argc > 0) { if (argc > 0) {
BLOCKS = strtol(argv[0],&tmp,0); BLOCKS = strtol(argv[0],&tmp,0);
if (*tmp) { if (*tmp) {
printf(_("strtol error: number of blocks not specified")); printf("strtol error: number of blocks not specified");
usage(); show_usage();
} }
} }
if (device_name && !BLOCKS) if (device_name && !BLOCKS)
BLOCKS = get_size (device_name) / 1024; BLOCKS = get_size (device_name) / 1024;
if (!device_name || BLOCKS<10) { if (!device_name || BLOCKS<10) {
usage(); show_usage();
} }
#ifdef HAVE_MINIX2 #ifdef HAVE_MINIX2
if (version2) { if (version2) {
@ -727,13 +718,13 @@ mkfs_minix_main(int argc, char ** argv)
strcpy(tmp+2,".badblocks"); strcpy(tmp+2,".badblocks");
DEV = open(device_name,O_RDWR ); DEV = open(device_name,O_RDWR );
if (DEV<0) if (DEV<0)
die(_("unable to open %s")); die("unable to open %s");
if (fstat(DEV,&statbuf)<0) if (fstat(DEV,&statbuf)<0)
die(_("unable to stat %s")); die("unable to stat %s");
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))
check=0; check=0;
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
die(_("will not try to make filesystem on '%s'")); die("will not try to make filesystem on '%s'");
setup_tables(); setup_tables();
if (check) if (check)
check_blocks(); check_blocks();

View File

@ -643,4 +643,6 @@ extern int parse_mode( const char* s, mode_t* theMode)
} }
#endif #endif
/* END CODE */ /* END CODE */