=== modified file 'grub-core/Makefile.core.def'
--- grub-core/Makefile.core.def	2011-01-14 18:21:06 +0000
+++ grub-core/Makefile.core.def	2011-02-19 06:38:36 +0000
@@ -959,6 +959,11 @@
 };
 
 module = {
+  name = minix3;
+  common = fs/minix3.c;
+};
+
+module = {
   name = nilfs2;
   common = fs/nilfs2.c;
 };

=== modified file 'grub-core/fs/minix.c'
--- grub-core/fs/minix.c	2010-10-16 20:16:52 +0000
+++ grub-core/fs/minix.c	2011-02-19 08:28:54 +0000
@@ -19,20 +19,24 @@
 
 #include <grub/err.h>
 #include <grub/file.h>
+#include <grub/partition.h>
 #include <grub/mm.h>
 #include <grub/misc.h>
 #include <grub/disk.h>
 #include <grub/dl.h>
 #include <grub/types.h>
 
-#ifdef MODE_MINIX2
+#ifdef MODE_MINIX3
+#define GRUB_MINIX_MAGIC	0x4D5A
+#elif defined(MODE_MINIX2)
 #define GRUB_MINIX_MAGIC	0x2468
 #define GRUB_MINIX_MAGIC_30	0x2478
 #else
 #define GRUB_MINIX_MAGIC	0x137F
 #define GRUB_MINIX_MAGIC_30	0x138F
 #endif
-#define GRUB_MINIX_BSIZE	1024U
+
+#define GRUB_MINIX_INODE_DIR_BLOCKS	7
 #define GRUB_MINIX_LOG2_BSIZE	1
 #define GRUB_MINIX_ROOT_INODE	1
 #define GRUB_MINIX_MAX_SYMLNK_CNT	8
@@ -41,7 +45,10 @@
 #define GRUB_MINIX_IFDIR	0040000U
 #define GRUB_MINIX_IFLNK	0120000U
 
-#ifdef MODE_MINIX2
+#if defined(MODE_MINIX3)
+typedef grub_uint32_t grub_minix_uintn_t;
+#define grub_minix_le_to_cpu_n grub_le_to_cpu32
+#elif defined(MODE_MINIX2)
 typedef grub_uint32_t grub_minix_uintn_t;
 #define grub_minix_le_to_cpu_n grub_le_to_cpu32
 #else
@@ -62,9 +69,28 @@
 
 #define GRUB_MINIX_LOG2_ZONESZ	(GRUB_MINIX_LOG2_BSIZE				\
 				 + grub_le_to_cpu16 (sblock->log2_zone_size))
-#define GRUB_MINIX_ZONESZ	(GRUB_MINIX_BSIZE 				\
+#define GRUB_MINIX_ZONESZ	(data->block_size 				\
 				 << grub_le_to_cpu16 (sblock->log2_zone_size))
 
+#ifdef MODE_MINIX3
+struct grub_minix_sblock
+{
+  grub_uint32_t inode_cnt;
+  grub_uint16_t zone_cnt;
+  grub_uint16_t inode_bmap_size;
+  grub_uint16_t zone_bmap_size;
+  grub_uint16_t first_data_zone;
+  grub_uint16_t log2_zone_size;
+  grub_uint16_t pad;
+  grub_uint32_t max_file_size;
+  grub_uint32_t zones;
+  grub_uint16_t magic;
+  
+  grub_uint16_t pad2;
+  grub_uint16_t block_size;
+  grub_uint8_t disk_version; 
+};
+#else
 struct grub_minix_sblock
 {
   grub_uint16_t inode_cnt;
@@ -76,8 +102,29 @@
   grub_uint32_t max_file_size;
   grub_uint16_t magic;
 };
-
-#ifndef MODE_MINIX2
+#endif
+
+#if defined(MODE_MINIX3)
+
+struct grub_minix_inode
+{
+  grub_uint16_t mode;
+  grub_uint16_t nlinks;
+  grub_uint16_t uid;
+  grub_uint8_t gid;
+  grub_uint8_t pad;
+  grub_uint32_t size;
+  grub_uint32_t atime;
+  grub_uint32_t mtime;
+  grub_uint32_t ctime;
+  grub_uint32_t dir_zones[7];
+  grub_uint32_t indir_zone;
+  grub_uint32_t double_indir_zone;
+  grub_uint32_t unused;
+
+};
+
+#elif defined(MODE_MINIX2)
 struct grub_minix_inode
 {
   grub_uint16_t mode;
@@ -121,6 +168,8 @@
   int linknest;
   grub_disk_t disk;
   int filename_size;
+  grub_uint16_t block_size;
+  grub_uint16_t ino_size;
 };
 
 static grub_dl_t my_mod;
