Module Name:    src
Committed By:   nonaka
Date:           Wed Jan 18 23:12:22 UTC 2012

Modified Files:
        src/sys/arch/zaurus/stand/zboot: Makefile boot.c boot.h bootmenu.c
            conf.c devopen.c diskprobe.c pathnames.h unixdev.c unixdev.h
            version
Added Files:
        src/sys/arch/zaurus/stand/zboot: pathfs.c pathfs.h

Log Message:
Support to read the kernel from local file system.

ex. boot path:/mnt/card/netbsd


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/zaurus/stand/zboot/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/zaurus/stand/zboot/boot.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/zaurus/stand/zboot/boot.h \
    src/sys/arch/zaurus/stand/zboot/bootmenu.c \
    src/sys/arch/zaurus/stand/zboot/conf.c \
    src/sys/arch/zaurus/stand/zboot/devopen.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/zaurus/stand/zboot/diskprobe.c \
    src/sys/arch/zaurus/stand/zboot/pathnames.h \
    src/sys/arch/zaurus/stand/zboot/unixdev.c \
    src/sys/arch/zaurus/stand/zboot/unixdev.h \
    src/sys/arch/zaurus/stand/zboot/version
cvs rdiff -u -r0 -r1.1 src/sys/arch/zaurus/stand/zboot/pathfs.c \
    src/sys/arch/zaurus/stand/zboot/pathfs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/zaurus/stand/zboot/Makefile
diff -u src/sys/arch/zaurus/stand/zboot/Makefile:1.7 src/sys/arch/zaurus/stand/zboot/Makefile:1.8
--- src/sys/arch/zaurus/stand/zboot/Makefile:1.7	Sun Dec 25 06:09:10 2011
+++ src/sys/arch/zaurus/stand/zboot/Makefile	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.7 2011/12/25 06:09:10 tsutsui Exp $
+#	$NetBSD: Makefile,v 1.8 2012/01/18 23:12:21 nonaka Exp $
 
 PROG=		zboot
 
@@ -8,6 +8,7 @@ SRCS=		crt0.c
 SRCS+=		boot.c bootinfo.c bootmenu.c conf.c devopen.c diskprobe.c
 SRCS+=		loadfile_zboot.c
 SRCS+=		getsecs.c termios.c unixcons.c unixdev.c unixsys.S
+SRCS+=		pathfs.c
 
 NOMAN=		# defined
 
@@ -33,7 +34,7 @@ NEWVERSWHAT?=   "Boot"
 VERSIONFILE?=	${.CURDIR}/version
 
 ### find out what to use for libkern
-KERN_AS=		library
+KERN_AS=	library
 .include "${S}/lib/libkern/Makefile.inc"
 LIBKERN=	${KERNLIB}
 
@@ -48,7 +49,7 @@ SAMISCMAKEFLAGS= SA_USE_CREAD=yes SA_USE
 .include "${S}/lib/libsa/Makefile.inc"
 LIBSA=		${SALIB}
 
