* Host filesystem access
@ 2007-05-17 21:28 Marco Gerards
2007-05-18 6:48 ` Robert Millan
2007-08-02 17:27 ` Marco Gerards
0 siblings, 2 replies; 8+ messages in thread
From: Marco Gerards @ 2007-05-17 21:28 UTC (permalink / raw)
To: grub-devel
Hi,
Here is a patch to make it possible to access the host filesystem from
grub-emu. This is especially useful for debugging purposes and will
make my life easier ;-).
This also adds a dummy disk which is used to give the host filesystem
a name. It is not particularly clean, but adding this as a network is
even worse. This can be used to access host filesystems on other
systems as well.
I will commit this after the weekend, if no-one objects.
--
Marco
2007-05-17 Marco Gerards <marco@gnu.org>
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `disk/host.c' and
`util/hostfs.c'.
* disk/host.c: New file.
* util/hostfs.c: Likewise.
* fs/hfsplus.c (grub_hfsplus_mount): When reading out of disk,
return `GRUB_ERR_BAD_FS'.
* fs/sfs.c (grub_sfs_mount): Likewise.
* fs/xfs.c (grub_xfs_mount): Likewise.
* include/grub/disk.h (enum grub_disk_dev_id): Add
`GRUB_DISK_DEVICE_HOST_ID'.
* util/grub-emu.c (main): Initialize and de-initialize hostfs.
Index: conf/i386-pc.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.77
diff -u -p -u -p -r1.77 i386-pc.rmk
--- conf/i386-pc.rmk 16 May 2007 15:19:38 -0000 1.77
+++ conf/i386-pc.rmk 17 May 2007 21:17:02 -0000
@@ -90,7 +90,7 @@ grub_emu_SOURCES = commands/boot.c comma
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
- disk/loopback.c disk/raid.c disk/lvm.c \
+ disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \
fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c \
io/gzio.c \
@@ -104,7 +104,7 @@ grub_emu_SOURCES = commands/boot.c comma
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
- util/console.c util/grub-emu.c util/misc.c \
+ util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
Index: disk/host.c
===================================================================
RCS file: disk/host.c
diff -N disk/host.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ disk/host.c 17 May 2007 21:17:02 -0000
@@ -0,0 +1,94 @@
+/* host.c - Dummy disk driver to provide access to the hosts filesystem */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* When using the disk, make a reference to this module. Otherwise
+ the user will end up with a useless module :-). */
+
+#include <grub/dl.h>
+#include <grub/disk.h>
+
+int grub_disk_host_i_want_a_reference;
+
+static int
+grub_host_iterate (int (*hook) (const char *name))
+{
+ if (hook ("host"))
+ return 1;
+ return 0;
+}
+
+static grub_err_t
+grub_host_open (const char *name __attribute((unused)), grub_disk_t disk)
+{
+ disk->total_sectors = 0;
+ disk->id = (int) "host";
+
+ disk->has_partitions = 0;
+ disk->data = 0;
+
+ return GRUB_ERR_NONE;
+}
+
+static void
+grub_host_close (grub_disk_t disk __attribute((unused)))
+{
+}
+
+static grub_err_t
+grub_host_read (grub_disk_t disk __attribute((unused)),
+ grub_disk_addr_t sector __attribute((unused)),
+ grub_size_t size __attribute((unused)),
+ char *buf __attribute((unused)))
+{
+ return GRUB_ERR_OUT_OF_RANGE;
+}
+
+static grub_err_t
+grub_host_write (grub_disk_t disk __attribute ((unused)),
+ grub_disk_addr_t sector __attribute ((unused)),
+ grub_size_t size __attribute ((unused)),
+ const char *buf __attribute ((unused)))
+{
+ return GRUB_ERR_OUT_OF_RANGE;
+}
+
+static struct grub_disk_dev grub_host_dev =
+ {
+ /* The only important line in this file :-) */
+ .name = "host",
+ .id = GRUB_DISK_DEVICE_HOST_ID,
+ .iterate = grub_host_iterate,
+ .open = grub_host_open,
+ .close = grub_host_close,
+ .read = grub_host_read,
+ .write = grub_host_write,
+ .next = 0
+ };
+
+GRUB_MOD_INIT(host)
+{
+ (void) mod; /* To stop warning. */
+ grub_disk_dev_register (&grub_host_dev);
+}
+
+GRUB_MOD_FINI(host)
+{
+ grub_disk_dev_unregister (&grub_host_dev);
+}
Index: fs/affs.c
===================================================================
RCS file: /sources/grub/grub2/fs/affs.c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 affs.c
--- fs/affs.c 4 Jun 2006 15:56:54 -0000 1.4
+++ fs/affs.c 17 May 2007 21:17:02 -0000
@@ -249,6 +249,9 @@ grub_affs_mount (grub_disk_t disk)
return data;
fail:
+ if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
+ grub_error (GRUB_ERR_BAD_FS, "not a affs filesystem");
+
grub_free (data);
grub_free (rootblock);
return 0;
Index: fs/hfsplus.c
===================================================================
RCS file: /sources/grub/grub2/fs/hfsplus.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 hfsplus.c
--- fs/hfsplus.c 4 Jun 2006 15:56:54 -0000 1.8
+++ fs/hfsplus.c 17 May 2007 21:17:02 -0000
@@ -482,6 +482,10 @@ grub_hfsplus_mount (grub_disk_t disk)
return data;
fail:
+
+ if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
+ grub_error (GRUB_ERR_BAD_FS, "not a hfsplus filesystem");
+
grub_free (data);
return 0;
}
Index: fs/sfs.c
===================================================================
RCS file: /sources/grub/grub2/fs/sfs.c,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 sfs.c
--- fs/sfs.c 4 Jun 2006 15:56:54 -0000 1.5
+++ fs/sfs.c 17 May 2007 21:17:02 -0000
@@ -317,6 +317,9 @@ grub_sfs_mount (grub_disk_t disk)
return data;
fail:
+ if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
+ grub_error (GRUB_ERR_BAD_FS, "not a sfs filesystem");
+
grub_free (data);
grub_free (rootobjc_data);
return 0;
Index: fs/xfs.c
===================================================================
RCS file: /sources/grub/grub2/fs/xfs.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 xfs.c
--- fs/xfs.c 4 Jun 2006 15:56:54 -0000 1.8
+++ fs/xfs.c 17 May 2007 21:17:02 -0000
@@ -515,6 +515,9 @@ grub_xfs_mount (grub_disk_t disk)
return data;
fail:
+ if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
+ grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem");
+
grub_free (data);
return 0;
Index: include/grub/disk.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/disk.h,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 disk.h
--- include/grub/disk.h 10 Nov 2006 23:31:54 -0000 1.12
+++ include/grub/disk.h 17 May 2007 21:17:02 -0000
@@ -34,7 +34,8 @@ enum grub_disk_dev_id
GRUB_DISK_DEVICE_LOOPBACK_ID,
GRUB_DISK_DEVICE_EFIDISK_ID,
GRUB_DISK_DEVICE_RAID_ID,
- GRUB_DISK_DEVICE_LVM_ID
+ GRUB_DISK_DEVICE_LVM_ID,
+ GRUB_DISK_DEVICE_HOST_ID
};
struct grub_disk;
Index: util/grub-emu.c
===================================================================
RCS file: /sources/grub/grub2/util/grub-emu.c,v
retrieving revision 1.34
diff -u -p -u -p -r1.34 grub-emu.c
--- util/grub-emu.c 16 May 2007 21:38:44 -0000 1.34
+++ util/grub-emu.c 17 May 2007 21:17:02 -0000
@@ -185,6 +185,8 @@ main (int argc, char *argv[])
/* XXX: This is a bit unportable. */
grub_util_biosdisk_init (args.dev_map);
+ grub_hostfs_init ();
+
grub_init_all ();
/* Make sure that there is a root device. */
@@ -210,6 +212,8 @@ main (int argc, char *argv[])
grub_fini_all ();
+ grub_hostfs_fini ();
+
grub_machine_fini ();
return 0;
Index: util/hostfs.c
===================================================================
RCS file: util/hostfs.c
diff -N util/hostfs.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ util/hostfs.c 17 May 2007 21:17:02 -0000
@@ -0,0 +1,131 @@
+/* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/fs.h>
+#include <grub/file.h>
+#include <grub/disk.h>
+#include <grub/misc.h>
+
+#include <dirent.h>
+#include <stdio.h>
+
+static grub_err_t
+grub_hostfs_dir (grub_device_t device, const char *path,
+ int (*hook) (const char *filename, int dir))
+{
+ DIR *dir;
+
+ /* Check if the disk is our dummy disk. */
+ if (grub_strcmp (device->disk->name, "host"))
+ return grub_error (GRUB_ERR_BAD_FS, "not a hostfs");
+
+ dir = opendir (path);
+ if (! dir)
+ return grub_error (GRUB_ERR_BAD_FILENAME,
+ "can't open the hostfs directory `%s'", path);
+
+ while (1)
+ {
+ struct dirent *de;
+
+ de = readdir (dir);
+ if (! de)
+ break;
+
+ hook (de->d_name, de->d_type == DT_DIR);
+ }
+
+ closedir (dir);
+
+ return GRUB_ERR_NONE;
+}
+
+/* Open a file named NAME and initialize FILE. */
+static grub_err_t
+grub_hostfs_open (struct grub_file *file, const char *name)
+{
+ FILE *f;
+
+ f = fopen (name, "r");
+ if (! f)
+ return grub_error (GRUB_ERR_BAD_FILENAME,
+ "can't open `%s'", name);
+ file->data = f;
+
+ fseek (f, 0, SEEK_END);
+ file->size = ftell (f);
+ fseek (f, 0, SEEK_SET);
+
+ return GRUB_ERR_NONE;
+}
+
+static grub_ssize_t
+grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len)
+{
+ FILE *f;
+
+ f = (FILE *) file->data;
+ int s= fread (buf, 1, len, f);
+
+ return s;
+}
+
+static grub_err_t
+grub_hostfs_close (grub_file_t file)
+{
+ FILE *f;
+
+ f = (FILE *) file->data;
+ fclose (f);
+
+ return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_hostfs_label (grub_device_t device __attribute ((unused)),
+ char **label __attribute ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+
+static struct grub_fs grub_hostfs_fs =
+ {
+ .name = "hostfs",
+ .dir = grub_hostfs_dir,
+ .open = grub_hostfs_open,
+ .read = grub_hostfs_read,
+ .close = grub_hostfs_close,
+ .label = grub_hostfs_label,
+ .next = 0
+ };
+
+\f
+
+void
+grub_hostfs_init (void)
+{
+ grub_fs_register (&grub_hostfs_fs);
+}
+
+void
+grub_hostfs_fini (void)
+{
+ grub_fs_unregister (&grub_hostfs_fs);
+}
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Host filesystem access
2007-05-17 21:28 Host filesystem access Marco Gerards
@ 2007-05-18 6:48 ` Robert Millan
2007-05-18 6:59 ` Marco Gerards
2007-05-18 11:35 ` Bruno Wolff III
2007-08-02 17:27 ` Marco Gerards
1 sibling, 2 replies; 8+ messages in thread
From: Robert Millan @ 2007-05-18 6:48 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, May 17, 2007 at 11:28:12PM +0200, Marco Gerards wrote:
> + grub_error (GRUB_ERR_BAD_FS, "not a affs filesystem");
> + grub_error (GRUB_ERR_BAD_FS, "not a hfsplus filesystem");
> + grub_error (GRUB_ERR_BAD_FS, "not a sfs filesystem");
I think these should be "an" (but not sure about all them, any native English
speaker around?).
> diff -u -p -u -p -r1.34 grub-emu.c
> --- util/grub-emu.c 16 May 2007 21:38:44 -0000 1.34
> +++ util/grub-emu.c 17 May 2007 21:17:02 -0000
> @@ -185,6 +185,8 @@ main (int argc, char *argv[])
> /* XXX: This is a bit unportable. */
> grub_util_biosdisk_init (args.dev_map);
>
> + grub_hostfs_init ();
> +
> grub_init_all ();
I find it counter-intuitive that grub_init_all doesn't imply grub_hostfs_init;
if there's a design reason for this, maybe the function should be renamed ?
(how about grub_filesystems_init + grub_partmaps_init ?)
--
Robert Millan
My spam trap is honeypot@aybabtu.com. Note: this address is only intended
for spam harvesters. Writing to it will get you added to my black list.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-18 6:48 ` Robert Millan
@ 2007-05-18 6:59 ` Marco Gerards
2007-05-18 16:08 ` Robert Millan
2007-05-18 11:35 ` Bruno Wolff III
1 sibling, 1 reply; 8+ messages in thread
From: Marco Gerards @ 2007-05-18 6:59 UTC (permalink / raw)
To: The development of GRUB 2
Robert Millan <rmh@aybabtu.com> writes:
> On Thu, May 17, 2007 at 11:28:12PM +0200, Marco Gerards wrote:
>> + grub_error (GRUB_ERR_BAD_FS, "not a affs filesystem");
>> + grub_error (GRUB_ERR_BAD_FS, "not a hfsplus filesystem");
>> + grub_error (GRUB_ERR_BAD_FS, "not a sfs filesystem");
>
> I think these should be "an" (but not sure about all them, any native English
> speaker around?).
Ehm, yes, I think so :-)
>> diff -u -p -u -p -r1.34 grub-emu.c
>> --- util/grub-emu.c 16 May 2007 21:38:44 -0000 1.34
>> +++ util/grub-emu.c 17 May 2007 21:17:02 -0000
>> @@ -185,6 +185,8 @@ main (int argc, char *argv[])
>> /* XXX: This is a bit unportable. */
>> grub_util_biosdisk_init (args.dev_map);
>>
>> + grub_hostfs_init ();
>> +
>> grub_init_all ();
>
> I find it counter-intuitive that grub_init_all doesn't imply grub_hostfs_init;
> if there's a design reason for this, maybe the function should be renamed ?
> (how about grub_filesystems_init + grub_partmaps_init ?)
The reason why I did this is that hostfs is not a module.
grub_init_all initializes all modules, there is no way you can split
this up in an easy way.
The main thing I had some doubts on was if the dummy disk driver is
way too ugly or not.
--
Marco
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-18 6:59 ` Marco Gerards
@ 2007-05-18 16:08 ` Robert Millan
0 siblings, 0 replies; 8+ messages in thread
From: Robert Millan @ 2007-05-18 16:08 UTC (permalink / raw)
To: The development of GRUB 2
On Fri, May 18, 2007 at 08:59:45AM +0200, Marco Gerards wrote:
> >
> > I find it counter-intuitive that grub_init_all doesn't imply grub_hostfs_init;
> > if there's a design reason for this, maybe the function should be renamed ?
> > (how about grub_filesystems_init + grub_partmaps_init ?)
>
> The reason why I did this is that hostfs is not a module.
> grub_init_all initializes all modules, there is no way you can split
> this up in an easy way.
But it could be renamed to grub_init_all_modules :-)
--
Robert Millan
My spam trap is honeypot@aybabtu.com. Note: this address is only intended
for spam harvesters. Writing to it will get you added to my black list.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-18 6:48 ` Robert Millan
2007-05-18 6:59 ` Marco Gerards
@ 2007-05-18 11:35 ` Bruno Wolff III
2007-05-18 14:08 ` Jan C. Kleinsorge
1 sibling, 1 reply; 8+ messages in thread
From: Bruno Wolff III @ 2007-05-18 11:35 UTC (permalink / raw)
To: The development of GRUB 2
On Fri, May 18, 2007 at 08:48:37 +0200,
Robert Millan <rmh@aybabtu.com> wrote:
> On Thu, May 17, 2007 at 11:28:12PM +0200, Marco Gerards wrote:
> > + grub_error (GRUB_ERR_BAD_FS, "not a affs filesystem");
> > + grub_error (GRUB_ERR_BAD_FS, "not a hfsplus filesystem");
> > + grub_error (GRUB_ERR_BAD_FS, "not a sfs filesystem");
>
> I think these should be "an" (but not sure about all them, any native English
> speaker around?).
If the file system types are read as acronyms then they will start with a
vowel sound and it sounds more natural to use 'an'. I am not sure what the
offical grammer rule is though.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-18 11:35 ` Bruno Wolff III
@ 2007-05-18 14:08 ` Jan C. Kleinsorge
2007-05-18 16:07 ` Robert Millan
0 siblings, 1 reply; 8+ messages in thread
From: Jan C. Kleinsorge @ 2007-05-18 14:08 UTC (permalink / raw)
To: The development of GRUB 2
"affs filesystem" is filesystem doubled anyway. How about ".. filesystem
is not of type hffs"?
Jan
Bruno Wolff III wrote:
> On Fri, May 18, 2007 at 08:48:37 +0200,
> Robert Millan <rmh@aybabtu.com> wrote:
>
>> On Thu, May 17, 2007 at 11:28:12PM +0200, Marco Gerards wrote:
>>
>>> + grub_error (GRUB_ERR_BAD_FS, "not a affs filesystem");
>>> + grub_error (GRUB_ERR_BAD_FS, "not a hfsplus filesystem");
>>> + grub_error (GRUB_ERR_BAD_FS, "not a sfs filesystem");
>>>
>> I think these should be "an" (but not sure about all them, any native English
>> speaker around?).
>>
>
> If the file system types are read as acronyms then they will start with a
> vowel sound and it sounds more natural to use 'an'. I am not sure what the
> offical grammer rule is though.
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-18 14:08 ` Jan C. Kleinsorge
@ 2007-05-18 16:07 ` Robert Millan
0 siblings, 0 replies; 8+ messages in thread
From: Robert Millan @ 2007-05-18 16:07 UTC (permalink / raw)
To: The development of GRUB 2
On Fri, May 18, 2007 at 04:08:38PM +0200, Jan C. Kleinsorge wrote:
> "affs filesystem" is filesystem doubled anyway. How about ".. filesystem
> is not of type hffs"?
Some acronyms appear to be designed on purpose to produce RAS syndrome... (GPT
comes to mind here).
Maybe we should just accept it ;-)
--
Robert Millan
My spam trap is honeypot@aybabtu.com. Note: this address is only intended
for spam harvesters. Writing to it will get you added to my black list.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Host filesystem access
2007-05-17 21:28 Host filesystem access Marco Gerards
2007-05-18 6:48 ` Robert Millan
@ 2007-08-02 17:27 ` Marco Gerards
1 sibling, 0 replies; 8+ messages in thread
From: Marco Gerards @ 2007-08-02 17:27 UTC (permalink / raw)
To: The development of GRUB 2
Marco Gerards <mgerards@xs4all.nl> writes:
Hi,
> Here is a patch to make it possible to access the host filesystem from
> grub-emu. This is especially useful for debugging purposes and will
> make my life easier ;-).
>
> This also adds a dummy disk which is used to give the host filesystem
> a name. It is not particularly clean, but adding this as a network is
> even worse. This can be used to access host filesystems on other
> systems as well.
>
> I will commit this after the weekend, if no-one objects.
Actually, I have completely forgotten about this. It's has been
committed now.
--
Marco
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-08-02 17:25 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-17 21:28 Host filesystem access Marco Gerards
2007-05-18 6:48 ` Robert Millan
2007-05-18 6:59 ` Marco Gerards
2007-05-18 16:08 ` Robert Millan
2007-05-18 11:35 ` Bruno Wolff III
2007-05-18 14:08 ` Jan C. Kleinsorge
2007-05-18 16:07 ` Robert Millan
2007-08-02 17:27 ` Marco Gerards
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.