All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bless command
@ 2009-04-18 18:59 Vladimir Serbinenko
  2009-04-18 19:00 ` Vladimir Serbinenko
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-18 18:59 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

Hello, due to request by ams I wrote this. It's an analog of "bless" command
available under OSX rewritten using grub2 fs functions and according to
apple specification of hfs+ on-disk format. This command only update the
blessed folder on a partition it doesn't change which drive is used for
booting. The later will be a separate command. Also you can choose which
volume to boot from by holding option key. Syntax:
hfspbless <DIRECTORY>
It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
unable to test this "in vivo"

[-- Attachment #2: Type: text/html, Size: 603 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-18 18:59 [PATCH] bless command Vladimir Serbinenko
@ 2009-04-18 19:00 ` Vladimir Serbinenko
  2009-04-18 19:22 ` Isaac Dupree
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-18 19:00 UTC (permalink / raw)
  To: The development of GRUB 2


[-- Attachment #1.1: Type: text/plain, Size: 681 bytes --]

Sorry, forgot to attach the file

On Sat, Apr 18, 2009 at 8:59 PM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

> Hello, due to request by ams I wrote this. It's an analog of "bless"
> command available under OSX rewritten using grub2 fs functions and according
> to apple specification of hfs+ on-disk format. This command only update the
> blessed folder on a partition it doesn't change which drive is used for
> booting. The later will be a separate command. Also you can choose which
> volume to boot from by holding option key. Syntax:
> hfspbless <DIRECTORY>
> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
> unable to test this "in vivo"
>
>
>

[-- Attachment #1.2: Type: text/html, Size: 977 bytes --]

[-- Attachment #2: bless.diff --]
[-- Type: text/x-diff, Size: 16455 bytes --]

diff --git a/commands/hfspbless.c b/commands/hfspbless.c
new file mode 100644
index 0000000..318a77c
--- /dev/null
+++ b/commands/hfspbless.c
@@ -0,0 +1,199 @@
+/* hfspbless.c - set the hfs+ boot directory.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2003,2005,2007,2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/command.h>
+#include <grub/fs.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/hfsplus.h>
+#include <grub/hfs.h>
+#include <grub/partition.h>
+#include <grub/file.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+
+static grub_uint64_t inode;
+static char *dirname;
+
+static int find_inode (const char *filename, 
+		       const struct grub_dirhook_info *info)
+{
+  if ((grub_strcmp (dirname, filename) == 0
+       || (info->case_insensitive && grub_strcasecmp (dirname, filename) == 0))
+      && info->dir && info->inodeset)
+    inode = info->inode;
+  return 0;
+}
+
+static grub_err_t
+grub_cmd_hfspbless (grub_command_t cmd __attribute__ ((unused)),
+		    int argc, char **args)
+{
+  char *device_name;
+  char *path = 0, *tail;
+  int embedded_offset;
+  grub_device_t dev;
+  grub_fs_t fs;
+
+  union {
+    struct grub_hfs_sblock hfs;
+    struct grub_hfsplus_volheader hfsplus;
+  } volheader;
+
+  if (argc != 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory required");
+  device_name = grub_file_get_device_name (args[0]);
+  dev = grub_device_open (device_name);
+
+  path = grub_strchr (args[0], ')');
+  if (! path)
+    path = grub_strdup (dirname);
+  else
+    path = grub_strdup (path + 1);
+  
+  if (! path || *path == 0 || ! device_name)
+    {
+      if (dev)
+	grub_device_close (dev);
+      
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
+    }
+
+  fs = grub_fs_probe (dev);
+  if (! fs || grub_strcmp (fs->name, "hfsplus") != 0)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_FS, "no suitable FS found");
+    }
+
+  tail = path + grub_strlen (path) - 1;
+
+  /* Remove trailing '/'. */
+  while (tail != path && *tail == '/')
+    *(tail--) = 0;
+  
+  tail = grub_strrchr (path, '/');
+  inode = 0;
+
+  if (tail)
+    {
+      *tail = 0;
+      dirname = tail + 1;
+      
+      (fs->dir) (dev, *path == 0 ?"/":path, find_inode);
+    }
+  else
+    {
+      dirname = path + 1;
+      (fs->dir) (dev, "/", find_inode);
+    }
+  grub_free (path);
+
+  if (inode == 0)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_FILE_NOT_FOUND, 
+			 "%s not found or isn't a directory\n",
+			 args[0]);
+    }
+
+  /* Read the bootblock.  */
+  grub_disk_read (dev->disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader),
+		  (char *) &volheader);
+  if (grub_errno)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_errno;
+    }
+
+  embedded_offset = 0;
+  if (grub_be_to_cpu16 (volheader.hfs.magic) == GRUB_HFS_MAGIC)
+    {
+      int extent_start;
+      int ablk_size;
+      int ablk_start;
+
+      /* See if there's an embedded HFS+ filesystem.  */
+      if (grub_be_to_cpu16 (volheader.hfs.embed_sig) != GRUB_HFSPLUS_MAGIC)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+
+      /* Calculate the offset needed to translate HFS+ sector numbers.  */
+      extent_start = grub_be_to_cpu16 (volheader.hfs.embed_extent.first_block);
+      ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz);
+      ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
+      embedded_offset = (ablk_start
+			 + extent_start
+			 * (ablk_size >> GRUB_DISK_SECTOR_BITS));
+
+      grub_disk_read (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		      sizeof (volheader), (char *) &volheader);
+      if (grub_errno)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+    }
+
+  /* Make sure this is an HFS+ filesystem.  XXX: Do we really support
+     HFX?  */
+  if ((grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUS_MAGIC)
+      && (grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUSX_MAGIC))
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
+    }
+  volheader.hfsplus.bootdir = grub_be_to_cpu32 (inode);
+  grub_disk_write (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		   sizeof (volheader), (char *) &volheader);
+  
+  grub_device_close (dev);
+  grub_free (device_name);
+  return grub_errno;
+}
+
+static grub_command_t cmd;
+\f
+GRUB_MOD_INIT(hfspbless)
+{
+  (void) mod;			/* To stop warning. */
+  cmd = grub_register_command ("hfspbless", grub_cmd_hfspbless,
+			       "hfspbless DIRECTORY", 
+			       "Bless DIRECTORY of HFS+ partition.");
+}
+
+GRUB_MOD_FINI(hfspbless)
+{
+  grub_unregister_command (cmd);
+}
diff --git a/conf/common.rmk b/conf/common.rmk
index 0e63da6..14b6184 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -531,3 +531,10 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
 bufio_mod_SOURCES = io/bufio.c
 bufio_mod_CFLAGS = $(COMMON_CFLAGS)
 bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += hfspbless.mod
+
+# For hfspbless.mod.
+hfspbless_mod_SOURCES = commands/hfspbless.c
+hfspbless_mod_CFLAGS = $(COMMON_CFLAGS)
+hfspbless_mod_LDFLAGS = $(COMMON_LDFLAGS)
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index 265b250..8662c11 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -122,6 +122,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/handler.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
+	commands/hfspbless.c						\
 	lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c disk/scsi.c				\
@@ -154,7 +155,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
-	commands/parttool.c parttool/pcpart.c				\
+	commands/parttool.c parttool/pcpart.c 				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
diff --git a/fs/hfsplus.c b/fs/hfsplus.c
index 82ec880..9831a3c 100644
--- a/fs/hfsplus.c
+++ b/fs/hfsplus.c
@@ -28,140 +28,7 @@
 #include <grub/types.h>
 #include <grub/fshelp.h>
 #include <grub/hfs.h>
-
-#define GRUB_HFSPLUS_MAGIC 0x482B
-#define GRUB_HFSPLUSX_MAGIC 0x4858
-#define GRUB_HFSPLUS_SBLOCK 2
-
-/* A HFS+ extent.  */
-struct grub_hfsplus_extent
-{
-  /* The first block of a file on disk.  */
-  grub_uint32_t start;
-  /* The amount of blocks described by this extent.  */
-  grub_uint32_t count;
-} __attribute__ ((packed));
-
-/* The descriptor of a fork.  */
-struct grub_hfsplus_forkdata
-{
-  grub_uint64_t size;
-  grub_uint32_t clumpsize;
-  grub_uint32_t blocks;
-  struct grub_hfsplus_extent extents[8];
-} __attribute__ ((packed));
-
-/* The HFS+ Volume Header.  */
-struct grub_hfsplus_volheader
-{
-  grub_uint16_t magic;
-  grub_uint16_t version;
-  grub_uint32_t attributes;
-  grub_uint8_t unused1[12];
-  grub_uint32_t utime;
-  grub_uint8_t unused2[16];
-  grub_uint32_t blksize;
-  grub_uint8_t unused3[68];
-  struct grub_hfsplus_forkdata allocations_file;
-  struct grub_hfsplus_forkdata extents_file;
-  struct grub_hfsplus_forkdata catalog_file;
-  struct grub_hfsplus_forkdata attrib_file;
-  struct grub_hfsplus_forkdata startup_file;
-} __attribute__ ((packed));
-
-/* The type of node.  */
-enum grub_hfsplus_btnode_type
-  {
-    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
-    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
-    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
-    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
-  };
-
-struct grub_hfsplus_btnode
-{
-  grub_uint32_t next;
-  grub_uint32_t prev;
-  grub_int8_t type;
-  grub_uint8_t height;
-  grub_uint16_t count;
-  grub_uint16_t unused;
-} __attribute__ ((packed));
-
-/* The header of a HFS+ B+ Tree.  */
-struct grub_hfsplus_btheader
-{
-  grub_uint16_t depth;
-  grub_uint32_t root;
-  grub_uint32_t leaf_records;
-  grub_uint32_t first_leaf_node;
-  grub_uint32_t last_leaf_node;
-  grub_uint16_t nodesize;
-  grub_uint16_t keysize;
-} __attribute__ ((packed));
-
-/* The on disk layout of a catalog key.  */
-struct grub_hfsplus_catkey
-{
-  grub_uint16_t keylen;
-  grub_uint32_t parent;
-  grub_uint16_t namelen;
-  grub_uint16_t name[30];
-} __attribute__ ((packed));
-
-/* The on disk layout of an extent overflow file key.  */
-struct grub_hfsplus_extkey
-{
-  grub_uint16_t keylen;
-  grub_uint8_t type;
-  grub_uint8_t unused;
-  grub_uint32_t fileid;
-  grub_uint32_t start;
-} __attribute__ ((packed));
-
-struct grub_hfsplus_key
-{
-  union
-  {
-    struct grub_hfsplus_extkey extkey;
-    struct grub_hfsplus_catkey catkey;
-    grub_uint16_t keylen;
-  };
-} __attribute__ ((packed));
-
-struct grub_hfsplus_catfile
-{
-  grub_uint16_t type;
-  grub_uint16_t flags;
-  grub_uint32_t reserved;
-  grub_uint32_t fileid;
-  grub_uint8_t unused1[4];
-  grub_uint32_t mtime;
-  grub_uint8_t unused2[22];
-  grub_uint16_t mode;
-  grub_uint8_t unused3[44];
-  struct grub_hfsplus_forkdata data;
-  struct grub_hfsplus_forkdata resource;
-} __attribute__ ((packed));
-
-/* Filetype information as used in inodes.  */
-#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
-#define GRUB_HFSPLUS_FILEMODE_REG	0100000
-#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
-#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
-
-/* Some pre-defined file IDs.  */
-#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
-#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
-#define GRUB_HFSPLUS_FILEID_CATALOG	4
-
-enum grub_hfsplus_filetype
-  {
-    GRUB_HFSPLUS_FILETYPE_DIR = 1,
-    GRUB_HFSPLUS_FILETYPE_REG = 2,
-    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
-    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
-  };
+#include <grub/hfsplus.h>
 
 /* Internal representation of a catalog key.  */
 struct grub_hfsplus_catkey_internal
@@ -225,6 +92,7 @@ struct grub_hfsplus_data
   int embedded_offset;
 };
 
+
 #ifndef GRUB_UTIL
 static grub_dl_t my_mod;
 #endif
@@ -910,6 +778,8 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
       info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
       info.mtimeset = 1;
       info.mtime = node->mtime;
+      info.inodeset = 1;
+      info.inode = node->fileid;
       info.case_insensitive = !! (filetype & GRUB_FSHELP_CASE_INSENSITIVE);
       grub_free (node);
       return hook (filename, &info);
diff --git a/include/grub/fs.h b/include/grub/fs.h
index fa2c070..1aee621 100644
--- a/include/grub/fs.h
+++ b/include/grub/fs.h
@@ -32,7 +32,9 @@ struct grub_dirhook_info
   int dir:1;
   int mtimeset:1;
   int case_insensitive:1;
+  int inodeset:1;
   grub_int32_t mtime;
+  grub_uint64_t inode;
 };
 
 /* Filesystem descriptor.  */
diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h
new file mode 100644
index 0000000..007ad90
--- /dev/null
+++ b/include/grub/hfsplus.h
@@ -0,0 +1,167 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2006,2007,2008,2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HFSPLUS_HEADER
+#define GRUB_HFSPLUS_HEADER	1
+
+#include <grub/types.h>
+
+#define GRUB_HFSPLUS_MAGIC 0x482B
+#define GRUB_HFSPLUSX_MAGIC 0x4858
+#define GRUB_HFSPLUS_SBLOCK 2
+
+/* A HFS+ extent.  */
+struct grub_hfsplus_extent
+{
+  /* The first block of a file on disk.  */
+  grub_uint32_t start;
+  /* The amount of blocks described by this extent.  */
+  grub_uint32_t count;
+} __attribute__ ((packed));
+
+/* The descriptor of a fork.  */
+struct grub_hfsplus_forkdata
+{
+  grub_uint64_t size;
+  grub_uint32_t clumpsize;
+  grub_uint32_t blocks;
+  struct grub_hfsplus_extent extents[8];
+} __attribute__ ((packed));
+
+/* The HFS+ Volume Header.  */
+struct grub_hfsplus_volheader
+{
+  grub_uint16_t magic;
+  grub_uint16_t version;
+  grub_uint32_t attributes;
+  grub_uint8_t unused1[12];
+  grub_uint32_t utime;
+  grub_uint8_t unused2[16];
+  grub_uint32_t blksize;
+  grub_uint8_t unused3[36];
+  grub_uint32_t bootdir;
+  grub_uint32_t finderdir;
+
+  /* Folder opened when disk is mounted. Unused by GRUB. */
+  grub_uint32_t showfolder;
+  grub_uint32_t os9folder;
+  grub_uint8_t unused4[4];
+  grub_uint32_t osxfolder;
+  grub_uint8_t volheader[8];
+  struct grub_hfsplus_forkdata allocations_file;
+  struct grub_hfsplus_forkdata extents_file;
+  struct grub_hfsplus_forkdata catalog_file;
+  struct grub_hfsplus_forkdata attrib_file;
+  struct grub_hfsplus_forkdata startup_file;
+} __attribute__ ((packed));
+
+/* The type of node.  */
+enum grub_hfsplus_btnode_type
+  {
+    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
+    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
+    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
+    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
+  };
+
+struct grub_hfsplus_btnode
+{
+  grub_uint32_t next;
+  grub_uint32_t prev;
+  grub_int8_t type;
+  grub_uint8_t height;
+  grub_uint16_t count;
+  grub_uint16_t unused;
+} __attribute__ ((packed));
+
+/* The header of a HFS+ B+ Tree.  */
+struct grub_hfsplus_btheader
+{
+  grub_uint16_t depth;
+  grub_uint32_t root;
+  grub_uint32_t leaf_records;
+  grub_uint32_t first_leaf_node;
+  grub_uint32_t last_leaf_node;
+  grub_uint16_t nodesize;
+  grub_uint16_t keysize;
+} __attribute__ ((packed));
+
+/* The on disk layout of a catalog key.  */
+struct grub_hfsplus_catkey
+{
+  grub_uint16_t keylen;
+  grub_uint32_t parent;
+  grub_uint16_t namelen;
+  grub_uint16_t name[30];
+} __attribute__ ((packed));
+
+/* The on disk layout of an extent overflow file key.  */
+struct grub_hfsplus_extkey
+{
+  grub_uint16_t keylen;
+  grub_uint8_t type;
+  grub_uint8_t unused;
+  grub_uint32_t fileid;
+  grub_uint32_t start;
+} __attribute__ ((packed));
+
+struct grub_hfsplus_key
+{
+  union
+  {
+    struct grub_hfsplus_extkey extkey;
+    struct grub_hfsplus_catkey catkey;
+    grub_uint16_t keylen;
+  };
+} __attribute__ ((packed));
+
+struct grub_hfsplus_catfile
+{
+  grub_uint16_t type;
+  grub_uint16_t flags;
+  grub_uint32_t reserved;
+  grub_uint32_t fileid;
+  grub_uint8_t unused1[4];
+  grub_uint32_t mtime;
+  grub_uint8_t unused2[22];
+  grub_uint16_t mode;
+  grub_uint8_t unused3[44];
+  struct grub_hfsplus_forkdata data;
+  struct grub_hfsplus_forkdata resource;
+} __attribute__ ((packed));
+
+/* Filetype information as used in inodes.  */
+#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
+#define GRUB_HFSPLUS_FILEMODE_REG	0100000
+#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
+#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
+
+/* Some pre-defined file IDs.  */
+#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
+#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
+#define GRUB_HFSPLUS_FILEID_CATALOG	4
+
+enum grub_hfsplus_filetype
+  {
+    GRUB_HFSPLUS_FILETYPE_DIR = 1,
+    GRUB_HFSPLUS_FILETYPE_REG = 2,
+    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
+    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
+  };
+
+#endif

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-18 18:59 [PATCH] bless command Vladimir Serbinenko
  2009-04-18 19:00 ` Vladimir Serbinenko