-${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN}
+${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${VERSIONFILE}
 	${HOST_SH} ${S}/conf/newvers_stand.sh ${${MKREPRO} == "yes" :?:-D} \
 	    ${VERSIONFILE} ${MACHINE} ${NEWVERSWHAT}
 	${CC} -c vers.c

Index: src/sys/arch/zaurus/stand/zboot/boot.c
diff -u src/sys/arch/zaurus/stand/zboot/boot.c:1.4 src/sys/arch/zaurus/stand/zboot/boot.c:1.5
--- src/sys/arch/zaurus/stand/zboot/boot.c:1.4	Sun Dec 25 06:09:10 2011
+++ src/sys/arch/zaurus/stand/zboot/boot.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.4 2011/12/25 06:09:10 tsutsui Exp $	*/
+/*	$NetBSD: boot.c,v 1.5 2012/01/18 23:12:21 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2009 NONAKA Kimihiro <[email protected]>
@@ -53,6 +53,7 @@ const char *default_filename;
 int default_timeout = 5;
 
 static char probed_disks[256];
+static char bootconfpath[1024];
 
 static void bootcmd_help(char *);
 static void bootcmd_ls(char *);
@@ -196,7 +197,10 @@ boot(dev_t bootdev)
 
 	diskprobe(probed_disks, sizeof(probed_disks));
 
-	parsebootconf(_PATH_BOOTCONF);
+	snprintf(bootconfpath, sizeof(bootconfpath), "%s%d%c:%s",
+	    default_devname, default_unit, 'a' + default_partition,
+	    _PATH_BOOTCONF);
+	parsebootconf(bootconfpath);
 
 #ifdef SUPPORT_CONSDEV
 	/*
@@ -296,8 +300,9 @@ bootcmd_help(char *arg)
 {
 
 	printf("commands are:\n"
-	    "boot [xdNx:][filename] [-acdqsv]\n"
-	    "     (ex. \"hd0a:netbsd.old -s\"\n"
+	    "boot [xdNx:][filename] [-1acdqsv]\n"
+	    "     (ex. \"boot hd0a:netbsd.old -s\")\n"
+	    "     (ex. \"boot path:/mnt/card/netbsd -1\")\n"
 	    "ls [path]\n"
 #ifdef SUPPORT_CONSDEV
 	    "consdev {glass|com [speed]}\n"

Index: src/sys/arch/zaurus/stand/zboot/boot.h
diff -u src/sys/arch/zaurus/stand/zboot/boot.h:1.1 src/sys/arch/zaurus/stand/zboot/boot.h:1.2
--- src/sys/arch/zaurus/stand/zboot/boot.h:1.1	Mon Mar  2 09:33:02 2009
+++ src/sys/arch/zaurus/stand/zboot/boot.h	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.h,v 1.1 2009/03/02 09:33:02 nonaka Exp $	*/
+/*	$NetBSD: boot.h,v 1.2 2012/01/18 23:12:21 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2009 NONAKA Kimihiro
@@ -52,6 +52,7 @@ void bootmenu(void);
 /* conf.c */
 extern char devname_hd[];
 extern char devname_mmcd[];
+extern char devname_path[];
 
 /* loadfile_zboot.c */
 int loadfile_zboot(const char *fname, u_long *marks, int flags);
Index: src/sys/arch/zaurus/stand/zboot/bootmenu.c
diff -u src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.1 src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.2
--- src/sys/arch/zaurus/stand/zboot/bootmenu.c:1.1	Mon Mar  2 09:33:02 2009
+++ src/sys/arch/zaurus/stand/zboot/bootmenu.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.c,v 1.1 2009/03/02 09:33:02 nonaka Exp $	*/
+/*	$NetBSD: bootmenu.c,v 1.2 2012/01/18 23:12:21 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@ parsebootconf(const char *conf)
 	/* automatically switch between letter and numbers on menu */
 	bootconf.menuformat = MENUFORMAT_AUTO;
 
-	fd = open(_PATH_BOOTCONF, 0);
+	fd = open(conf, 0);
 	if (fd < 0)
 		return;
 
@@ -118,6 +118,7 @@ parsebootconf(const char *conf)
 	bc = alloc(st.st_size + 1);
 	if (bc == NULL) {
 		printf("Could not allocate memory for boot configuration\n");
+		close(fd);
 		return;
 	}
 
Index: src/sys/arch/zaurus/stand/zboot/conf.c
diff -u src/sys/arch/zaurus/stand/zboot/conf.c:1.1 src/sys/arch/zaurus/stand/zboot/conf.c:1.2
--- src/sys/arch/zaurus/stand/zboot/conf.c:1.1	Mon Mar  2 09:33:02 2009
+++ src/sys/arch/zaurus/stand/zboot/conf.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: conf.c,v 1.1 2009/03/02 09:33:02 nonaka Exp $	*/
+/*	$NetBSD: conf.c,v 1.2 2012/01/18 23:12:21 nonaka Exp $	*/
 
 /*
  * Copyright (c) 2009 NONAKA Kimihiro <[email protected]>
@@ -30,20 +30,23 @@
 
 #include <lib/libsa/ufs.h>
 #include <lib/libsa/ext2fs.h>
+#include "pathfs.h"
 
 char devname_hd[] = "hd";
 char devname_mmcd[] = "mmcd";
+char devname_path[] = "path";
 
 struct devsw devsw[] = {
-    { devname_hd, unixstrategy, unixopen, unixclose, unixioctl},
-    { devname_mmcd, unixstrategy, unixopen, unixclose, unixioctl},
+    { devname_hd, unixstrategy, unixopen, unixclose, unixioctl },
+    { devname_mmcd, unixstrategy, unixopen, unixclose, unixioctl },
+    { devname_path, unixstrategy, unixpathopen, unixclose, unixioctl },
 };
 int ndevs = __arraycount(devsw);
 
 struct fs_ops file_system[] = {
-    FS_OPS(ufs),
     FS_OPS(ffsv1),
     FS_OPS(ffsv2),
     FS_OPS(ext2fs),
+    FS_OPS(pathfs),
 };
 int nfsys = __arraycount(file_system);
Index: src/sys/arch/zaurus/stand/zboot/devopen.c
diff -u src/sys/arch/zaurus/stand/zboot/devopen.c:1.1 src/sys/arch/zaurus/stand/zboot/devopen.c:1.2
--- src/sys/arch/zaurus/stand/zboot/devopen.c:1.1	Mon Mar  2 09:33:02 2009
+++ src/sys/arch/zaurus/stand/zboot/devopen.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: devopen.c,v 1.1 2009/03/02 09:33:02 nonaka Exp $	*/
+/*	$NetBSD: devopen.c,v 1.2 2012/01/18 23:12:21 nonaka Exp $	*/
 
 /*-
  *  Copyright (c) 1993 John Brezak
@@ -80,7 +80,7 @@ devopen(struct open_file *f, const char 
 {
 	struct devsw *dp;
 	char *fsname, *devname;
-	unsigned int dev, ctlr, unit, partition;
+	u_int dev, unit, partition;
 	int biosdev;
 	int error;
 
@@ -88,7 +88,6 @@ devopen(struct open_file *f, const char 
 	printf("devopen: fname = %s\n", fname ? fname : "(null)");
 #endif
 
-	ctlr = 0;
 	if ((error = parsebootfile(fname, &fsname, &devname, &unit, &partition,
 	    (const char **)file)) != 0) {
 		return error;
@@ -118,13 +117,13 @@ devopen(struct open_file *f, const char 
 #if defined(UNIX_DEBUG)
 		printf("devopen: bios disk\n");
 #endif
-		return (unixopen(f, biosdev, devname, unit, partition, *file));
+		return unixopen(f, devname, unit, partition, *file);
 	}
 
 #if defined(UNIX_DEBUG)
 	printf("devopen: dev->dv_open()\n");
 #endif
-	if ((error = (*dp->dv_open)(f, ctlr, unit, partition)) == 0) {
+	if ((error = (*dp->dv_open)(f, devname, unit, partition, *file)) == 0) {
 #if defined(UNIX_DEBUG)
 		printf("devopen: dev->dv_open() opened\n");
 #endif

Index: src/sys/arch/zaurus/stand/zboot/diskprobe.c
diff -u src/sys/arch/zaurus/stand/zboot/diskprobe.c:1.2 src/sys/arch/zaurus/stand/zboot/diskprobe.c:1.3
--- src/sys/arch/zaurus/stand/zboot/diskprobe.c:1.2	Mon Jun 20 12:39:21 2011
+++ src/sys/arch/zaurus/stand/zboot/diskprobe.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: diskprobe.c,v 1.2 2011/06/20 12:39:21 nonaka Exp $	*/
+/*	$NetBSD: diskprobe.c,v 1.3 2012/01/18 23:12:21 nonaka Exp $	*/
 /*	$OpenBSD: diskprobe.c,v 1.3 2006/10/13 00:00:55 krw Exp $	*/
 
 /*
@@ -69,7 +69,6 @@ hardprobe(char *buf, size_t bufsiz)
 	static const int order[] = { 0x80, 0x82, 0x00 };
 	char devname[MAXDEVNAME];
 	struct diskinfo *dip;
-	u_int disk = 0;
 	u_int hd_disk = 0;
 	u_int mmcd_disk = 0;
 	uint unit = 0;
@@ -90,16 +89,13 @@ hardprobe(char *buf, size_t bufsiz)
 
 		bios_devname(order[i], devname, sizeof(devname));
 		if (order[i] & 0x80) {
-			unit = hd_disk;
-			snprintf(dip->devname, sizeof(dip->devname), "%s%d",
-			    devname, hd_disk++);
+			unit = hd_disk++;
 		} else {
-			unit = mmcd_disk;
-			snprintf(dip->devname, sizeof(dip->devname), "%s%d",
-			    devname, mmcd_disk++);
+			unit = mmcd_disk++;
 		}
+		snprintf(dip->devname, sizeof(dip->devname), "%s%d", devname,
+		    unit);
 		strlcat(buf, dip->devname, bufsiz);
-		disk++;
 
 		/* Try to find the label, to figure out device type. */
 		if (bios_getdisklabel(&dip->bios_info, &dip->disklabel)
@@ -111,6 +107,7 @@ hardprobe(char *buf, size_t bufsiz)
 				    sizeof(disk_devname));
 				default_devname = disk_devname;
 				default_unit = unit;
+				default_partition = 0;
 			}
 		} else {
 			/* Best guess */
@@ -131,8 +128,17 @@ hardprobe(char *buf, size_t bufsiz)
 
 		strlcat(buf, " ", bufsiz);
 	}
