Home | History | Annotate | Line # | Download | only in v7fs
v7fs_file.c revision 1.6
      1  1.6   hannken /*	$NetBSD: v7fs_file.c,v 1.6 2014/12/29 15:28:58 hannken Exp $	*/
      2  1.1       uch 
      3  1.1       uch /*-
      4  1.1       uch  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  1.1       uch  * All rights reserved.
      6  1.1       uch  *
      7  1.1       uch  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1       uch  * by UCHIYAMA Yasushi.
      9  1.1       uch  *
     10  1.1       uch  * Redistribution and use in source and binary forms, with or without
     11  1.1       uch  * modification, are permitted provided that the following conditions
     12  1.1       uch  * are met:
     13  1.1       uch  * 1. Redistributions of source code must retain the above copyright
     14  1.1       uch  *    notice, this list of conditions and the following disclaimer.
     15  1.1       uch  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1       uch  *    notice, this list of conditions and the following disclaimer in the
     17  1.1       uch  *    documentation and/or other materials provided with the distribution.
     18  1.1       uch  *
     19  1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1       uch  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1       uch  */
     31  1.1       uch 
     32  1.2       apb #if HAVE_NBTOOL_CONFIG_H
     33  1.2       apb #include "nbtool_config.h"
     34  1.2       apb #endif
     35  1.2       apb 
     36  1.1       uch #include <sys/cdefs.h>
     37  1.6   hannken __KERNEL_RCSID(0, "$NetBSD: v7fs_file.c,v 1.6 2014/12/29 15:28:58 hannken Exp $");
     38  1.1       uch #if defined _KERNEL_OPT
     39  1.1       uch #include "opt_v7fs.h"
     40  1.1       uch #endif
     41  1.1       uch 
     42  1.4  christos #include <sys/param.h>
     43  1.1       uch #ifdef _KERNEL
     44  1.1       uch #include <sys/systm.h>
     45  1.1       uch #else
     46  1.1       uch #include <stdio.h>
     47  1.1       uch #include <string.h>
     48  1.1       uch #include <errno.h>
     49  1.1       uch #endif
     50  1.1       uch 
     51  1.1       uch #include "v7fs.h"
     52  1.1       uch #include "v7fs_impl.h"
     53  1.1       uch #include "v7fs_endian.h"
     54  1.1       uch #include "v7fs_inode.h"
     55  1.1       uch #include "v7fs_dirent.h"
     56  1.1       uch #include "v7fs_file.h"
     57  1.1       uch #include "v7fs_datablock.h"
     58  1.1       uch 
     59  1.1       uch #ifdef V7FS_FILE_DEBUG
     60  1.1       uch #define	DPRINTF(fmt, args...)	printf("%s: " fmt, __func__, ##args)
     61  1.1       uch #else
     62  1.1       uch #define	DPRINTF(fmt, args...)	((void)0)
     63  1.1       uch #endif
     64  1.1       uch 
     65  1.1       uch static int lookup_subr(struct v7fs_self *, void *, v7fs_daddr_t, size_t);
     66  1.1       uch static int remove_subr(struct v7fs_self *, void *, v7fs_daddr_t, size_t);
     67  1.1       uch 
     68  1.1       uch int
     69  1.1       uch v7fs_file_lookup_by_name(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
     70  1.1       uch     const char *name, v7fs_ino_t *ino)
     71  1.1       uch {
     72  1.1       uch 	char filename[V7FS_NAME_MAX + 1];
     73  1.1       uch 	char *q;
     74  1.1       uch 	int error;
     75  1.1       uch 	size_t len;
     76  1.1       uch 
     77  1.1       uch 	if ((q = strchr(name, '/'))) {
     78  1.1       uch 		/* Zap following path. */
     79  1.5   msaitoh 		len = MIN(V7FS_NAME_MAX, q - name);
     80  1.1       uch 		memcpy(filename, name, len);
     81  1.1       uch 		filename[len] = '\0';	/* '/' -> '\0' */
     82  1.1       uch 	} else {
     83  1.1       uch 		v7fs_dirent_filename(filename, name);
     84  1.1       uch 	}
     85  1.1       uch 	DPRINTF("%s(%s) dir=%d\n", filename, name, parent_dir->inode_number);
     86  1.1       uch 
     87  1.1       uch 	struct v7fs_lookup_arg lookup_arg = { .name = filename,
     88  1.1       uch 					      .inode_number = 0 };
     89  1.1       uch 	if ((error = v7fs_datablock_foreach(fs, parent_dir, lookup_subr,
     90  1.1       uch 		    &lookup_arg)) != V7FS_ITERATOR_BREAK) {
     91  1.1       uch 		DPRINTF("not found.\n");
     92  1.1       uch 		return ENOENT;
     93  1.1       uch 	}
     94  1.1       uch 
     95  1.1       uch 	*ino = lookup_arg.inode_number;
     96  1.1       uch 	DPRINTF("done. ino=%d\n", *ino);
     97  1.1       uch 
     98  1.1       uch 	return 0;
     99  1.1       uch }
    100  1.1       uch 
    101  1.1       uch static int
    102  1.1       uch lookup_subr(struct v7fs_self *fs, void *ctx, v7fs_daddr_t blk, size_t sz)
    103  1.1       uch {
    104  1.1       uch 	struct v7fs_lookup_arg *p = (struct v7fs_lookup_arg *)ctx;
    105  1.1       uch 	struct v7fs_dirent *dir;
    106  1.1       uch 	const char *name = p->name;
    107  1.1       uch 	void *buf;
    108  1.1       uch 	size_t i, n;
    109  1.1       uch 	int ret = 0;
    110  1.1       uch 
    111  1.1       uch 	if (!(buf = scratch_read(fs, blk)))
    112  1.1       uch 		return EIO;
    113  1.1       uch 
    114  1.1       uch 	dir = (struct v7fs_dirent *)buf;
    115  1.1       uch 	n = sz / sizeof(*dir);
    116  1.1       uch 	v7fs_dirent_endian_convert(fs, dir, n);
    117  1.1       uch 
    118  1.1       uch 	for (i = 0; i < n; i++, dir++) {
    119  1.1       uch 		if (dir->inode_number < 1) {
    120  1.1       uch 			DPRINTF("*** bad inode #%d ***\n", dir->inode_number);
    121  1.1       uch 			continue;
    122  1.1       uch 		}
    123  1.1       uch 
    124  1.1       uch 		if (strncmp((const char *)dir->name, name, V7FS_NAME_MAX) == 0)
    125  1.1       uch 		{
    126  1.1       uch 			p->inode_number = dir->inode_number;
    127  1.1       uch 			ret =  V7FS_ITERATOR_BREAK; /* found */
    128  1.1       uch 			break;
    129  1.1       uch 		}
    130  1.1       uch 	}
    131  1.1       uch 	scratch_free(fs, buf);
    132  1.1       uch 
    133  1.1       uch 	return ret;
    134  1.1       uch }
    135  1.1       uch 
    136  1.1       uch int
    137  1.1       uch v7fs_file_allocate(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
    138  1.1       uch     const char *srcname, struct v7fs_fileattr *attr, v7fs_ino_t *ino)
    139  1.1       uch {
    140  1.1       uch 	struct v7fs_inode inode;
    141  1.1       uch 	char filename[V7FS_NAME_MAX + 1];
    142  1.1       uch 	struct v7fs_dirent *dir;
    143  1.1       uch 	int error;
    144  1.1       uch 
    145  1.1       uch 	/* Truncate filename. */
    146  1.1       uch 	v7fs_dirent_filename(filename, srcname);
    147  1.1       uch 	DPRINTF("%s(%s)\n", filename, srcname);
    148  1.1       uch 
    149  1.1       uch 	/* Check filename. */
    150  1.1       uch 	if (v7fs_file_lookup_by_name(fs, parent_dir, filename, ino) == 0) {
    151  1.1       uch 		DPRINTF("%s exists\n", filename);
    152  1.1       uch 		return EEXIST;
    153  1.1       uch 	}
    154  1.1       uch 
    155  1.1       uch 	/* Get new inode. */
    156  1.1       uch 	if ((error = v7fs_inode_allocate(fs, ino)))
    157  1.1       uch 		return error;
    158  1.1       uch 
    159  1.1       uch 	/* Set initial attribute. */
    160  1.1       uch 	memset(&inode, 0, sizeof(inode));
    161  1.1       uch 	inode.inode_number = *ino;
    162  1.1       uch 	inode.mode = attr->mode;
    163  1.1       uch 	inode.uid = attr->uid;
    164  1.1       uch 	inode.gid = attr->gid;
    165  1.1       uch 	if (attr->ctime)
    166  1.1       uch 		inode.ctime = attr->ctime;
    167  1.1       uch 	if (attr->mtime)
    168  1.1       uch 		inode.mtime = attr->mtime;
    169  1.1       uch 	if (attr->atime)
    170  1.1       uch 		inode.atime = attr->atime;
    171  1.1       uch 
    172  1.1       uch 	switch (inode.mode & V7FS_IFMT)	{
    173  1.1       uch 	default:
    174  1.1       uch 		DPRINTF("Can't allocate %o type.\n", inode.mode);
    175  1.1       uch 		v7fs_inode_deallocate(fs, *ino);
    176  1.1       uch 		return EINVAL;
    177  1.1       uch 	case V7FS_IFCHR:
    178  1.1       uch 		/* FALLTHROUGH */
    179  1.1       uch 	case V7FS_IFBLK:
    180  1.1       uch 		inode.nlink = 1;
    181  1.1       uch 		inode.device = attr->device;
    182  1.1       uch 		inode.addr[0] = inode.device;
    183  1.1       uch 		break;
    184  1.1       uch 	case V7FSBSD_IFFIFO:
    185  1.1       uch 		/* FALLTHROUGH */
    186  1.1       uch 	case V7FSBSD_IFSOCK:
    187  1.1       uch 		/* FALLTHROUGH */
    188  1.1       uch 	case V7FSBSD_IFLNK:
    189  1.1       uch 		/* FALLTHROUGH */
    190  1.1       uch 	case V7FS_IFREG:
    191  1.1       uch 		inode.nlink = 1;
    192  1.1       uch 		break;
    193  1.1       uch 	case V7FS_IFDIR:
    194  1.1       uch 		inode.nlink = 2;	/* . + .. */
    195  1.1       uch 		if ((error = v7fs_datablock_expand(fs, &inode, sizeof(*dir) * 2
    196  1.1       uch 		    ))) {
    197  1.1       uch 			v7fs_inode_deallocate(fs, *ino);
    198  1.1       uch 			return error;
    199  1.1       uch 		}
    200  1.1       uch 		v7fs_daddr_t blk = inode.addr[0];
    201  1.1       uch 		void *buf;
    202  1.1       uch 		if (!(buf = scratch_read(fs, blk))) {
    203  1.1       uch 			v7fs_inode_deallocate(fs, *ino);
    204  1.1       uch 			return EIO;
    205  1.1       uch 		}
    206  1.1       uch 		dir = (struct v7fs_dirent *)buf;
    207  1.1       uch 		strcpy(dir[0].name, ".");
    208  1.1       uch 		dir[0].inode_number = V7FS_VAL16(fs, *ino);
    209  1.1       uch 		strcpy(dir[1].name, "..");
    210  1.1       uch 		dir[1].inode_number = V7FS_VAL16(fs, parent_dir->inode_number);
    211  1.1       uch 		if (!fs->io.write(fs->io.cookie, buf, blk)) {
    212  1.1       uch 			scratch_free(fs, buf);
    213  1.1       uch 			return EIO;
    214  1.1       uch 		}
    215  1.1       uch 		scratch_free(fs, buf);
    216  1.1       uch 		break;
    217  1.1       uch 	}
    218  1.1       uch 
    219  1.1       uch 	v7fs_inode_writeback(fs, &inode);
    220  1.1       uch 
    221  1.1       uch 	/* Link this inode to parent directory. */
    222  1.1       uch 	if ((error = v7fs_directory_add_entry(fs, parent_dir, *ino, filename)))
    223  1.1       uch 	{
    224  1.1       uch 		DPRINTF("can't add dirent.\n");
    225  1.1       uch 		return error;
    226  1.1       uch 	}
    227  1.1       uch 
    228  1.1       uch 	return 0;
    229  1.1       uch }
    230  1.1       uch 
    231  1.1       uch int
    232  1.1       uch v7fs_file_deallocate(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
    233  1.1       uch     const char *name)
    234  1.1       uch {
    235  1.1       uch 	v7fs_ino_t ino;
    236  1.1       uch 	struct v7fs_inode inode;
    237  1.1       uch 	int error;
    238  1.1       uch 
    239  1.1       uch 	DPRINTF("%s\n", name);
    240  1.1       uch 	if ((error = v7fs_file_lookup_by_name(fs, parent_dir, name, &ino))) {
    241  1.1       uch 		DPRINTF("no such a file: %s\n", name);
    242  1.1       uch 		return error;
    243  1.1       uch 	}
    244  1.1       uch 	DPRINTF("%s->#%d\n", name, ino);
    245  1.1       uch 	if ((error = v7fs_inode_load(fs, &inode, ino)))
    246  1.1       uch 		return error;
    247  1.1       uch 
    248  1.1       uch 	if (v7fs_inode_isdir(&inode)) {
    249  1.3       uch 		char filename[V7FS_NAME_MAX + 1];
    250  1.3       uch 		v7fs_dirent_filename(filename, name);
    251  1.3       uch 		/* Check parent */
    252  1.3       uch 		if (strncmp(filename, "..", V7FS_NAME_MAX) == 0) {
    253  1.3       uch 			DPRINTF("can not remove '..'\n");
    254  1.3       uch 			return EINVAL; /* t_vnops rename_dotdot */
    255  1.3       uch 		}
    256  1.3       uch 		/* Check empty */
    257  1.1       uch 		if (v7fs_inode_filesize(&inode) !=
    258  1.1       uch 		    sizeof(struct v7fs_dirent) * 2 /*"." + ".."*/) {
    259  1.3       uch 			DPRINTF("directory not empty.\n");
    260  1.3       uch 			return ENOTEMPTY;/* t_vnops dir_noempty, rename_dir(6)*/
    261  1.1       uch 		}
    262  1.6   hannken 		error = v7fs_datablock_size_change(fs, 0, &inode);
    263  1.6   hannken 		if (error)
    264  1.6   hannken 			return error;
    265  1.1       uch 		inode.nlink = 0;	/* remove this. */
    266  1.1       uch 	} else {
    267  1.1       uch 		/* Decrement reference count. */
    268  1.1       uch 		--inode.nlink;	/* regular file. */
    269  1.3       uch 		DPRINTF("%s nlink=%d\n", name, inode.nlink);
    270  1.1       uch 	}
    271  1.1       uch 
    272  1.1       uch 
    273  1.1       uch 	if ((error = v7fs_directory_remove_entry(fs, parent_dir, name)))
    274  1.1       uch 		return error;
    275  1.1       uch 	DPRINTF("remove dirent\n");
    276  1.1       uch 
    277  1.6   hannken 	v7fs_inode_writeback(fs, &inode);
    278  1.1       uch 
    279  1.1       uch 	return 0;
    280  1.1       uch }
    281  1.1       uch 
    282  1.1       uch int
    283  1.1       uch v7fs_directory_add_entry(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
    284  1.1       uch     v7fs_ino_t ino, const char *srcname)
    285  1.1       uch {
    286  1.1       uch 	struct v7fs_inode inode;
    287  1.1       uch 	struct v7fs_dirent *dir;
    288  1.1       uch 	int error = 0;
    289  1.1       uch 	v7fs_daddr_t blk;
    290  1.1       uch 	void *buf;
    291  1.1       uch 	char filename[V7FS_NAME_MAX + 1];
    292  1.1       uch 
    293  1.1       uch 	/* Truncate filename. */
    294  1.1       uch 	v7fs_dirent_filename(filename, srcname);
    295  1.1       uch 	DPRINTF("%s(%s) %d\n", filename, srcname, ino);
    296  1.1       uch 
    297  1.1       uch 	/* Target inode */
    298  1.1       uch 	if ((error = v7fs_inode_load(fs, &inode, ino)))
    299  1.1       uch 		return error;
    300  1.1       uch 
    301  1.1       uch 	/* Expand datablock. */
    302  1.1       uch 	if ((error = v7fs_datablock_expand(fs, parent_dir, sizeof(*dir))))
    303  1.1       uch 		return error;
    304  1.1       uch 
    305  1.1       uch 	/* Read last entry. */
    306  1.1       uch 	if (!(blk = v7fs_datablock_last(fs, parent_dir,
    307  1.1       uch 	    v7fs_inode_filesize(parent_dir))))
    308  1.1       uch 		return EIO;
    309  1.1       uch 
    310  1.1       uch 	/* Load dirent block. This vnode(parent dir) is locked by VFS layer. */
    311  1.1       uch 	if (!(buf = scratch_read(fs, blk)))
    312  1.1       uch 		return EIO;
    313  1.1       uch 
    314  1.1       uch 	size_t sz = v7fs_inode_filesize(parent_dir);
    315  1.1       uch 	sz = V7FS_RESIDUE_BSIZE(sz);	/* last block payload. */
    316  1.1       uch 	int n = sz / sizeof(*dir) - 1;
    317  1.1       uch 	/* Add dirent. */
    318  1.1       uch 	dir = (struct v7fs_dirent *)buf;
    319  1.1       uch 	dir[n].inode_number = V7FS_VAL16(fs, ino);
    320  1.1       uch 	memcpy((char *)dir[n].name, filename, V7FS_NAME_MAX);
    321  1.1       uch 	/* Write back datablock */
    322  1.1       uch 	if (!fs->io.write(fs->io.cookie, buf, blk))
    323  1.1       uch 		error = EIO;
    324  1.1       uch 	scratch_free(fs, buf);
    325  1.1       uch 
    326  1.1       uch 	if (v7fs_inode_isdir(&inode)) {
    327  1.1       uch 		parent_dir->nlink++;
    328  1.1       uch 		v7fs_inode_writeback(fs, parent_dir);
    329  1.1       uch 	}
    330  1.1       uch 
    331  1.1       uch 	DPRINTF("done. (dirent size=%dbyte)\n", parent_dir->filesize);
    332  1.1       uch 
    333  1.1       uch 	return error;
    334  1.1       uch }
    335  1.1       uch 
    336  1.1       uch int
    337  1.1       uch v7fs_directory_remove_entry(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
    338  1.1       uch     const char *name)
    339  1.1       uch {
    340  1.1       uch 	struct v7fs_inode inode;
    341  1.1       uch 	int error;
    342  1.1       uch 	struct v7fs_dirent lastdirent;
    343  1.1       uch 	v7fs_daddr_t lastblk;
    344  1.1       uch 	size_t sz, lastsz;
    345  1.1       uch 	v7fs_off_t pos;
    346  1.1       uch 	void *buf;
    347  1.1       uch 
    348  1.1       uch 	/* Setup replaced entry. */
    349  1.1       uch 	sz = parent_dir->filesize;
    350  1.1       uch 	lastblk = v7fs_datablock_last(fs, parent_dir,
    351  1.1       uch 	    v7fs_inode_filesize(parent_dir));
    352  1.1       uch 	lastsz = V7FS_RESIDUE_BSIZE(sz);
    353  1.1       uch 	pos = lastsz - sizeof(lastdirent);
    354  1.1       uch 
    355  1.1       uch 	if (!(buf = scratch_read(fs, lastblk)))
    356  1.1       uch 		return EIO;
    357  1.1       uch 	lastdirent = *((struct v7fs_dirent *)((uint8_t *)buf + pos));
    358  1.1       uch 	scratch_free(fs, buf);
    359  1.1       uch 	DPRINTF("last dirent=%d %s pos=%d\n",
    360  1.1       uch 	    V7FS_VAL16(fs, lastdirent.inode_number), lastdirent.name, pos);
    361  1.1       uch 
    362  1.1       uch 	struct v7fs_lookup_arg lookup_arg =
    363  1.1       uch 	    { .name = name, .replace = &lastdirent/*disk endian */ };
    364  1.1       uch 	/* Search entry that removed. replace it to last dirent. */
    365  1.1       uch 	if ((error = v7fs_datablock_foreach(fs, parent_dir, remove_subr,
    366  1.1       uch 	    &lookup_arg)) != V7FS_ITERATOR_BREAK)
    367  1.1       uch 		return ENOENT;
    368  1.1       uch 
    369  1.1       uch 	/* Contract dirent entries. */
    370  1.1       uch 	v7fs_datablock_contract(fs, parent_dir, sizeof(lastdirent));
    371  1.1       uch 	DPRINTF("done. (dirent size=%dbyte)\n", parent_dir->filesize);
    372  1.1       uch 
    373  1.1       uch 	/* Target inode */
    374  1.1       uch 	if ((error = v7fs_inode_load(fs, &inode, lookup_arg.inode_number)))
    375  1.1       uch 		return error;
    376  1.1       uch 
    377  1.1       uch 	if (v7fs_inode_isdir(&inode)) {
    378  1.1       uch 		parent_dir->nlink--;
    379  1.1       uch 		v7fs_inode_writeback(fs, parent_dir);
    380  1.1       uch 	}
    381  1.1       uch 
    382  1.1       uch 	return 0;
    383  1.1       uch }
    384  1.1       uch 
    385  1.1       uch static int
    386  1.1       uch remove_subr(struct v7fs_self *fs, void *ctx, v7fs_daddr_t blk, size_t sz)
    387  1.1       uch {
    388  1.1       uch 	struct v7fs_lookup_arg *p = (struct v7fs_lookup_arg *)ctx;
    389  1.1       uch 	struct v7fs_dirent *dir;
    390  1.1       uch 	void *buf;
    391  1.1       uch 	size_t i;
    392  1.1       uch 	int ret = 0;
    393  1.1       uch 
    394  1.1       uch 	DPRINTF("match start blk=%x\n", blk);
    395  1.1       uch 	if (!(buf = scratch_read(fs, blk)))
    396  1.1       uch 		return EIO;
    397  1.1       uch 
    398  1.1       uch 	dir = (struct v7fs_dirent *)buf;
    399  1.1       uch 
    400  1.1       uch 	for (i = 0; i < sz / sizeof(*dir); i++, dir++) {
    401  1.1       uch 		DPRINTF("%d\n", V7FS_VAL16(fs, dir->inode_number));
    402  1.1       uch 		if (strncmp(p->name,
    403  1.1       uch 			(const char *)dir->name, V7FS_NAME_MAX) == 0) {
    404  1.1       uch 			p->inode_number = V7FS_VAL16(fs, dir->inode_number);
    405  1.1       uch 			/* Replace to last dirent. */
    406  1.1       uch 			*dir = *(p->replace); /* disk endian */
    407  1.1       uch 			/* Write back. */
    408  1.1       uch 			if (!fs->io.write(fs->io.cookie, buf, blk))
    409  1.1       uch 				ret = EIO;
    410  1.1       uch 			else
    411  1.1       uch 				ret = V7FS_ITERATOR_BREAK;
    412  1.1       uch 			break;
    413  1.1       uch 		}
    414  1.1       uch 	}
    415  1.1       uch 	scratch_free(fs, buf);
    416  1.1       uch 
    417  1.1       uch 	return ret;
    418  1.1       uch }
    419