@ 2009-04-18 19:22 ` Isaac Dupree
  2009-04-19  4:51 ` Peter Cros
  2009-06-19  6:08 ` Peter Cros
  3 siblings, 0 replies; 28+ messages in thread
From: Isaac Dupree @ 2009-04-18 19:22 UTC (permalink / raw)
  To: grub-devel; +Cc: Vladimir Serbinenko

Vladimir Serbinenko wrote:
> Syntax:
> hfspbless <DIRECTORY>
> It works only on HFS+ volumes.

Could it be named 'hfsplusbless' (or possibly 'hfs+bless') (I guess our 
current naming style involves no underscores or other word-separation)?  For 
example, Linux `mount` calls the filesystem `hfsplus`, and I like naming-
consistency.  But feel free to mention counterexamples too!

-Isaac
 



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-18 18:59 [PATCH] bless command Vladimir Serbinenko
  2009-04-18 19:00 ` Vladimir Serbinenko
  2009-04-18 19:22 ` Isaac Dupree
@ 2009-04-19  4:51 ` Peter Cros
  2009-04-19 10:50   ` Vladimir Serbinenko
  2009-06-19  6:08 ` Peter Cros
  3 siblings, 1 reply; 28+ messages in thread
From: Peter Cros @ 2009-04-19  4:51 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1606 bytes --]

Hi,

Tested and works on Apple imac81 with Mac OSX 10.5, patch applied to r 2074

grub> hfspbless (hd0,3)/efi

Last login: Sun Apr 19 14:30:23 on console
im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:     52 => Blessed System Folder is /Volumes/hfsp/efi
finderinfo[1]:      0 => No Blessed System File
finderinfo[2]:      0 => Open-folder linked list empty
finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
finderinfo[4]:      0 => Unused field unset
finderinfo[5]:      0 => No OS 9 + X blessed X folder
64-bit VSDB volume id:  0x0F87F7680B9C5211
im81:~ pxw$

Now it just needs to bless the file in order to boot from grub.efi on Apple
EFI

hfspbless <DIRECTORY> <FILE>

This would be VERY useful, making grub.efi boot possible on Apple Mac
without needing Mac OSX or refit.

hfspbless is fine for a name


2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>

> Hello, due to request by ams I wrote this. It's an analog of "bless"
> command available under OSX rewritten using grub2 fs functions and according
> to apple specification of hfs+ on-disk format. This command only update the
> blessed folder on a partition it doesn't change which drive is used for
> booting. The later will be a separate command. Also you can choose which
> volume to boot from by holding option key. Syntax:
> hfspbless <DIRECTORY>
> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
> unable to test this "in vivo"
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>


-- 
Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 2364 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19  4:51 ` Peter Cros
@ 2009-04-19 10:50   ` Vladimir Serbinenko
  2009-04-19 11:25     ` Drew Rosen
  2009-04-19 13:26     ` Peter Cros
  0 siblings, 2 replies; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-19 10:50 UTC (permalink / raw)
  To: The development of GRUB 2


[-- Attachment #1.1: Type: text/plain, Size: 2439 bytes --]

Hello, thank you for the testing. Two concepts together (system folder and
system file) are clearly redundant. I thought that intel macs look which
folder is blessed and load boot.efi file from this directory. Here I attach
a patch which updates finderinfo[0] when argument is a directory and
finderinfo[1] when argument is a file. Can you do a test and tell me which
concept is really used by intel macs? When doing tests don't forget to hold
option key and select your testing partition. I will do a similar test on my
ppc mac

On Sun, Apr 19, 2009 at 6:51 AM, Peter Cros <pxwpxw8@gmail.com> wrote:

> Hi,
>
> Tested and works on Apple imac81 with Mac OSX 10.5, patch applied to r 2074
>
> grub> hfspbless (hd0,3)/efi
>
> Last login: Sun Apr 19 14:30:23 on console
> im81:~ pxw$ bless --info /Volumes/hfsp
> finderinfo[0]:     52 => Blessed System Folder is /Volumes/hfsp/efi
> finderinfo[1]:      0 => No Blessed System File
> finderinfo[2]:      0 => Open-folder linked list empty
> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
> finderinfo[4]:      0 => Unused field unset
> finderinfo[5]:      0 => No OS 9 + X blessed X folder
> 64-bit VSDB volume id:  0x0F87F7680B9C5211
> im81:~ pxw$
>
> Now it just needs to bless the file in order to boot from grub.efi on Apple
> EFI
>
> hfspbless <DIRECTORY> <FILE>
>
> This would be VERY useful, making grub.efi boot possible on Apple Mac
> without needing Mac OSX or refit.
>
> hfspbless is fine for a name
>
>
> 2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>
>
>> Hello, due to request by ams I wrote this. It's an analog of "bless"
>> command available under OSX rewritten using grub2 fs functions and according
>> to apple specification of hfs+ on-disk format. This command only update the
>> blessed folder on a partition it doesn't change which drive is used for
>> booting. The later will be a separate command. Also you can choose which
>> volume to boot from by holding option key. Syntax:
>> hfspbless <DIRECTORY>
>> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
>> unable to test this "in vivo"
>>
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
>
> --
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>

[-- Attachment #1.2: Type: text/html, Size: 3637 bytes --]

[-- Attachment #2: bless.diff --]
[-- Type: text/x-diff, Size: 16578 bytes --]

diff --git a/commands/hfspbless.c b/commands/hfspbless.c
new file mode 100644
index 0000000..c2bddee
--- /dev/null
+++ b/commands/hfspbless.c
@@ -0,0 +1,207 @@
+/* hfspbless.c - set the hfs+ boot directory.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2003,2005,2007,2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/command.h>
+#include <grub/fs.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/hfsplus.h>
+#include <grub/hfs.h>
+#include <grub/partition.h>
+#include <grub/file.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+
+static grub_uint64_t inode;
+static char *dirname;
+static int found;
+
+static int find_inode (const char *filename, 
+		       const struct grub_dirhook_info *info)
+{
+  if ((grub_strcmp (dirname, filename) == 0
+       || (info->case_insensitive && grub_strcasecmp (dirname, filename) == 0))
+       && info->inodeset)
+    {
+      inode = info->inode;
+      found = info->dir ? 2 : 1;
+    }
+  return 0;
+}
+
+static grub_err_t
+grub_cmd_hfspbless (grub_command_t cmd __attribute__ ((unused)),
+		    int argc, char **args)
+{
+  char *device_name;
+  char *path = 0, *tail;
+  int embedded_offset;
+  grub_device_t dev;
+  grub_fs_t fs;
+
+  union {
+    struct grub_hfs_sblock hfs;
+    struct grub_hfsplus_volheader hfsplus;
+  } volheader;
+
+  if (argc != 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory required");
+  device_name = grub_file_get_device_name (args[0]);
+  dev = grub_device_open (device_name);
+
+  path = grub_strchr (args[0], ')');
+  if (! path)
+    path = grub_strdup (dirname);
+  else
+    path = grub_strdup (path + 1);
+  
+  if (! path || *path == 0 || ! device_name)
+    {
+      if (dev)
+	grub_device_close (dev);
+      
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
+    }
+
+  fs = grub_fs_probe (dev);
+  if (! fs || grub_strcmp (fs->name, "hfsplus") != 0)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_FS, "no suitable FS found");
+    }
+
+  tail = path + grub_strlen (path) - 1;
+
+  /* Remove trailing '/'. */
+  while (tail != path && *tail == '/')
+    *(tail--) = 0;
+  
+  tail = grub_strrchr (path, '/');
+  found = 0;
+
+  if (tail)
+    {
+      *tail = 0;
+      dirname = tail + 1;
+      
+      (fs->dir) (dev, *path == 0 ?"/":path, find_inode);
+    }
+  else
+    {
+      dirname = path + 1;
+      (fs->dir) (dev, "/", find_inode);
+    }
+  grub_free (path);
+
+  if (! found)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_FILE_NOT_FOUND, 
+			 "%s not found\n",
+			 args[0]);
+    }
+
+  /* Read the bootblock.  */
+  grub_disk_read (dev->disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader),
+		  (char *) &volheader);
+  if (grub_errno)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_errno;
+    }
+
+  embedded_offset = 0;
+  if (grub_be_to_cpu16 (volheader.hfs.magic) == GRUB_HFS_MAGIC)
+    {
+      int extent_start;
+      int ablk_size;
+      int ablk_start;
+
+      /* See if there's an embedded HFS+ filesystem.  */
+      if (grub_be_to_cpu16 (volheader.hfs.embed_sig) != GRUB_HFSPLUS_MAGIC)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+
+      /* Calculate the offset needed to translate HFS+ sector numbers.  */
+      extent_start = grub_be_to_cpu16 (volheader.hfs.embed_extent.first_block);
+      ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz);
+      ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
+      embedded_offset = (ablk_start
+			 + extent_start
+			 * (ablk_size >> GRUB_DISK_SECTOR_BITS));
+
+      grub_disk_read (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		      sizeof (volheader), (char *) &volheader);
+      if (grub_errno)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+    }
+
+  /* Make sure this is an HFS+ filesystem.  XXX: Do we really support
+     HFX?  */
+  if ((grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUS_MAGIC)
+      && (grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUSX_MAGIC))
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
+    }
+  if (found == 2)
+    volheader.hfsplus.bootdir = grub_be_to_cpu32 (inode);
+  else
+    volheader.hfsplus.bootfile = grub_be_to_cpu32 (inode);
+
+  grub_disk_write (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		   sizeof (volheader), (char *) &volheader);
+  
+  grub_device_close (dev);
+  grub_free (device_name);
+  return grub_errno;
+}
+
+static grub_command_t cmd;
+\f
+GRUB_MOD_INIT(hfspbless)
+{
+  (void) mod;			/* To stop warning. */
+  cmd = grub_register_command ("hfspbless", grub_cmd_hfspbless,
+			       "hfspbless DIRECTORY", 
+			       "Bless DIRECTORY of HFS+ partition.");
+}
+
+GRUB_MOD_FINI(hfspbless)
+{
+  grub_unregister_command (cmd);
+}
diff --git a/conf/common.rmk b/conf/common.rmk
index 0e63da6..14b6184 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -531,3 +531,10 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
 bufio_mod_SOURCES = io/bufio.c
 bufio_mod_CFLAGS = $(COMMON_CFLAGS)
 bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += hfspbless.mod
