Implements dir method for ISO9660 filesystem.

0 > dir cd:\ 
      2048 2007-02-01 13:50:07 .\
      2048 2007-02-01 13:50:07 ..\
      2048 2007-02-01 13:54:13 ppc\
 ok
0 > dir cd:\ppc 
      2048 2007-02-01 13:54:13 .\
      2048 2007-02-01 13:50:07 ..\
       190 2007-02-01 13:54:13 bootinfo.txt
      2048 2007-02-01 13:51:11 chrp\

Signed-off-by: Laurent Vivier <Laurent@vivier.eu>



git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@631 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Laurent Vivier
2009-11-22 10:03:00 +00:00
parent 576f234a27
commit 7c3091927c

View File

@@ -6,6 +6,15 @@
#include "libiso9660.h"
#include "openbios/fs.h"
#include "libc/vsprintf.h"
typedef struct {
enum { FILE, DIR } type;
union {
iso9660_FILE *file;
iso9660_DIR * dir;
};
} iso9660_COMMON;
static void
umount( fs_ops_t *fs )
@@ -15,23 +24,66 @@ umount( fs_ops_t *fs )
iso9660_umount( volume );
}
static void
dir_fs ( file_desc_t *fd )
{
iso9660_COMMON *common = (iso9660_COMMON *)fd;
struct iso_directory_record *idr;
char name_buf[256];
if (common->type != DIR)
return;
forth_printf("\n");
while ( (idr = iso9660_readdir(common->dir)) ) {
forth_printf("% 10d ", isonum_733(idr->size));
forth_printf("%d-%02d-%02d %02d:%02d:%02d ",
idr->date[0] + 1900, /* year */
idr->date[1], /* month */
idr->date[2], /* day */
idr->date[3], idr->date[4], idr->date[5]);
iso9660_name(common->dir->volume, idr, name_buf);
if (idr->flags[0] & 2)
forth_printf("%s\\\n", name_buf);
else
forth_printf("%s\n", name_buf);
}
}
static file_desc_t *
open_path( fs_ops_t *fs, const char *path )
{
iso9660_VOLUME *volume = (iso9660_VOLUME *)fs->fs_data;
iso9660_FILE *file;
iso9660_COMMON *common;
file = iso9660_open(volume, path);
common = (iso9660_COMMON *)malloc(sizeof(*common));
if (common == NULL)
return NULL;
return (file_desc_t *)file;
common->dir = iso9660_opendir(volume, path);
if (common->dir == NULL) {
common->file = iso9660_open(volume, path);
if (common->file == NULL) {
free(common);
return NULL;
}
common->type = FILE;
return (file_desc_t *)common;
}
common->type = DIR;
return (file_desc_t *)common;
}
static char *
get_path( file_desc_t *fd, char *buf, int size )
{
iso9660_FILE *file = (iso9660_FILE*)fd;
iso9660_COMMON *common = (iso9660_COMMON *)fd;
strncpy(buf, file->path, size);
if (common->type != FILE)
return NULL;
strncpy(buf, common->file->path, size);
return buf;
}
@@ -39,25 +91,35 @@ get_path( file_desc_t *fd, char *buf, int size )
static int
file_lseek( file_desc_t *fd, off_t offs, int whence )
{
iso9660_FILE *file = (iso9660_FILE*)fd;
iso9660_COMMON *common = (iso9660_COMMON *)fd;
return iso9660_lseek(file, offs, whence);
if (common->type != FILE)
return -1;
return iso9660_lseek(common->file, offs, whence);
}
static void
file_close( file_desc_t *fd )
{
iso9660_FILE *file = (iso9660_FILE*)fd;
iso9660_COMMON *common = (iso9660_COMMON *)fd;
iso9660_close(file);
if (common->type == FILE)
iso9660_close(common->file);
else if (common->type == DIR)
iso9660_closedir(common->dir);
free(common);
}
static int
file_read( file_desc_t *fd, void *buf, size_t count )
{
iso9660_FILE *file = (iso9660_FILE*)fd;
iso9660_COMMON *common = (iso9660_COMMON *)fd;
return iso9660_read(file, buf, count);
if (common->type != FILE)
return -1;
return iso9660_read(common->file, buf, count);
}
static char *
@@ -77,6 +139,7 @@ get_fstype( fs_ops_t *fs )
}
static const fs_ops_t iso9660_ops = {
.dir = dir_fs,
.close_fs = umount,
.open_path = open_path,