-	if (disk == 0)
-		strlcat(buf, "none...", bufsiz);
+
+	/* path */
+	strlcat(buf, devname_path, bufsiz);
+	strlcat(buf, "*", bufsiz);
+	if (first) {
+		first = 0;
+		strlcpy(disk_devname, devname_path, sizeof(disk_devname));
+		default_devname = disk_devname;
+		default_unit = 0;
+		default_partition = 0;
+	}
 }
 
 static void
Index: src/sys/arch/zaurus/stand/zboot/pathnames.h
diff -u src/sys/arch/zaurus/stand/zboot/pathnames.h:1.2 src/sys/arch/zaurus/stand/zboot/pathnames.h:1.3
--- src/sys/arch/zaurus/stand/zboot/pathnames.h:1.2	Mon Jun 20 12:39:21 2011
+++ src/sys/arch/zaurus/stand/zboot/pathnames.h	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pathnames.h,v 1.2 2011/06/20 12:39:21 nonaka Exp $	*/
+/*	$NetBSD: pathnames.h,v 1.3 2012/01/18 23:12:21 nonaka Exp $	*/
 /*	$OpenBSD: pathnames.h,v 1.3 2005/01/14 08:10:16 uwe Exp $	*/
 
 /*
@@ -17,6 +17,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define _PATH_BOOTCONF		"/boot.cfg"
+#define _PATH_BOOTCONF		"boot.cfg"
 #define _PATH_ZBOOT		"/proc/zboot"
 #define _PATH_PARTITIONS	"/proc/partitions"
Index: src/sys/arch/zaurus/stand/zboot/unixdev.c
diff -u src/sys/arch/zaurus/stand/zboot/unixdev.c:1.2 src/sys/arch/zaurus/stand/zboot/unixdev.c:1.3
--- src/sys/arch/zaurus/stand/zboot/unixdev.c:1.2	Sun Jul 17 20:54:50 2011
+++ src/sys/arch/zaurus/stand/zboot/unixdev.c	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: unixdev.c,v 1.2 2011/07/17 20:54:50 joerg Exp $	*/
+/*	$NetBSD: unixdev.c,v 1.3 2012/01/18 23:12:21 nonaka Exp $	*/
 /*	$OpenBSD: unixdev.c,v 1.6 2007/06/16 00:26:33 deraadt Exp $	*/
 
 /*
@@ -73,18 +73,21 @@ unixopen(struct open_file *f, ...)
 	struct diskinfo *dip;
 	char *devname;
 	const char *fname;
-	int dev;
 	u_int unit, partition;
 	int dospart;
 
 	va_start(ap, f);
-	dev = va_arg(ap, int);
 	devname = va_arg(ap, char *);
 	unit = va_arg(ap, u_int);
 	partition = va_arg(ap, u_int);
 	fname = va_arg(ap, char *);
 	va_end(ap);
 
+#ifdef UNIX_DEBUG
+	printf("%s: devname=%s, unit=%d, partition=%d, fname=%s\n",
+	    __func__, devname, unit, partition, fname);
+#endif
+
 	f->f_devdata = NULL;
 
 	/* Find device. */