@@ -140,19 +189,26 @@
   int grub_get_indir (int zone, int num)
     {
       grub_minix_uintn_t indirn;
+#ifdef MODE_MINIX3
+      grub_disk_read (data->disk,
+                      zone * (data->block_size / GRUB_DISK_SECTOR_SIZE),
+                      sizeof (grub_uint32_t) * num,
+                      sizeof (grub_uint32_t), (char *) &indirn);
+#else
       grub_disk_read (data->disk,
 		      zone << GRUB_MINIX_LOG2_ZONESZ,
 		      sizeof (grub_minix_uintn_t) * num,
 		      sizeof (grub_minix_uintn_t), (char *) &indirn);
+#endif
       return grub_minix_le_to_cpu_n (indirn);
     }
 
   /* Direct block.  */
-  if (blk < 7)
+  if (blk < GRUB_MINIX_INODE_DIR_BLOCKS)
     return GRUB_MINIX_INODE_DIR_ZONES (data, blk);
 
   /* Indirect block.  */
-  blk -= 7;
+  blk -= GRUB_MINIX_INODE_DIR_BLOCKS;
   if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))
     {
       indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk);
@@ -195,45 +251,49 @@
   if (len + pos > GRUB_MINIX_INODE_SIZE (data))
     len = GRUB_MINIX_INODE_SIZE (data) - pos;
 
-  blockcnt = (len + pos + GRUB_MINIX_BSIZE - 1) / GRUB_MINIX_BSIZE;
+  blockcnt = (unsigned)(len + pos + data->block_size - 1) / data->block_size;
 
-  for (i = pos / GRUB_MINIX_BSIZE; i < blockcnt; i++)
+  for (i = pos / data->block_size; i < blockcnt; i++)
     {
       int blknr;
-      int blockoff = pos % GRUB_MINIX_BSIZE;
-      int blockend = GRUB_MINIX_BSIZE;
+      int blockoff = (unsigned)pos % data->block_size;
+      int blockend = data->block_size;
 
       int skipfirst = 0;
 
       blknr = grub_minix_get_file_block (data, i);
       if (grub_errno)
 	return -1;
-
       /* Last block.  */
       if (i == blockcnt - 1)
 	{
-	  blockend = (len + pos) % GRUB_MINIX_BSIZE;
+	  blockend = (unsigned)(len + pos) % data->block_size;
 
 	  if (!blockend)
-	    blockend = GRUB_MINIX_BSIZE;
+	    blockend = data->block_size;
 	}
 
       /* First block.  */
-      if (i == (pos / (int) GRUB_MINIX_BSIZE))
+      if (i == (pos / (int) data->block_size))
 	{
 	  skipfirst = blockoff;
 	  blockend -= skipfirst;
 	}
 
       data->disk->read_hook = read_hook;
+#ifdef MODE_MINIX3
+      grub_disk_read (data->disk, blknr * 
+        (sblock->block_size / GRUB_DISK_SECTOR_SIZE),
+        skipfirst, blockend, buf);
+#else
       grub_disk_read (data->disk, blknr << GRUB_MINIX_LOG2_ZONESZ,
 		      skipfirst, blockend, buf);
-
+#endif
       data->disk->read_hook = 0;
       if (grub_errno)
 	return -1;
 
-      buf += GRUB_MINIX_BSIZE - skipfirst;
+      buf += data->block_size - skipfirst;
     }
 
   return len;
@@ -253,11 +313,15 @@
 
   /* The first inode in minix is inode 1.  */
   ino--;
-
+#ifndef MODE_MINIX3
   block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size)
 	    + grub_le_to_cpu16 (sblock->zone_bmap_size))
 	   << GRUB_MINIX_LOG2_BSIZE);
