[OpenBIOS] [commit] r815 - in trunk/openbios-devel: fs/grubfs packages
repository service
svn at openbios.org
Sun Jul 4 15:37:00 CEST 2010
Author: mcayland
Date: Sun Jul 4 15:37:00 2010
New Revision: 815
URL: http://tracker.coreboot.org/trac/openbios/changeset/815
Log:
Move the grubfs filesystem handler into its own new package /packages/grubfs-files. This is the last of the filesystems to be
migrated to a standard package. Note that with this in place /packages/misc-files is obsolete (it is currently disabled) and
very likely to be removed.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
Modified:
trunk/openbios-devel/fs/grubfs/grubfs_fs.c
trunk/openbios-devel/packages/init.c
trunk/openbios-devel/packages/misc-files.c
trunk/openbios-devel/packages/packages.h
Modified: trunk/openbios-devel/fs/grubfs/grubfs_fs.c
==============================================================================
--- trunk/openbios-devel/fs/grubfs/grubfs_fs.c Sun Jul 4 12:56:05 2010 (r814)
+++ trunk/openbios-devel/fs/grubfs/grubfs_fs.c Sun Jul 4 15:37:00 2010 (r815)
@@ -1,10 +1,11 @@
/*
- * <grubfs_fs.c>
+ * /packages/grubfs-files
*
* grub vfs
*
* Copyright (C) 2004 Stefan Reinauer
* Copyright (C) 2004 Samuel Rydh
+ * Copyright (C) 2010 Mark Cave-Ayland
*
* inspired by HFS code from Samuel Rydh
*
@@ -22,6 +23,8 @@
#include "libc/diskio.h"
#include "libc/vsprintf.h"
+extern void grubfs_init( void );
+
/************************************************************************/
/* grub GLOBALS (horrible... but difficult to fix) */
/************************************************************************/
@@ -91,49 +94,180 @@
unsigned long pos;
unsigned long len;
const char *path;
- const fs_ops_t *fs;
} grubfile_t;
typedef struct {
const struct fsys_entry *fsys;
grubfile_t *fd;
- int dev_fd;
- llong offset; /* Offset added onto each device read; should only ever be non-zero
+ int dev_fd;
+ llong offset; /* Offset added onto each device read; should only ever be non-zero
when probing a partition for a filesystem */
} grubfs_t;
+typedef struct {
+ grubfs_t *gfs;
+} grubfs_info_t;
+
+/* Static block and global pointer required for I/O glue */
static grubfs_t dummy_fs;
-static grubfs_t *curfs=&dummy_fs;
+static grubfs_t *curfs = &dummy_fs;
+
+DECLARE_NODE( grubfs, 0, sizeof(grubfs_info_t), "+/packages/grubfs-files" );
+
+
+/************************************************************************/
+/* I/O glue (called by grub source) */
+/************************************************************************/
+
+int
+devread( unsigned long sector, unsigned long byte_offset,
+ unsigned long byte_len, void *buf )
+{
+ llong offs = (llong)sector * 512 + byte_offset;
+
+#ifdef CONFIG_DEBUG_FS
+ //printk("devread s=%x buf=%x, fd=%x\n",sector, buf, curfs->dev_fd);
+#endif
+
+ if( !curfs ) {
+#ifdef CONFIG_DEBUG_FS
+ printk("devread: fsys == NULL!\n");
+#endif
+ return -1;
+ }
+
+ if( seek_io(curfs->dev_fd, offs + curfs->offset) ) {
+#ifdef CONFIG_DEBUG_FS
+ printk("seek failure\n");
+#endif
+ return -1;
+ }
+ return (read_io(curfs->dev_fd, buf, byte_len) == byte_len) ? 1:0;
+}
+
+int
+file_read( void *buf, unsigned long len )
+{
+ if (filepos < 0 || filepos > filemax)
+ filepos = filemax;
+ if (len > filemax-filepos)
+ len = filemax - filepos;
+ errnum = 0;
+ return curfs->fsys->read_func( buf, len );
+}
+
/************************************************************************/
-/* file/fs ops */
+/* Standard package methods */
/************************************************************************/
+/* ( -- success? ) */
+static void
+grubfs_files_open( grubfs_info_t *mi )
+{
+ int fd, i;
+ char *path = my_args_copy();
+ char *s;
+
+ fd = open_ih( my_parent() );
+ if ( fd == -1 ) {
+ free( path );
+ RET( 0 );
+ }
+
+ mi->gfs = &dummy_fs;
+
+ for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) {
+#ifdef CONFIG_DEBUG_FS
+ printk("Trying %s\n", fsys_table[i].name);
+#endif
+ if (fsys_table[i].mount_func()) {
+ const fsys_entry_t *fsys = &fsys_table[i];
+#ifdef CONFIG_DEBUG_FS
+ printk("Mounted %s\n", fsys->name);
+#endif
+ mi->gfs = malloc(sizeof(grubfs_t));
+ mi->gfs->fsys = fsys;
+ mi->gfs->dev_fd = fd;
+ mi->gfs->offset = 0;
+
+ s = path;
+ while (*s) {
+ if(*s=='\\') *s='/';
+ s++;
+ }
+#ifdef CONFIG_DEBUG_FS
+ printk("Path=%s\n",path);
+#endif
+ if (!mi->gfs->fsys->dir_func((char *) path)) {
+ forth_printf("File not found\n");
+ RET( 0 );
+ }
+
+ mi->gfs->fd = malloc(sizeof(grubfile_t));
+ mi->gfs->fd->pos = filepos;
+ mi->gfs->fd->len = filemax;
+ mi->gfs->fd->path = strdup(path);
+
+ RET( -1 );
+ }
+ }
+#ifdef CONFIG_DEBUG_FS
+ printk("Unknown filesystem type\n");
+#endif
+
+ RET( 0 );
+}
+
+/* ( -- ) */
static void
-grubfs_file_close( file_desc_t *fd )
+grubfs_files_close( grubfs_info_t *mi )
{
- grubfile_t *gf = (grubfile_t *)fd;
+ grubfile_t *gf = mi->gfs->fd;
if (gf->path)
free((void *)(gf->path));
- free(fd);
- filepos=0;
- filemax=0;
+ free(gf);
+
+ filepos = 0;
+ filemax = 0;
}
-static int
-grubfs_file_lseek( file_desc_t *fd, off_t offs, int whence )
+/* ( buf len -- actlen ) */
+static void
+grubfs_files_read( grubfs_info_t *mi )
{
- grubfile_t *file = (grubfile_t*)fd;
+ int count = POP();
+ char *buf = (char *)POP();
+
+ grubfile_t *file = mi->gfs->fd;
+ int ret;
+
+ filepos = file->pos;
+ filemax = file->len;
+
+ if (count > filemax - filepos)
+ count = filemax - filepos;
+
+ ret = mi->gfs->fsys->read_func(buf, count);
+
+ file->pos = filepos;
+
+ RET( ret );
+}
+
+/* ( pos.d -- status ) */
+static void
+grubfs_files_seek( grubfs_info_t *mi )
+{
+ llong pos = DPOP();
+ int offs = (int)pos;
+ int whence = SEEK_SET;
+
+ grubfile_t *file = mi->gfs->fd;
unsigned long newpos;
switch( whence ) {
- case SEEK_CUR:
- if (offs < 0 && (unsigned long) -offs > file->pos)
- newpos = 0;
- else
- newpos = file->pos + offs;
- break;
case SEEK_END:
if (offs < 0 && (unsigned long) -offs > file->len)
newpos = 0;
@@ -145,203 +279,107 @@
newpos = (offs < 0) ? 0 : offs;
break;
}
+
if (newpos > file->len)
newpos = file->len;
file->pos = newpos;
- return newpos;
-}
-
-static int
-grubfs_file_read( file_desc_t *fd, void *buf, size_t count )
-{
- grubfile_t *file = (grubfile_t*)fd;
- int ret;
-
- curfs = (grubfs_t *)file->fs->fs_data;
-
- filepos=file->pos;
- filemax=file->len;
-
- if (count > filemax - filepos)
- count = filemax - filepos;
-
- ret=curfs->fsys->read_func(buf, count);
-
- file->pos=filepos;
- return ret;
+ if (newpos)
+ RET( -1 );
+ else
+ RET( 0 );
}
-static char *
-get_path( file_desc_t *fd, char *retbuf, int len )
+/* ( addr -- size ) */
+static void
+grubfs_files_load( grubfs_info_t *mi )
{
- const char *path=((grubfile_t *)fd)->path;
+ char *buf = (char *)POP();
+ int count, ret;
- if(strlen(path) > len)
- return NULL;
+ grubfile_t *file = mi->gfs->fd;
+ count = file->len;
- strcpy( retbuf, path );
+ ret = mi->gfs->fsys->read_func(buf, count);
+ file->pos = filepos;
- return retbuf;
+ RET( ret );
}
-static file_desc_t *
-open_path( fs_ops_t *fs, const char *path )
+/* ( -- cstr ) */
+static void
+grubfs_files_get_path( grubfs_info_t *mi )
{
- grubfile_t *ret = NULL;
- char *s = (char *)path;
-
- curfs = (grubfs_t *)fs->fs_data;
+ grubfile_t *file = mi->gfs->fd;
+ const char *path = file->path;
- while(*s) {
- if(*s=='\\') *s='/';
- s++;
- }
-#ifdef CONFIG_DEBUG_FS
- printk("Path=%s\n",path);
-#endif
- if (!curfs->fsys->dir_func((char *) path)) {
- forth_printf("File not found\n");
- return NULL;
- }
- ret=malloc(sizeof(grubfile_t));
-
- ret->pos=filepos;
- ret->len=filemax;
- ret->path=strdup(path);
- ret->fs=fs;
-
- return (file_desc_t *)ret;
+ RET( (ucell) strdup(path) );
}
+/* ( -- cstr ) */
static void
-close_fs( fs_ops_t *fs )
+grubfs_files_get_fstype( grubfs_info_t *mi )
{
- free( fs->fs_data );
- fs->fs_data = NULL;
-
- /* callers responsibility to call free(fs) */
-}
+ grubfs_t *gfs = mi->gfs;
-static const char *
-grubfs_get_fstype( fs_ops_t *fs )
-{
- grubfs_t *gfs = (grubfs_t*)fs->fs_data;
- return gfs->fsys->name;
+ PUSH( (ucell)strdup(gfs->fsys->name) );
}
-static const fs_ops_t grubfs_ops = {
- .close_fs = close_fs,
- .open_path = open_path,
- .get_path = get_path,
- .close = grubfs_file_close,
- .read = grubfs_file_read,
- .lseek = grubfs_file_lseek,
-
- .get_fstype = grubfs_get_fstype,
-};
-/* mount */
-int
-fs_grubfs_open( int fd, fs_ops_t *fs )
+/* static method, ( pos.d ih -- flag? ) */
+static void
+grubfs_files_probe( grubfs_info_t *dummy )
{
- grubfs_t *gfs;
+ ihandle_t ih = POP_ih();
+ llong offs = DPOP();
int i;
- curfs=&dummy_fs;
-
- curfs->dev_fd = fd;
- curfs->offset = 0;
+ curfs->dev_fd = open_ih(ih);
+ curfs->offset = offs;
for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) {
#ifdef CONFIG_DEBUG_FS
- printk("Trying %s\n", fsys_table[i].name);
+ printk("Probing for %s\n", fsys_table[i].name);
#endif
if (fsys_table[i].mount_func()) {
- const fsys_entry_t *fsys = &fsys_table[i];
-#ifdef CONFIG_DEBUG_FS
- printk("Mounted %s\n", fsys->name);
-#endif
-
- gfs = malloc(sizeof(*gfs));
- gfs->fsys = fsys;
- gfs->dev_fd = fd;
-
- *fs=grubfs_ops;
- fs->fs_data = (void*)gfs;
- return 0;
+ RET( -1 );
}
}
+
#ifdef CONFIG_DEBUG_FS
printk("Unknown filesystem type\n");
#endif
- return -1;
-}
-/* Probe for filesystem (with partition offset); returns 0 on success */
-int
-fs_grubfs_probe( int fd, llong offs )
-{
- int i;
-
- curfs = &dummy_fs;
-
- curfs->dev_fd = fd;
- curfs->offset = offs;
+ close_io(curfs->dev_fd);
- for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) {
-#ifdef CONFIG_DEBUG_FS
- printk("Probing for %s\n", fsys_table[i].name);
-#endif
- if (fsys_table[i].mount_func())
- return 0;
- }
-
-#ifdef CONFIG_DEBUG_FS
- printk("Unknown filesystem type\n");
-#endif
- return -1;
+ RET ( 0 );
}
-/************************************************************************/
-/* I/O glue (called by grub source) */
-/************************************************************************/
-
-int
-devread( unsigned long sector, unsigned long byte_offset,
- unsigned long byte_len, void *buf )
+static void
+grubfs_initializer( grubfs_info_t *dummy )
{
- llong offs = (llong)sector * 512 + byte_offset;
+ fword("register-fs-package");
+}
-#ifdef CONFIG_DEBUG_FS
- //printk("devread s=%x buf=%x, fd=%x\n",sector, buf, curfs->dev_fd);
-#endif
+NODE_METHODS( grubfs ) = {
+ { "probe", grubfs_files_probe },
+ { "open", grubfs_files_open },
+ { "close", grubfs_files_close },
+ { "read", grubfs_files_read },
+ { "seek", grubfs_files_seek },
+ { "load", grubfs_files_load },
- if( !curfs ) {
-#ifdef CONFIG_DEBUG_FS
- printk("devread: fsys == NULL!\n");
-#endif
- return -1;
- }
+ /* special */
+ { "get-path", grubfs_files_get_path },
+ { "get-fstype", grubfs_files_get_fstype },
- if( seek_io(curfs->dev_fd, offs + curfs->offset) ) {
-#ifdef CONFIG_DEBUG_FS
- printk("seek failure\n");
-#endif
- return -1;
- }
- return (read_io(curfs->dev_fd, buf, byte_len) == byte_len) ? 1:0;
-}
+ { NULL, grubfs_initializer },
+};
-int
-file_read( void *buf, unsigned long len )
+void
+grubfs_init( void )
{
- if (filepos < 0 || filepos > filemax)
- filepos = filemax;
- if (len > filemax-filepos)
- len = filemax - filepos;
- errnum = 0;
- return curfs->fsys->read_func( buf, len );
+ REGISTER_NODE( grubfs );
}
Modified: trunk/openbios-devel/packages/init.c
==============================================================================
--- trunk/openbios-devel/packages/init.c Sun Jul 4 12:56:05 2010 (r814)
+++ trunk/openbios-devel/packages/init.c Sun Jul 4 15:37:00 2010 (r815)
@@ -42,6 +42,9 @@
#ifdef CONFIG_ISO9660
iso9660_init();
#endif
+#ifdef CONFIG_GRUBFS
+ grubfs_init();
+#endif
#ifdef CONFIG_FS
files_init();
#endif
Modified: trunk/openbios-devel/packages/misc-files.c
==============================================================================
--- trunk/openbios-devel/packages/misc-files.c Sun Jul 4 12:56:05 2010 (r814)
+++ trunk/openbios-devel/packages/misc-files.c Sun Jul 4 15:37:00 2010 (r815)
@@ -58,7 +58,7 @@
if( !err ) {
- err = fs_grubfs_open(fd, fs);
+ err = -1;
DPRINTF("--- grubfs returned %d\n", err);
fs->fd = fd;
@@ -333,8 +333,8 @@
err = (fd = open_ih(ih)) == -1;
if( !err ) {
- err = fs_grubfs_probe(fd, offs);
- DPRINTF("--- grubfs returned %d\n", err);
+ err = -1;
+ offs = 0;
}
if (fd)
Modified: trunk/openbios-devel/packages/packages.h
==============================================================================
--- trunk/openbios-devel/packages/packages.h Sun Jul 4 12:56:05 2010 (r814)
+++ trunk/openbios-devel/packages/packages.h Sun Jul 4 15:37:00 2010 (r815)
@@ -24,6 +24,7 @@
extern void hfsp_init( void );
extern void hfs_init( void );
extern void ext2_init( void );
+extern void grubfs_init( void );
extern void macparts_init( void );
extern void pcparts_init( void );
extern void sunparts_init( void );
More information about the OpenBIOS
mailing list