1
/* hostfs.c - Dummy filesystem to provide access to the hosts filesystem */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2007 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <grub/file.h>
22
#include <grub/disk.h>
23
#include <grub/misc.h>
29
grub_hostfs_dir (grub_device_t device, const char *path,
30
int (*hook) (const char *filename, int dir))
34
/* Check if the disk is our dummy disk. */
35
if (grub_strcmp (device->disk->name, "host"))
36
return grub_error (GRUB_ERR_BAD_FS, "not a hostfs");
40
return grub_error (GRUB_ERR_BAD_FILENAME,
41
"can't open the hostfs directory `%s'", path);
51
hook (de->d_name, de->d_type == DT_DIR);
59
/* Open a file named NAME and initialize FILE. */
61
grub_hostfs_open (struct grub_file *file, const char *name)
65
f = fopen (name, "r");
67
return grub_error (GRUB_ERR_BAD_FILENAME,
68
"can't open `%s'", name);
71
fseek (f, 0, SEEK_END);
72
file->size = ftell (f);
73
fseek (f, 0, SEEK_SET);
79
grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len)
83
f = (FILE *) file->data;
84
int s= fread (buf, 1, len, f);
90
grub_hostfs_close (grub_file_t file)
94
f = (FILE *) file->data;
101
grub_hostfs_label (grub_device_t device __attribute ((unused)),
102
char **label __attribute ((unused)))
104
return GRUB_ERR_NONE;
107
static struct grub_fs grub_hostfs_fs =
110
.dir = grub_hostfs_dir,
111
.open = grub_hostfs_open,
112
.read = grub_hostfs_read,
113
.close = grub_hostfs_close,
114
.label = grub_hostfs_label,
121
grub_hostfs_init (void)
123
grub_fs_register (&grub_hostfs_fs);
127
grub_hostfs_fini (void)
129
grub_fs_unregister (&grub_hostfs_fs);