-
+#else
+  block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size)
+	    + grub_le_to_cpu16 (sblock->zone_bmap_size))
+	   *(sblock->block_size/GRUB_DISK_SECTOR_SIZE));
+#endif
   block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode));
   int offs = (ino % (GRUB_DISK_SECTOR_SIZE
 		     / sizeof (struct grub_minix_inode))
@@ -333,16 +397,16 @@
 
   do
     {
-      grub_uint16_t ino;
+      grub_minix_uintn_t ino;
       char filename[data->filename_size + 1];
 
       if (grub_strlen (name) == 0)
 	return GRUB_ERR_NONE;
 
-      if (grub_minix_read_file (data, 0, pos, sizeof (ino),
+      if (grub_minix_read_file (data, 0, pos, GRUB_MINIX_INODE_BLKSZ(data),
 				(char *) &ino) < 0)
 	return grub_errno;
-      if (grub_minix_read_file (data, 0, pos + sizeof (ino),
+      if (grub_minix_read_file (data, 0, pos + GRUB_MINIX_INODE_BLKSZ(data),
 				data->filename_size, (char *) filename)< 0)
 	return grub_errno;
 
@@ -407,22 +471,37 @@
 		  sizeof (struct grub_minix_sblock),&data->sblock);
   if (grub_errno)
     goto fail;
-
   if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC)
+  {
+#if !defined(MODE_MINIX3)
     data->filename_size = 14;
+#else
+    data->filename_size = 60;
+#endif
+  }
+#if !defined(MODE_MINIX3)
   else if (grub_le_to_cpu16 (data->sblock.magic) == GRUB_MINIX_MAGIC_30)
     data->filename_size = 30;
+#endif
   else
     goto fail;
 
   data->disk = disk;
   data->linknest = 0;
-
+#ifdef MODE_MINIX3
+  data->block_size = data->sblock.block_size;
+  data->ino_size = 4;
+#else
+  data->block_size = 1024U;
+  data->ino_size = 2;
+#endif
   return data;
 
  fail:
   grub_free (data);
-#ifdef MODE_MINIX2
+#if defined(MODE_MINIX3)
+  grub_error (GRUB_ERR_BAD_FS, "not a minix3 filesystem");
+#elif defined(MODE_MINIX2)
   grub_error (GRUB_ERR_BAD_FS, "not a minix2 filesystem");
 #else
   grub_error (GRUB_ERR_BAD_FS, "not a minix filesystem");
@@ -437,11 +516,9 @@
 {
   struct grub_minix_data *data = 0;
   unsigned int pos = 0;
-
   data = grub_minix_mount (device->disk);
   if (!data)
     return grub_errno;
-
   grub_minix_read_inode (data, GRUB_MINIX_ROOT_INODE);
   if (grub_errno)
     goto fail;
@@ -458,35 +535,33 @@
 
   while (pos < GRUB_MINIX_INODE_SIZE (data))
     {
-      grub_uint16_t ino;
+      grub_uint32_t ino;
       char filename[data->filename_size + 1];
       int dirino = data->ino;
       struct grub_dirhook_info info;
       grub_memset (&info, 0, sizeof (info));
 
-
-      if (grub_minix_read_file (data, 0, pos, sizeof (ino),
+      if (grub_minix_read_file (data, 0, pos, data->ino_size,
 				(char *) &ino) < 0)
 	return grub_errno;
-
-      if (grub_minix_read_file (data, 0, pos + sizeof (ino),
+      if (grub_minix_read_file (data, 0, pos + data->ino_size,
 				data->filename_size,
 				(char *) filename) < 0)
 	return grub_errno;
       filename[data->filename_size] = '\0';
-
-      /* The filetype is not stored in the dirent.  Read the inode to
-	 find out the filetype.  This *REALLY* sucks.  */
-      grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
-      info.dir = ((GRUB_MINIX_INODE_MODE (data)
-		   & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR);
-      if (hook (filename, &info) ? 1 : 0)
-	break;
-
-      /* Load the old inode back in.  */
-      grub_minix_read_inode (data, dirino);
-
-      pos += sizeof (ino) + data->filename_size;
+      if(ino)
+      {
+        /* The filetype is not stored in the dirent.  Read the inode to
+	   find out the filetype.  This *REALLY* sucks.  */
+        grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
+        info.dir = ((GRUB_MINIX_INODE_MODE (data)
+	  	   & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR);
+        if (hook (filename, &info) ? 1 : 0)
+	  break;
+        /* Load the old inode back in.  */
+        grub_minix_read_inode (data, dirino);
+      }
+      pos += data->ino_size + data->filename_size;
     }
 
  fail:
@@ -556,7 +631,9 @@
 
 static struct grub_fs grub_minix_fs =
   {
-#ifdef MODE_MINIX2
+#if defined(MODE_MINIX3)
+    .name = "minix3",
+#elif defined(MODE_MINIX2)
     .name = "minix2",
 #else
     .name = "minix",
@@ -568,7 +645,9 @@
     .next = 0
   };
 
-#ifdef MODE_MINIX2
+#if defined(MODE_MINIX3)
+GRUB_MOD_INIT(minix3)
+#elif defined(MODE_MINIX2)
 GRUB_MOD_INIT(minix2)
 #else
 GRUB_MOD_INIT(minix)
@@ -578,7 +657,9 @@
   my_mod = mod;
 }
 
-#ifdef MODE_MINIX2
+#if defined(MODE_MINIX3)
+GRUB_MOD_FINI(minix3)
+#elif defined(MODE_MINIX2)
 GRUB_MOD_FINI(minix2)
 #else
 GRUB_MOD_FINI(minix)

=== added file 'grub-core/fs/minix3.c'
--- grub-core/fs/minix3.c	1970-01-01 00:00:00 +0000
+++ grub-core/fs/minix3.c	2011-02-19 06:50:46 +0000
@@ -0,0 +1,2 @@
+#define MODE_MINIX3 1
+#include "minix.c"

