17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*ae115bc7Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Basic file system reading code for standalone I/O system.
307c478bd9Sstevel@tonic-gate * Simulates a primitive UNIX I/O system (read(), write(), open(), etc).
317c478bd9Sstevel@tonic-gate * Does not support writes.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
387c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
397c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
427c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
437c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
447c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
457c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
467c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h>
477c478bd9Sstevel@tonic-gate #include <sys/filep.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #ifdef _BOOT
507c478bd9Sstevel@tonic-gate #include "../common/util.h"
517c478bd9Sstevel@tonic-gate #else
527c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate #define hdbtodb(n) ((ISO_SECTOR_SIZE / DEV_BSIZE) * (n))
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate #define HSFS_NUM_SIG 14
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #define SUSP_SP_IX 0
607c478bd9Sstevel@tonic-gate #define SUSP_CE_IX 1
617c478bd9Sstevel@tonic-gate #define SUSP_PD_IX 2
627c478bd9Sstevel@tonic-gate #define SUSP_ST_IX 3
637c478bd9Sstevel@tonic-gate #define SUSP_ER_IX 4
647c478bd9Sstevel@tonic-gate #define RRIP_PX_IX 5
657c478bd9Sstevel@tonic-gate #define RRIP_PN_IX 6
667c478bd9Sstevel@tonic-gate #define RRIP_SL_IX 7
677c478bd9Sstevel@tonic-gate #define RRIP_CL_IX 8
687c478bd9Sstevel@tonic-gate #define RRIP_PL_IX 9
697c478bd9Sstevel@tonic-gate #define RRIP_RE_IX 10
707c478bd9Sstevel@tonic-gate #define RRIP_RF_IX 11
717c478bd9Sstevel@tonic-gate #define RRIP_RR_IX 12
727c478bd9Sstevel@tonic-gate #define RRIP_NM_IX 13
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #ifdef _BOOT
757c478bd9Sstevel@tonic-gate #define dprintf if (bootrd_debug) printf
767c478bd9Sstevel@tonic-gate #else
777c478bd9Sstevel@tonic-gate #define printf kobj_printf
787c478bd9Sstevel@tonic-gate #define dprintf if (bootrd_debug) kobj_printf
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */
817c478bd9Sstevel@tonic-gate extern void kobj_printf(char *, ...);
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate extern int bootrd_debug;
857c478bd9Sstevel@tonic-gate extern void *bkmem_alloc(size_t);
867c478bd9Sstevel@tonic-gate extern void bkmem_free(void *, size_t);
87*ae115bc7Smrj extern int cf_check_compressed(fileid_t *);
88*ae115bc7Smrj extern void cf_close(fileid_t *);
89*ae115bc7Smrj extern void cf_seek(fileid_t *, off_t, int);
90*ae115bc7Smrj extern int cf_read(fileid_t *, caddr_t, size_t);
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate struct dirstuff {
937c478bd9Sstevel@tonic-gate int loc;
947c478bd9Sstevel@tonic-gate fileid_t *filep;
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate struct hs_direct {
987c478bd9Sstevel@tonic-gate struct direct hs_ufs_dir;
997c478bd9Sstevel@tonic-gate struct hs_direntry hs_dir;
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate static uint_t root_ino = 0;
1037c478bd9Sstevel@tonic-gate static struct hs_volume *hsfsp;
1047c478bd9Sstevel@tonic-gate static fileid_t *head;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate static char *hsfs_sig_tab[] = {
1077c478bd9Sstevel@tonic-gate SUSP_SP,
1087c478bd9Sstevel@tonic-gate SUSP_CE,
1097c478bd9Sstevel@tonic-gate SUSP_PD,
1107c478bd9Sstevel@tonic-gate SUSP_ST,
1117c478bd9Sstevel@tonic-gate SUSP_ER,
1127c478bd9Sstevel@tonic-gate RRIP_PX,
1137c478bd9Sstevel@tonic-gate RRIP_PN,
1147c478bd9Sstevel@tonic-gate RRIP_SL,
1157c478bd9Sstevel@tonic-gate RRIP_CL,
1167c478bd9Sstevel@tonic-gate RRIP_PL,
1177c478bd9Sstevel@tonic-gate RRIP_RE,
1187c478bd9Sstevel@tonic-gate RRIP_TF,
1197c478bd9Sstevel@tonic-gate RRIP_RR,
1207c478bd9Sstevel@tonic-gate RRIP_NM
1217c478bd9Sstevel@tonic-gate };
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate static int hsfs_num_sig = sizeof (hsfs_sig_tab) / sizeof (hsfs_sig_tab[0]);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate * Local prototypes
1277c478bd9Sstevel@tonic-gate */
1287c478bd9Sstevel@tonic-gate static struct hs_direct *readdir(struct dirstuff *);
1297c478bd9Sstevel@tonic-gate static uint_t parse_dir(fileid_t *, int, struct hs_direct *);
1307c478bd9Sstevel@tonic-gate static uint_t parse_susp(char *, uint_t *, struct hs_direct *);
1317c478bd9Sstevel@tonic-gate static ino_t dlook(char *, fileid_t *);
1327c478bd9Sstevel@tonic-gate static int opendir(ino_t, fileid_t *);
1337c478bd9Sstevel@tonic-gate static ino_t find(char *, fileid_t *);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate static int bhsfs_mountroot(char *str);
1367c478bd9Sstevel@tonic-gate static int bhsfs_unmountroot(void);
1377c478bd9Sstevel@tonic-gate static int bhsfs_open(char *str, int flags);
1387c478bd9Sstevel@tonic-gate static int bhsfs_close(int fd);
1397c478bd9Sstevel@tonic-gate static void bhsfs_closeall(void);
1407c478bd9Sstevel@tonic-gate static ssize_t bhsfs_read(int fdesc, char *buf, size_t count);
1417c478bd9Sstevel@tonic-gate static off_t bhsfs_lseek(int fdesc, off_t addr, int whence);
142ea8dc4b6Seschrock static int bhsfs_fstat(int fdesc, struct bootstat *stp);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate static fileid_t *
find_fp(int fd)1457c478bd9Sstevel@tonic-gate find_fp(int fd)
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate fileid_t *filep = head;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if (fd >= 0) {
1507c478bd9Sstevel@tonic-gate while ((filep = filep->fi_forw) != head)
1517c478bd9Sstevel@tonic-gate if (fd == filep->fi_filedes)
1527c478bd9Sstevel@tonic-gate return (filep->fi_taken ? filep : 0);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate return (0);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate static int
opendir(ino_t inode,fileid_t * filep)1597c478bd9Sstevel@tonic-gate opendir(ino_t inode, fileid_t *filep)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate struct hs_direct hsdep;
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate dprintf("opendir: inode = %ld\n", inode);
1647c478bd9Sstevel@tonic-gate /* Set up the IO request */
1657c478bd9Sstevel@tonic-gate filep->fi_offset = 0;
1667c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(inode);
1677c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE;
1687c478bd9Sstevel@tonic-gate filep->fi_memp = 0;
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate if (diskread(filep))
1717c478bd9Sstevel@tonic-gate return (0);
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate filep->fi_offset = 0;
1747c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(inode);
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate if (inode != root_ino)
1777c478bd9Sstevel@tonic-gate return (0);
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate if (parse_dir(filep, 0, &hsdep) > 0) {
1807c478bd9Sstevel@tonic-gate struct inode *ip;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate ip = filep->fi_inode;
1837c478bd9Sstevel@tonic-gate if (ip == NULL)
1847c478bd9Sstevel@tonic-gate ip = filep->fi_inode = bkmem_alloc(sizeof (*ip));
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate ip->i_size = hsdep.hs_dir.ext_size;
1877c478bd9Sstevel@tonic-gate ip->i_smode = hsdep.hs_dir.mode;
1887c478bd9Sstevel@tonic-gate ip->i_number = inode;
1897c478bd9Sstevel@tonic-gate return (0);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate return (1);
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate static ino_t
find(char * path,fileid_t * filep)1957c478bd9Sstevel@tonic-gate find(char *path, fileid_t *filep)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate char *q;
1987c478bd9Sstevel@tonic-gate char c;
1997c478bd9Sstevel@tonic-gate ino_t n;
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate dprintf("find: %s\n", path);
2027c478bd9Sstevel@tonic-gate if (path == NULL || *path == '\0')
2037c478bd9Sstevel@tonic-gate return (0);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate if (opendir(root_ino, filep))
2067c478bd9Sstevel@tonic-gate return (0);
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate while (*path) {
2097c478bd9Sstevel@tonic-gate while (*path == '/')
2107c478bd9Sstevel@tonic-gate path++;
2117c478bd9Sstevel@tonic-gate q = path;
2127c478bd9Sstevel@tonic-gate while (*q != '/' && *q != '\0')
2137c478bd9Sstevel@tonic-gate q++;
2147c478bd9Sstevel@tonic-gate c = *q;
2157c478bd9Sstevel@tonic-gate *q = '\0';
216f55ce205Sszhou n = dlook(path, filep);
217f55ce205Sszhou *q = c;
218f55ce205Sszhou path = q;
2197c478bd9Sstevel@tonic-gate
220f55ce205Sszhou if (n != 0) {
2217c478bd9Sstevel@tonic-gate if (c == '\0')
2227c478bd9Sstevel@tonic-gate break;
2237c478bd9Sstevel@tonic-gate if (opendir(n, filep))
2247c478bd9Sstevel@tonic-gate return (0);
2257c478bd9Sstevel@tonic-gate continue;
2267c478bd9Sstevel@tonic-gate } else {
2277c478bd9Sstevel@tonic-gate return (0);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate return ((ino_t)n);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate static ino_t
dlook(char * s,fileid_t * filep)2347c478bd9Sstevel@tonic-gate dlook(char *s, fileid_t *filep)
2357c478bd9Sstevel@tonic-gate {
2367c478bd9Sstevel@tonic-gate struct hs_direct *hsdep;
2377c478bd9Sstevel@tonic-gate struct direct *udp;
2387c478bd9Sstevel@tonic-gate struct inode *ip;
2397c478bd9Sstevel@tonic-gate struct dirstuff dirp;
2407c478bd9Sstevel@tonic-gate int len;
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate dprintf("dlook: %s\n", s);
2437c478bd9Sstevel@tonic-gate ip = filep->fi_inode;
2447c478bd9Sstevel@tonic-gate if (s == NULL || *s == '\0')
2457c478bd9Sstevel@tonic-gate return (0);
2467c478bd9Sstevel@tonic-gate if ((ip->i_smode & IFMT) != IFDIR) {
2477c478bd9Sstevel@tonic-gate return (0);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate if (ip->i_size == 0) {
2507c478bd9Sstevel@tonic-gate return (0);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate len = strlen(s);
2537c478bd9Sstevel@tonic-gate dirp.loc = 0;
2547c478bd9Sstevel@tonic-gate dirp.filep = filep;
2557c478bd9Sstevel@tonic-gate for (hsdep = readdir(&dirp); hsdep != NULL; hsdep = readdir(&dirp)) {
2567c478bd9Sstevel@tonic-gate udp = &hsdep->hs_ufs_dir;
2577c478bd9Sstevel@tonic-gate if (udp->d_namlen == 1 &&
2587c478bd9Sstevel@tonic-gate udp->d_name[0] == '.' &&
2597c478bd9Sstevel@tonic-gate udp->d_name[1] == '\0')
2607c478bd9Sstevel@tonic-gate continue;
2617c478bd9Sstevel@tonic-gate if (udp->d_namlen == 2 &&
2627c478bd9Sstevel@tonic-gate udp->d_name[0] == '.' &&
2637c478bd9Sstevel@tonic-gate udp->d_name[1] == '.' &&
2647c478bd9Sstevel@tonic-gate udp->d_name[2] == '\0')
2657c478bd9Sstevel@tonic-gate continue;
2667c478bd9Sstevel@tonic-gate if (udp->d_namlen == len && (strcmp(s, udp->d_name)) == 0) {
2677c478bd9Sstevel@tonic-gate struct inode *ip = filep->fi_inode;
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate filep->fi_offset = 0;
2707c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(udp->d_ino);
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate bzero(filep->fi_inode, sizeof (struct inode));
2737c478bd9Sstevel@tonic-gate ip->i_size = hsdep->hs_dir.ext_size;
2747c478bd9Sstevel@tonic-gate ip->i_smode = hsdep->hs_dir.mode;
2757c478bd9Sstevel@tonic-gate ip->i_number = udp->d_ino;
2767c478bd9Sstevel@tonic-gate return (udp->d_ino);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate return (0);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate * get next entry in a directory.
2847c478bd9Sstevel@tonic-gate */
2857c478bd9Sstevel@tonic-gate static struct hs_direct *
readdir(struct dirstuff * dirp)2867c478bd9Sstevel@tonic-gate readdir(struct dirstuff *dirp)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate static struct hs_direct hsdep;
2897c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep.hs_ufs_dir;
2907c478bd9Sstevel@tonic-gate struct inode *ip;
2917c478bd9Sstevel@tonic-gate fileid_t *filep;
2927c478bd9Sstevel@tonic-gate daddr_t lbn;
2937c478bd9Sstevel@tonic-gate int off;
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate dprintf("readdir: start\n");
2967c478bd9Sstevel@tonic-gate filep = dirp->filep;
2977c478bd9Sstevel@tonic-gate ip = filep->fi_inode;
2987c478bd9Sstevel@tonic-gate for (;;) {
2997c478bd9Sstevel@tonic-gate if (dirp->loc >= ip->i_size) {
3007c478bd9Sstevel@tonic-gate return (NULL);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate off = dirp->loc & ((1 << ISO_SECTOR_SHIFT) - 1);
3037c478bd9Sstevel@tonic-gate if (off == 0) {
3047c478bd9Sstevel@tonic-gate lbn = hdbtodb(dirp->loc >> ISO_SECTOR_SHIFT);
3057c478bd9Sstevel@tonic-gate filep->fi_blocknum = lbn + hdbtodb(ip->i_number);
3067c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE;
3077c478bd9Sstevel@tonic-gate filep->fi_memp = 0;
3087c478bd9Sstevel@tonic-gate if (diskread(filep)) {
3097c478bd9Sstevel@tonic-gate dprintf("readdir: diskread failed\n");
3107c478bd9Sstevel@tonic-gate return (NULL);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate dirp->loc += parse_dir(filep, off, &hsdep);
3147c478bd9Sstevel@tonic-gate if (udp->d_reclen == 0 && dirp->loc <= ip->i_size) {
3157c478bd9Sstevel@tonic-gate dirp->loc = roundup(dirp->loc, ISO_SECTOR_SIZE);
3167c478bd9Sstevel@tonic-gate continue;
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate return (&hsdep);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate static int
getblock(fileid_t * filep)3237c478bd9Sstevel@tonic-gate getblock(fileid_t *filep)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate struct inode *ip = filep->fi_inode;
3267c478bd9Sstevel@tonic-gate int off, size, diff;
3277c478bd9Sstevel@tonic-gate daddr_t lbn;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate dprintf("getblock: start\n");
3307c478bd9Sstevel@tonic-gate diff = ip->i_size - filep->fi_offset;
3317c478bd9Sstevel@tonic-gate if (diff <= 0)
3327c478bd9Sstevel@tonic-gate return (-1);
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /* which block (or frag) in the file do we read? */
3357c478bd9Sstevel@tonic-gate lbn = hdbtodb(filep->fi_offset >> ISO_SECTOR_SHIFT);
3367c478bd9Sstevel@tonic-gate filep->fi_blocknum = lbn + hdbtodb(ip->i_number);
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate off = filep->fi_offset & ((1 << ISO_SECTOR_SHIFT) - 1);
3397c478bd9Sstevel@tonic-gate size = filep->fi_count = ISO_SECTOR_SIZE;
3407c478bd9Sstevel@tonic-gate filep->fi_memp = 0;
3417c478bd9Sstevel@tonic-gate if (diskread(filep)) /* Trap errors */
3427c478bd9Sstevel@tonic-gate return (-1);
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate if (filep->fi_offset - off + size >= ip->i_size)
3457c478bd9Sstevel@tonic-gate filep->fi_count = diff + off;
3467c478bd9Sstevel@tonic-gate filep->fi_count -= off;
3477c478bd9Sstevel@tonic-gate filep->fi_memp += off;
3487c478bd9Sstevel@tonic-gate dprintf("getblock: end\n");
3497c478bd9Sstevel@tonic-gate return (0);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate static ssize_t
bhsfs_read(int fd,caddr_t buf,size_t count)3537c478bd9Sstevel@tonic-gate bhsfs_read(int fd, caddr_t buf, size_t count)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate int i, j;
3567c478bd9Sstevel@tonic-gate fileid_t *filep;
3577c478bd9Sstevel@tonic-gate struct inode *ip;
3587c478bd9Sstevel@tonic-gate caddr_t n;
3597c478bd9Sstevel@tonic-gate
360*ae115bc7Smrj dprintf("bhsfs_read %d, ", fd);
361*ae115bc7Smrj dprintf("count 0x%lx\n", count);
3627c478bd9Sstevel@tonic-gate filep = find_fp(fd);
3637c478bd9Sstevel@tonic-gate if (filep == NULL)
3647c478bd9Sstevel@tonic-gate return (-1);
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate ip = filep->fi_inode;
3677c478bd9Sstevel@tonic-gate n = buf;
368*ae115bc7Smrj if ((filep->fi_flags & FI_COMPRESSED) == 0 &&
369*ae115bc7Smrj filep->fi_offset + count > ip->i_size)
3707c478bd9Sstevel@tonic-gate count = ip->i_size - filep->fi_offset;
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate if ((i = count) <= 0)
3737c478bd9Sstevel@tonic-gate return (0);
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate while (i > 0) {
376*ae115bc7Smrj if (filep->fi_flags & FI_COMPRESSED) {
377*ae115bc7Smrj if ((j = cf_read(filep, buf, count)) < 0)
378*ae115bc7Smrj return (0); /* encountered an error */
379*ae115bc7Smrj if (j < i)
380*ae115bc7Smrj i = j; /* short read, must have hit EOF */
381*ae115bc7Smrj } else {
38230f5cf21Sjg if (filep->fi_count == 0) {
3837c478bd9Sstevel@tonic-gate if (getblock(filep) == -1)
3847c478bd9Sstevel@tonic-gate return (0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate j = MIN(i, filep->fi_count);
3877c478bd9Sstevel@tonic-gate bcopy(filep->fi_memp, buf, (uint_t)j);
388*ae115bc7Smrj }
3897c478bd9Sstevel@tonic-gate filep->fi_memp += j;
3907c478bd9Sstevel@tonic-gate filep->fi_offset += j;
3917c478bd9Sstevel@tonic-gate filep->fi_count -= j;
392*ae115bc7Smrj buf += j;
3937c478bd9Sstevel@tonic-gate i -= j;
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate dprintf("bhsfs_read: read 0x%x\n", (int)(buf - n));
3977c478bd9Sstevel@tonic-gate return (buf - n);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4017c478bd9Sstevel@tonic-gate static int
bhsfs_mountroot(char * str)4027c478bd9Sstevel@tonic-gate bhsfs_mountroot(char *str)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate char *bufp;
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate if (hsfsp != NULL)
4077c478bd9Sstevel@tonic-gate return (0); /* already mounted */
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate dprintf("mounting ramdisk as hsfs\n");
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate hsfsp = bkmem_alloc(sizeof (*hsfsp));
4127c478bd9Sstevel@tonic-gate bzero(hsfsp, sizeof (*hsfsp));
4137c478bd9Sstevel@tonic-gate head = bkmem_alloc(sizeof (*head));
4147c478bd9Sstevel@tonic-gate bzero(head, sizeof (*head));
4157c478bd9Sstevel@tonic-gate head->fi_back = head->fi_forw = head;
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /* now read the superblock. */
4187c478bd9Sstevel@tonic-gate head->fi_blocknum = hdbtodb(ISO_VOLDESC_SEC);
4197c478bd9Sstevel@tonic-gate head->fi_offset = 0;
4207c478bd9Sstevel@tonic-gate head->fi_count = ISO_SECTOR_SIZE;
4217c478bd9Sstevel@tonic-gate head->fi_memp = head->fi_buf;
4227c478bd9Sstevel@tonic-gate if (diskread(head)) {
4237c478bd9Sstevel@tonic-gate printf("failed to read superblock\n");
4247c478bd9Sstevel@tonic-gate bhsfs_closeall();
4257c478bd9Sstevel@tonic-gate return (-1);
4267c478bd9Sstevel@tonic-gate }
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate /* Since RRIP is based on ISO9660, that's where we start */
4297c478bd9Sstevel@tonic-gate bufp = head->fi_buf;
4307c478bd9Sstevel@tonic-gate if ((ISO_DESC_TYPE(bufp) != ISO_VD_PVD) ||
4317c478bd9Sstevel@tonic-gate (strncmp((const char *)ISO_std_id(bufp), ISO_ID_STRING,
4327c478bd9Sstevel@tonic-gate ISO_ID_STRLEN) != 0) || (ISO_STD_VER(bufp) != ISO_ID_VER)) {
4337c478bd9Sstevel@tonic-gate dprintf("volume type does not match\n");
4347c478bd9Sstevel@tonic-gate bhsfs_closeall();
4357c478bd9Sstevel@tonic-gate return (-1);
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate /* Now we fill in the volume descriptor */
4397c478bd9Sstevel@tonic-gate hsfsp->vol_size = ISO_VOL_SIZE(bufp);
4407c478bd9Sstevel@tonic-gate hsfsp->lbn_size = ISO_BLK_SIZE(bufp);
4417c478bd9Sstevel@tonic-gate hsfsp->lbn_shift = ISO_SECTOR_SHIFT;
4427c478bd9Sstevel@tonic-gate hsfsp->lbn_secshift = ISO_SECTOR_SHIFT;
4437c478bd9Sstevel@tonic-gate hsfsp->vol_set_size = (ushort_t)ISO_SET_SIZE(bufp);
4447c478bd9Sstevel@tonic-gate hsfsp->vol_set_seq = (ushort_t)ISO_SET_SEQ(bufp);
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate /* Make sure we have a valid logical block size */
4477c478bd9Sstevel@tonic-gate if (hsfsp->lbn_size & ~(1 << hsfsp->lbn_shift)) {
4487c478bd9Sstevel@tonic-gate printf("%d invalid logical block size\n", hsfsp->lbn_size);
4497c478bd9Sstevel@tonic-gate bhsfs_closeall();
4507c478bd9Sstevel@tonic-gate return (-1);
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate /* Since an HSFS root could be located anywhere on the media! */
4547c478bd9Sstevel@tonic-gate root_ino = IDE_EXT_LBN(ISO_root_dir(bufp));
4557c478bd9Sstevel@tonic-gate return (0);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate static int
bhsfs_unmountroot(void)4597c478bd9Sstevel@tonic-gate bhsfs_unmountroot(void)
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate if (hsfsp == NULL)
4627c478bd9Sstevel@tonic-gate return (-1);
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate bhsfs_closeall();
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate return (0);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate /*
4707c478bd9Sstevel@tonic-gate * Open a file.
4717c478bd9Sstevel@tonic-gate */
4727c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4737c478bd9Sstevel@tonic-gate int
bhsfs_open(char * str,int flags)4747c478bd9Sstevel@tonic-gate bhsfs_open(char *str, int flags)
4757c478bd9Sstevel@tonic-gate {
4767c478bd9Sstevel@tonic-gate static int filedes = 1;
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate fileid_t *filep;
4797c478bd9Sstevel@tonic-gate ino_t ino;
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate dprintf("open %s\n", str);
4827c478bd9Sstevel@tonic-gate filep = (fileid_t *)bkmem_alloc(sizeof (fileid_t));
4837c478bd9Sstevel@tonic-gate filep->fi_back = head->fi_back;
4847c478bd9Sstevel@tonic-gate filep->fi_forw = head;
4857c478bd9Sstevel@tonic-gate head->fi_back->fi_forw = filep;
4867c478bd9Sstevel@tonic-gate head->fi_back = filep;
4877c478bd9Sstevel@tonic-gate filep->fi_filedes = filedes++;
4887c478bd9Sstevel@tonic-gate filep->fi_taken = 1;
4897c478bd9Sstevel@tonic-gate filep->fi_path = (char *)bkmem_alloc(strlen(str) + 1);
4907c478bd9Sstevel@tonic-gate (void) strcpy(filep->fi_path, str);
4917c478bd9Sstevel@tonic-gate filep->fi_inode = NULL;
4927c478bd9Sstevel@tonic-gate bzero(filep->fi_buf, MAXBSIZE);
493*ae115bc7Smrj filep->fi_getblock = getblock;
494*ae115bc7Smrj filep->fi_flags = 0;
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate ino = find(str, filep);
4977c478bd9Sstevel@tonic-gate if (ino == 0) {
4987c478bd9Sstevel@tonic-gate (void) bhsfs_close(filep->fi_filedes);
4997c478bd9Sstevel@tonic-gate return (-1);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(ino);
5037c478bd9Sstevel@tonic-gate filep->fi_offset = 0;
5047c478bd9Sstevel@tonic-gate filep->fi_count = 0;
5057c478bd9Sstevel@tonic-gate filep->fi_memp = 0;
5067c478bd9Sstevel@tonic-gate
507*ae115bc7Smrj if (cf_check_compressed(filep) != 0)
508*ae115bc7Smrj return (-1);
5097c478bd9Sstevel@tonic-gate dprintf("open done\n");
5107c478bd9Sstevel@tonic-gate return (filep->fi_filedes);
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate int
bhsfs_close(int fd)5147c478bd9Sstevel@tonic-gate bhsfs_close(int fd)
5157c478bd9Sstevel@tonic-gate {
5167c478bd9Sstevel@tonic-gate fileid_t *filep;
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate dprintf("close %d\n", fd);
5197c478bd9Sstevel@tonic-gate if (!(filep = find_fp(fd)))
5207c478bd9Sstevel@tonic-gate return (-1);
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate if (filep->fi_taken == 0 || filep == head) {
523*ae115bc7Smrj printf("File descripter %d not allocated!\n", fd);
5247c478bd9Sstevel@tonic-gate return (-1);
5257c478bd9Sstevel@tonic-gate }
5267c478bd9Sstevel@tonic-gate
527*ae115bc7Smrj cf_close(filep);
5287c478bd9Sstevel@tonic-gate /* unlink and deallocate node */
5297c478bd9Sstevel@tonic-gate filep->fi_forw->fi_back = filep->fi_back;
5307c478bd9Sstevel@tonic-gate filep->fi_back->fi_forw = filep->fi_forw;
5317c478bd9Sstevel@tonic-gate if (filep->fi_inode)
5327c478bd9Sstevel@tonic-gate bkmem_free(filep->fi_inode, sizeof (struct inode));
5337c478bd9Sstevel@tonic-gate bkmem_free(filep->fi_path, strlen(filep->fi_path) + 1);
5347c478bd9Sstevel@tonic-gate bkmem_free((char *)filep, sizeof (fileid_t));
5357c478bd9Sstevel@tonic-gate dprintf("close done\n");
5367c478bd9Sstevel@tonic-gate return (0);
5377c478bd9Sstevel@tonic-gate }
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate static void
bhsfs_closeall(void)5407c478bd9Sstevel@tonic-gate bhsfs_closeall(void)
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate fileid_t *filep;
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate while ((filep = head->fi_forw) != head)
5457c478bd9Sstevel@tonic-gate if (filep->fi_taken && bhsfs_close(filep->fi_filedes))
5467c478bd9Sstevel@tonic-gate printf("Filesystem may be inconsistent.\n");
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate bkmem_free(hsfsp, sizeof (*hsfsp));
5497c478bd9Sstevel@tonic-gate bkmem_free(head, sizeof (fileid_t));
5507c478bd9Sstevel@tonic-gate hsfsp = NULL;
5517c478bd9Sstevel@tonic-gate head = NULL;
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate /*
5557c478bd9Sstevel@tonic-gate * This version of seek() only performs absolute seeks (whence == 0).
5567c478bd9Sstevel@tonic-gate */
5577c478bd9Sstevel@tonic-gate static off_t
bhsfs_lseek(int fd,off_t addr,int whence)5587c478bd9Sstevel@tonic-gate bhsfs_lseek(int fd, off_t addr, int whence)
5597c478bd9Sstevel@tonic-gate {
5607c478bd9Sstevel@tonic-gate fileid_t *filep;
5617c478bd9Sstevel@tonic-gate
562*ae115bc7Smrj dprintf("lseek %d, ", fd);
563*ae115bc7Smrj dprintf("off = %lx\n", addr);
5647c478bd9Sstevel@tonic-gate if (!(filep = find_fp(fd)))
5657c478bd9Sstevel@tonic-gate return (-1);
5667c478bd9Sstevel@tonic-gate
567*ae115bc7Smrj if (filep->fi_flags & FI_COMPRESSED) {
568*ae115bc7Smrj cf_seek(filep, addr, whence);
569*ae115bc7Smrj } else {
5707c478bd9Sstevel@tonic-gate switch (whence) {
5717c478bd9Sstevel@tonic-gate case SEEK_CUR:
5727c478bd9Sstevel@tonic-gate filep->fi_offset += addr;
5737c478bd9Sstevel@tonic-gate break;
5747c478bd9Sstevel@tonic-gate case SEEK_SET:
5757c478bd9Sstevel@tonic-gate filep->fi_offset = addr;
5767c478bd9Sstevel@tonic-gate break;
5777c478bd9Sstevel@tonic-gate default:
5787c478bd9Sstevel@tonic-gate case SEEK_END:
5797c478bd9Sstevel@tonic-gate printf("lseek(): invalid whence value %d\n", whence);
5807c478bd9Sstevel@tonic-gate break;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate filep->fi_blocknum = addr / DEV_BSIZE;
583*ae115bc7Smrj }
584*ae115bc7Smrj
5857c478bd9Sstevel@tonic-gate filep->fi_count = 0;
5867c478bd9Sstevel@tonic-gate return (0);
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate
589ea8dc4b6Seschrock static int
bhsfs_fstat(int fd,struct bootstat * stp)590ea8dc4b6Seschrock bhsfs_fstat(int fd, struct bootstat *stp)
591ea8dc4b6Seschrock {
592ea8dc4b6Seschrock fileid_t *filep;
593ea8dc4b6Seschrock struct inode *ip;
594ea8dc4b6Seschrock
595ea8dc4b6Seschrock if (!(filep = find_fp(fd)))
596ea8dc4b6Seschrock return (-1);
597ea8dc4b6Seschrock
598ea8dc4b6Seschrock ip = filep->fi_inode;
599ea8dc4b6Seschrock
600ea8dc4b6Seschrock stp->st_mode = 0;
601ea8dc4b6Seschrock stp->st_size = 0;
602ea8dc4b6Seschrock
603ea8dc4b6Seschrock if (ip == NULL)
604ea8dc4b6Seschrock return (0);
605ea8dc4b6Seschrock
606ea8dc4b6Seschrock switch (ip->i_smode & IFMT) {
607ea8dc4b6Seschrock case IFDIR:
608ea8dc4b6Seschrock stp->st_mode = S_IFDIR;
609ea8dc4b6Seschrock break;
610ea8dc4b6Seschrock case IFREG:
611ea8dc4b6Seschrock stp->st_mode = S_IFREG;
612ea8dc4b6Seschrock break;
613ea8dc4b6Seschrock default:
614ea8dc4b6Seschrock break;
615ea8dc4b6Seschrock }
616*ae115bc7Smrj /*
617*ae115bc7Smrj * NOTE: this size will be the compressed size for a compressed file
618*ae115bc7Smrj * This could confuse the caller since we decompress the file behind
619*ae115bc7Smrj * the scenes when the file is read.
620*ae115bc7Smrj */
621ea8dc4b6Seschrock stp->st_size = ip->i_size;
622ea8dc4b6Seschrock
623ea8dc4b6Seschrock /* file times */
624ea8dc4b6Seschrock stp->st_atim.tv_sec = ip->i_atime.tv_sec;
625ea8dc4b6Seschrock stp->st_atim.tv_nsec = ip->i_atime.tv_usec * 1000;
626ea8dc4b6Seschrock stp->st_mtim.tv_sec = ip->i_mtime.tv_sec;
627ea8dc4b6Seschrock stp->st_mtim.tv_nsec = ip->i_mtime.tv_usec * 1000;
628ea8dc4b6Seschrock stp->st_ctim.tv_sec = ip->i_ctime.tv_sec;
629ea8dc4b6Seschrock stp->st_ctim.tv_nsec = ip->i_ctime.tv_usec * 1000;
630ea8dc4b6Seschrock
631ea8dc4b6Seschrock return (0);
632ea8dc4b6Seschrock
633ea8dc4b6Seschrock }
634ea8dc4b6Seschrock
635ea8dc4b6Seschrock
6367c478bd9Sstevel@tonic-gate /*
6377c478bd9Sstevel@tonic-gate * Parse a directory entry.
6387c478bd9Sstevel@tonic-gate *
6397c478bd9Sstevel@tonic-gate */
6407c478bd9Sstevel@tonic-gate static uint_t
parse_dir(fileid_t * filep,int offset,struct hs_direct * hsdep)6417c478bd9Sstevel@tonic-gate parse_dir(fileid_t *filep, int offset, struct hs_direct *hsdep)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate char *bufp = (char *)(filep->fi_memp + offset);
6447c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep->hs_ufs_dir; /* ufs-style dir info */
6457c478bd9Sstevel@tonic-gate struct hs_direntry *hdp = &hsdep->hs_dir; /* hsfs-style dir info */
6467c478bd9Sstevel@tonic-gate uint_t ce_lbn;
6477c478bd9Sstevel@tonic-gate uint_t ce_len;
6487c478bd9Sstevel@tonic-gate uint_t nmlen;
6497c478bd9Sstevel@tonic-gate uint_t i;
6507c478bd9Sstevel@tonic-gate uchar_t c;
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate dprintf("parse_dir: offset = %d\n", offset);
6537c478bd9Sstevel@tonic-gate /* a zero length dir entry terminates the dir block */
6547c478bd9Sstevel@tonic-gate udp->d_reclen = IDE_DIR_LEN(bufp);
6557c478bd9Sstevel@tonic-gate if (udp->d_reclen == 0)
6567c478bd9Sstevel@tonic-gate return (0);
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate /* fill in some basic hsfs info */
6597c478bd9Sstevel@tonic-gate hdp->ext_lbn = IDE_EXT_LBN(bufp);
6607c478bd9Sstevel@tonic-gate hdp->ext_size = IDE_EXT_SIZE(bufp);
6617c478bd9Sstevel@tonic-gate hdp->xar_len = IDE_XAR_LEN(bufp);
6627c478bd9Sstevel@tonic-gate hdp->intlf_sz = IDE_INTRLV_SIZE(bufp);
6637c478bd9Sstevel@tonic-gate hdp->intlf_sk = IDE_INTRLV_SKIP(bufp);
6647c478bd9Sstevel@tonic-gate hdp->sym_link = NULL;
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate /* we use lbn of data extent as an inode # equivalent */
6677c478bd9Sstevel@tonic-gate udp->d_ino = hdp->ext_lbn;
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate c = IDE_FLAGS(bufp);
6707c478bd9Sstevel@tonic-gate if (IDE_REGULAR_FILE(c)) {
6717c478bd9Sstevel@tonic-gate hdp->type = VREG;
6727c478bd9Sstevel@tonic-gate hdp->mode = IFREG;
6737c478bd9Sstevel@tonic-gate hdp->nlink = 1;
6747c478bd9Sstevel@tonic-gate } else if (IDE_REGULAR_DIR(c)) {
6757c478bd9Sstevel@tonic-gate hdp->type = VDIR;
6767c478bd9Sstevel@tonic-gate hdp->mode = IFDIR;
6777c478bd9Sstevel@tonic-gate hdp->nlink = 2;
6787c478bd9Sstevel@tonic-gate } else {
6797c478bd9Sstevel@tonic-gate printf("pd(): file type=0x%x unknown.\n", c);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate /*
6837c478bd9Sstevel@tonic-gate * Massage hsfs name, recognizing special entries for . and ..
6847c478bd9Sstevel@tonic-gate * else lopping off version junk.
6857c478bd9Sstevel@tonic-gate */
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate /* Some initial conditions */
6887c478bd9Sstevel@tonic-gate nmlen = IDE_NAME_LEN(bufp);
6897c478bd9Sstevel@tonic-gate c = *IDE_NAME(bufp);
6907c478bd9Sstevel@tonic-gate /* Special Case: Current Directory */
6917c478bd9Sstevel@tonic-gate if (nmlen == 1 && c == '\0') {
6927c478bd9Sstevel@tonic-gate udp->d_name[0] = '.';
6937c478bd9Sstevel@tonic-gate udp->d_name[1] = '\0';
6947c478bd9Sstevel@tonic-gate udp->d_namlen = 1;
6957c478bd9Sstevel@tonic-gate /* Special Case: Parent Directory */
6967c478bd9Sstevel@tonic-gate } else if (nmlen == 1 && c == '\001') {
6977c478bd9Sstevel@tonic-gate udp->d_name[0] = '.';
6987c478bd9Sstevel@tonic-gate udp->d_name[1] = '.';
6997c478bd9Sstevel@tonic-gate udp->d_name[2] = '\0';
7007c478bd9Sstevel@tonic-gate udp->d_namlen = 2;
7017c478bd9Sstevel@tonic-gate /* Other file name */
7027c478bd9Sstevel@tonic-gate } else {
7037c478bd9Sstevel@tonic-gate udp->d_namlen = 0;
7047c478bd9Sstevel@tonic-gate for (i = 0; i < nmlen; i++) {
7057c478bd9Sstevel@tonic-gate c = *(IDE_name(bufp)+i);
7067c478bd9Sstevel@tonic-gate if (c == ';')
7077c478bd9Sstevel@tonic-gate break;
7087c478bd9Sstevel@tonic-gate else if (c == ' ')
7097c478bd9Sstevel@tonic-gate continue;
7107c478bd9Sstevel@tonic-gate else
7117c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen++] = c;
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen] = '\0';
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate /* System Use Fields */
7177c478bd9Sstevel@tonic-gate ce_len = IDE_SUA_LEN(bufp);
7187c478bd9Sstevel@tonic-gate
71930f5cf21Sjg if (ce_len == 0)
7207c478bd9Sstevel@tonic-gate return (udp->d_reclen);
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate /* there is an SUA for this dir entry; go parse it */
7237c478bd9Sstevel@tonic-gate ce_lbn = parse_susp((char *)IDE_sys_use_area(bufp), &ce_len, hsdep);
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate if (ce_lbn) {
7267c478bd9Sstevel@tonic-gate /*
7277c478bd9Sstevel@tonic-gate * store away current position in dir,
7287c478bd9Sstevel@tonic-gate * as we will be using the iobuf to reading SUA.
7297c478bd9Sstevel@tonic-gate */
7307c478bd9Sstevel@tonic-gate daddr_t save_bn = filep->fi_blocknum;
7317c478bd9Sstevel@tonic-gate daddr_t save_offset = filep->fi_offset;
7327c478bd9Sstevel@tonic-gate caddr_t save_ma = filep->fi_memp;
7337c478bd9Sstevel@tonic-gate int save_cc = filep->fi_count;
7347c478bd9Sstevel@tonic-gate do {
7357c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE;
7367c478bd9Sstevel@tonic-gate filep->fi_offset = 0;
7377c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(ce_lbn);
7387c478bd9Sstevel@tonic-gate filep->fi_memp = 0;
7397c478bd9Sstevel@tonic-gate if (diskread(filep)) {
7407c478bd9Sstevel@tonic-gate printf("failed to read cont. area\n");
7417c478bd9Sstevel@tonic-gate ce_len = 0;
7427c478bd9Sstevel@tonic-gate ce_lbn = 0;
7437c478bd9Sstevel@tonic-gate break;
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate ce_lbn = parse_susp(filep->fi_memp, &ce_len,
7467c478bd9Sstevel@tonic-gate hsdep);
7477c478bd9Sstevel@tonic-gate } while (ce_lbn);
7487c478bd9Sstevel@tonic-gate filep->fi_count = save_cc;
7497c478bd9Sstevel@tonic-gate filep->fi_offset = save_offset;
7507c478bd9Sstevel@tonic-gate filep->fi_blocknum = save_bn;
7517c478bd9Sstevel@tonic-gate filep->fi_memp = save_ma;
7527c478bd9Sstevel@tonic-gate }
7537c478bd9Sstevel@tonic-gate return (udp->d_reclen);
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate * Parse the System Use Fields in this System Use Area.
7587c478bd9Sstevel@tonic-gate * Return blk number of continuation/SUA, or 0 if no continuation/not a SUA.
7597c478bd9Sstevel@tonic-gate */
7607c478bd9Sstevel@tonic-gate static uint_t
parse_susp(char * bufp,uint_t * len,struct hs_direct * hsdep)7617c478bd9Sstevel@tonic-gate parse_susp(char *bufp, uint_t *len, struct hs_direct *hsdep)
7627c478bd9Sstevel@tonic-gate {
7637c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep->hs_ufs_dir; /* ufs-style info */
7647c478bd9Sstevel@tonic-gate char *susp;
7657c478bd9Sstevel@tonic-gate uint_t cur_off = 0;
7667c478bd9Sstevel@tonic-gate uint_t blk_len = *len;
7677c478bd9Sstevel@tonic-gate uint_t susp_len = 0;
7687c478bd9Sstevel@tonic-gate uint_t ce_lbn = 0;
7697c478bd9Sstevel@tonic-gate uint_t i;
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate dprintf("parse_susp: len = %d\n", *len);
7727c478bd9Sstevel@tonic-gate while (cur_off < blk_len) {
7737c478bd9Sstevel@tonic-gate susp = (char *)(bufp + cur_off);
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate /*
7767c478bd9Sstevel@tonic-gate * A null entry, or an entry with zero length
7777c478bd9Sstevel@tonic-gate * terminates the SUSP.
7787c478bd9Sstevel@tonic-gate */
7797c478bd9Sstevel@tonic-gate if (susp[0] == '\0' || susp[1] == '\0' ||
7807c478bd9Sstevel@tonic-gate (susp_len = SUF_LEN(susp)) == 0)
7817c478bd9Sstevel@tonic-gate break;
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate /*
7847c478bd9Sstevel@tonic-gate * Compare current entry to all known signatures.
7857c478bd9Sstevel@tonic-gate */
7867c478bd9Sstevel@tonic-gate for (i = 0; i < hsfs_num_sig; i++)
7877c478bd9Sstevel@tonic-gate if (strncmp(hsfs_sig_tab[i], susp, SUF_SIG_LEN) == 0)
7887c478bd9Sstevel@tonic-gate break;
7897c478bd9Sstevel@tonic-gate switch (i) {
7907c478bd9Sstevel@tonic-gate case SUSP_CE_IX:
7917c478bd9Sstevel@tonic-gate /*
7927c478bd9Sstevel@tonic-gate * CE signature: continuation of SUSP.
7937c478bd9Sstevel@tonic-gate * will want to return new lbn, len.
7947c478bd9Sstevel@tonic-gate */
7957c478bd9Sstevel@tonic-gate ce_lbn = CE_BLK_LOC(susp);
7967c478bd9Sstevel@tonic-gate *len = CE_CONT_LEN(susp);
7977c478bd9Sstevel@tonic-gate break;
7987c478bd9Sstevel@tonic-gate case RRIP_NM_IX:
7997c478bd9Sstevel@tonic-gate /* NM signature: POSIX-style file name */
8007c478bd9Sstevel@tonic-gate if (!RRIP_NAME_FLAGS(susp)) {
8017c478bd9Sstevel@tonic-gate udp->d_namlen = RRIP_NAME_LEN(susp);
8027c478bd9Sstevel@tonic-gate bcopy((char *)RRIP_name(susp),
8037c478bd9Sstevel@tonic-gate udp->d_name, udp->d_namlen);
8047c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen] = '\0';
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate break;
8077c478bd9Sstevel@tonic-gate case HSFS_NUM_SIG:
8087c478bd9Sstevel@tonic-gate /* couldn't find a legit susp, terminate loop */
8097c478bd9Sstevel@tonic-gate case SUSP_ST_IX:
8107c478bd9Sstevel@tonic-gate /* ST signature: terminates SUSP */
8117c478bd9Sstevel@tonic-gate return (ce_lbn);
8127c478bd9Sstevel@tonic-gate case SUSP_SP_IX:
8137c478bd9Sstevel@tonic-gate case RRIP_RR_IX:
8147c478bd9Sstevel@tonic-gate default:
8157c478bd9Sstevel@tonic-gate break;
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate cur_off += susp_len;
8187c478bd9Sstevel@tonic-gate }
8197c478bd9Sstevel@tonic-gate return (ce_lbn);
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate struct boot_fs_ops bhsfs_ops = {
8237c478bd9Sstevel@tonic-gate "boot_hsfs",
8247c478bd9Sstevel@tonic-gate bhsfs_mountroot,
8257c478bd9Sstevel@tonic-gate bhsfs_unmountroot,
8267c478bd9Sstevel@tonic-gate bhsfs_open,
8277c478bd9Sstevel@tonic-gate bhsfs_close,
8287c478bd9Sstevel@tonic-gate bhsfs_read,
8297c478bd9Sstevel@tonic-gate bhsfs_lseek,
830ea8dc4b6Seschrock bhsfs_fstat,
8317c478bd9Sstevel@tonic-gate NULL
8327c478bd9Sstevel@tonic-gate };
833