1 /* Interface between GRUB's fs drivers and application code */
3 #include <console/console.h>
11 void (*disk_read_hook) (int, int, int);
12 void (*disk_read_func) (int, int, int);
13 char FSYS_BUF[FSYS_BUFLEN];
18 int (*mount_func) (void);
19 int (*read_func) (char *buf, int len);
20 int (*dir_func) (char *dirname);
21 void (*close_func) (void);
22 int (*embed_func) (int *start_sector, int needed_sectors);
25 struct fsys_entry fsys_table[] = {
26 # if CONFIG_FS_FAT == 1
27 {"fat", fat_mount, fat_read, fat_dir, 0, 0},
29 # if CONFIG_FS_EXT2 == 1
30 {"ext2fs", ext2fs_mount, ext2fs_read, ext2fs_dir, 0, 0},
32 # if CONFIG_FS_ISO9660 == 1
33 {"iso9660", iso9660_mount, iso9660_read, iso9660_dir, 0, 0},
37 /* NULLFS is used to read images from raw device */
38 static int nullfs_dir(char *name)
43 printk_debug("can't have a named file\n");
47 dev_size = (uint64_t) part_length << 9;
48 /* GRUB code doesn't like 2GB or bigger files */
49 if (dev_size > 0x7fffffff)
50 dev_size = 0x7fffffff;
55 static int nullfs_read(char *buf, int len)
57 if (devread(filepos>>9, filepos&0x1ff, len, buf)) {
64 static struct fsys_entry nullfs =
65 {"nullfs", 0, nullfs_read, nullfs_dir, 0, 0};
67 static struct fsys_entry *fsys;
73 for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) {
74 if (fsys_table[i].mount_func()) {
75 fsys = &fsys_table[i];
76 printk_info("Mounted %s\n", fsys->name);
81 printk_info("Unknown filesystem type\n");
85 int file_open(const char *filename)
93 path = strchr(filename, ':');
95 len = path - filename;
97 dev = malloc(len + 1);
98 memcpy(dev, filename, len);
101 /* No colon is given. Is this device or filename? */
102 if (filename[0] == '/') {
103 /* Anything starts with '/' must be a filename */
107 dev = strdup(filename);
111 printk_debug("dev=%s, path=%s\n", dev, path);
114 if (!devopen(dev, &reopen)) {
123 if (!fsys || fsys==&nullfs) {
129 printk_info("No filename is given\n");
137 if (!fsys->dir_func((char *) path)) {
138 printk_info("File not found\n");
148 int file_read(void *buf, unsigned long len)
150 if (filepos < 0 || filepos > filemax)
152 if (len < 0 || len > filemax-filepos)
153 len = filemax - filepos;
155 return fsys->read_func(buf, len);
158 int file_seek(unsigned long offset)
164 unsigned long file_pos(void)
169 unsigned long file_size(void)
174 void file_close(void)