[OpenBIOS] [commit] r813 - in trunk/openbios-devel: fs/ext2 packages
repository service
svn at openbios.org
Sun Jul 4 12:18:04 CEST 2010
Author: mcayland
Date: Sun Jul 4 12:18:03 2010
New Revision: 813
URL: http://tracker.coreboot.org/trac/openbios/changeset/813
Log:
Move the ext2 filesystem handler into its own new package /packages/ext2-files.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
Modified:
trunk/openbios-devel/fs/ext2/ext2_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/ext2/ext2_fs.c
==============================================================================
--- trunk/openbios-devel/fs/ext2/ext2_fs.c Sun Jul 4 01:29:37 2010 (r812)
+++ trunk/openbios-devel/fs/ext2/ext2_fs.c Sun Jul 4 12:18:03 2010 (r813)
@@ -1,15 +1,22 @@
/*
+ * /packages/ext2-files
*
* (c) 2008-2009 Laurent Vivier <Laurent at lvivier.info>
+ * (c) 2010 Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
*
* This file has been copied from EMILE, http://emile.sf.net
*
*/
+#include "config.h"
+#include "libopenbios/bindings.h"
#include "libext2.h"
#include "ext2_utils.h"
#include "fs/fs.h"
#include "libc/vsprintf.h"
+#include "libc/diskio.h"
+
+extern void ext2_init( void );
typedef struct {
enum { FILE, DIR } type;
@@ -19,14 +26,14 @@
};
} ext2_COMMON;
-static void
-umount( fs_ops_t *fs )
-{
- ext2_VOLUME *volume = (ext2_VOLUME *)fs->fs_data;
+typedef struct {
+ ext2_VOLUME *volume;
+ ext2_COMMON *common;
+} ext2_info_t;
- ext2_umount( volume );
-}
+DECLARE_NODE( ext2, 0, sizeof(ext2_info_t), "+/packages/ext2-files" );
+/*
static const int days_month[12] =
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static const int days_month_leap[12] =
@@ -97,115 +104,177 @@
forth_printf("%s\n", entry->name);
}
}
+*/
+
+/************************************************************************/
+/* Standard package methods */
+/************************************************************************/
-static file_desc_t *
-open_path( fs_ops_t *fs, const char *path )
+/* ( -- success? ) */
+static void
+ext2_files_open( ext2_info_t *mi )
{
- ext2_VOLUME *volume = (ext2_VOLUME *)fs->fs_data;
- ext2_COMMON *common;
+ int fd;
+ char *path = my_args_copy();
- common = (ext2_COMMON*)malloc(sizeof(*common));
- if (common == NULL)
- return NULL;
-
- common->dir = ext2_opendir(volume, path);
- if (common->dir == NULL) {
- common->file = ext2_open(volume, path);
- if (common->file == NULL) {
- free(common);
- return NULL;
+ fd = open_ih( my_parent() );
+ if ( fd == -1 ) {
+ free( path );
+ RET( 0 );
+ }
+
+ mi->volume = ext2_mount(fd);
+ if (!mi->volume) {
+ RET( 0 );
+ }
+
+ mi->common = (ext2_COMMON*)malloc(sizeof(ext2_COMMON));
+ if (mi->common == NULL)
+ RET( 0 );
+
+ mi->common->dir = ext2_opendir(mi->volume, path);
+ if (mi->common->dir == NULL) {
+ mi->common->file = ext2_open(mi->volume, path);
+ if (mi->common->file == NULL) {
+ free(mi->common);
+ RET( 0 );
}
- common->type = FILE;
- return (file_desc_t *)common;
+ mi->common->type = FILE;
+ RET( -1 );
}
- common->type = DIR;
- return (file_desc_t *)common;
+ mi->common->type = DIR;
+ RET( -1 );
}
-static char *
-get_path( file_desc_t *fd, char *buf, int size )
+/* ( -- ) */
+static void
+ext2_files_close( ext2_info_t *mi )
{
- ext2_COMMON *common =(ext2_COMMON *)fd;
-
- if (common->type != FILE)
- return NULL;
+ ext2_COMMON *common = mi->common;
- strncpy(buf, common->file->path, size);
+ if (common->type == FILE)
+ ext2_close(common->file);
+ else if (common->type == DIR)
+ ext2_closedir(common->dir);
+ free(common);
- return buf;
+ ext2_umount(mi->volume);
}
-static int
-file_lseek( file_desc_t *fd, off_t offs, int whence )
+/* ( buf len -- actlen ) */
+static void
+ext2_files_read( ext2_info_t *mi )
{
- ext2_COMMON *common =(ext2_COMMON *)fd;
+ int count = POP();
+ char *buf = (char *)POP();
+ ext2_COMMON *common = mi->common;
if (common->type != FILE)
- return -1;
+ RET( -1 );
- return ext2_lseek(common->file, offs, whence);
+ RET ( ext2_read( common->file, buf, count ) );
}
+/* ( pos.d -- status ) */
static void
-file_close( file_desc_t *fd )
+ext2_files_seek( ext2_info_t *mi )
{
- ext2_COMMON *common =(ext2_COMMON *)fd;
+ llong pos = DPOP();
+ int offs = (int)pos;
+ int whence = SEEK_SET;
+ int ret;
+ ext2_COMMON *common = mi->common;
- if (common->type == FILE)
- ext2_close(common->file);
- else if (common->type == DIR)
- ext2_closedir(common->dir);
- free(common);
+ if (common->type != FILE)
+ RET( -1 );
+
+ ret = ext2_lseek(common->file, offs, whence);
+ if (ret)
+ RET( -1 );
+ else
+ RET( 0 );
}
-static int
-file_read( file_desc_t *fd, void *buf, size_t count )
+/* ( addr -- size ) */
+static void
+ext2_files_load( ext2_info_t *mi )
{
- ext2_COMMON *common =(ext2_COMMON *)fd;
+ char *buf = (char *)POP();
+ int count;
+ ext2_COMMON *common = mi->common;
if (common->type != FILE)
- return -1;
+ RET( -1 );
+
+ /* Seek to the end in order to get the file size */
+ ext2_lseek(common->file, 0, SEEK_END);
+ count = common->file->offset;
+ ext2_lseek(common->file, 0, SEEK_SET);
- return ext2_read(common->file, buf, count);
+ RET ( ext2_read( common->file, buf, count ) );
}
-static const char *
-get_fstype( fs_ops_t *fs)
+/* ( -- cstr ) */
+static void
+ext2_files_get_path( ext2_info_t *mi )
{
- return "EXT2";
-}
+ ext2_COMMON *common = mi->common;
-static const fs_ops_t ext2_ops = {
- .dir = dir_fs,
- .close_fs = umount,
+ if (common->type != FILE)
+ RET( 0 );
- .open_path = open_path,
- .get_path = get_path,
- .close = file_close,
- .read = file_read,
- .lseek = file_lseek,
+ RET( (ucell) strdup(common->file->path) );
+}
- .get_fstype = get_fstype,
-};
+/* ( -- cstr ) */
+static void
+ext2_files_get_fstype( ext2_info_t *mi )
+{
+ PUSH( (ucell)strdup("ext2") );
+}
-int fs_ext2_open(int fd, fs_ops_t *fs)
+
+/* static method, ( pos.d ih -- flag? ) */
+static void
+ext2_files_probe( ext2_info_t *dummy )
{
- ext2_VOLUME *volume;
+ ihandle_t ih = POP_ih();
+ llong offs = DPOP();
+ int fd, ret = 0;
- volume = ext2_mount(fd);
- if (volume == NULL)
- return -1;
+ fd = open_ih(ih);
+ if (ext2_probe(fd, offs))
+ ret = -1;
- *fs = ext2_ops;
- fs->fs_data = volume;
+ close_io(fd);
- return 0;
+ RET (ret);
}
-int fs_ext2_probe(int fd, llong offs)
+
+static void
+ext2_initializer( ext2_info_t *dummy )
{
- if (ext2_probe(fd, offs))
- return 0;
+ fword("register-fs-package");
+}
+
+NODE_METHODS( ext2 ) = {
+ { "probe", ext2_files_probe },
+ { "open", ext2_files_open },
+ { "close", ext2_files_close },
+ { "read", ext2_files_read },
+ { "seek", ext2_files_seek },
+ { "load", ext2_files_load },
+
+ /* special */
+ { "get-path", ext2_files_get_path },
+ { "get-fstype", ext2_files_get_fstype },
- return -1;
+ { NULL, ext2_initializer },
+};
+
+void
+ext2_init( void )
+{
+ REGISTER_NODE( ext2 );
}
Modified: trunk/openbios-devel/packages/init.c
==============================================================================
--- trunk/openbios-devel/packages/init.c Sun Jul 4 01:29:37 2010 (r812)
+++ trunk/openbios-devel/packages/init.c Sun Jul 4 12:18:03 2010 (r813)
@@ -36,6 +36,9 @@
#ifdef CONFIG_HFS
hfs_init();
#endif
+#ifdef CONFIG_EXT2
+ ext2_init();
+#endif
#ifdef CONFIG_ISO9660
iso9660_init();
#endif
Modified: trunk/openbios-devel/packages/misc-files.c
==============================================================================
--- trunk/openbios-devel/packages/misc-files.c Sun Jul 4 01:29:37 2010 (r812)
+++ trunk/openbios-devel/packages/misc-files.c Sun Jul 4 12:18:03 2010 (r813)
@@ -58,13 +58,8 @@
if( !err ) {
- err = fs_ext2_open(fd, fs);
- DPRINTF("--- ext2 returned %d\n", err);
-
- if( err ) {
- err = fs_grubfs_open(fd, fs);
- DPRINTF("--- grubfs returned %d\n", err);
- }
+ err = fs_grubfs_open(fd, fs);
+ DPRINTF("--- grubfs returned %d\n", err);
fs->fd = fd;
}
@@ -338,13 +333,8 @@
err = (fd = open_ih(ih)) == -1;
if( !err ) {
- err = fs_ext2_probe(fd, offs);
- DPRINTF("--- ext2 returned %d\n", err);
-
- if( err ) {
- err = fs_grubfs_probe(fd, offs);
- DPRINTF("--- grubfs returned %d\n", err);
- }
+ err = fs_grubfs_probe(fd, offs);
+ DPRINTF("--- grubfs returned %d\n", err);
}
if (fd)
Modified: trunk/openbios-devel/packages/packages.h
==============================================================================
--- trunk/openbios-devel/packages/packages.h Sun Jul 4 01:29:37 2010 (r812)
+++ trunk/openbios-devel/packages/packages.h Sun Jul 4 12:18:03 2010 (r813)
@@ -23,6 +23,7 @@
extern void iso9660_init( void );
extern void hfsp_init( void );
extern void hfs_init( void );
+extern void ext2_init( void );
extern void macparts_init( void );
extern void pcparts_init( void );
extern void sunparts_init( void );
More information about the OpenBIOS
mailing list