+
+# For hfspbless.mod.
+hfspbless_mod_SOURCES = commands/hfspbless.c
+hfspbless_mod_CFLAGS = $(COMMON_CFLAGS)
+hfspbless_mod_LDFLAGS = $(COMMON_LDFLAGS)
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index 265b250..8662c11 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -122,6 +122,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/handler.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
+	commands/hfspbless.c						\
 	lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c disk/scsi.c				\
@@ -154,7 +155,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
-	commands/parttool.c parttool/pcpart.c				\
+	commands/parttool.c parttool/pcpart.c 				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
diff --git a/fs/hfsplus.c b/fs/hfsplus.c
index 82ec880..9831a3c 100644
--- a/fs/hfsplus.c
+++ b/fs/hfsplus.c
@@ -28,140 +28,7 @@
 #include <grub/types.h>
 #include <grub/fshelp.h>
 #include <grub/hfs.h>
-
-#define GRUB_HFSPLUS_MAGIC 0x482B
-#define GRUB_HFSPLUSX_MAGIC 0x4858
-#define GRUB_HFSPLUS_SBLOCK 2
-
-/* A HFS+ extent.  */
-struct grub_hfsplus_extent
-{
-  /* The first block of a file on disk.  */
-  grub_uint32_t start;
-  /* The amount of blocks described by this extent.  */
-  grub_uint32_t count;
-} __attribute__ ((packed));
-
-/* The descriptor of a fork.  */
-struct grub_hfsplus_forkdata
-{
-  grub_uint64_t size;
-  grub_uint32_t clumpsize;
-  grub_uint32_t blocks;
-  struct grub_hfsplus_extent extents[8];
-} __attribute__ ((packed));
-
-/* The HFS+ Volume Header.  */
-struct grub_hfsplus_volheader
-{
-  grub_uint16_t magic;
-  grub_uint16_t version;
-  grub_uint32_t attributes;
-  grub_uint8_t unused1[12];
-  grub_uint32_t utime;
-  grub_uint8_t unused2[16];
-  grub_uint32_t blksize;
-  grub_uint8_t unused3[68];
-  struct grub_hfsplus_forkdata allocations_file;
-  struct grub_hfsplus_forkdata extents_file;
-  struct grub_hfsplus_forkdata catalog_file;
-  struct grub_hfsplus_forkdata attrib_file;
-  struct grub_hfsplus_forkdata startup_file;
-} __attribute__ ((packed));
-
-/* The type of node.  */
-enum grub_hfsplus_btnode_type
-  {
-    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
-    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
-    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
-    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
-  };
-
-struct grub_hfsplus_btnode
-{
-  grub_uint32_t next;
-  grub_uint32_t prev;
-  grub_int8_t type;
-  grub_uint8_t height;
-  grub_uint16_t count;
-  grub_uint16_t unused;
-} __attribute__ ((packed));
-
-/* The header of a HFS+ B+ Tree.  */
-struct grub_hfsplus_btheader
-{
-  grub_uint16_t depth;
-  grub_uint32_t root;
-  grub_uint32_t leaf_records;
-  grub_uint32_t first_leaf_node;
-  grub_uint32_t last_leaf_node;
-  grub_uint16_t nodesize;
-  grub_uint16_t keysize;
-} __attribute__ ((packed));
-
-/* The on disk layout of a catalog key.  */
-struct grub_hfsplus_catkey
-{
-  grub_uint16_t keylen;
-  grub_uint32_t parent;
-  grub_uint16_t namelen;
-  grub_uint16_t name[30];
-} __attribute__ ((packed));
-
-/* The on disk layout of an extent overflow file key.  */
-struct grub_hfsplus_extkey
-{
-  grub_uint16_t keylen;
-  grub_uint8_t type;
-  grub_uint8_t unused;
-  grub_uint32_t fileid;
-  grub_uint32_t start;
-} __attribute__ ((packed));
-
-struct grub_hfsplus_key
-{
-  union
-  {
-    struct grub_hfsplus_extkey extkey;
-    struct grub_hfsplus_catkey catkey;
-    grub_uint16_t keylen;
-  };
-} __attribute__ ((packed));
-
-struct grub_hfsplus_catfile
-{
-  grub_uint16_t type;
-  grub_uint16_t flags;
-  grub_uint32_t reserved;
-  grub_uint32_t fileid;
-  grub_uint8_t unused1[4];
-  grub_uint32_t mtime;
-  grub_uint8_t unused2[22];
-  grub_uint16_t mode;
-  grub_uint8_t unused3[44];
-  struct grub_hfsplus_forkdata data;
-  struct grub_hfsplus_forkdata resource;
-} __attribute__ ((packed));
-
-/* Filetype information as used in inodes.  */
-#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
-#define GRUB_HFSPLUS_FILEMODE_REG	0100000
-#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
-#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
-
-/* Some pre-defined file IDs.  */
-#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
-#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
-#define GRUB_HFSPLUS_FILEID_CATALOG	4
-
-enum grub_hfsplus_filetype
-  {
-    GRUB_HFSPLUS_FILETYPE_DIR = 1,
-    GRUB_HFSPLUS_FILETYPE_REG = 2,
-    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
-    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
-  };
+#include <grub/hfsplus.h>
 
 /* Internal representation of a catalog key.  */
 struct grub_hfsplus_catkey_internal
@@ -225,6 +92,7 @@ struct grub_hfsplus_data
   int embedded_offset;
 };
 
+
 #ifndef GRUB_UTIL
 static grub_dl_t my_mod;
 #endif
@@ -910,6 +778,8 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
       info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
       info.mtimeset = 1;
       info.mtime = node->mtime;
+      info.inodeset = 1;
+      info.inode = node->fileid;
       info.case_insensitive = !! (filetype & GRUB_FSHELP_CASE_INSENSITIVE);
       grub_free (node);
       return hook (filename, &info);
diff --git a/include/grub/fs.h b/include/grub/fs.h
index fa2c070..1aee621 100644
--- a/include/grub/fs.h
+++ b/include/grub/fs.h
@@ -32,7 +32,9 @@ struct grub_dirhook_info
   int dir:1;
   int mtimeset:1;
   int case_insensitive:1;
+  int inodeset:1;
   grub_int32_t mtime;
+  grub_uint64_t inode;
 };
 
 /* Filesystem descriptor.  */
diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h
new file mode 100644
index 0000000..e711165
--- /dev/null
+++ b/include/grub/hfsplus.h
@@ -0,0 +1,167 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2006,2007,2008,2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HFSPLUS_HEADER
+#define GRUB_HFSPLUS_HEADER	1
+
+#include <grub/types.h>
+
+#define GRUB_HFSPLUS_MAGIC 0x482B
+#define GRUB_HFSPLUSX_MAGIC 0x4858
+#define GRUB_HFSPLUS_SBLOCK 2
+
+/* A HFS+ extent.  */
+struct grub_hfsplus_extent
+{
+  /* The first block of a file on disk.  */
+  grub_uint32_t start;
+  /* The amount of blocks described by this extent.  */
+  grub_uint32_t count;
+} __attribute__ ((packed));
+
+/* The descriptor of a fork.  */
+struct grub_hfsplus_forkdata
+{
+  grub_uint64_t size;
+  grub_uint32_t clumpsize;
+  grub_uint32_t blocks;
+  struct grub_hfsplus_extent extents[8];
+} __attribute__ ((packed));
+
+/* The HFS+ Volume Header.  */
+struct grub_hfsplus_volheader
+{
+  grub_uint16_t magic;
+  grub_uint16_t version;
+  grub_uint32_t attributes;
+  grub_uint8_t unused1[12];
+  grub_uint32_t utime;
+  grub_uint8_t unused2[16];
+  grub_uint32_t blksize;
+  grub_uint8_t unused3[36];
+  grub_uint32_t bootdir;
+  grub_uint32_t bootfile;
+
+  /* Folder opened when disk is mounted. Unused by GRUB. */
+  grub_uint32_t showfolder;
+  grub_uint32_t os9folder;
+  grub_uint8_t unused4[4];
+  grub_uint32_t osxfolder;
+  grub_uint8_t volheader[8];
+  struct grub_hfsplus_forkdata allocations_file;
+  struct grub_hfsplus_forkdata extents_file;
+  struct grub_hfsplus_forkdata catalog_file;
+  struct grub_hfsplus_forkdata attrib_file;
+  struct grub_hfsplus_forkdata startup_file;
+} __attribute__ ((packed));
+
+/* The type of node.  */
+enum grub_hfsplus_btnode_type
+  {
+    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
+    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
+    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
+    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
+  };
+
+struct grub_hfsplus_btnode
+{
+  grub_uint32_t next;
+  grub_uint32_t prev;
+  grub_int8_t type;
+  grub_uint8_t height;
+  grub_uint16_t count;
+  grub_uint16_t unused;
+} __attribute__ ((packed));
+
+/* The header of a HFS+ B+ Tree.  */
+struct grub_hfsplus_btheader
+{
+  grub_uint16_t depth;
+  grub_uint32_t root;
+  grub_uint32_t leaf_records;
+  grub_uint32_t first_leaf_node;
+  grub_uint32_t last_leaf_node;
+  grub_uint16_t nodesize;
+  grub_uint16_t keysize;
+} __attribute__ ((packed));
+
+/* The on disk layout of a catalog key.  */
+struct grub_hfsplus_catkey
+{
+  grub_uint16_t keylen;
+  grub_uint32_t parent;
+  grub_uint16_t namelen;
+  grub_uint16_t name[30];
+} __attribute__ ((packed));
+
+/* The on disk layout of an extent overflow file key.  */
+struct grub_hfsplus_extkey
+{
+  grub_uint16_t keylen;
+  grub_uint8_t type;
+  grub_uint8_t unused;
+  grub_uint32_t fileid;
+  grub_uint32_t start;
+} __attribute__ ((packed));
+
+struct grub_hfsplus_key
+{
+  union
+  {
+    struct grub_hfsplus_extkey extkey;
+    struct grub_hfsplus_catkey catkey;
+    grub_uint16_t keylen;
+  };
+} __attribute__ ((packed));
+
+struct grub_hfsplus_catfile
+{
+  grub_uint16_t type;
+  grub_uint16_t flags;
+  grub_uint32_t reserved;
+  grub_uint32_t fileid;
+  grub_uint8_t unused1[4];
+  grub_uint32_t mtime;
+  grub_uint8_t unused2[22];
+  grub_uint16_t mode;
+  grub_uint8_t unused3[44];
+  struct grub_hfsplus_forkdata data;
+  struct grub_hfsplus_forkdata resource;
+} __attribute__ ((packed));
+
+/* Filetype information as used in inodes.  */
+#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
+#define GRUB_HFSPLUS_FILEMODE_REG	0100000
+#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
+#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
+
+/* Some pre-defined file IDs.  */
+#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
+#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
+#define GRUB_HFSPLUS_FILEID_CATALOG	4
+
+enum grub_hfsplus_filetype
+  {
+    GRUB_HFSPLUS_FILETYPE_DIR = 1,
+    GRUB_HFSPLUS_FILETYPE_REG = 2,
+    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
+    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
+  };
+
+#endif

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 10:50   ` Vladimir Serbinenko
@ 2009-04-19 11:25     ` Drew Rosen
  2009-04-19 13:26     ` Peter Cros
  1 sibling, 0 replies; 28+ messages in thread
From: Drew Rosen @ 2009-04-19 11:25 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 2927 bytes --]

I'd also like to help test this as I have a first gen macintel mac pro  
that needs to run centos. It was difficult to get a 2nd gen machine to  
see the os drive last time I loaded centos...

---
Drew Rosen

On Apr 19, 2009, at 3:50 AM, Vladimir Serbinenko <phcoder@gmail.com>  
wrote:

> Hello, thank you for the testing. Two concepts together (system  
> folder and system file) are clearly redundant. I thought that intel  
> macs look which folder is blessed and load boot.efi file from this  
> directory. Here I attach a patch which updates finderinfo[0] when  
> argument is a directory and finderinfo[1] when argument is a file.  
> Can you do a test and tell me which concept is really used by intel  
> macs? When doing tests don't forget to hold option key and select  
> your testing partition. I will do a similar test on my ppc mac
>
> On Sun, Apr 19, 2009 at 6:51 AM, Peter Cros <pxwpxw8@gmail.com> wrote:
> Hi,
>
> Tested and works on Apple imac81 with Mac OSX 10.5, patch applied to  
> r 2074
>
> grub> hfspbless (hd0,3)/efi
>
> Last login: Sun Apr 19 14:30:23 on console
> im81:~ pxw$ bless --info /Volumes/hfsp
> finderinfo[0]:     52 => Blessed System Folder is /Volumes/hfsp/efi
> finderinfo[1]:      0 => No Blessed System File
> finderinfo[2]:      0 => Open-folder linked list empty
> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
> finderinfo[4]:      0 => Unused field unset
> finderinfo[5]:      0 => No OS 9 + X blessed X folder
> 64-bit VSDB volume id:  0x0F87F7680B9C5211
> im81:~ pxw$
>
> Now it just needs to bless the file in order to boot from grub.efi  
> on Apple EFI
>
> hfspbless <DIRECTORY> <FILE>
>
> This would be VERY useful, making grub.efi boot possible on Apple  
> Mac without needing Mac OSX or refit.
>
> hfspbless is fine for a name
>
>
> 2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>
> Hello, due to request by ams I wrote this. It's an analog of "bless"  
> command available under OSX rewritten using grub2 fs functions and  
> according to apple specification of hfs+ on-disk format. This  
> command only update the blessed folder on a partition it doesn't  
> change which drive is used for booting. The later will be a separate  
> command. Also you can choose which volume to boot from by holding  
> option key. Syntax:
> hfspbless <DIRECTORY>
> It works only on HFS+ volumes. Also due to the lack of hardware I  
> wasn't unable to test this "in vivo"
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
>
>
> -- 
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> <bless.diff>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel

[-- Attachment #2: Type: text/html, Size: 4874 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 10:50   ` Vladimir Serbinenko
  2009-04-19 11:25     ` Drew Rosen
@ 2009-04-19 13:26     ` Peter Cros
  2009-04-19 14:14       ` Vladimir Serbinenko
  1 sibling, 1 reply; 28+ messages in thread
From: Peter Cros @ 2009-04-19 13:26 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 4175 bytes --]

bless.diff version 2.
success.

cleared all bless on hfsplus partition in OSX.

grub> hfspbless (hd0,3)/efi/test/grub523.efi

Back to  OSX -
Last login: Sun Apr 19 22:48:43 on console
im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:     75 => Blessed System Folder is <missing>
finderinfo[1]:   7857 => Blessed System File is
/Volumes/hfsp/efi/test/grub523.efi
finderinfo[2]:      0 => Open-folder linked list empty
finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
finderinfo[4]:      0 => Unused field unset
finderinfo[5]:      0 => No OS 9 + X blessed X folder
64-bit VSDB volume id:  0x0F87F7680B9C5211

It boots -
Restart with option key gives the Apple EFI disk icon, which boots
grub523.efi
Confirmed with shutdown-restart again.

Redundant info -
I checked the OSX bless utility, it requires both folder and file, or it
will not agree to bless the file.

im81:~ pxw$ sudo bless --folder /Volumes/hfsp/efi/test --file
/Volumes/hfsp/efi/test/grub523.efi
im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:   7882 => Blessed System Folder is /Volumes/hfsp/efi/test
finderinfo[1]:   7885 => Blessed System File is
/Volumes/hfsp/efi/test/grub523.efi


Now all we need is  --setBoot to make grub.efi the default boot, no Option
key required.

Oh, and how do we get grub.efi booted to bless itself - the only way I know
at present is to use a rEFIt CD, which is bootable by Apple EFI.


On Sun, Apr 19, 2009 at 8:50 PM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

> Hello, thank you for the testing. Two concepts together (system folder and
> system file) are clearly redundant. I thought that intel macs look which
> folder is blessed and load boot.efi file from this directory. Here I attach
> a patch which updates finderinfo[0] when argument is a directory and
> finderinfo[1] when argument is a file. Can you do a test and tell me which
> concept is really used by intel macs? When doing tests don't forget to hold
> option key and select your testing partition. I will do a similar test on my
> ppc mac
>
>
> On Sun, Apr 19, 2009 at 6:51 AM, Peter Cros <pxwpxw8@gmail.com> wrote:
>
>> Hi,
>>
>> Tested and works on Apple imac81 with Mac OSX 10.5, patch applied to r
>> 2074
>>
>> grub> hfspbless (hd0,3)/efi
>>
>> Last login: Sun Apr 19 14:30:23 on console
>> im81:~ pxw$ bless --info /Volumes/hfsp
>> finderinfo[0]:     52 => Blessed System Folder is /Volumes/hfsp/efi
>> finderinfo[1]:      0 => No Blessed System File
>> finderinfo[2]:      0 => Open-folder linked list empty
>> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
>> finderinfo[4]:      0 => Unused field unset
>> finderinfo[5]:      0 => No OS 9 + X blessed X folder
>> 64-bit VSDB volume id:  0x0F87F7680B9C5211
>> im81:~ pxw$
>>
>> Now it just needs to bless the file in order to boot from grub.efi on
>> Apple EFI
>>
>> hfspbless <DIRECTORY> <FILE>
>>
>> This would be VERY useful, making grub.efi boot possible on Apple Mac
>> without needing Mac OSX or refit.
>>
>> hfspbless is fine for a name
>>
>>
>> 2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>
>>
>>> Hello, due to request by ams I wrote this. It's an analog of "bless"
>>> command available under OSX rewritten using grub2 fs functions and according
>>> to apple specification of hfs+ on-disk format. This command only update the
>>> blessed folder on a partition it doesn't change which drive is used for
>>> booting. The later will be a separate command. Also you can choose which
>>> volume to boot from by holding option key. Syntax:
>>> hfspbless <DIRECTORY>
>>> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
>>> unable to test this "in vivo"
>>>
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>>
>>
>>
>> --
>> Cros (pxw)
>>
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>


-- 
Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 6206 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 13:26     ` Peter Cros
@ 2009-04-19 14:14       ` Vladimir Serbinenko
  2009-04-19 15:30         ` Peter Cros
  2009-08-28 22:59         ` Michal Suchanek
  0 siblings, 2 replies; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-19 14:14 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 4280 bytes --]

Thank you for the testing and info.

>
> Redundant info -
> I checked the OSX bless utility, it requires both folder and file, or it
> will not agree to bless the file.
>
I'm nearly sure now that folder blessing (+tbxi attribute) is used on ppc
macs and file blessing on  intel macs. Now the question is how we do it. We
can either keep the current syntax or IMO it's better to have two commands:
intelmacbless and ppcmacbless both accepting file as an argument. First one
updates finderInfo[1] and the second one updates finderInfo[0] and sets
filetype of given file to tbxi and if any other file has the type tbxi in
the same directory then change it to any other value (e.g. tbxj)

>
> Now all we need is  --setBoot to make grub.efi the default boot, no Option
> key required.
>
In my todo. Thanks to ams I have all the needed info now

>
> Oh, and how do we get grub.efi booted to bless itself - the only way I know
> at present is to use a rEFIt CD, which is bootable by Apple EFI.
>
I don't understand your question but hfspbless works in grub-emu too. Also I
guess we have to write grub-setup wrapper around hfspbless and
grub-mkrescue. I've seen that genisoimage can create iso+hfs disks. Is
anybody interested in writing corresponding script?

>
>
> On Sun, Apr 19, 2009 at 8:50 PM, Vladimir Serbinenko <phcoder@gmail.com>wrote:
>
>> Hello, thank you for the testing. Two concepts together (system folder and
>> system file) are clearly redundant. I thought that intel macs look which
>> folder is blessed and load boot.efi file from this directory. Here I attach
>> a patch which updates finderinfo[0] when argument is a directory and
>> finderinfo[1] when argument is a file. Can you do a test and tell me which
>> concept is really used by intel macs? When doing tests don't forget to hold
>> option key and select your testing partition. I will do a similar test on my
>> ppc mac
>>
>>
>> On Sun, Apr 19, 2009 at 6:51 AM, Peter Cros <pxwpxw8@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> Tested and works on Apple imac81 with Mac OSX 10.5, patch applied to r
>>> 2074
>>>
>>> grub> hfspbless (hd0,3)/efi
>>>
>>> Last login: Sun Apr 19 14:30:23 on console
>>> im81:~ pxw$ bless --info /Volumes/hfsp
>>> finderinfo[0]:     52 => Blessed System Folder is /Volumes/hfsp/efi
>>> finderinfo[1]:      0 => No Blessed System File
>>> finderinfo[2]:      0 => Open-folder linked list empty
>>> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
>>> finderinfo[4]:      0 => Unused field unset
>>> finderinfo[5]:      0 => No OS 9 + X blessed X folder
>>> 64-bit VSDB volume id:  0x0F87F7680B9C5211
>>> im81:~ pxw$
>>>
>>> Now it just needs to bless the file in order to boot from grub.efi on
>>> Apple EFI
>>>
>>> hfspbless <DIRECTORY> <FILE>
>>>
>>> This would be VERY useful, making grub.efi boot possible on Apple Mac
>>> without needing Mac OSX or refit.
>>>
>>> hfspbless is fine for a name
>>>
>>>
>>> 2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>
>>>
>>>> Hello, due to request by ams I wrote this. It's an analog of "bless"
>>>> command available under OSX rewritten using grub2 fs functions and according
>>>> to apple specification of hfs+ on-disk format. This command only update the
>>>> blessed folder on a partition it doesn't change which drive is used for
>>>> booting. The later will be a separate command. Also you can choose which
>>>> volume to boot from by holding option key. Syntax:
>>>> hfspbless <DIRECTORY>
>>>> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
>>>> unable to test this "in vivo"
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Grub-devel mailing list
>>>> Grub-devel@gnu.org
>>>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>>>
>>>>
>>>
>>>
>>> --
>>> Cros (pxw)
>>>
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
>
> --
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>

[-- Attachment #2: Type: text/html, Size: 6823 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 14:14       ` Vladimir Serbinenko
@ 2009-04-19 15:30         ` Peter Cros
  2009-04-19 20:05           ` Vladimir Serbinenko
  2009-08-28 22:59         ` Michal Suchanek
  1 sibling, 1 reply; 28+ messages in thread
From: Peter Cros @ 2009-04-19 15:30 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 3110 bytes --]

Thanks that is going to be very useful.

Just some further comment from the little I know -

On Mon, Apr 20, 2009 at 12:14 AM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

>
>>
>
Now the question is how we do it. We can either keep the current syntax or
> IMO it's better to have two commands:
> intelmacbless and ppcmacbless both accepting file as an argument. First one
> updates finderInfo[1] and the second one updates finderInfo[0] and sets
> filetype of given file to tbxi and if any other file has the type tbxi in
> the same directory then change it to any other value (e.g. tbxj)
>

The finderinfo[1] file blessing does seem the best for intel mac, but just
based on my imac81 test with current EFI.


>> Now all we need is  --setBoot to make grub.efi the default boot, no Option
>> key required.
>>
> In my todo. Thanks to ams I have all the needed info now
>
>> Oh, and how do we get grub.efi booted to bless itself - the only way I
>> know at present is to use a rEFIt CD, which is bootable by Apple EFI.
>>
> I don't understand your question but hfspbless works in grub-emu too.
>

Do you mean run grub-emu as part of a linux installation to bless grub.ef?
It seems to leave the problem of booting the linux installer, which is easy
to do from grub.efi - if it is blessed.
At present we install grub.efi manually, using only grub-mkimage to build
grub.efi, without using other grub utilities, and mostly just use preloaded
modules.


Here is some more info for the intel mac -

Further checking shows that Apple EFI will detect and boot an unblessed file
named boot.efi but only if the enclosing folder is blessed.
Will not boot unblessed grub.efi in the same folder.

im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:   7891 => Blessed System Folder is /Volumes/hfsp/efi/test
finderinfo[1]:      0 => No Blessed System File
finderinfo[2]:      0 => Open-folder linked list empty
finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
finderinfo[4]:      0 => Unused field unset
finderinfo[5]:   7891 => OS X blessed folder is /Volumes/hfsp/efi/test
64-bit VSDB volume id:  0x0F87F7680B9C5211

im81:~ pxw$ ls /Volumes/hfsp/efi/test
boot.efi grub.cfg grub523.efi grub523.icns grub64.icns
im81:~ pxw$
That boots boot.efi using the Option key.

For OSX boot.efi -
im81:~ pxw$ bless --info /
finderinfo[0]:    149 => Blessed System Folder is
/System/Library/CoreServices
finderinfo[1]: 297081 => Blessed System File is
/System/Library/CoreServices/boot.efi
finderinfo[2]:      0 => Open-folder linked list empty
finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
finderinfo[4]:      0 => Unused field unset
finderinfo[5]:    149 => OS X blessed folder is /System/Library/CoreServices
64-bit VSDB volume id:  0x0F8CB2A6A4C456E8

>
>>>>
>> --
>> Cros (pxw)
>>
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>


-- 
Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 6090 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 15:30         ` Peter Cros
@ 2009-04-19 20:05           ` Vladimir Serbinenko
  2009-04-20  9:17             ` Peter Cros
  0 siblings, 1 reply; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-19 20:05 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 2573 bytes --]

