xref: /freebsd/stand/libsa/cd9660read.c (revision 7c43148a974877188a930e4078a164f83da8e652)
17acb51f6SBenno Rice /*
27acb51f6SBenno Rice  * Copyright (C) 1996 Wolfgang Solfrank.
37acb51f6SBenno Rice  * Copyright (C) 1996 TooLs GmbH.
47acb51f6SBenno Rice  * All rights reserved.
57acb51f6SBenno Rice  *
67acb51f6SBenno Rice  * Redistribution and use in source and binary forms, with or without
77acb51f6SBenno Rice  * modification, are permitted provided that the following conditions
87acb51f6SBenno Rice  * are met:
97acb51f6SBenno Rice  * 1. Redistributions of source code must retain the above copyright
107acb51f6SBenno Rice  *    notice, this list of conditions and the following disclaimer.
117acb51f6SBenno Rice  * 2. Redistributions in binary form must reproduce the above copyright
127acb51f6SBenno Rice  *    notice, this list of conditions and the following disclaimer in the
137acb51f6SBenno Rice  *    documentation and/or other materials provided with the distribution.
147acb51f6SBenno Rice  * 3. All advertising materials mentioning features or use of this software
157acb51f6SBenno Rice  *    must display the following acknowledgement:
167acb51f6SBenno Rice  *	This product includes software developed by TooLs GmbH.
177acb51f6SBenno Rice  * 4. The name of TooLs GmbH may not be used to endorse or promote products
187acb51f6SBenno Rice  *    derived from this software without specific prior written permission.
197acb51f6SBenno Rice  *
207acb51f6SBenno Rice  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
217acb51f6SBenno Rice  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
227acb51f6SBenno Rice  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
237acb51f6SBenno Rice  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
247acb51f6SBenno Rice  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
257acb51f6SBenno Rice  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
267acb51f6SBenno Rice  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
277acb51f6SBenno Rice  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
287acb51f6SBenno Rice  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
297acb51f6SBenno Rice  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
307acb51f6SBenno Rice  */
317acb51f6SBenno Rice 
327acb51f6SBenno Rice /* Originally derived from libsa/cd9660.c: */
337acb51f6SBenno Rice /*	$NetBSD: cd9660.c,v 1.5 1997/06/26 19:11:33 drochner Exp $	*/
347acb51f6SBenno Rice 
35*8ac66965SToomas Soome #include <sys/param.h>
367acb51f6SBenno Rice #include <fs/cd9660/iso.h>
377acb51f6SBenno Rice #include <fs/cd9660/cd9660_rrip.h>
387acb51f6SBenno Rice 
397acb51f6SBenno Rice static uint64_t cd9660_lookup(const char *);
407acb51f6SBenno Rice static ssize_t cd9660_fsread(uint64_t, void *, size_t);
417acb51f6SBenno Rice 
427acb51f6SBenno Rice #define	SUSP_CONTINUATION	"CE"
437acb51f6SBenno Rice #define	SUSP_PRESENT		"SP"
447acb51f6SBenno Rice #define	SUSP_STOP		"ST"
457acb51f6SBenno Rice #define	SUSP_EXTREF		"ER"
467acb51f6SBenno Rice #define	RRIP_NAME		"NM"
477acb51f6SBenno Rice 
487acb51f6SBenno Rice typedef struct {
497acb51f6SBenno Rice 	ISO_SUSP_HEADER		h;
507acb51f6SBenno Rice 	u_char signature	[ISODCL (  5,    6)];
517acb51f6SBenno Rice 	u_char len_skp		[ISODCL (  7,    7)]; /* 711 */
527acb51f6SBenno Rice } ISO_SUSP_PRESENT;
537acb51f6SBenno Rice 
547acb51f6SBenno Rice static int
read_iso_block(void * buffer,daddr_t blkno)557acb51f6SBenno Rice read_iso_block(void *buffer, daddr_t blkno)
567acb51f6SBenno Rice {
577acb51f6SBenno Rice 
587acb51f6SBenno Rice 	return (drvread(&dsk, buffer, blkno * 4, 4));
597acb51f6SBenno Rice }
607acb51f6SBenno Rice 
617acb51f6SBenno Rice static ISO_SUSP_HEADER *
susp_lookup_record(const char * identifier,struct iso_directory_record * dp,int lenskip)627acb51f6SBenno Rice susp_lookup_record(const char *identifier, struct iso_directory_record *dp,
637acb51f6SBenno Rice     int lenskip)
647acb51f6SBenno Rice {
657acb51f6SBenno Rice 	static char susp_buffer[ISO_DEFAULT_BLOCK_SIZE];
667acb51f6SBenno Rice 	ISO_SUSP_HEADER *sh;
677acb51f6SBenno Rice 	ISO_RRIP_CONT *shc;
687acb51f6SBenno Rice 	char *p, *end;
697acb51f6SBenno Rice 	int error;
707acb51f6SBenno Rice 
717acb51f6SBenno Rice 	p = dp->name + isonum_711(dp->name_len) + lenskip;
727acb51f6SBenno Rice 	/* Names of even length have a padding byte after the name. */
737acb51f6SBenno Rice 	if ((isonum_711(dp->name_len) & 1) == 0)
747acb51f6SBenno Rice 		p++;
757acb51f6SBenno Rice 	end = (char *)dp + isonum_711(dp->length);
767acb51f6SBenno Rice 	while (p + 3 < end) {
777acb51f6SBenno Rice 		sh = (ISO_SUSP_HEADER *)p;
787acb51f6SBenno Rice 		if (bcmp(sh->type, identifier, 2) == 0)
797acb51f6SBenno Rice 			return (sh);
807acb51f6SBenno Rice 		if (bcmp(sh->type, SUSP_STOP, 2) == 0)
817acb51f6SBenno Rice 			return (NULL);
827acb51f6SBenno Rice 		if (bcmp(sh->type, SUSP_CONTINUATION, 2) == 0) {
837acb51f6SBenno Rice 			shc = (ISO_RRIP_CONT *)sh;
847acb51f6SBenno Rice 			error = read_iso_block(susp_buffer,
857acb51f6SBenno Rice 			    isonum_733(shc->location));
867acb51f6SBenno Rice 
877acb51f6SBenno Rice 			/* Bail if it fails. */
887acb51f6SBenno Rice 			if (error != 0)
897acb51f6SBenno Rice 				return (NULL);
907acb51f6SBenno Rice 			p = susp_buffer + isonum_733(shc->offset);
917acb51f6SBenno Rice 			end = p + isonum_733(shc->length);
927acb51f6SBenno Rice 		} else {
937acb51f6SBenno Rice 			/* Ignore this record and skip to the next. */
947acb51f6SBenno Rice 			p += isonum_711(sh->length);
957acb51f6SBenno Rice 
967acb51f6SBenno Rice 			/* Avoid infinite loops with corrupted file systems */
977acb51f6SBenno Rice 			if (isonum_711(sh->length) == 0)
987acb51f6SBenno Rice 				return (NULL);
997acb51f6SBenno Rice 		}
1007acb51f6SBenno Rice 	}
1017acb51f6SBenno Rice 	return (NULL);
1027acb51f6SBenno Rice }
1037acb51f6SBenno Rice 
1047acb51f6SBenno Rice static const char *
rrip_lookup_name(struct iso_directory_record * dp,int lenskip,size_t * len)1057acb51f6SBenno Rice rrip_lookup_name(struct iso_directory_record *dp, int lenskip, size_t *len)
1067acb51f6SBenno Rice {
1077acb51f6SBenno Rice 	ISO_RRIP_ALTNAME *p;
1087acb51f6SBenno Rice 
1097acb51f6SBenno Rice 	if (len == NULL)
1107acb51f6SBenno Rice 		return (NULL);
1117acb51f6SBenno Rice 
1127acb51f6SBenno Rice 	p = (ISO_RRIP_ALTNAME *)susp_lookup_record(RRIP_NAME, dp, lenskip);
1137acb51f6SBenno Rice 	if (p == NULL)
1147acb51f6SBenno Rice 		return (NULL);
1157acb51f6SBenno Rice 	switch (*p->flags) {
1167acb51f6SBenno Rice 	case ISO_SUSP_CFLAG_CURRENT:
1177acb51f6SBenno Rice 		*len = 1;
1187acb51f6SBenno Rice 		return (".");
1197acb51f6SBenno Rice 	case ISO_SUSP_CFLAG_PARENT:
1207acb51f6SBenno Rice 		*len = 2;
1217acb51f6SBenno Rice 		return ("..");
1227acb51f6SBenno Rice 	case 0:
1237acb51f6SBenno Rice 		*len = isonum_711(p->h.length) - 5;
1247acb51f6SBenno Rice 		return ((char *)p + 5);
1257acb51f6SBenno Rice 	default:
1267acb51f6SBenno Rice 		/*
1277acb51f6SBenno Rice 		 * We don't handle hostnames or continued names as they are
1287acb51f6SBenno Rice 		 * too hard, so just bail and use the default name.
1297acb51f6SBenno Rice 		 */
1307acb51f6SBenno Rice 		return (NULL);
1317acb51f6SBenno Rice 	}
1327acb51f6SBenno Rice }
1337acb51f6SBenno Rice 
1347acb51f6SBenno Rice static int
rrip_check(struct iso_directory_record * dp,int * lenskip)1357acb51f6SBenno Rice rrip_check(struct iso_directory_record *dp, int *lenskip)
1367acb51f6SBenno Rice {
1377acb51f6SBenno Rice 	ISO_SUSP_PRESENT *sp;
1387acb51f6SBenno Rice 	ISO_RRIP_EXTREF *er;
1397acb51f6SBenno Rice 	char *p;
1407acb51f6SBenno Rice 
1417acb51f6SBenno Rice 	/* First, see if we can find a SP field. */
1427acb51f6SBenno Rice 	p = dp->name + isonum_711(dp->name_len);
1437acb51f6SBenno Rice 	if (p > (char *)dp + isonum_711(dp->length)) {
1447acb51f6SBenno Rice 		return (0);
1457acb51f6SBenno Rice 	}
1467acb51f6SBenno Rice 	sp = (ISO_SUSP_PRESENT *)p;
1477acb51f6SBenno Rice 	if (bcmp(sp->h.type, SUSP_PRESENT, 2) != 0) {
1487acb51f6SBenno Rice 		return (0);
1497acb51f6SBenno Rice 	}
1507acb51f6SBenno Rice 	if (isonum_711(sp->h.length) != sizeof(ISO_SUSP_PRESENT)) {
1517acb51f6SBenno Rice 		return (0);
1527acb51f6SBenno Rice 	}
1537acb51f6SBenno Rice 	if (sp->signature[0] != 0xbe || sp->signature[1] != 0xef) {
1547acb51f6SBenno Rice 		return (0);
1557acb51f6SBenno Rice 	}
1567acb51f6SBenno Rice 	*lenskip = isonum_711(sp->len_skp);
1577acb51f6SBenno Rice 
1587acb51f6SBenno Rice 	/*
1597acb51f6SBenno Rice 	 * Now look for an ER field.  If RRIP is present, then there must
1607acb51f6SBenno Rice 	 * be at least one of these.  It would be more pedantic to walk
1617acb51f6SBenno Rice 	 * through the list of fields looking for a Rock Ridge ER field.
1627acb51f6SBenno Rice 	 */
1637acb51f6SBenno Rice 	er = (ISO_RRIP_EXTREF *)susp_lookup_record(SUSP_EXTREF, dp, 0);
1647acb51f6SBenno Rice 	if (er == NULL) {
1657acb51f6SBenno Rice 		return (0);
1667acb51f6SBenno Rice 	}
1677acb51f6SBenno Rice 	return (1);
1687acb51f6SBenno Rice }
1697acb51f6SBenno Rice 
1707acb51f6SBenno Rice static int
dirmatch(const char * path,struct iso_directory_record * dp,int use_rrip,int lenskip)1717acb51f6SBenno Rice dirmatch(const char *path, struct iso_directory_record *dp, int use_rrip,
1727acb51f6SBenno Rice     int lenskip)
1737acb51f6SBenno Rice {
1747acb51f6SBenno Rice 	size_t len;
175b1e0bc12SToomas Soome 	const char *cp = NULL;
1767acb51f6SBenno Rice 	int i, icase;
1777acb51f6SBenno Rice 
1787acb51f6SBenno Rice 	if (use_rrip)
1797acb51f6SBenno Rice 		cp = rrip_lookup_name(dp, lenskip, &len);
1807acb51f6SBenno Rice 	else
1817acb51f6SBenno Rice 		cp = NULL;
1827acb51f6SBenno Rice 	if (cp == NULL) {
1837acb51f6SBenno Rice 		len = isonum_711(dp->name_len);
1847acb51f6SBenno Rice 		cp = dp->name;
1857acb51f6SBenno Rice 		icase = 1;
1867acb51f6SBenno Rice 	} else
1877acb51f6SBenno Rice 		icase = 0;
1887acb51f6SBenno Rice 	for (i = len; --i >= 0; path++, cp++) {
1897acb51f6SBenno Rice 		if (!*path || *path == '/')
1907acb51f6SBenno Rice 			break;
1917acb51f6SBenno Rice 		if (*path == *cp)
1927acb51f6SBenno Rice 			continue;
1937acb51f6SBenno Rice 		if (!icase && toupper(*path) == *cp)
1947acb51f6SBenno Rice 			continue;
1957acb51f6SBenno Rice 		return 0;
1967acb51f6SBenno Rice 	}
1977acb51f6SBenno Rice 	if (*path && *path != '/') {
1987acb51f6SBenno Rice 		return 0;
1997acb51f6SBenno Rice 	}
2007acb51f6SBenno Rice 	/*
2017acb51f6SBenno Rice 	 * Allow stripping of trailing dots and the version number.
2027acb51f6SBenno Rice 	 * Note that this will find the first instead of the last version
2037acb51f6SBenno Rice 	 * of a file.
2047acb51f6SBenno Rice 	 */
2057acb51f6SBenno Rice 	if (i >= 0 && (*cp == ';' || *cp == '.')) {
2067acb51f6SBenno Rice 		/* This is to prevent matching of numeric extensions */
2077acb51f6SBenno Rice 		if (*cp == '.' && cp[1] != ';') {
2087acb51f6SBenno Rice 			return 0;
2097acb51f6SBenno Rice 		}
2107acb51f6SBenno Rice 		while (--i >= 0)
2117acb51f6SBenno Rice 			if (*++cp != ';' && (*cp < '0' || *cp > '9')) {
2127acb51f6SBenno Rice 				return 0;
2137acb51f6SBenno Rice 			}
2147acb51f6SBenno Rice 	}
2157acb51f6SBenno Rice 	return 1;
2167acb51f6SBenno Rice }
2177acb51f6SBenno Rice 
2187acb51f6SBenno Rice static uint64_t
cd9660_lookup(const char * path)2197acb51f6SBenno Rice cd9660_lookup(const char *path)
2207acb51f6SBenno Rice {
221*8ac66965SToomas Soome 	static char blkbuf[MAX(ISO_DEFAULT_BLOCK_SIZE,
222*8ac66965SToomas Soome 	    sizeof(struct iso_primary_descriptor))];
2237acb51f6SBenno Rice 	struct iso_primary_descriptor *vd;
2247acb51f6SBenno Rice 	struct iso_directory_record rec;
2257acb51f6SBenno Rice 	struct iso_directory_record *dp = NULL;
2267acb51f6SBenno Rice 	size_t dsize, off;
2277acb51f6SBenno Rice 	daddr_t bno, boff;
2287acb51f6SBenno Rice 	int rc, first, use_rrip, lenskip;
2297acb51f6SBenno Rice 	uint64_t cookie;
2307acb51f6SBenno Rice 
2317acb51f6SBenno Rice 	for (bno = 16;; bno++) {
2327acb51f6SBenno Rice 		rc = read_iso_block(blkbuf, bno);
2337acb51f6SBenno Rice 		vd = (struct iso_primary_descriptor *)blkbuf;
2347acb51f6SBenno Rice 
2357acb51f6SBenno Rice 		if (bcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
2367acb51f6SBenno Rice 			return (0);
2377acb51f6SBenno Rice 		if (isonum_711(vd->type) == ISO_VD_END)
2387acb51f6SBenno Rice 			return (0);
2397acb51f6SBenno Rice 		if (isonum_711(vd->type) == ISO_VD_PRIMARY)
2407acb51f6SBenno Rice 			break;
2417acb51f6SBenno Rice 	}
2427acb51f6SBenno Rice 
24317e2c266SToomas Soome 	bcopy(vd->root_directory_record, &rec, sizeof(rec));
2447acb51f6SBenno Rice 	if (*path == '/') path++; /* eat leading '/' */
2457acb51f6SBenno Rice 
2467acb51f6SBenno Rice 	first = 1;
2477acb51f6SBenno Rice 	use_rrip = 0;
248213f235fSToomas Soome 	lenskip = 0;
2497acb51f6SBenno Rice 	while (*path) {
2507acb51f6SBenno Rice 		bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
2517acb51f6SBenno Rice 		dsize = isonum_733(rec.size);
2527acb51f6SBenno Rice 		off = 0;
2537acb51f6SBenno Rice 		boff = 0;
2547acb51f6SBenno Rice 
2557acb51f6SBenno Rice 		while (off < dsize) {
2567acb51f6SBenno Rice 			if ((off % ISO_DEFAULT_BLOCK_SIZE) == 0) {
2577acb51f6SBenno Rice 				rc = read_iso_block(blkbuf, bno + boff);
2587acb51f6SBenno Rice 				if (rc) {
2597acb51f6SBenno Rice 					return (0);
2607acb51f6SBenno Rice 				}
2617acb51f6SBenno Rice 				boff++;
2627acb51f6SBenno Rice 				dp = (struct iso_directory_record *) blkbuf;
2637acb51f6SBenno Rice 			}
2647acb51f6SBenno Rice 			if (isonum_711(dp->length) == 0) {
2657acb51f6SBenno Rice 				/* skip to next block, if any */
2667acb51f6SBenno Rice 				off = boff * ISO_DEFAULT_BLOCK_SIZE;
2677acb51f6SBenno Rice 				continue;
2687acb51f6SBenno Rice 			}
2697acb51f6SBenno Rice 
2707acb51f6SBenno Rice 			/* See if RRIP is in use. */
2717acb51f6SBenno Rice 			if (first)
2727acb51f6SBenno Rice 				use_rrip = rrip_check(dp, &lenskip);
2737acb51f6SBenno Rice 
2747acb51f6SBenno Rice 			if (dirmatch(path, dp, use_rrip,
2757acb51f6SBenno Rice 			    first ? 0 : lenskip)) {
2767acb51f6SBenno Rice 				first = 0;
2777acb51f6SBenno Rice 				break;
2787acb51f6SBenno Rice 			} else
2797acb51f6SBenno Rice 				first = 0;
2807acb51f6SBenno Rice 
2817acb51f6SBenno Rice 			dp = (struct iso_directory_record *)
2827acb51f6SBenno Rice 			    ((char *) dp + isonum_711(dp->length));
2837acb51f6SBenno Rice 			/* If the new block has zero length, it is padding. */
2847acb51f6SBenno Rice 			if (isonum_711(dp->length) == 0) {
2857acb51f6SBenno Rice 				/* Skip to next block, if any. */
2867acb51f6SBenno Rice 				off = boff * ISO_DEFAULT_BLOCK_SIZE;
2877acb51f6SBenno Rice 				continue;
2887acb51f6SBenno Rice 			}
2897acb51f6SBenno Rice 			off += isonum_711(dp->length);
2907acb51f6SBenno Rice 		}
2917acb51f6SBenno Rice 		if (off >= dsize) {
2927acb51f6SBenno Rice 			return (0);
2937acb51f6SBenno Rice 		}
2947acb51f6SBenno Rice 
2957acb51f6SBenno Rice 		rec = *dp;
2967acb51f6SBenno Rice 		while (*path && *path != '/') /* look for next component */
2977acb51f6SBenno Rice 			path++;
2987acb51f6SBenno Rice 		if (*path) path++; /* skip '/' */
2997acb51f6SBenno Rice 	}
3007acb51f6SBenno Rice 
3017acb51f6SBenno Rice 	if ((isonum_711(rec.flags) & 2) != 0) {
3027acb51f6SBenno Rice 		return (0);
3037acb51f6SBenno Rice 	}
3047acb51f6SBenno Rice 
3057acb51f6SBenno Rice 	cookie = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
3067acb51f6SBenno Rice 	cookie = (cookie << 32) | isonum_733(rec.size);
3077acb51f6SBenno Rice 
3087acb51f6SBenno Rice 	return (cookie);
3097acb51f6SBenno Rice }
3107acb51f6SBenno Rice 
3117acb51f6SBenno Rice static ssize_t
cd9660_fsread(uint64_t cookie,void * buf,size_t nbytes)3127acb51f6SBenno Rice cd9660_fsread(uint64_t cookie, void *buf, size_t nbytes)
3137acb51f6SBenno Rice {
3147acb51f6SBenno Rice 	static char blkbuf[ISO_DEFAULT_BLOCK_SIZE];
3157acb51f6SBenno Rice 	static daddr_t curstart = 0, curblk = 0;
3167acb51f6SBenno Rice 	daddr_t blk, blk_off;
3177acb51f6SBenno Rice 	off_t byte_off;
3187acb51f6SBenno Rice 	size_t size, remaining, n;
3197acb51f6SBenno Rice 	char *s;
3207acb51f6SBenno Rice 
3217acb51f6SBenno Rice 	size = cookie & 0xffffffff;
3227acb51f6SBenno Rice 	blk = (cookie >> 32) & 0xffffffff;
3237acb51f6SBenno Rice 
3247acb51f6SBenno Rice 	/* Make sure we're looking at the right file. */
3257acb51f6SBenno Rice 	if (((blk << 32) | size) != cookie) {
3267acb51f6SBenno Rice 		return (-1);
3277acb51f6SBenno Rice 	}
3287acb51f6SBenno Rice 
3297acb51f6SBenno Rice 	if (blk != curstart) {
3307acb51f6SBenno Rice 		curstart = blk;
3317acb51f6SBenno Rice 		fs_off = 0;
3327acb51f6SBenno Rice 	}
3337acb51f6SBenno Rice 
3347acb51f6SBenno Rice 	size -= fs_off;
3357acb51f6SBenno Rice 	if (size < nbytes) {
3367acb51f6SBenno Rice 		nbytes = size;
3377acb51f6SBenno Rice 	}
3387acb51f6SBenno Rice 	remaining = nbytes;
3397acb51f6SBenno Rice 	s = buf;
3407acb51f6SBenno Rice 
3417acb51f6SBenno Rice 	while (remaining > 0) {
3427acb51f6SBenno Rice 		blk_off = fs_off >> ISO_DEFAULT_BLOCK_SHIFT;
3437acb51f6SBenno Rice 		byte_off = fs_off & (ISO_DEFAULT_BLOCK_SIZE - 1);
3447acb51f6SBenno Rice 
3457acb51f6SBenno Rice 		if (curblk != curstart + blk_off) {
3467acb51f6SBenno Rice 			curblk = curstart + blk_off;
3477acb51f6SBenno Rice 			read_iso_block(blkbuf, curblk);
3487acb51f6SBenno Rice 		}
3497acb51f6SBenno Rice 
3507acb51f6SBenno Rice 		if (remaining < ISO_DEFAULT_BLOCK_SIZE - byte_off) {
3517acb51f6SBenno Rice 			n = remaining;
3527acb51f6SBenno Rice 		} else {
3537acb51f6SBenno Rice 			n = ISO_DEFAULT_BLOCK_SIZE - byte_off;
3547acb51f6SBenno Rice 		}
3557acb51f6SBenno Rice 		memcpy(s, blkbuf + byte_off, n);
3567acb51f6SBenno Rice 		remaining -= n;
3577acb51f6SBenno Rice 		s += n;
3587acb51f6SBenno Rice 
3597acb51f6SBenno Rice 		fs_off += n;
3607acb51f6SBenno Rice 	}
3617acb51f6SBenno Rice 
3627acb51f6SBenno Rice 	return (nbytes);
3637acb51f6SBenno Rice }
364