Hello again!

I have written a better patch for Minix filesystem support.
It adds correct support for Minixfs version 1 with 30-character filenames.

Please discard my previous hack.

Changelog:

        * stage2/fsys_minix.c: Correct support for modified minixfs
        version 1 (filenames up to 30 characters)

Pavel Roskin
Index: stage2/fsys_minix.c
===================================================================
RCS file: /gd/gnu/anoncvsroot/grub/stage2/fsys_minix.c,v
retrieving revision 1.1
diff -u -u -r1.1 fsys_minix.c
--- fsys_minix.c        1999/08/26 09:42:57     1.1
+++ fsys_minix.c        1999/08/28 15:58:01
@@ -20,7 +20,7 @@
 /* Restrictions:
    This is MINIX V1 only (yet)
    Disk creation is like:
-   mkfs.minix  -c -n14 DEVICE 
+   mkfs.minix -c DEVICE 
 */
 
 #ifdef FSYS_MINIX
@@ -31,7 +31,7 @@
 /* #define DEBUG_MINIX */
 
 /* indirect blocks */
-static int mapblock1, mapblock2;
+static int mapblock1, mapblock2, namelen;
 
 /* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
 #define DEV_BSIZE 512
@@ -80,8 +80,6 @@
    here we have */
 #define INODE_VERSION(inode)   (SUPERBLOCK->s_version)
 
-#define MINIX_NAME_LEN         14 /* XXX depend on version */
-
 /*
  * This is the original minix inode layout on disk.
  * Note the 8-bit gid and atime and ctime.
@@ -162,19 +160,30 @@
 int
 minix_mount (void)
 {
-  int retval = 1;
-
-  if ((((current_drive & 0x80 || current_slice != 0))
-       && (current_slice != PC_SLICE_TYPE_MINIX)
-       && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER))
-      || part_length < (SBLOCK + 
-                       (sizeof (struct minix_super_block) / DEV_BSIZE))
-      || ! devread (SBLOCK, 0, sizeof (struct minix_super_block),
-                   (char *) SUPERBLOCK)
-      || SUPERBLOCK->s_magic != MINIX_SUPER_MAGIC)
-    retval = 0;
+  if (((current_drive & 0x80 || current_slice != 0))
+      && (current_slice != PC_SLICE_TYPE_MINIX)
+      && !IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER))
+    return 0;                  /* The partition is not of MINIX type */
+
+  if (part_length < (SBLOCK +
+                    (sizeof (struct minix_super_block) / DEV_BSIZE)))
+      return 0;                        /* The partition is too short */
+
+  if (!devread (SBLOCK, 0, sizeof (struct minix_super_block),
+                 (char *) SUPERBLOCK))
+      return 0;                        /* Cannot read superblock */
 
-  return retval;
+  switch (SUPERBLOCK->s_magic)
+    {
+    case MINIX_SUPER_MAGIC:
+      namelen = 14;
+      return 1;
+    case MINIX_SUPER_MAGIC2:
+      namelen = 30;
+      return 1;
+    default:
+      return 0;                        /* Unsupported type */
+    }
 }
 
 /* Takes a file system block number and reads it into BUFFER. */
@@ -482,9 +491,10 @@
          off = loc & (BLOCK_SIZE - 1);
          dp = (struct minix_dir_entry *) (DATABLOCK2 + off);
          /* advance loc prematurely to next on-disk directory entry  */
-         loc += sizeof (dp->inode) + 14; /* XXX */
+         loc += sizeof (dp->inode) + namelen;
 
-         /* NOTE: minix filenames are NULL terminated if < 14 else exact */
+         /* NOTE: minix filenames are NULL terminated if < namelen
+            else exact */
 
 #ifdef DEBUG_MINIX
          printf ("directory entry ino=%d\n", dp->inode);
@@ -494,9 +504,9 @@
 
          if (dp->inode)
            {
-             int saved_c = dp->name[MINIX_NAME_LEN+1];
+             int saved_c = dp->name[namelen+1];
 
-             dp->name[MINIX_NAME_LEN+1] = 0;
+             dp->name[namelen+1] = 0;
              str_chk = substring (dirname, dp->name);
 
 # ifndef STAGE1_5
@@ -509,7 +519,7 @@
                }
 # endif
 
-             dp->name[MINIX_NAME_LEN+1] = saved_c;
+             dp->name[namelen+1] = saved_c;
            }
 
        }

Reply via email to