Hello

> Do you mean run grub-emu as part of a linux installation to bless grub.ef?
> It seems to leave the problem of booting the linux installer, which is easy
> to do from grub.efi - if it is blessed.
> At present we install grub.efi manually, using only grub-mkimage to build
> grub.efi, without using other grub utilities, and mostly just use preloaded
> modules.
>
You can use the bootable CD of your favourite distro. I hope that grub2.efi
will become a default bootloader to install on efi system for major linux
distributions

>
>
> Here is some more info for the intel mac -
>
> Further checking shows that Apple EFI will detect and boot an unblessed
> file named boot.efi but only if the enclosing folder is blessed.
> Will not boot unblessed grub.efi in the same folder.
>
> im81:~ pxw$ bless --info /Volumes/hfsp
> finderinfo[0]:   7891 => Blessed System Folder is /Volumes/hfsp/efi/test
> finderinfo[1]:      0 => No Blessed System File
> finderinfo[2]:      0 => Open-folder linked list empty
> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
> finderinfo[4]:      0 => Unused field unset
> finderinfo[5]:   7891 => OS X blessed folder is /Volumes/hfsp/efi/test
> 64-bit VSDB volume id:  0x0F87F7680B9C5211
>
> im81:~ pxw$ ls /Volumes/hfsp/efi/test
> boot.efi grub.cfg grub523.efi grub523.icns grub64.icns
> im81:~ pxw$
> That boots boot.efi using the Option key.
>
Could you determine the priority? E.g. if you have both blessed file and
boot.efi in blessed directory which one is loaded?


>
> For OSX boot.efi -
> im81:~ pxw$ bless --info /
> finderinfo[0]:    149 => Blessed System Folder is
> /System/Library/CoreServices
> finderinfo[1]: 297081 => Blessed System File is
> /System/Library/CoreServices/boot.efi
> finderinfo[2]:      0 => Open-folder linked list empty
> finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
> finderinfo[4]:      0 => Unused field unset
> finderinfo[5]:    149 => OS X blessed folder is
> /System/Library/CoreServices
> 64-bit VSDB volume id:  0x0F8CB2A6A4C456E8
>
>>
>>>>>
>>> --
>>> Cros (pxw)
>>>
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
>
> --
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>

[-- Attachment #2: Type: text/html, Size: 5092 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 20:05           ` Vladimir Serbinenko
@ 2009-04-20  9:17             ` Peter Cros
  2009-04-20 11:52               ` Vladimir Serbinenko
  0 siblings, 1 reply; 28+ messages in thread
From: Peter Cros @ 2009-04-20  9:17 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]

Hi,

On Mon, Apr 20, 2009 at 6:05 AM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

> Hello
>
>>
>> You can use the bootable CD of your favourite distro. I hope that
> grub2.efi will become a default bootloader to install on efi system for
> major linux distributions
>

The thought was just to avoid dependance on the apple pc-bios emulation and
go toward a grub.efi installation as you suggest. (Also the apple Xserve
machines do not have pc-bios emulation.)


> Could you determine the priority? E.g. if you have both blessed file and
>> boot.efi in blessed directory which one is loaded?
>>
>
In both these cases the blessed grub.efi file is selected and boots.
The boot.efi file here is a copy of the OSX boot.efi

im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:   7891 => Blessed System Folder is <missing>
finderinfo[1]:   8123 => Blessed System File is
/Volumes/hfsp/efi/test/grub523.efi

im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:   8120 => Blessed System Folder is /Volumes/hfsp/efi/test
finderinfo[1]:   8123 => Blessed System File is
/Volumes/hfsp/efi/test/grub523.efi

im81:~ pxw$ ls /Volumes/hfsp/efi/test/*.efi
/Volumes/hfsp/efi/test/boot.efi
/Volumes/hfsp/efi/test/grub523.efi

-- 
Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 2345 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-20  9:17             ` Peter Cros
@ 2009-04-20 11:52               ` Vladimir Serbinenko
  2009-04-21  2:28                 ` Peter Cros
  0 siblings, 1 reply; 28+ messages in thread
From: Vladimir Serbinenko @ 2009-04-20 11:52 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1699 bytes --]

On Mon, Apr 20, 2009 at 11:17 AM, Peter Cros <pxwpxw8@gmail.com> wrote:

> Hi,
>
> On Mon, Apr 20, 2009 at 6:05 AM, Vladimir Serbinenko <phcoder@gmail.com>wrote:
>
>> Hello
>>
>>>
>>> You can use the bootable CD of your favourite distro. I hope that
>> grub2.efi will become a default bootloader to install on efi system for
>> major linux distributions
>>
>
> The thought was just to avoid dependance on the apple pc-bios emulation and
> go toward a grub.efi installation as you suggest. (Also the apple Xserve
> machines do not have pc-bios emulation.)
>
>
The bootable cd can have both eltorito (bios) and grub2.efi

> Could you determine the priority? E.g. if you have both blessed file and
>>> boot.efi in blessed directory which one is loaded?
>>>
>>
> In both these cases the blessed grub.efi file is selected and boots.
> The boot.efi file here is a copy of the OSX boot.efi
>
But what happens if you do something like:
blessed folder -> /test1 contains boot.efi
blessed file -> /test2/grub2.efi

>
> im81:~ pxw$ bless --info /Volumes/hfsp
> finderinfo[0]:   7891 => Blessed System Folder is <missing>
> finderinfo[1]:   8123 => Blessed System File is
> /Volumes/hfsp/efi/test/grub523.efi
>
> im81:~ pxw$ bless --info /Volumes/hfsp
> finderinfo[0]:   8120 => Blessed System Folder is /Volumes/hfsp/efi/test
> finderinfo[1]:   8123 => Blessed System File is
> /Volumes/hfsp/efi/test/grub523.efi
>
> im81:~ pxw$ ls /Volumes/hfsp/efi/test/*.efi
> /Volumes/hfsp/efi/test/boot.efi
> /Volumes/hfsp/efi/test/grub523.efi
>
> --
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>

[-- Attachment #2: Type: text/html, Size: 3827 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-20 11:52               ` Vladimir Serbinenko
@ 2009-04-21  2:28                 ` Peter Cros
  0 siblings, 0 replies; 28+ messages in thread
From: Peter Cros @ 2009-04-21  2:28 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

My reply was delayed by network going down.

On Mon, Apr 20, 2009 at 9:52 PM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

>
>
>>
> The bootable cd can have both eltorito (bios) and grub2.efi
>

I like the grub.efi CD.


> But what happens if you do something like:
> blessed folder -> /test1 contains boot.efi
> blessed file -> /test2/grub2.efi
>

grub.efi wins.

We have this -  (not exactly as above )

/Volumes/hfsp/boot.efi
/Volumes/hfsp/efi/test/grub523.efi

im81:~ pxw$ bless --info /Volumes/hfsp
finderinfo[0]:      2 => Blessed System Folder is /Volumes/hfsp/
finderinfo[1]:   8256 => Blessed System File is
/Volumes/hfsp/efi/test/grub523.efi
finderinfo[2]:      0 => Open-folder linked list empty
finderinfo[3]:      0 => No OS 9 + X blessed 9 folder
finderinfo[4]:      0 => Unused field unset
finderinfo[5]:      2 => OS X blessed folder is /Volumes/hfsp/
64-bit VSDB volume id:  0x0F87F7680B9C5211

Apple Option restart shows the EFI boot icon, this boots grub523.efi,


Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 1958 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-18 18:59 [PATCH] bless command Vladimir Serbinenko
                   ` (2 preceding siblings ...)
  2009-04-19  4:51 ` Peter Cros
@ 2009-06-19  6:08 ` Peter Cros
  2009-06-19 11:53   ` Vladimir 'phcoder' Serbinenko
  3 siblings, 1 reply; 28+ messages in thread
From: Peter Cros @ 2009-06-19  6:08 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]

Hi again,

Could the hfspbless patch be updated and hopefully committted to provide the
hfspbless module as standard in grub2.

It is valuable to enable auto-booting grub.efi installation on Apple Intel
Mac efi and also where Mac OSX/refit is not installed. Potentially for
automated grub.efi installation on Apple.

The old patch has not caught up with subsequent changes to hfsplus.c and
requires editing to get it to work.


On Sun, Apr 19, 2009 at 4:59 AM, Vladimir Serbinenko <phcoder@gmail.com>wrote:

> Hello, due to request by ams I wrote this. It's an analog of "bless"
> command available under OSX rewritten using grub2 fs functions and according
> to apple specification of hfs+ on-disk format. This command only update the
> blessed folder on a partition it doesn't change which drive is used for
> booting. The later will be a separate command. Also you can choose which
> volume to boot from by holding option key. Syntax:
> hfspbless <DIRECTORY>
> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
> unable to test this "in vivo"
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>


-- 
Cros (pxw)

[-- Attachment #2: Type: text/html, Size: 1730 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-06-19  6:08 ` Peter Cros
@ 2009-06-19 11:53   ` Vladimir 'phcoder' Serbinenko
  2009-06-19 16:15     ` Pavel Roskin
  2009-06-21 11:05     ` Robert Millan
  0 siblings, 2 replies; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-06-19 11:53 UTC (permalink / raw)
  To: The development of GRUB 2


[-- Attachment #1.1: Type: text/plain, Size: 1820 bytes --]

On Fri, Jun 19, 2009 at 8:08 AM, Peter Cros <pxwpxw8@gmail.com> wrote:

> Hi again,
>
> Could the hfspbless patch be updated and hopefully committted to provide
> the hfspbless module as standard in grub2.
>
 Attached to this e-mail and on my personal git repository in branch bless
the rediff. I was thinking of adding ppc mac support but haven't done it yet
I think we can incorporate apple intel support without the ppc counterpart
yet. Does anyone object?

>
> It is valuable to enable auto-booting grub.efi installation on Apple Intel
> Mac efi and also where Mac OSX/refit is not installed. Potentially for
> automated grub.efi installation on Apple.
>
> The old patch has not caught up with subsequent changes to hfsplus.c and
> requires editing to get it to work.
>
>
> On Sun, Apr 19, 2009 at 4:59 AM, Vladimir Serbinenko <phcoder@gmail.com>wrote:
>
>> Hello, due to request by ams I wrote this. It's an analog of "bless"
>> command available under OSX rewritten using grub2 fs functions and according
>> to apple specification of hfs+ on-disk format. This command only update the
>> blessed folder on a partition it doesn't change which drive is used for
>> booting. The later will be a separate command. Also you can choose which
>> volume to boot from by holding option key. Syntax:
>> hfspbless <DIRECTORY>
>> It works only on HFS+ volumes. Also due to the lack of hardware I wasn't
>> unable to test this "in vivo"
>>
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>
>
> --
> Cros (pxw)
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>


-- 
Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #1.2: Type: text/html, Size: 3023 bytes --]

[-- Attachment #2: bless.diff --]
[-- Type: text/x-diff, Size: 17788 bytes --]

diff --git a/ChangeLog b/ChangeLog
index 982c8bc..fd13e5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-06-19  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	HFS+ blessing
+	
+	* commands/hfspbless.c: new file
+	* conf/common.rmk (pkglib_MODULES): add hfspbless.mod
+	(hfspbless_mod_SOURCES): new variable
+	(hfspbless_mod_CFLAGS): likewise
+	(hfspbless_mod_LDFLAGS): likewise
+	* conf/i386-pc.rmk (grub_emu_SOURCES): add commands/hfspbless.c
+	* fs/hfsplus.c: move definitions
+	* include/grub/hfsplus.h: here
+	* fs/hfsplus.c (grub_hfsplus_dir): set inode
+	* include/grub/fs.h (grub_dirhook_info): new fields inode and inodeset
+
 2009-06-18  Pavel Roskin  <proski@gnu.org>
 
 	* conf/common.rmk: Add fs_file.mod.
diff --git a/commands/hfspbless.c b/commands/hfspbless.c
new file mode 100644
index 0000000..a044623
--- /dev/null
+++ b/commands/hfspbless.c
@@ -0,0 +1,207 @@
+/* hfspbless.c - set the hfs+ boot directory.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2003,2005,2007,2008,2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/command.h>
+#include <grub/fs.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/hfsplus.h>
+#include <grub/hfs.h>
+#include <grub/partition.h>
+#include <grub/file.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+
+static grub_uint64_t inode;
+static char *dirname;
+static int found;
+
+static int find_inode (const char *filename,
+		       const struct grub_dirhook_info *info)
+{
+  if ((grub_strcmp (dirname, filename) == 0
+       || (info->case_insensitive && grub_strcasecmp (dirname, filename) == 0))
+       && info->inodeset)
+    {
+      inode = info->inode;
+      found = info->dir ? 2 : 1;
+    }
+  return 0;
+}
+
+static grub_err_t
+grub_cmd_hfspbless (grub_command_t cmd __attribute__ ((unused)),
+		    int argc, char **args)
+{
+  char *device_name;
+  char *path = 0, *tail;
+  int embedded_offset;
+  grub_device_t dev;
+  grub_fs_t fs;
+
+  union {
+    struct grub_hfs_sblock hfs;
+    struct grub_hfsplus_volheader hfsplus;
+  } volheader;
+
+  if (argc != 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory or file required");
+  device_name = grub_file_get_device_name (args[0]);
+  dev = grub_device_open (device_name);
+
+  path = grub_strchr (args[0], ')');
+  if (! path)
+    path = grub_strdup (dirname);
+  else
+    path = grub_strdup (path + 1);
+
+  if (! path || *path == 0 || ! device_name)
+    {
+      if (dev)
+	grub_device_close (dev);
+
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
+    }
+
+  fs = grub_fs_probe (dev);
+  if (! fs || grub_strcmp (fs->name, "hfsplus") != 0)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      grub_free (path);
+
+      return grub_error (GRUB_ERR_BAD_FS, "no suitable FS found");
+    }
+
+  tail = path + grub_strlen (path) - 1;
+
+  /* Remove trailing '/'. */
+  while (tail != path && *tail == '/')
+    *(tail--) = 0;
+
+  tail = grub_strrchr (path, '/');
+  found = 0;
+
+  if (tail)
+    {
+      *tail = 0;
+      dirname = tail + 1;
+
+      (fs->dir) (dev, *path == 0 ?"/":path, find_inode);
+    }
+  else
+    {
+      dirname = path + 1;
+      (fs->dir) (dev, "/", find_inode);
+    }
+  grub_free (path);
+
+  if (! found)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_FILE_NOT_FOUND,
+			 "%s not found\n",
+			 args[0]);
+    }
+
+  /* Read the bootblock.  */
+  grub_disk_read (dev->disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader),
+		  (char *) &volheader);
+  if (grub_errno)
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_errno;
+    }
+
+  embedded_offset = 0;
+  if (grub_be_to_cpu16 (volheader.hfs.magic) == GRUB_HFS_MAGIC)
+    {
+      int extent_start;
+      int ablk_size;
+      int ablk_start;
+
+      /* See if there's an embedded HFS+ filesystem.  */
+      if (grub_be_to_cpu16 (volheader.hfs.embed_sig) != GRUB_HFSPLUS_MAGIC)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+
+      /* Calculate the offset needed to translate HFS+ sector numbers.  */
+      extent_start = grub_be_to_cpu16 (volheader.hfs.embed_extent.first_block);
+      ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz);
+      ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
+      embedded_offset = (ablk_start
+			 + extent_start
+			 * (ablk_size >> GRUB_DISK_SECTOR_BITS));
+
+      grub_disk_read (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		      sizeof (volheader), (char *) &volheader);
+      if (grub_errno)
+	{
+	  grub_device_close (dev);
+	  grub_free (device_name);
+	  return grub_errno;
+	}
+    }
+
+  /* Make sure this is an HFS+ filesystem.  XXX: Do we really support
+     HFX?  */
+  if ((grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUS_MAGIC)
+      && (grub_be_to_cpu16 (volheader.hfsplus.magic) != GRUB_HFSPLUSX_MAGIC))
+    {
+      grub_device_close (dev);
+      grub_free (device_name);
+      return grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
+    }
+  if (found == 2)
+    volheader.hfsplus.bootdir = grub_be_to_cpu32 (inode);
+  else
+    volheader.hfsplus.bootfile = grub_be_to_cpu32 (inode);
+
+  grub_disk_write (dev->disk, embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
+		   sizeof (volheader), (char *) &volheader);
+
+  grub_device_close (dev);
+  grub_free (device_name);
+  return grub_errno;
+}
+
+static grub_command_t cmd;
+\f
+GRUB_MOD_INIT(hfspbless)
+{
+  (void) mod;			/* To stop warning. */
+  cmd = grub_register_command ("hfspbless", grub_cmd_hfspbless,
+			       "hfspbless [DIRECTORY|FILE]",
+			       "Bless DIRECTORY or FILE of HFS+ partition.");
+}
+
+GRUB_MOD_FINI(hfspbless)
+{
+  grub_unregister_command (cmd);
+}
diff --git a/conf/common.rmk b/conf/common.rmk
index fbca2e4..8799e6e 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -598,3 +598,10 @@ pkglib_MODULES += xnu_uuid.mod
 xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
 xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
 xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += hfspbless.mod
