[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Host filesystem access
From: |
Marco Gerards |
Subject: |
Host filesystem access |
Date: |
Thu, 17 May 2007 23:28:12 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
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 <address@hidden>
* 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
+ };
+
+
+
+void
+grub_hostfs_init (void)
+{
+ grub_fs_register (&grub_hostfs_fs);
+}
+
+void
+grub_hostfs_fini (void)
+{
+ grub_fs_unregister (&grub_hostfs_fs);
+}
- Host filesystem access,
Marco Gerards <=