[OpenBIOS] r631 - trunk/openbios-devel/fs/iso9660

svn at openbios.org svn at openbios.org
Sun Nov 22 11:03:00 CET 2009


Author: laurent
Date: 2009-11-22 11:03:00 +0100 (Sun, 22 Nov 2009)
New Revision: 631

Modified:
   trunk/openbios-devel/fs/iso9660/iso9660_fs.c
Log:
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 at vivier.eu>



Modified: trunk/openbios-devel/fs/iso9660/iso9660_fs.c
===================================================================
--- trunk/openbios-devel/fs/iso9660/iso9660_fs.c	2009-11-22 09:58:01 UTC (rev 630)
+++ trunk/openbios-devel/fs/iso9660/iso9660_fs.c	2009-11-22 10:03:00 UTC (rev 631)
@@ -6,7 +6,16 @@
 
 #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,49 +24,102 @@
 	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;
 }
 
 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 @@
 }
 
 static const fs_ops_t iso9660_ops = {
+	.dir		= dir_fs,
 	.close_fs	= umount,
 
 	.open_path	= open_path,




More information about the OpenBIOS mailing list