+
+# For hfspbless.mod.
+hfspbless_mod_SOURCES = commands/hfspbless.c
+hfspbless_mod_CFLAGS = $(COMMON_CFLAGS)
+hfspbless_mod_LDFLAGS = $(COMMON_LDFLAGS)
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index 20c31ef..427ad0e 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -126,6 +126,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/handler.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
+	commands/hfspbless.c						\
 	lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c		\
 	commands/gptsync.c commands/probe.c commands/xnu_uuid.c		\
 	commands/i386/cpuid.c	\
@@ -160,7 +161,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
-	commands/parttool.c parttool/pcpart.c				\
+	commands/parttool.c parttool/pcpart.c 				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
diff --git a/fs/hfsplus.c b/fs/hfsplus.c
index 31bb540..132933c 100644
--- a/fs/hfsplus.c
+++ b/fs/hfsplus.c
@@ -29,151 +29,6 @@
 #include <grub/fshelp.h>
 #include <grub/hfs.h>
 
-#define GRUB_HFSPLUS_MAGIC 0x482B
-#define GRUB_HFSPLUSX_MAGIC 0x4858
-#define GRUB_HFSPLUS_SBLOCK 2
-
-/* A HFS+ extent.  */
-struct grub_hfsplus_extent
-{
-  /* The first block of a file on disk.  */
-  grub_uint32_t start;
-  /* The amount of blocks described by this extent.  */
-  grub_uint32_t count;
-} __attribute__ ((packed));
-
-/* The descriptor of a fork.  */
-struct grub_hfsplus_forkdata
-{
-  grub_uint64_t size;
-  grub_uint32_t clumpsize;
-  grub_uint32_t blocks;
-  struct grub_hfsplus_extent extents[8];
-} __attribute__ ((packed));
-
-/* The HFS+ Volume Header.  */
-struct grub_hfsplus_volheader
-{
-  grub_uint16_t magic;
-  grub_uint16_t version;
-  grub_uint32_t attributes;
-  grub_uint8_t unused1[12];
-  grub_uint32_t utime;
-  grub_uint8_t unused2[16];
-  grub_uint32_t blksize;
-  grub_uint8_t unused3[60];
-  grub_uint64_t num_serial;
-  struct grub_hfsplus_forkdata allocations_file;
-  struct grub_hfsplus_forkdata extents_file;
-  struct grub_hfsplus_forkdata catalog_file;
-  struct grub_hfsplus_forkdata attrib_file;
-  struct grub_hfsplus_forkdata startup_file;
-} __attribute__ ((packed));
-
-/* The type of node.  */
-enum grub_hfsplus_btnode_type
-  {
-    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
-    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
-    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
-    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
-  };
-
-struct grub_hfsplus_btnode
-{
-  grub_uint32_t next;
-  grub_uint32_t prev;
-  grub_int8_t type;
-  grub_uint8_t height;
-  grub_uint16_t count;
-  grub_uint16_t unused;
-} __attribute__ ((packed));
-
-/* The header of a HFS+ B+ Tree.  */
-struct grub_hfsplus_btheader
-{
-  grub_uint16_t depth;
-  grub_uint32_t root;
-  grub_uint32_t leaf_records;
-  grub_uint32_t first_leaf_node;
-  grub_uint32_t last_leaf_node;
-  grub_uint16_t nodesize;
-  grub_uint16_t keysize;
-  grub_uint32_t total_nodes;
-  grub_uint32_t free_nodes;
-  grub_uint16_t reserved1;
-  grub_uint32_t clump_size;  /* ignored */
-  grub_uint8_t btree_type;
-  grub_uint8_t key_compare;
-  grub_uint32_t attributes;
-} __attribute__ ((packed));
-
-/* The on disk layout of a catalog key.  */
-struct grub_hfsplus_catkey
-{
-  grub_uint16_t keylen;
-  grub_uint32_t parent;
-  grub_uint16_t namelen;
-  grub_uint16_t name[30];
-} __attribute__ ((packed));
-
-/* The on disk layout of an extent overflow file key.  */
-struct grub_hfsplus_extkey
-{
-  grub_uint16_t keylen;
-  grub_uint8_t type;
-  grub_uint8_t unused;
-  grub_uint32_t fileid;
-  grub_uint32_t start;
-} __attribute__ ((packed));
-
-struct grub_hfsplus_key
-{
-  union
-  {
-    struct grub_hfsplus_extkey extkey;
-    struct grub_hfsplus_catkey catkey;
-    grub_uint16_t keylen;
-  };
-} __attribute__ ((packed));
-
-struct grub_hfsplus_catfile
-{
-  grub_uint16_t type;
-  grub_uint16_t flags;
-  grub_uint32_t reserved;
-  grub_uint32_t fileid;
-  grub_uint8_t unused1[4];
-  grub_uint32_t mtime;
-  grub_uint8_t unused2[22];
-  grub_uint16_t mode;
-  grub_uint8_t unused3[44];
-  struct grub_hfsplus_forkdata data;
-  struct grub_hfsplus_forkdata resource;
-} __attribute__ ((packed));
-
-/* Filetype information as used in inodes.  */
-#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
-#define GRUB_HFSPLUS_FILEMODE_REG	0100000
-#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
-#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
-
-/* Some pre-defined file IDs.  */
-#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
-#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
-#define GRUB_HFSPLUS_FILEID_CATALOG	4
-
-enum grub_hfsplus_filetype
-  {
-    GRUB_HFSPLUS_FILETYPE_DIR = 1,
-    GRUB_HFSPLUS_FILETYPE_REG = 2,
-    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
-    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
-  };
-
-#define GRUB_HFSPLUSX_BINARYCOMPARE	0xBC
-#define GRUB_HFSPLUSX_CASEFOLDING	0xCF
-
 /* Internal representation of a catalog key.  */
 struct grub_hfsplus_catkey_internal
 {
@@ -918,6 +773,8 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
       info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
       info.mtimeset = 1;
       info.mtime = node->mtime;
+      info.inodeset = 1;
+      info.inode = node->fileid;
       info.case_insensitive = !! (filetype & GRUB_FSHELP_CASE_INSENSITIVE);
       grub_free (node);
       return hook (filename, &info);
diff --git a/include/grub/fs.h b/include/grub/fs.h
index 41732e4..558a113 100644
--- a/include/grub/fs.h
+++ b/include/grub/fs.h
@@ -32,7 +32,9 @@ struct grub_dirhook_info
   int dir:1;
   int mtimeset:1;
   int case_insensitive:1;
+  int inodeset:1;
   grub_int32_t mtime;
+  grub_uint64_t inode;
 };
 
 /* Filesystem descriptor.  */
diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h
new file mode 100644
index 0000000..95a061c
--- /dev/null
+++ b/include/grub/hfsplus.h
@@ -0,0 +1,177 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2006,2007,2008,2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HFSPLUS_HEADER
+#define GRUB_HFSPLUS_HEADER	1
+
+#include <grub/types.h>
+
+#define GRUB_HFSPLUS_MAGIC 0x482B
+#define GRUB_HFSPLUSX_MAGIC 0x4858
+#define GRUB_HFSPLUS_SBLOCK 2
+
+/* A HFS+ extent.  */
+struct grub_hfsplus_extent
+{
+  /* The first block of a file on disk.  */
+  grub_uint32_t start;
+  /* The amount of blocks described by this extent.  */
+  grub_uint32_t count;
+} __attribute__ ((packed));
+
+/* The descriptor of a fork.  */
+struct grub_hfsplus_forkdata
+{
+  grub_uint64_t size;
+  grub_uint32_t clumpsize;
+  grub_uint32_t blocks;
+  struct grub_hfsplus_extent extents[8];
+} __attribute__ ((packed));
+
+/* The HFS+ Volume Header.  */
+struct grub_hfsplus_volheader
+{
+  grub_uint16_t magic;
+  grub_uint16_t version;
+  grub_uint32_t attributes;
+  grub_uint8_t unused1[12];
+  grub_uint32_t utime;
+  grub_uint8_t unused2[16];
+  grub_uint32_t blksize;
+  grub_uint8_t unused3[36];
+  grub_uint32_t bootdir;
+  grub_uint32_t bootfile;
+
+  /* Folder opened when disk is mounted. Unused by GRUB. */
+  grub_uint32_t showfolder;
+  grub_uint32_t os9folder;
+  grub_uint8_t unused4[4];
+  grub_uint32_t osxfolder;
+  grub_uint64_t num_serial;
+  struct grub_hfsplus_forkdata allocations_file;
+  struct grub_hfsplus_forkdata extents_file;
+  struct grub_hfsplus_forkdata catalog_file;
+  struct grub_hfsplus_forkdata attrib_file;
+  struct grub_hfsplus_forkdata startup_file;
+} __attribute__ ((packed));
+
+/* The type of node.  */
+enum grub_hfsplus_btnode_type
+  {
+    GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
+    GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
+    GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
+    GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
+  };
+
+struct grub_hfsplus_btnode
+{
+  grub_uint32_t next;
+  grub_uint32_t prev;
+  grub_int8_t type;
+  grub_uint8_t height;
+  grub_uint16_t count;
+  grub_uint16_t unused;
+} __attribute__ ((packed));
+
+/* The header of a HFS+ B+ Tree.  */
+struct grub_hfsplus_btheader
+{
+  grub_uint16_t depth;
+  grub_uint32_t root;
+  grub_uint32_t leaf_records;
+  grub_uint32_t first_leaf_node;
+  grub_uint32_t last_leaf_node;
+  grub_uint16_t nodesize;
+  grub_uint16_t keysize;
+  grub_uint32_t total_nodes;
+  grub_uint32_t free_nodes;
+  grub_uint16_t reserved1;
+  grub_uint32_t clump_size;  /* ignored */
+  grub_uint8_t btree_type;
+  grub_uint8_t key_compare;
+  grub_uint32_t attributes;
+} __attribute__ ((packed));
+
+/* The on disk layout of a catalog key.  */
+struct grub_hfsplus_catkey
+{
+  grub_uint16_t keylen;
+  grub_uint32_t parent;
+  grub_uint16_t namelen;
+  grub_uint16_t name[30];
+} __attribute__ ((packed));
+
+/* The on disk layout of an extent overflow file key.  */
+struct grub_hfsplus_extkey
+{
+  grub_uint16_t keylen;
+  grub_uint8_t type;
+  grub_uint8_t unused;
+  grub_uint32_t fileid;
+  grub_uint32_t start;
+} __attribute__ ((packed));
+
+struct grub_hfsplus_key
+{
+  union
+  {
+    struct grub_hfsplus_extkey extkey;
+    struct grub_hfsplus_catkey catkey;
+    grub_uint16_t keylen;
+  };
+} __attribute__ ((packed));
+
+struct grub_hfsplus_catfile
+{
+  grub_uint16_t type;
+  grub_uint16_t flags;
+  grub_uint32_t reserved;
+  grub_uint32_t fileid;
+  grub_uint8_t unused1[4];
+  grub_uint32_t mtime;
+  grub_uint8_t unused2[22];
+  grub_uint16_t mode;
+  grub_uint8_t unused3[44];
+  struct grub_hfsplus_forkdata data;
+  struct grub_hfsplus_forkdata resource;
+} __attribute__ ((packed));
+
+/* Filetype information as used in inodes.  */
+#define GRUB_HFSPLUS_FILEMODE_MASK	0170000
+#define GRUB_HFSPLUS_FILEMODE_REG	0100000
+#define GRUB_HFSPLUS_FILEMODE_DIRECTORY	0040000
+#define GRUB_HFSPLUS_FILEMODE_SYMLINK	0120000
+
+/* Some pre-defined file IDs.  */
+#define GRUB_HFSPLUS_FILEID_ROOTDIR	2
+#define GRUB_HFSPLUS_FILEID_OVERFLOW	3
+#define GRUB_HFSPLUS_FILEID_CATALOG	4
+
+enum grub_hfsplus_filetype
+  {
+    GRUB_HFSPLUS_FILETYPE_DIR = 1,
+    GRUB_HFSPLUS_FILETYPE_REG = 2,
+    GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
+    GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
+  };
+
+#define GRUB_HFSPLUSX_BINARYCOMPARE	0xBC
+#define GRUB_HFSPLUSX_CASEFOLDING	0xCF
+
+#endif

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-06-19 11:53   ` Vladimir 'phcoder' Serbinenko
@ 2009-06-19 16:15     ` Pavel Roskin
  2009-06-19 16:24       ` Vladimir 'phcoder' Serbinenko
  2009-06-21 11:05     ` Robert Millan
  1 sibling, 1 reply; 28+ messages in thread
From: Pavel Roskin @ 2009-06-19 16:15 UTC (permalink / raw)
  To: The development of GRUB 2

On Fri, 2009-06-19 at 13:53 +0200, Vladimir 'phcoder' Serbinenko wrote:

>  Attached to this e-mail and on my personal git repository in branch
> bless the rediff. I was thinking of adding ppc mac support but haven't
> done it yet I think we can incorporate apple intel support without the
> ppc counterpart yet. Does anyone object?

I don't see how PowerPC support would be different.  It's a filesystem
issue.  Actually, on PowerPC blessing on HFS (not on HFS+) would be
needed.

I think it would be better to name the command "hfsbless".  The way, HFS
support could be added to the same command later.

Adding commands/hfspbless.c to grub_emu_SOURCES only on i386-pc seems
inconsistent.  Either it should be added everywhere or nowhere.  I think
we need a build system reorganization to allow grub_emu_SOURCES to be
mostly platform independent.

The spacing change in conf/i386-pc.rmk is unnecessary.

"(void) mod;" is unnecessary.

fs/hfsplus.c should include grub/hfsplus.h or it won't compile.

In find_inode(), the core start with

if(! info->inodeset)
  return 0;

It's both faster and more readable.

Please run hfspbless.c through indent.  It would fix such things as

(fs->dir) (dev, *path == 0 ?"/":path, find_inode);

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-06-19 16:15     ` Pavel Roskin
@ 2009-06-19 16:24       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-06-19 16:24 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Bean

[-- Attachment #1: Type: text/plain, Size: 2171 bytes --]

On Fri, Jun 19, 2009 at 6:15 PM, Pavel Roskin <proski@gnu.org> wrote:

> On Fri, 2009-06-19 at 13:53 +0200, Vladimir 'phcoder' Serbinenko wrote:
>
> >  Attached to this e-mail and on my personal git repository in branch
> > bless the rediff. I was thinking of adding ppc mac support but haven't
> > done it yet I think we can incorporate apple intel support without the
> > ppc counterpart yet. Does anyone object?
>
> I don't see how PowerPC support would be different.  It's a filesystem
> issue.  Actually, on PowerPC blessing on HFS (not on HFS+) would be
> needed.
>
You need to set file type to tbxi on PowerPC. On HFS+ there are 2 relevant
entries: blessed directory and blessed file. On EFI it works like:
first tries blessed file if it's missing it tries (blessed
directory)/boot.efi
On PowerPC it searches for the first file of type tbxi in blessed directory

>
> I think it would be better to name the command "hfsbless".  The way, HFS
> support could be added to the same command later.

I'm ok with renaming

>
>
> Adding commands/hfspbless.c to grub_emu_SOURCES only on i386-pc seems
> inconsistent.  Either it should be added everywhere or nowhere.  I think
> we need a build system reorganization to allow grub_emu_SOURCES to be
> mostly platform independent.
>
I completely agree. Bean was interested in doing so. Bean: what's your
status?

>
> The spacing change in conf/i386-pc.rmk is unnecessary.
>
> "(void) mod;" is unnecessary.
>
> fs/hfsplus.c should include grub/hfsplus.h or it won't compile.
>
> In find_inode(), the core start with
>
> if(! info->inodeset)
>  return 0;
>
> It's both faster and more readable.
>
> Please run hfspbless.c through indent.  It would fix such things as
>
> (fs->dir) (dev, *path == 0 ?"/":path, find_inode);
>
Thank you for these comments. I'll fix it as soon as I finish the build
system additions I promised Carles

>
> --
> Regards,
> Pavel Roskin
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git

[-- Attachment #2: Type: text/html, Size: 3604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-06-19 11:53   ` Vladimir 'phcoder' Serbinenko
  2009-06-19 16:15     ` Pavel Roskin
@ 2009-06-21 11:05     ` Robert Millan
  2009-08-28 15:19       ` Vladimir 'phcoder' Serbinenko
  1 sibling, 1 reply; 28+ messages in thread
From: Robert Millan @ 2009-06-21 11:05 UTC (permalink / raw)
  To: The development of GRUB 2

On Fri, Jun 19, 2009 at 01:53:18PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> On Fri, Jun 19, 2009 at 8:08 AM, Peter Cros <pxwpxw8@gmail.com> wrote:
> 
> > Hi again,
> >
> > Could the hfspbless patch be updated and hopefully committted to provide
> > the hfspbless module as standard in grub2.
> >
>  Attached to this e-mail and on my personal git repository in branch bless
> the rediff. I was thinking of adding ppc mac support but haven't done it yet
> I think we can incorporate apple intel support without the ppc counterpart
> yet. Does anyone object?

Hi!

Please observe the usual hierrachy, i.e. ieee1275-specific stuff in a ieee1275/
directory, same for powerpc-specific stuff, etc.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-06-21 11:05     ` Robert Millan
@ 2009-08-28 15:19       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-28 15:19 UTC (permalink / raw)
  To: The development of GRUB 2

On Sun, Jun 21, 2009 at 1:05 PM, Robert Millan<rmh@aybabtu.com> wrote:
> On Fri, Jun 19, 2009 at 01:53:18PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> On Fri, Jun 19, 2009 at 8:08 AM, Peter Cros <pxwpxw8@gmail.com> wrote:
>>
>> > Hi again,
>> >
>> > Could the hfspbless patch be updated and hopefully committted to provide
>> > the hfspbless module as standard in grub2.
>> >
>>  Attached to this e-mail and on my personal git repository in branch bless
>> the rediff. I was thinking of adding ppc mac support but haven't done it yet
>> I think we can incorporate apple intel support without the ppc counterpart
>> yet. Does anyone object?
>
> Hi!
>
> Please observe the usual hierrachy, i.e. ieee1275-specific stuff in a ieee1275/
> directory, same for powerpc-specific stuff, etc.
>
Actually it's not so platform-specific. It's just a value which stored
in fs in a bit different places and not something to do with the
platform itself
> --
> Robert Millan
>
>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>  how) you may access your data; but nobody's threatening your freedom: we
>  still allow you to remove your data and not access it at all."
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-04-19 14:14       ` Vladimir Serbinenko
  2009-04-19 15:30         ` Peter Cros
@ 2009-08-28 22:59         ` Michal Suchanek
  2009-08-29  3:48           ` Bean
  1 sibling, 1 reply; 28+ messages in thread
From: Michal Suchanek @ 2009-08-28 22:59 UTC (permalink / raw)
  To: The development of GRUB 2

Hello

the bless command is nice.

2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>:
> Thank you for the testing and info.
>>
>> Redundant info -
>> I checked the OSX bless utility, it requires both folder and file, or it
>> will not agree to bless the file.
>
> I'm nearly sure now that folder blessing (+tbxi attribute) is used on ppc
> macs and file blessing on  intel macs. Now the question is how we do it. We
> can either keep the current syntax or IMO it's better to have two commands:

Wouldn't it be reasonable to bless both the file and the directory?

> intelmacbless and ppcmacbless both accepting file as an argument. First one
> updates finderInfo[1] and the second one updates finderInfo[0] and sets
> filetype of given file to tbxi and if any other file has the type tbxi in
> the same directory then change it to any other value (e.g. tbxj)

Couldn't the bless command check the machine type of the file and
change file type on ppc files and bless the file for i386 files?

It's OK if the command has parameters that specify what to do and are
explained in the help but it should just do the right thing when you
specify the file to bless.

Would it be possible to make an i386+ppc efi boot CD this way? Would
the i386 grub boot on 64bit systems or are two CDs needed for i386 and
amd64?

Thanks

Michal



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-28 22:59         ` Michal Suchanek
@ 2009-08-29  3:48           ` Bean
  2009-08-29  6:27             ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 28+ messages in thread
From: Bean @ 2009-08-29  3:48 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, Aug 29, 2009 at 6:59 AM, Michal Suchanek<hramrach@centrum.cz> wrote:
> Hello
>
> the bless command is nice.
>
> 2009/4/19 Vladimir Serbinenko <phcoder@gmail.com>:
>> Thank you for the testing and info.
>>>
>>> Redundant info -
>>> I checked the OSX bless utility, it requires both folder and file, or it
>>> will not agree to bless the file.
>>
>> I'm nearly sure now that folder blessing (+tbxi attribute) is used on ppc
>> macs and file blessing on  intel macs. Now the question is how we do it. We
>> can either keep the current syntax or IMO it's better to have two commands:
>
> Wouldn't it be reasonable to bless both the file and the directory?

Hi,

Actually, I think the correct handling is to first bless a boot
directory (storing the directory id in header), then bless a boot file
(add +tbxi attribute), that's why the bless command in OSX needs needs
both --folder and --file option.

>
>> intelmacbless and ppcmacbless both accepting file as an argument. First one
>> updates finderInfo[1] and the second one updates finderInfo[0] and sets
>> filetype of given file to tbxi and if any other file has the type tbxi in
>> the same directory then change it to any other value (e.g. tbxj)
>
> Couldn't the bless command check the machine type of the file and
> change file type on ppc files and bless the file for i386 files?
>
> It's OK if the command has parameters that specify what to do and are
> explained in the help but it should just do the right thing when you
> specify the file to bless.
>
> Would it be possible to make an i386+ppc efi boot CD this way? Would
> the i386 grub boot on 64bit systems or are two CDs needed for i386 and
> amd64?

Yeah, osx support fat binaries that contains code from multiple architecture.

