Oops. Forgot the usleep.c file.
[oweals/busybox.git] / fsck_minix.c
index 084c76d36cd5ee31c612e75b2fb9ac344d110023..aa0a82432c6a85c3717955876a1746abcc84bb2f 100644 (file)
@@ -143,9 +143,10 @@ static struct termios termios;
 static int termios_set = 0;
 
 /* File-name data */
-#define MAX_DEPTH 50
+#define MAX_DEPTH 32
 static int name_depth = 0;
-static char name_list[MAX_DEPTH][PATH_MAX + 1];
+// static char name_list[MAX_DEPTH][PATH_MAX + 1];
+static char **name_list = NULL;
 
 static char *inode_buffer = NULL;
 
@@ -602,23 +603,13 @@ static void read_superblock(void)
 
 static void read_tables(void)
 {
-       inode_map = malloc(IMAPS * BLOCK_SIZE);
-       if (!inode_map)
-               die("Unable to allocate buffer for inode map");
-       zone_map = malloc(ZMAPS * BLOCK_SIZE);
-       if (!inode_map)
-               die("Unable to allocate buffer for zone map");
+       inode_map = xmalloc(IMAPS * BLOCK_SIZE);
+       zone_map = xmalloc(ZMAPS * BLOCK_SIZE);
        memset(inode_map, 0, sizeof(inode_map));
        memset(zone_map, 0, sizeof(zone_map));
-       inode_buffer = malloc(INODE_BUFFER_SIZE);
-       if (!inode_buffer)
-               die("Unable to allocate buffer for inodes");
-       inode_count = malloc(INODES + 1);
-       if (!inode_count)
-               die("Unable to allocate buffer for inode count");
-       zone_count = malloc(ZONES);
-       if (!zone_count)
-               die("Unable to allocate buffer for zone count");
+       inode_buffer = xmalloc(INODE_BUFFER_SIZE);
+       inode_count = xmalloc(INODES + 1);
+       zone_count = xmalloc(ZONES);
        if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
                die("Unable to read inode map");
        if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
@@ -1240,12 +1231,46 @@ static void check2(void)
 }
 #endif
 
+/* Wed Feb  9 15:17:06 MST 2000 */
+/* dynamically allocate name_list (instead of making it static) */
+static void alloc_name_list(void)
+{
+       int i;
+
+       name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
+       for (i = 0; i < MAX_DEPTH; i++)
+               name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
+}
+
+#if 0
+/* execute this atexit() to deallocate name_list[] */
+/* piptigger was here */
+static void free_name_list(void)
+{
+       int i;
+
+       if (name_list) { 
+               for (i = 0; i < MAX_DEPTH; i++) {
+                       if (name_list[i]) {
+                               free(name_list[i]);
+                       }
+               }
+               free(name_list);
+       }
+}
+#endif
+
 extern int fsck_minix_main(int argc, char **argv)
 {
        struct termios tmp;
        int count;
        int retcode = 0;
 
+       alloc_name_list();
+       /* Don't bother to free memory.  Exit does
+        * that automagically, so we can save a few bytes */
+       //atexit(free_name_list);
+
        if (argc && *argv)
                program_name = *argv;
        if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)