aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/fsck_minix.c253
-rw-r--r--util-linux/mkfs_minix.c1
2 files changed, 130 insertions, 124 deletions
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c
index 74cccf671..795a5493c 100644
--- a/util-linux/fsck_minix.c
+++ b/util-linux/fsck_minix.c
@@ -87,62 +87,120 @@
87 * enforced (but it's not much fun on a character device :-). 87 * enforced (but it's not much fun on a character device :-).
88 */ 88 */
89 89
90#include "libbb.h"
91#include <mntent.h> 90#include <mntent.h>
92 91#include "libbb.h"
93#include "minix.h" 92#include "minix.h"
94 93
95#ifndef BLKGETSIZE 94#ifndef BLKGETSIZE
96#define BLKGETSIZE _IO(0x12,96) /* return device size */ 95#define BLKGETSIZE _IO(0x12,96) /* return device size */
97#endif 96#endif
98 97
99#ifdef UNUSED
100enum { 98enum {
99#ifdef UNUSED
101 MINIX1_LINK_MAX = 250, 100 MINIX1_LINK_MAX = 250,
102 MINIX2_LINK_MAX = 65530, 101 MINIX2_LINK_MAX = 65530,
103 MINIX_I_MAP_SLOTS = 8, 102 MINIX_I_MAP_SLOTS = 8,
104 MINIX_Z_MAP_SLOTS = 64, 103 MINIX_Z_MAP_SLOTS = 64,
105 MINIX_V1 = 0x0001, /* original minix fs */ 104 MINIX_V1 = 0x0001, /* original minix fs */
106 MINIX_V2 = 0x0002, /* minix V2 fs */ 105 MINIX_V2 = 0x0002, /* minix V2 fs */
107 NAME_MAX = 255, /* # chars in a file name */
108};
109#endif 106#endif
107 MINIX_NAME_MAX = 255, /* # chars in a file name */
108};
110 109
111#if ENABLE_FEATURE_MINIX2 110#if !ENABLE_FEATURE_MINIX2
112static smallint version2;
113#else
114enum { version2 = 0 }; 111enum { version2 = 0 };
115#endif 112#endif
116 113
117static smallint repair, automatic, verbose, list, show, warn_mode, force; 114enum { MAX_DEPTH = 32 };
118static smallint changed; /* is filesystem modified? */
119static smallint errors_uncorrected; /* flag if some error was not corrected */
120
121static smallint termios_set;
122static struct termios termios;
123
124static char *device_name;
125static int IN;
126static int directory, regular, blockdev, chardev, links, symlinks, total;
127
128//also smallint?
129static int dirsize = 16;
130static int namelen = 14;
131
132static char *inode_buffer;
133 115
134static struct { 116struct globals {
117 int dev_fd;
118#if ENABLE_FEATURE_MINIX2
119 smallint version2;
120#endif
121 smallint repair, automatic, verbose, list, show, warn_mode, force;
122 smallint changed; /* is filesystem modified? */
123 smallint errors_uncorrected; /* flag if some error was not corrected */
124 smallint termios_set;
125 smallint dirsize;
126 smallint namelen;
127 char *device_name;
128 int directory, regular, blockdev, chardev, links, symlinks, total;
129 char *inode_buffer;
130
131 char *inode_map;
132 char *zone_map;
133
134 unsigned char *inode_count;
135 unsigned char *zone_count;
136
137 /* File-name data */
138 int name_depth;
139 char *name_component[MAX_DEPTH+1];
140
141 /* Bigger stuff */
142 struct termios sv_termios;
135 char super_block_buffer[BLOCK_SIZE]; 143 char super_block_buffer[BLOCK_SIZE];
136 char add_zone_ind_blk[BLOCK_SIZE]; 144 char add_zone_ind_blk[BLOCK_SIZE];
137 char add_zone_dind_blk[BLOCK_SIZE]; 145 char add_zone_dind_blk[BLOCK_SIZE];
138 USE_FEATURE_MINIX2(char add_zone_tind_blk[BLOCK_SIZE];) 146 USE_FEATURE_MINIX2(char add_zone_tind_blk[BLOCK_SIZE];)
139 char check_file_blk[BLOCK_SIZE]; 147 char check_file_blk[BLOCK_SIZE];
140} *blockbuf; 148
149 /* File-name data */
150 char current_name[MAX_DEPTH * MINIX_NAME_MAX];
151};
152
153#define G (*ptr_to_globals)
154#define dev_fd (G.dev_fd )
155#if ENABLE_FEATURE_MINIX2
156#define version2 (G.version2 )
157#endif
158#define repair (G.repair )
159#define automatic (G.automatic )
160#define verbose (G.verbose )
161#define list (G.list )
162#define show (G.show )
163#define warn_mode (G.warn_mode )
164#define force (G.force )
165#define changed (G.changed )
166#define errors_uncorrected (G.errors_uncorrected )
167#define termios_set (G.termios_set )
168#define dirsize (G.dirsize )
169#define namelen (G.namelen )
170#define device_name (G.device_name )
171#define directory (G.directory )
172#define regular (G.regular )
173#define blockdev (G.blockdev )
174#define chardev (G.chardev )
175#define links (G.links )
176#define symlinks (G.symlinks )
177#define total (G.total )
178#define inode_buffer (G.inode_buffer )
179#define inode_map (G.inode_map )
180#define zone_map (G.zone_map )
181#define inode_count (G.inode_count )
182#define zone_count (G.zone_count )
183#define name_depth (G.name_depth )
184#define name_component (G.name_component )
185#define sv_termios (G.sv_termios )
186#define super_block_buffer (G.super_block_buffer )
187#define add_zone_ind_blk (G.add_zone_ind_blk )
188#define add_zone_dind_blk (G.add_zone_dind_blk )
189#define add_zone_tind_blk (G.add_zone_tind_blk )
190#define check_file_blk (G.check_file_blk )
191#define current_name (G.current_name )
192#define INIT_G() do { \
193 dirsize = 16; \
194 namelen = 14; \
195 current_name[0] = '/'; \
196 /*current_name[1] = '\0';*/ \
197 name_component[0] = &current_name[0]; \
198} while (0)
141 199
142#define Inode1 (((struct minix1_inode *) inode_buffer)-1) 200#define Inode1 (((struct minix1_inode *) inode_buffer)-1)
143#define Inode2 (((struct minix2_inode *) inode_buffer)-1) 201#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
144 202
145#define Super (*(struct minix_super_block *)(blockbuf->super_block_buffer)) 203#define Super (*(struct minix_super_block *)(super_block_buffer))
146 204
147#if ENABLE_FEATURE_MINIX2 205#if ENABLE_FEATURE_MINIX2
148# define ZONES ((unsigned)(version2 ? Super.s_zones : Super.s_nzones)) 206# define ZONES ((unsigned)(version2 ? Super.s_zones : Super.s_nzones))
@@ -173,12 +231,6 @@ static ALWAYS_INLINE unsigned div_roundup(unsigned size, unsigned n)
173#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) 231#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
174#define NORM_FIRSTZONE (2 + IMAPS + ZMAPS + INODE_BLOCKS) 232#define NORM_FIRSTZONE (2 + IMAPS + ZMAPS + INODE_BLOCKS)
175 233
176static char *inode_map;
177static char *zone_map;
178
179static unsigned char *inode_count;
180static unsigned char *zone_count;
181
182/* Before you ask "where they come from?": */ 234/* Before you ask "where they come from?": */
183/* setbit/clrbit are supplied by sys/param.h */ 235/* setbit/clrbit are supplied by sys/param.h */
184 236
@@ -205,8 +257,8 @@ static void minix_clrbit(char *a, unsigned i)
205#define mark_inode(x) (minix_setbit(inode_map,(x))) 257#define mark_inode(x) (minix_setbit(inode_map,(x)))
206#define unmark_inode(x) (minix_clrbit(inode_map,(x))) 258#define unmark_inode(x) (minix_clrbit(inode_map,(x)))
207 259
208#define mark_zone(x) (minix_setbit(zone_map,(x)-FIRSTZONE+1)) 260#define mark_zone(x) (minix_setbit(zone_map,(x)-FIRSTZONE+1))
209#define unmark_zone(x) (minix_clrbit(zone_map,(x)-FIRSTZONE+1)) 261#define unmark_zone(x) (minix_clrbit(zone_map,(x)-FIRSTZONE+1))
210 262
211 263
212static void recursive_check(unsigned ino); 264static void recursive_check(unsigned ino);
@@ -218,35 +270,10 @@ static void die(const char *str) ATTRIBUTE_NORETURN;
218static void die(const char *str) 270static void die(const char *str)
219{ 271{
220 if (termios_set) 272 if (termios_set)
221 tcsetattr(0, TCSANOW, &termios); 273 tcsetattr(0, TCSANOW, &sv_termios);
222 bb_error_msg_and_die("%s", str); 274 bb_error_msg_and_die("%s", str);
223} 275}
224 276
225/* File-name data */
226enum { MAX_DEPTH = 32 };
227static int name_depth;
228static char *current_name;
229static char *name_component[MAX_DEPTH+1];
230
231/* Wed Feb 9 15:17:06 MST 2000 */
232/* dynamically allocate name_list (instead of making it static) */
233static void alloc_current_name(void)
234{
235 current_name = xmalloc(MAX_DEPTH * (BUFSIZ + 1));
236 current_name[0] = '/';
237 current_name[1] = '\0';
238 name_component[0] = &current_name[0];
239}
240
241#if ENABLE_FEATURE_CLEAN_UP
242/* execute this atexit() to deallocate name_list[] */
243/* piptigger was here */
244static void free_current_name(void)
245{
246 free(current_name);
247}
248#endif
249
250static void push_filename(const char *name) 277static void push_filename(const char *name)
251{ 278{
252 // /dir/dir/dir/file 279 // /dir/dir/dir/file
@@ -401,12 +428,12 @@ static void read_block(unsigned nr, char *addr)
401 memset(addr, 0, BLOCK_SIZE); 428 memset(addr, 0, BLOCK_SIZE);
402 return; 429 return;
403 } 430 }
404 if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) { 431 if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) {
405 printf("%s: cannot seek to block in file '%s'\n", 432 printf("%s: cannot seek to block in file '%s'\n",
406 bb_msg_read_error, current_name); 433 bb_msg_read_error, current_name);
407 errors_uncorrected = 1; 434 errors_uncorrected = 1;
408 memset(addr, 0, BLOCK_SIZE); 435 memset(addr, 0, BLOCK_SIZE);
409 } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { 436 } else if (BLOCK_SIZE != read(dev_fd, addr, BLOCK_SIZE)) {
410 printf("%s: bad block in file '%s'\n", 437 printf("%s: bad block in file '%s'\n",
411 bb_msg_read_error, current_name); 438 bb_msg_read_error, current_name);
412 errors_uncorrected = 1; 439 errors_uncorrected = 1;
@@ -427,9 +454,9 @@ static void write_block(unsigned nr, char *addr)
427 errors_uncorrected = 1; 454 errors_uncorrected = 1;
428 return; 455 return;
429 } 456 }
430 if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) 457 if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET))
431 die("seek failed in write_block"); 458 die("seek failed in write_block");
432 if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { 459 if (BLOCK_SIZE != write(dev_fd, addr, BLOCK_SIZE)) {
433 printf("%s: bad block in file '%s'\n", 460 printf("%s: bad block in file '%s'\n",
434 bb_msg_write_error, current_name); 461 bb_msg_write_error, current_name);
435 errors_uncorrected = 1; 462 errors_uncorrected = 1;
@@ -547,9 +574,9 @@ static void write_super_block(void)
547 if (!errors_uncorrected) 574 if (!errors_uncorrected)
548 Super.s_state &= ~MINIX_ERROR_FS; 575 Super.s_state &= ~MINIX_ERROR_FS;
549 576
550 if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) 577 if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET))
551 die("seek failed in write_super_block"); 578 die("seek failed in write_super_block");
552 if (BLOCK_SIZE != write(IN, blockbuf->super_block_buffer, BLOCK_SIZE)) 579 if (BLOCK_SIZE != write(dev_fd, super_block_buffer, BLOCK_SIZE))
553 die("cannot write super-block"); 580 die("cannot write super-block");
554} 581}
555 582
@@ -557,11 +584,11 @@ static void write_tables(void)
557{ 584{
558 write_super_block(); 585 write_super_block();
559 586
560 if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) 587 if (IMAPS * BLOCK_SIZE != write(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
561 die("cannot write inode map"); 588 die("cannot write inode map");
562 if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) 589 if (ZMAPS * BLOCK_SIZE != write(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
563 die("cannot write zone map"); 590 die("cannot write zone map");
564 if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) 591 if (INODE_BUFFER_SIZE != write(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
565 die("cannot write inodes"); 592 die("cannot write inodes");
566} 593}
567 594
@@ -590,9 +617,9 @@ static void get_dirsize(void)
590 617
591static void read_superblock(void) 618static void read_superblock(void)
592{ 619{
593 if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) 620 if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET))
594 die("seek failed"); 621 die("seek failed");
595 if (BLOCK_SIZE != read(IN, blockbuf->super_block_buffer, BLOCK_SIZE)) 622 if (BLOCK_SIZE != read(dev_fd, super_block_buffer, BLOCK_SIZE))
596 die("cannot read super block"); 623 die("cannot read super block");
597 /* already initialized to: 624 /* already initialized to:
598 namelen = 14; 625 namelen = 14;
@@ -628,11 +655,11 @@ static void read_tables(void)
628 inode_buffer = xmalloc(INODE_BUFFER_SIZE); 655 inode_buffer = xmalloc(INODE_BUFFER_SIZE);
629 inode_count = xmalloc(INODES + 1); 656 inode_count = xmalloc(INODES + 1);
630 zone_count = xmalloc(ZONES); 657 zone_count = xmalloc(ZONES);
631 if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) 658 if (IMAPS * BLOCK_SIZE != read(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
632 die("cannot read inode map"); 659 die("cannot read inode map");
633 if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) 660 if (ZMAPS * BLOCK_SIZE != read(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
634 die("cannot read zone map"); 661 die("cannot read zone map");
635 if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) 662 if (INODE_BUFFER_SIZE != read(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
636 die("cannot read inodes"); 663 die("cannot read inodes");
637 if (NORM_FIRSTZONE != FIRSTZONE) { 664 if (NORM_FIRSTZONE != FIRSTZONE) {
638 printf("warning: firstzone!=norm_firstzone\n"); 665 printf("warning: firstzone!=norm_firstzone\n");
@@ -832,7 +859,6 @@ static int add_zone2(uint32_t *znr, smallint *corrected)
832 859
833static void add_zone_ind(uint16_t *znr, smallint *corrected) 860static void add_zone_ind(uint16_t *znr, smallint *corrected)
834{ 861{
835#define blk (blockbuf->add_zone_ind_blk)
836 int i; 862 int i;
837 int block; 863 int block;
838 smallint chg_blk = 0; 864 smallint chg_blk = 0;
@@ -840,18 +866,16 @@ static void add_zone_ind(uint16_t *znr, smallint *corrected)
840 block = add_zone(znr, corrected); 866 block = add_zone(znr, corrected);
841 if (!block) 867 if (!block)
842 return; 868 return;
843 read_block(block, blk); 869 read_block(block, add_zone_ind_blk);
844 for (i = 0; i < (BLOCK_SIZE >> 1); i++) 870 for (i = 0; i < (BLOCK_SIZE >> 1); i++)
845 add_zone(i + (uint16_t *) blk, &chg_blk); 871 add_zone(i + (uint16_t *) add_zone_ind_blk, &chg_blk);
846 if (chg_blk) 872 if (chg_blk)
847 write_block(block, blk); 873 write_block(block, add_zone_ind_blk);
848#undef blk
849} 874}
850 875
851#if ENABLE_FEATURE_MINIX2 876#if ENABLE_FEATURE_MINIX2
852static void add_zone_ind2(uint32_t *znr, smallint *corrected) 877static void add_zone_ind2(uint32_t *znr, smallint *corrected)
853{ 878{
854#define blk (blockbuf->add_zone_ind_blk)
855 int i; 879 int i;
856 int block; 880 int block;
857 smallint chg_blk = 0; 881 smallint chg_blk = 0;
@@ -859,18 +883,16 @@ static void add_zone_ind2(uint32_t *znr, smallint *corrected)
859 block = add_zone2(znr, corrected); 883 block = add_zone2(znr, corrected);
860 if (!block) 884 if (!block)
861 return; 885 return;
862 read_block(block, blk); 886 read_block(block, add_zone_ind_blk);
863 for (i = 0; i < BLOCK_SIZE >> 2; i++) 887 for (i = 0; i < BLOCK_SIZE >> 2; i++)
864 add_zone2(i + (uint32_t *) blk, &chg_blk); 888 add_zone2(i + (uint32_t *) add_zone_ind_blk, &chg_blk);
865 if (chg_blk) 889 if (chg_blk)
866 write_block(block, blk); 890 write_block(block, add_zone_ind_blk);
867#undef blk
868} 891}
869#endif 892#endif
870 893
871static void add_zone_dind(uint16_t *znr, smallint *corrected) 894static void add_zone_dind(uint16_t *znr, smallint *corrected)
872{ 895{
873#define blk (blockbuf->add_zone_dind_blk)
874 int i; 896 int i;
875 int block; 897 int block;
876 smallint chg_blk = 0; 898 smallint chg_blk = 0;
@@ -878,18 +900,16 @@ static void add_zone_dind(uint16_t *znr, smallint *corrected)
878 block = add_zone(znr, corrected); 900 block = add_zone(znr, corrected);
879 if (!block) 901 if (!block)
880 return; 902 return;
881 read_block(block, blk); 903 read_block(block, add_zone_dind_blk);
882 for (i = 0; i < (BLOCK_SIZE >> 1); i++) 904 for (i = 0; i < (BLOCK_SIZE >> 1); i++)
883 add_zone_ind(i + (uint16_t *) blk, &chg_blk); 905 add_zone_ind(i + (uint16_t *) add_zone_dind_blk, &chg_blk);
884 if (chg_blk) 906 if (chg_blk)
885 write_block(block, blk); 907 write_block(block, add_zone_dind_blk);
886#undef blk
887} 908}
888 909
889#if ENABLE_FEATURE_MINIX2 910#if ENABLE_FEATURE_MINIX2
890static void add_zone_dind2(uint32_t *znr, smallint *corrected) 911static void add_zone_dind2(uint32_t *znr, smallint *corrected)
891{ 912{
892#define blk (blockbuf->add_zone_dind_blk)
893 int i; 913 int i;
894 int block; 914 int block;
895 smallint chg_blk = 0; 915 smallint chg_blk = 0;
@@ -897,17 +917,15 @@ static void add_zone_dind2(uint32_t *znr, smallint *corrected)
897 block = add_zone2(znr, corrected); 917 block = add_zone2(znr, corrected);
898 if (!block) 918 if (!block)
899 return; 919 return;
900 read_block(block, blk); 920 read_block(block, add_zone_dind_blk);
901 for (i = 0; i < BLOCK_SIZE >> 2; i++) 921 for (i = 0; i < BLOCK_SIZE >> 2; i++)
902 add_zone_ind2(i + (uint32_t *) blk, &chg_blk); 922 add_zone_ind2(i + (uint32_t *) add_zone_dind_blk, &chg_blk);
903 if (chg_blk) 923 if (chg_blk)
904 write_block(block, blk); 924 write_block(block, add_zone_dind_blk);
905#undef blk
906} 925}
907 926
908static void add_zone_tind2(uint32_t *znr, smallint *corrected) 927static void add_zone_tind2(uint32_t *znr, smallint *corrected)
909{ 928{
910#define blk (blockbuf->add_zone_tind_blk)
911 int i; 929 int i;
912 int block; 930 int block;
913 smallint chg_blk = 0; 931 smallint chg_blk = 0;
@@ -915,12 +933,11 @@ static void add_zone_tind2(uint32_t *znr, smallint *corrected)
915 block = add_zone2(znr, corrected); 933 block = add_zone2(znr, corrected);
916 if (!block) 934 if (!block)
917 return; 935 return;
918 read_block(block, blk); 936 read_block(block, add_zone_tind_blk);
919 for (i = 0; i < BLOCK_SIZE >> 2; i++) 937 for (i = 0; i < BLOCK_SIZE >> 2; i++)
920 add_zone_dind2(i + (uint32_t *) blk, &chg_blk); 938 add_zone_dind2(i + (uint32_t *) add_zone_tind_blk, &chg_blk);
921 if (chg_blk) 939 if (chg_blk)
922 write_block(block, blk); 940 write_block(block, add_zone_tind_blk);
923#undef blk
924} 941}
925#endif 942#endif
926 943
@@ -964,22 +981,21 @@ static void check_zones2(unsigned i)
964 981
965static void check_file(struct minix1_inode *dir, unsigned offset) 982static void check_file(struct minix1_inode *dir, unsigned offset)
966{ 983{
967#define blk (blockbuf->check_file_blk)
968 struct minix1_inode *inode; 984 struct minix1_inode *inode;
969 int ino; 985 int ino;
970 char *name; 986 char *name;
971 int block; 987 int block;
972 988
973 block = map_block(dir, offset / BLOCK_SIZE); 989 block = map_block(dir, offset / BLOCK_SIZE);
974 read_block(block, blk); 990 read_block(block, check_file_blk);
975 name = blk + (offset % BLOCK_SIZE) + 2; 991 name = check_file_blk + (offset % BLOCK_SIZE) + 2;
976 ino = *(uint16_t *) (name - 2); 992 ino = *(uint16_t *) (name - 2);
977 if (ino > INODES) { 993 if (ino > INODES) {
978 printf("%s contains a bad inode number for file '%.*s'. ", 994 printf("%s contains a bad inode number for file '%.*s'. ",
979 current_name, namelen, name); 995 current_name, namelen, name);
980 if (ask("Remove", 1)) { 996 if (ask("Remove", 1)) {
981 *(uint16_t *) (name - 2) = 0; 997 *(uint16_t *) (name - 2) = 0;
982 write_block(block, blk); 998 write_block(block, check_file_blk);
983 } 999 }
984 ino = 0; 1000 ino = 0;
985 } 1001 }
@@ -1010,28 +1026,26 @@ static void check_file(struct minix1_inode *dir, unsigned offset)
1010 if (inode && S_ISDIR(inode->i_mode)) 1026 if (inode && S_ISDIR(inode->i_mode))
1011 recursive_check(ino); 1027 recursive_check(ino);
1012 pop_filename(); 1028 pop_filename();
1013#undef blk
1014} 1029}
1015 1030
1016#if ENABLE_FEATURE_MINIX2 1031#if ENABLE_FEATURE_MINIX2
1017static void check_file2(struct minix2_inode *dir, unsigned offset) 1032static void check_file2(struct minix2_inode *dir, unsigned offset)
1018{ 1033{
1019#define blk (blockbuf->check_file_blk)
1020 struct minix2_inode *inode; 1034 struct minix2_inode *inode;
1021 int ino; 1035 int ino;
1022 char *name; 1036 char *name;
1023 int block; 1037 int block;
1024 1038
1025 block = map_block2(dir, offset / BLOCK_SIZE); 1039 block = map_block2(dir, offset / BLOCK_SIZE);
1026 read_block(block, blk); 1040 read_block(block, check_file_blk);
1027 name = blk + (offset % BLOCK_SIZE) + 2; 1041 name = check_file_blk + (offset % BLOCK_SIZE) + 2;
1028 ino = *(uint16_t *) (name - 2); 1042 ino = *(uint16_t *) (name - 2);
1029 if (ino > INODES) { 1043 if (ino > INODES) {
1030 printf("%s contains a bad inode number for file '%.*s'. ", 1044 printf("%s contains a bad inode number for file '%.*s'. ",
1031 current_name, namelen, name); 1045 current_name, namelen, name);
1032 if (ask("Remove", 1)) { 1046 if (ask("Remove", 1)) {
1033 *(uint16_t *) (name - 2) = 0; 1047 *(uint16_t *) (name - 2) = 0;
1034 write_block(block, blk); 1048 write_block(block, check_file_blk);
1035 } 1049 }
1036 ino = 0; 1050 ino = 0;
1037 } 1051 }
@@ -1062,7 +1076,6 @@ static void check_file2(struct minix2_inode *dir, unsigned offset)
1062 if (inode && S_ISDIR(inode->i_mode)) 1076 if (inode && S_ISDIR(inode->i_mode))
1063 recursive_check2(ino); 1077 recursive_check2(ino);
1064 pop_filename(); 1078 pop_filename();
1065#undef blk
1066} 1079}
1067#endif 1080#endif
1068 1081
@@ -1104,9 +1117,9 @@ static int bad_zone(int i)
1104{ 1117{
1105 char buffer[BLOCK_SIZE]; 1118 char buffer[BLOCK_SIZE];
1106 1119
1107 if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) 1120 if (BLOCK_SIZE * i != lseek(dev_fd, BLOCK_SIZE * i, SEEK_SET))
1108 die("seek failed in bad_zone"); 1121 die("seek failed in bad_zone");
1109 return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); 1122 return (BLOCK_SIZE != read(dev_fd, buffer, BLOCK_SIZE));
1110} 1123}
1111 1124
1112static void check_counts(void) 1125static void check_counts(void)
@@ -1242,14 +1255,8 @@ int fsck_minix_main(int argc, char **argv)
1242 int retcode = 0; 1255 int retcode = 0;
1243 1256
1244 xfunc_error_retval = 8; 1257 xfunc_error_retval = 8;
1245 blockbuf = xzalloc(sizeof(*blockbuf));
1246 1258
1247 alloc_current_name(); 1259 INIT_G();
1248#if ENABLE_FEATURE_CLEAN_UP
1249 /* Don't bother to free memory. Exit does
1250 * that automagically, so we can save a few bytes */
1251 atexit(free_current_name);
1252#endif
1253 1260
1254 if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE) 1261 if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE)
1255 die("bad inode size"); 1262 die("bad inode size");
@@ -1303,7 +1310,7 @@ int fsck_minix_main(int argc, char **argv)
1303 if (!isatty(0) || !isatty(1)) 1310 if (!isatty(0) || !isatty(1))
1304 die("need terminal for interactive repairs"); 1311 die("need terminal for interactive repairs");
1305 } 1312 }
1306 IN = xopen(device_name, repair ? O_RDWR : O_RDONLY); 1313 dev_fd = xopen(device_name, repair ? O_RDWR : O_RDONLY);
1307 1314
1308 /*sync(); paranoia? */ 1315 /*sync(); paranoia? */
1309 read_superblock(); 1316 read_superblock();
@@ -1331,8 +1338,8 @@ int fsck_minix_main(int argc, char **argv)
1331 read_tables(); 1338 read_tables();
1332 1339
1333 if (repair && !automatic) { 1340 if (repair && !automatic) {
1334 tcgetattr(0, &termios); 1341 tcgetattr(0, &sv_termios);
1335 tmp = termios; 1342 tmp = sv_termios;
1336 tmp.c_lflag &= ~(ICANON | ECHO); 1343 tmp.c_lflag &= ~(ICANON | ECHO);
1337 tcsetattr(0, TCSANOW, &tmp); 1344 tcsetattr(0, TCSANOW, &tmp);
1338 termios_set = 1; 1345 termios_set = 1;
@@ -1379,7 +1386,7 @@ int fsck_minix_main(int argc, char **argv)
1379 write_super_block(); 1386 write_super_block();
1380 1387
1381 if (repair && !automatic) 1388 if (repair && !automatic)
1382 tcsetattr(0, TCSANOW, &termios); 1389 tcsetattr(0, TCSANOW, &sv_termios);
1383 1390
1384 if (changed) 1391 if (changed)
1385 retcode += 3; 1392 retcode += 3;
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 92d640407..34a4a91ab 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -90,7 +90,6 @@ enum { version2 = 0 };
90#endif 90#endif
91 91
92struct globals { 92struct globals {
93
94 int dev_fd; 93 int dev_fd;
95 94
96#if ENABLE_FEATURE_MINIX2 95#if ENABLE_FEATURE_MINIX2