-- 
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  3:48           ` Bean
@ 2009-08-29  6:27             ` Vladimir 'phcoder' Serbinenko
  2009-08-29  7:53               ` Bean
  0 siblings, 1 reply; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-29  6:27 UTC (permalink / raw)
  To: The development of GRUB 2

>> Wouldn't it be reasonable to bless both the file and the directory?
>
> Hi,
>
> Actually, I think the correct handling is to first bless a boot
> directory (storing the directory id in header), then bless a boot file
> (add +tbxi attribute), that's why the bless command in OSX needs needs
> both --folder and --file option.
AFAIK --file has no effect for intel macs.
>
>>
>>> intelmacbless and ppcmacbless both accepting file as an argument. First one
>>> updates finderInfo[1] and the second one updates finderInfo[0] and sets
>>> filetype of given file to tbxi and if any other file has the type tbxi in
>>> the same directory then change it to any other value (e.g. tbxj)
>>
>> Couldn't the bless command check the machine type of the file and
>> change file type on ppc files and bless the file for i386 files?
>>
>> It's OK if the command has parameters that specify what to do and are
>> explained in the help but it should just do the right thing when you
>> specify the file to bless.
>>
>> Would it be possible to make an i386+ppc efi boot CD this way? Would
>> the i386 grub boot on 64bit systems or are two CDs needed for i386 and
>> amd64?
>
> Yeah, osx support fat binaries that contains code from multiple architecture.
>
In the case of OFW (and not EFI) boot for ppc macs You can (and have
to) specify a completely different file. OSX bootable disks and
partitions do it that way
> --
> Bean
>
> gitgrub home: http://github.com/grub/grub/
> my fork page: http://github.com/bean123/grub/
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  6:27             ` Vladimir 'phcoder' Serbinenko
@ 2009-08-29  7:53               ` Bean
  2009-08-29  7:58                 ` Michal Suchanek
  2009-08-29  8:06                 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 2 replies; 28+ messages in thread
From: Bean @ 2009-08-29  7:53 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, Aug 29, 2009 at 2:27 PM, Vladimir 'phcoder'
Serbinenko<phcoder@gmail.com> wrote:
>> Actually, I think the correct handling is to first bless a boot
>> directory (storing the directory id in header), then bless a boot file
>> (add +tbxi attribute), that's why the bless command in OSX needs needs
>> both --folder and --file option.
> AFAIK --file has no effect for intel macs.

Hi,

After more testing, I believe the booting process works like this:

One important difference between openfirmware and efi is that
openfirmware stores file path in nvram, while efi stores device path.
The default boot file for openfirmware is like this:

device:\\+tbxi

Which means the files which +tbxi attribute in the blessed directory.

But efi only store the boot device (uuid), so it needs to use the
blessed file to boot.

So to distinguish these two situation, we can have too options for bless:

bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]

--bootinfo set the blessed directory plus +tbxi, while --bootefi set
the blessed file, this way we could specify different boot files for
openfirmware and efi, something like this:

bless --bootinfo /grub.elf --bootefi grub.efi

-- 
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  7:53               ` Bean
@ 2009-08-29  7:58                 ` Michal Suchanek
  2009-08-29  8:07                   ` Vladimir 'phcoder' Serbinenko
  2009-08-29  8:10                   ` Bean
  2009-08-29  8:06                 ` Vladimir 'phcoder' Serbinenko
  1 sibling, 2 replies; 28+ messages in thread
From: Michal Suchanek @ 2009-08-29  7:58 UTC (permalink / raw)
  To: The development of GRUB 2

2009/8/29 Bean <bean123ch@gmail.com>:
> On Sat, Aug 29, 2009 at 2:27 PM, Vladimir 'phcoder'
> Serbinenko<phcoder@gmail.com> wrote:
>>> Actually, I think the correct handling is to first bless a boot
>>> directory (storing the directory id in header), then bless a boot file
>>> (add +tbxi attribute), that's why the bless command in OSX needs needs
>>> both --folder and --file option.
>> AFAIK --file has no effect for intel macs.
>
> Hi,
>
> After more testing, I believe the booting process works like this:
>
> One important difference between openfirmware and efi is that
> openfirmware stores file path in nvram, while efi stores device path.
> The default boot file for openfirmware is like this:
>
> device:\\+tbxi
>
> Which means the files which +tbxi attribute in the blessed directory.
>
> But efi only store the boot device (uuid), so it needs to use the
> blessed file to boot.
>
> So to distinguish these two situation, we can have too options for bless:
>
> bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]
>
> --bootinfo set the blessed directory plus +tbxi, while --bootefi set
> the blessed file, this way we could specify different boot files for
> openfirmware and efi, something like this:
>
> bless --bootinfo /grub.elf --bootefi grub.efi
>

Wouldn't it be possible to do a check in bless that determines if the
file is for openfirmware of efi?

Thanks

Michal



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  7:53               ` Bean
  2009-08-29  7:58                 ` Michal Suchanek
@ 2009-08-29  8:06                 ` Vladimir 'phcoder' Serbinenko
  1 sibling, 0 replies; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-29  8:06 UTC (permalink / raw)
  To: The development of GRUB 2

> Hi,
>
> After more testing, I believe the booting process works like this:
>
> One important difference between openfirmware and efi is that
> openfirmware stores file path in nvram, while efi stores device path.
> The default boot file for openfirmware is like this:
>
> device:\\+tbxi
>
> Which means the files which +tbxi attribute in the blessed directory.
>
> But efi only store the boot device (uuid), so it needs to use the
> blessed file to boot.
>
> So to distinguish these two situation, we can have too options for bless:
>
> bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]
>
> --bootinfo set the blessed directory plus +tbxi, while --bootefi set
> the blessed file, this way we could specify different boot files for
> openfirmware and efi, something like this:
>
> bless --bootinfo /grub.elf --bootefi grub.efi
The --botinfo and --bootefi in this case are independent. I don't see
why it would be stuffed in the same command. What about:
blessefi - change blessed file
blessofw - change blessed directory +tbxi
blessdir - change blessed directory
>
> --
> Bean
>
> gitgrub home: http://github.com/grub/grub/
> my fork page: http://github.com/bean123/grub/
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  7:58                 ` Michal Suchanek
@ 2009-08-29  8:07                   ` Vladimir 'phcoder' Serbinenko
  2009-08-29  8:10                   ` Bean
  1 sibling, 0 replies; 28+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-29  8:07 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, Aug 29, 2009 at 9:58 AM, Michal Suchanek<hramrach@centrum.cz> wrote:
> 2009/8/29 Bean <bean123ch@gmail.com>:
>> On Sat, Aug 29, 2009 at 2:27 PM, Vladimir 'phcoder'
>> Serbinenko<phcoder@gmail.com> wrote:
>>>> Actually, I think the correct handling is to first bless a boot
>>>> directory (storing the directory id in header), then bless a boot file
>>>> (add +tbxi attribute), that's why the bless command in OSX needs needs
>>>> both --folder and --file option.
>>> AFAIK --file has no effect for intel macs.
>>
>> Hi,
>>
>> After more testing, I believe the booting process works like this:
>>
>> One important difference between openfirmware and efi is that
>> openfirmware stores file path in nvram, while efi stores device path.
>> The default boot file for openfirmware is like this:
>>
>> device:\\+tbxi
>>
>> Which means the files which +tbxi attribute in the blessed directory.
>>
>> But efi only store the boot device (uuid), so it needs to use the
>> blessed file to boot.
>>
>> So to distinguish these two situation, we can have too options for bless:
>>
>> bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]
>>
>> --bootinfo set the blessed directory plus +tbxi, while --bootefi set
>> the blessed file, this way we could specify different boot files for
>> openfirmware and efi, something like this:
>>
>> bless --bootinfo /grub.elf --bootefi grub.efi
>>
>
> Wouldn't it be possible to do a check in bless that determines if the
> file is for openfirmware of efi?
>
Actually it's even easy. EFI files are exes (Mark Zbykowsky or some
fat binaries signatures) while OFW files are ELF AFAIR
> Thanks
>
> Michal
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  7:58                 ` Michal Suchanek
  2009-08-29  8:07                   ` Vladimir 'phcoder' Serbinenko
@ 2009-08-29  8:10                   ` Bean
  2009-08-29  8:43                     ` Michal Suchanek
  1 sibling, 1 reply; 28+ messages in thread
From: Bean @ 2009-08-29  8:10 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, Aug 29, 2009 at 3:58 PM, Michal Suchanek<hramrach@centrum.cz> wrote:
> 2009/8/29 Bean <bean123ch@gmail.com>:
>> On Sat, Aug 29, 2009 at 2:27 PM, Vladimir 'phcoder'
>> Serbinenko<phcoder@gmail.com> wrote:
>>>> Actually, I think the correct handling is to first bless a boot
>>>> directory (storing the directory id in header), then bless a boot file
>>>> (add +tbxi attribute), that's why the bless command in OSX needs needs
>>>> both --folder and --file option.
>>> AFAIK --file has no effect for intel macs.
>>
>> Hi,
>>
>> After more testing, I believe the booting process works like this:
>>
>> One important difference between openfirmware and efi is that
>> openfirmware stores file path in nvram, while efi stores device path.
>> The default boot file for openfirmware is like this:
>>
>> device:\\+tbxi
>>
>> Which means the files which +tbxi attribute in the blessed directory.
>>
>> But efi only store the boot device (uuid), so it needs to use the
>> blessed file to boot.
>>
>> So to distinguish these two situation, we can have too options for bless:
>>
>> bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]
>>
>> --bootinfo set the blessed directory plus +tbxi, while --bootefi set
>> the blessed file, this way we could specify different boot files for
>> openfirmware and efi, something like this:
>>
>> bless --bootinfo /grub.elf --bootefi grub.efi
>>
>
> Wouldn't it be possible to do a check in bless that determines if the
> file is for openfirmware of efi?

Hi,

I think it would be better to specify the type explicitly, as there
are multiple formats supports by both platform. OpenFirmware support
bootinfo, xcoff and elf, while efi support i386-efi, x86_64-efi and
fat binary.

-- 
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] bless command
  2009-08-29  8:10                   ` Bean
@ 2009-08-29  8:43                     ` Michal Suchanek
  0 siblings, 0 replies; 28+ messages in thread
From: Michal Suchanek @ 2009-08-29  8:43 UTC (permalink / raw)
  To: The development of GRUB 2

2009/8/29 Bean <bean123ch@gmail.com>:
> On Sat, Aug 29, 2009 at 3:58 PM, Michal Suchanek<hramrach@centrum.cz> wrote:
>> 2009/8/29 Bean <bean123ch@gmail.com>:
>>> On Sat, Aug 29, 2009 at 2:27 PM, Vladimir 'phcoder'
>>> Serbinenko<phcoder@gmail.com> wrote:
>>>>> Actually, I think the correct handling is to first bless a boot
>>>>> directory (storing the directory id in header), then bless a boot file
>>>>> (add +tbxi attribute), that's why the bless command in OSX needs needs
>>>>> both --folder and --file option.
>>>> AFAIK --file has no effect for intel macs.
>>>
>>> Hi,
>>>
>>> After more testing, I believe the booting process works like this:
>>>
>>> One important difference between openfirmware and efi is that
>>> openfirmware stores file path in nvram, while efi stores device path.
>>> The default boot file for openfirmware is like this:
>>>
>>> device:\\+tbxi
>>>
>>> Which means the files which +tbxi attribute in the blessed directory.
>>>
>>> But efi only store the boot device (uuid), so it needs to use the
>>> blessed file to boot.
>>>
>>> So to distinguish these two situation, we can have too options for bless:
>>>
>>> bless [--bootinfo PATH_TO_BOOTX] [[--bootefi PATH_TO_BOOTEFI]
>>>
>>> --bootinfo set the blessed directory plus +tbxi, while --bootefi set
>>> the blessed file, this way we could specify different boot files for
>>> openfirmware and efi, something like this:
>>>
>>> bless --bootinfo /grub.elf --bootefi grub.efi
>>>
>>
>> Wouldn't it be possible to do a check in bless that determines if the
>> file is for openfirmware of efi?
>
> Hi,
>
> I think it would be better to specify the type explicitly, as there
> are multiple formats supports by both platform. OpenFirmware support
> bootinfo, xcoff and elf, while efi support i386-efi, x86_64-efi and
> fat binary.
>

They are multiple but different. I guess automatic detection would be
nice to have but writing detection for multiple formats might take
some time so it would be better to get a bless command without
detection initially and possibly add detection later.

Thanks

Michal



^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2009-08-29  8:43 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-18 18:59 [PATCH] bless command Vladimir Serbinenko
2009-04-18 19:00 ` Vladimir Serbinenko
2009-04-18 19:22 ` Isaac Dupree
2009-04-19  4:51 ` Peter Cros
2009-04-19 10:50   ` Vladimir Serbinenko
2009-04-19 11:25     ` Drew Rosen
2009-04-19 13:26     ` Peter Cros
2009-04-19 14:14       ` Vladimir Serbinenko
2009-04-19 15:30         ` Peter Cros
2009-04-19 20:05           ` Vladimir Serbinenko
2009-04-20  9:17             ` Peter Cros
2009-04-20 11:52               ` Vladimir Serbinenko
2009-04-21  2:28                 ` Peter Cros
2009-08-28 22:59         ` Michal Suchanek
2009-08-29  3:48           ` Bean
2009-08-29  6:27             ` Vladimir 'phcoder' Serbinenko
2009-08-29  7:53               ` Bean
2009-08-29  7:58                 ` Michal Suchanek
2009-08-29  8:07                   ` Vladimir 'phcoder' Serbinenko
2009-08-29  8:10                   ` Bean
2009-08-29  8:43                     ` Michal Suchanek
2009-08-29  8:06                 ` Vladimir 'phcoder' Serbinenko
2009-06-19  6:08 ` Peter Cros
2009-06-19 11:53   ` Vladimir 'phcoder' Serbinenko
2009-06-19 16:15     ` Pavel Roskin
2009-06-19 16:24       ` Vladimir 'phcoder' Serbinenko
2009-06-21 11:05     ` Robert Millan
2009-08-28 15:19       ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.