Home | History | Annotate | Line # | Download | only in zboot
      1  1.1  nonaka /*	$NetBSD: pathfs.c,v 1.1 2012/01/18 23:12:21 nonaka Exp $	*/
      2  1.1  nonaka 
      3  1.1  nonaka /*-
      4  1.1  nonaka  * Copyright (C) 2012 NONAKA Kimihiro <nonaka (at) netbsd.org>
      5  1.1  nonaka  * All rights reserved.
      6  1.1  nonaka  *
      7  1.1  nonaka  * Redistribution and use in source and binary forms, with or without
      8  1.1  nonaka  * modification, are permitted provided that the following conditions
      9  1.1  nonaka  * are met:
     10  1.1  nonaka  * 1. Redistributions of source code must retain the above copyright
     11  1.1  nonaka  *    notice, this list of conditions and the following disclaimer.
     12  1.1  nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  nonaka  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  nonaka  *    documentation and/or other materials provided with the distribution.
     15  1.1  nonaka  *
     16  1.1  nonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  nonaka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  nonaka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  nonaka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  nonaka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  nonaka  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  nonaka  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  nonaka  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  nonaka  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  nonaka  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  nonaka  */
     27  1.1  nonaka 
     28  1.1  nonaka #include "boot.h"
     29  1.1  nonaka #include "pathfs.h"
     30  1.1  nonaka #include "unixdev.h"
     31  1.1  nonaka #include "compat_linux.h"
     32  1.1  nonaka 
     33  1.1  nonaka __compactcall int
     34  1.1  nonaka pathfs_open(const char *path, struct open_file *fd)
     35  1.1  nonaka {
     36  1.1  nonaka 
     37  1.1  nonaka 	if (strcmp(fd->f_dev->dv_name, "path"))
     38  1.1  nonaka 		return EINVAL;
     39  1.1  nonaka 
     40  1.1  nonaka 	(void) ulseek((int)fd->f_devdata, 0L, SEEK_SET);
     41  1.1  nonaka 	return 0;
     42  1.1  nonaka }
     43  1.1  nonaka 
     44  1.1  nonaka __compactcall int
     45  1.1  nonaka pathfs_read(struct open_file *fd, void *vbuf, size_t nbyte, size_t *resid)
     46  1.1  nonaka {
     47  1.1  nonaka 	char *buf = vbuf;
     48  1.1  nonaka 	size_t off = 0;
     49  1.1  nonaka 	ssize_t rsz;
     50  1.1  nonaka 
     51  1.1  nonaka 	while (off < nbyte) {
     52  1.1  nonaka 		rsz = uread((int)fd->f_devdata, buf + off, nbyte - off);
     53  1.1  nonaka 		if (rsz < 0)
     54  1.1  nonaka 			return errno;
     55  1.1  nonaka 		if (rsz == 0)
     56  1.1  nonaka 			break;
     57  1.1  nonaka 		off += rsz;
     58  1.1  nonaka 	}
     59  1.1  nonaka 
     60  1.1  nonaka 	*resid -= off;
     61  1.1  nonaka 	return 0;
     62  1.1  nonaka }
     63  1.1  nonaka 
     64  1.1  nonaka __compactcall int
     65  1.1  nonaka pathfs_write(struct open_file *fd, void *vbuf, size_t size, size_t *resid)
     66  1.1  nonaka {
     67  1.1  nonaka 
     68  1.1  nonaka 	return EROFS;
     69  1.1  nonaka }
     70  1.1  nonaka 
     71  1.1  nonaka __compactcall off_t
     72  1.1  nonaka pathfs_seek(struct open_file *fd, off_t offset, int whence)
     73  1.1  nonaka {
     74  1.1  nonaka 
     75  1.1  nonaka 	return ulseek((int)fd->f_devdata, offset, whence);
     76  1.1  nonaka }
     77  1.1  nonaka 
     78  1.1  nonaka __compactcall int
     79  1.1  nonaka pathfs_close(struct open_file *fd)
     80  1.1  nonaka {
     81  1.1  nonaka 
     82  1.1  nonaka 	return 0;
     83  1.1  nonaka }
     84  1.1  nonaka 
     85  1.1  nonaka __compactcall int
     86  1.1  nonaka pathfs_stat(struct open_file *fd, struct stat *sb)
     87  1.1  nonaka {
     88  1.1  nonaka 	struct linux_stat lsb;
     89  1.1  nonaka 	int rv;
     90  1.1  nonaka 
     91  1.1  nonaka 	rv = ufstat((int)fd->f_devdata, &lsb);
     92  1.1  nonaka 	if (rv < 0)
     93  1.1  nonaka 		return errno;
     94  1.1  nonaka 
     95  1.1  nonaka 	sb->st_ino = lsb.lst_ino;
     96  1.1  nonaka 	sb->st_mode = lsb.lst_mode;
     97  1.1  nonaka 	sb->st_nlink = lsb.lst_nlink;
     98  1.1  nonaka 	sb->st_uid = lsb.lst_uid;
     99  1.1  nonaka 	sb->st_gid = lsb.lst_gid;
    100  1.1  nonaka 	sb->st_size = lsb.lst_size;
    101  1.1  nonaka 	sb->st_blksize = lsb.lst_blksize;
    102  1.1  nonaka 	sb->st_blocks = lsb.lst_blocks;
    103  1.1  nonaka 	sb->st_atime = lsb.lst_atime;
    104  1.1  nonaka 	sb->st_mtime = lsb.lst_mtime;
    105  1.1  nonaka 	sb->st_ctime = lsb.lst_ctime;
    106  1.1  nonaka 	return 0;
    107  1.1  nonaka }
    108  1.1  nonaka 
    109  1.1  nonaka __compactcall void
    110  1.1  nonaka pathfs_ls(struct open_file *f, const char *pattern)
    111  1.1  nonaka {
    112  1.1  nonaka 
    113  1.1  nonaka 	printf("Currently ls command is unsupported by pathfs.\n");
    114  1.1  nonaka }
    115