@@ -126,9 +129,45 @@ unixopen(struct open_file *f, ...)
 }
 
 int
+unixpathopen(struct open_file *f, ...)
+{
+	va_list	ap;
+	char *devname;
+	const char *fname;
+	u_int unit, partition;
+
+	va_start(ap, f);
+	devname = va_arg(ap, char *);
+	unit = va_arg(ap, u_int);
+	partition = va_arg(ap, u_int);
+	fname = va_arg(ap, char *);
+	va_end(ap);
+
+#ifdef UNIX_DEBUG
+	printf("%s: devname=%s, unit=%d, partition=%d, fname=%s\n",
+	    __func__, devname, unit, partition, fname);
+#endif
+
+	if (fname == NULL || fname[0] == '\0')
+		return EINVAL;
+
+	f->f_devdata = (void *)uopen(fname, LINUX_O_RDONLY);
+	if ((int)f->f_devdata == -1)
+		return errno;
+
+	bi_del(BTINFO_BOOTDISK);
+
+	return 0;
+}
+
+int
 unixclose(struct open_file *f)
 {
 
+#ifdef UNIX_DEBUG
+	printf("%s\n", __func__);
+#endif
+
 	return uclose((int)f->f_devdata);
 }
 
@@ -136,6 +175,10 @@ int
 unixioctl(struct open_file *f, u_long cmd, void *data)
 {
 
+#ifdef UNIX_DEBUG
+	printf("%s: cmd=0x%08lx\n", __func__, cmd);
+#endif
+
 	return uioctl((int)f->f_devdata, cmd, data);
 }
 
Index: src/sys/arch/zaurus/stand/zboot/unixdev.h
diff -u src/sys/arch/zaurus/stand/zboot/unixdev.h:1.2 src/sys/arch/zaurus/stand/zboot/unixdev.h:1.3
--- src/sys/arch/zaurus/stand/zboot/unixdev.h:1.2	Mon Jun 20 12:39:21 2011
+++ src/sys/arch/zaurus/stand/zboot/unixdev.h	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: unixdev.h,v 1.2 2011/06/20 12:39:21 nonaka Exp $	*/
+/*	$NetBSD: unixdev.h,v 1.3 2012/01/18 23:12:21 nonaka Exp $	*/
 /*	$OpenBSD: unixdev.h,v 1.1 2005/05/24 20:38:20 uwe Exp $	*/
 
 /*
@@ -43,6 +43,7 @@ int awaitkey(int, int);
 
 /* unixdev.c */
 int unixopen(struct open_file *, ...);
+int unixpathopen(struct open_file *, ...);
 int unixclose(struct open_file *);
 int unixioctl(struct open_file *, u_long, void *);
 int unixstrategy(void *, int, daddr_t, size_t, void *, size_t *);
Index: src/sys/arch/zaurus/stand/zboot/version
diff -u src/sys/arch/zaurus/stand/zboot/version:1.2 src/sys/arch/zaurus/stand/zboot/version:1.3
--- src/sys/arch/zaurus/stand/zboot/version:1.2	Mon Jun 20 12:39:21 2011
+++ src/sys/arch/zaurus/stand/zboot/version	Wed Jan 18 23:12:21 2012
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.2 2011/06/20 12:39:21 nonaka Exp $
+$NetBSD: version,v 1.3 2012/01/18 23:12:21 nonaka Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -6,3 +6,4 @@ is taken as the current.
 
 1.0:	Initial version.
 1.1:	Support SL-C1000.
+1.2:	Support to read the kernel from local file system.

Added files:

Index: src/sys/arch/zaurus/stand/zboot/pathfs.c
diff -u /dev/null src/sys/arch/zaurus/stand/zboot/pathfs.c:1.1
--- /dev/null	Wed Jan 18 23:12:22 2012
+++ src/sys/arch/zaurus/stand/zboot/pathfs.c	Wed Jan 18 23:12:21 2012
@@ -0,0 +1,114 @@
+/*	$NetBSD: pathfs.c,v 1.1 2012/01/18 23:12:21 nonaka Exp $	*/
+
+/*-
+ * Copyright (C) 2012 NONAKA Kimihiro <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "boot.h"
+#include "pathfs.h"
+#include "unixdev.h"
+#include "compat_linux.h"
+
+__compactcall int
+pathfs_open(const char *path, struct open_file *fd)
+{
+
+	if (strcmp(fd->f_dev->dv_name, "path"))
+		return EINVAL;
+
+	(void) ulseek((int)fd->f_devdata, 0L, SEEK_SET);
+	return 0;
+}
+
+__compactcall int
+pathfs_read(struct open_file *fd, void *vbuf, size_t nbyte, size_t *resid)
+{
+	char *buf = vbuf;
+	size_t off = 0;
+	ssize_t rsz;
+
+	while (off < nbyte) {
+		rsz = uread((int)fd->f_devdata, buf + off, nbyte - off);
+		if (rsz < 0)
+			return errno;
+		if (rsz == 0)
+			break;
+		off += rsz;
+	}
+
+	*resid -= off;
+	return 0;
+}
+
+__compactcall int
+pathfs_write(struct open_file *fd, void *vbuf, size_t size, size_t *resid)
+{
+
+	return EROFS;
+}
+
+__compactcall off_t
+pathfs_seek(struct open_file *fd, off_t offset, int whence)
+{
+
+	return ulseek((int)fd->f_devdata, offset, whence);
+}
+
+__compactcall int
+pathfs_close(struct open_file *fd)
+{
+
+	return 0;
+}
+
+__compactcall int
+pathfs_stat(struct open_file *fd, struct stat *sb)
+{
+	struct linux_stat lsb;
+	int rv;
+
+	rv = ufstat((int)fd->f_devdata, &lsb);
+	if (rv < 0)
+		return errno;
+
+	sb->st_ino = lsb.lst_ino;
+	sb->st_mode = lsb.lst_mode;
+	sb->st_nlink = lsb.lst_nlink;
+	sb->st_uid = lsb.lst_uid;
+	sb->st_gid = lsb.lst_gid;
+	sb->st_size = lsb.lst_size;
+	sb->st_blksize = lsb.lst_blksize;
+	sb->st_blocks = lsb.lst_blocks;
+	sb->st_atime = lsb.lst_atime;
+	sb->st_mtime = lsb.lst_mtime;
+	sb->st_ctime = lsb.lst_ctime;
+	return 0;
+}
+
+__compactcall void
+pathfs_ls(struct open_file *f, const char *pattern)
+{
+
+	printf("Currently ls command is unsupported by pathfs.\n");
+}
Index: src/sys/arch/zaurus/stand/zboot/pathfs.h
diff -u /dev/null src/sys/arch/zaurus/stand/zboot/pathfs.h:1.1
--- /dev/null	Wed Jan 18 23:12:22 2012
+++ src/sys/arch/zaurus/stand/zboot/pathfs.h	Wed Jan 18 23:12:21 2012
@@ -0,0 +1,28 @@
+/*	$NetBSD: pathfs.h,v 1.1 2012/01/18 23:12:21 nonaka Exp $	*/
+
+/*-
+ * Copyright (C) 2012 NONAKA Kimihiro <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+FS_DEF(pathfs);

Reply via email to