1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Basic file system reading code for standalone I/O system. 31*7c478bd9Sstevel@tonic-gate * Simulates a primitive UNIX I/O system (read(), write(), open(), etc). 32*7c478bd9Sstevel@tonic-gate * Does not support writes. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/filep.h> 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #ifdef _BOOT 51*7c478bd9Sstevel@tonic-gate #include "../common/util.h" 52*7c478bd9Sstevel@tonic-gate #else 53*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 54*7c478bd9Sstevel@tonic-gate #endif 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #define hdbtodb(n) ((ISO_SECTOR_SIZE / DEV_BSIZE) * (n)) 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #define HSFS_NUM_SIG 14 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate #define SUSP_SP_IX 0 61*7c478bd9Sstevel@tonic-gate #define SUSP_CE_IX 1 62*7c478bd9Sstevel@tonic-gate #define SUSP_PD_IX 2 63*7c478bd9Sstevel@tonic-gate #define SUSP_ST_IX 3 64*7c478bd9Sstevel@tonic-gate #define SUSP_ER_IX 4 65*7c478bd9Sstevel@tonic-gate #define RRIP_PX_IX 5 66*7c478bd9Sstevel@tonic-gate #define RRIP_PN_IX 6 67*7c478bd9Sstevel@tonic-gate #define RRIP_SL_IX 7 68*7c478bd9Sstevel@tonic-gate #define RRIP_CL_IX 8 69*7c478bd9Sstevel@tonic-gate #define RRIP_PL_IX 9 70*7c478bd9Sstevel@tonic-gate #define RRIP_RE_IX 10 71*7c478bd9Sstevel@tonic-gate #define RRIP_RF_IX 11 72*7c478bd9Sstevel@tonic-gate #define RRIP_RR_IX 12 73*7c478bd9Sstevel@tonic-gate #define RRIP_NM_IX 13 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate #ifdef _BOOT 76*7c478bd9Sstevel@tonic-gate #define dprintf if (bootrd_debug) printf 77*7c478bd9Sstevel@tonic-gate #else 78*7c478bd9Sstevel@tonic-gate #define printf kobj_printf 79*7c478bd9Sstevel@tonic-gate #define dprintf if (bootrd_debug) kobj_printf 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */ 82*7c478bd9Sstevel@tonic-gate extern void kobj_printf(char *, ...); 83*7c478bd9Sstevel@tonic-gate #endif 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate extern int bootrd_debug; 86*7c478bd9Sstevel@tonic-gate extern void *bkmem_alloc(size_t); 87*7c478bd9Sstevel@tonic-gate extern void bkmem_free(void *, size_t); 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate struct dirstuff { 90*7c478bd9Sstevel@tonic-gate int loc; 91*7c478bd9Sstevel@tonic-gate fileid_t *filep; 92*7c478bd9Sstevel@tonic-gate }; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate struct hs_direct { 95*7c478bd9Sstevel@tonic-gate struct direct hs_ufs_dir; 96*7c478bd9Sstevel@tonic-gate struct hs_direntry hs_dir; 97*7c478bd9Sstevel@tonic-gate }; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate static uint_t root_ino = 0; 100*7c478bd9Sstevel@tonic-gate static struct hs_volume *hsfsp; 101*7c478bd9Sstevel@tonic-gate static fileid_t *head; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate static char *hsfs_sig_tab[] = { 104*7c478bd9Sstevel@tonic-gate SUSP_SP, 105*7c478bd9Sstevel@tonic-gate SUSP_CE, 106*7c478bd9Sstevel@tonic-gate SUSP_PD, 107*7c478bd9Sstevel@tonic-gate SUSP_ST, 108*7c478bd9Sstevel@tonic-gate SUSP_ER, 109*7c478bd9Sstevel@tonic-gate RRIP_PX, 110*7c478bd9Sstevel@tonic-gate RRIP_PN, 111*7c478bd9Sstevel@tonic-gate RRIP_SL, 112*7c478bd9Sstevel@tonic-gate RRIP_CL, 113*7c478bd9Sstevel@tonic-gate RRIP_PL, 114*7c478bd9Sstevel@tonic-gate RRIP_RE, 115*7c478bd9Sstevel@tonic-gate RRIP_TF, 116*7c478bd9Sstevel@tonic-gate RRIP_RR, 117*7c478bd9Sstevel@tonic-gate RRIP_NM 118*7c478bd9Sstevel@tonic-gate }; 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate static int hsfs_num_sig = sizeof (hsfs_sig_tab) / sizeof (hsfs_sig_tab[0]); 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * Local prototypes 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate static struct hs_direct *readdir(struct dirstuff *); 126*7c478bd9Sstevel@tonic-gate static uint_t parse_dir(fileid_t *, int, struct hs_direct *); 127*7c478bd9Sstevel@tonic-gate static uint_t parse_susp(char *, uint_t *, struct hs_direct *); 128*7c478bd9Sstevel@tonic-gate static ino_t dlook(char *, fileid_t *); 129*7c478bd9Sstevel@tonic-gate static int opendir(ino_t, fileid_t *); 130*7c478bd9Sstevel@tonic-gate static ino_t find(char *, fileid_t *); 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate static int bhsfs_mountroot(char *str); 133*7c478bd9Sstevel@tonic-gate static int bhsfs_unmountroot(void); 134*7c478bd9Sstevel@tonic-gate static int bhsfs_open(char *str, int flags); 135*7c478bd9Sstevel@tonic-gate static int bhsfs_close(int fd); 136*7c478bd9Sstevel@tonic-gate static void bhsfs_closeall(void); 137*7c478bd9Sstevel@tonic-gate static ssize_t bhsfs_read(int fdesc, char *buf, size_t count); 138*7c478bd9Sstevel@tonic-gate static off_t bhsfs_lseek(int fdesc, off_t addr, int whence); 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate static fileid_t * 141*7c478bd9Sstevel@tonic-gate find_fp(int fd) 142*7c478bd9Sstevel@tonic-gate { 143*7c478bd9Sstevel@tonic-gate fileid_t *filep = head; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate if (fd >= 0) { 146*7c478bd9Sstevel@tonic-gate while ((filep = filep->fi_forw) != head) 147*7c478bd9Sstevel@tonic-gate if (fd == filep->fi_filedes) 148*7c478bd9Sstevel@tonic-gate return (filep->fi_taken ? filep : 0); 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate return (0); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate static int 155*7c478bd9Sstevel@tonic-gate opendir(ino_t inode, fileid_t *filep) 156*7c478bd9Sstevel@tonic-gate { 157*7c478bd9Sstevel@tonic-gate struct hs_direct hsdep; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate dprintf("opendir: inode = %ld\n", inode); 160*7c478bd9Sstevel@tonic-gate /* Set up the IO request */ 161*7c478bd9Sstevel@tonic-gate filep->fi_offset = 0; 162*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(inode); 163*7c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE; 164*7c478bd9Sstevel@tonic-gate filep->fi_memp = 0; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate if (diskread(filep)) 167*7c478bd9Sstevel@tonic-gate return (0); 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate filep->fi_offset = 0; 170*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(inode); 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate if (inode != root_ino) 173*7c478bd9Sstevel@tonic-gate return (0); 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate if (parse_dir(filep, 0, &hsdep) > 0) { 176*7c478bd9Sstevel@tonic-gate struct inode *ip; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate ip = filep->fi_inode; 179*7c478bd9Sstevel@tonic-gate if (ip == NULL) 180*7c478bd9Sstevel@tonic-gate ip = filep->fi_inode = bkmem_alloc(sizeof (*ip)); 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate ip->i_size = hsdep.hs_dir.ext_size; 183*7c478bd9Sstevel@tonic-gate ip->i_smode = hsdep.hs_dir.mode; 184*7c478bd9Sstevel@tonic-gate ip->i_number = inode; 185*7c478bd9Sstevel@tonic-gate return (0); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate return (1); 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate static ino_t 191*7c478bd9Sstevel@tonic-gate find(char *path, fileid_t *filep) 192*7c478bd9Sstevel@tonic-gate { 193*7c478bd9Sstevel@tonic-gate char *q; 194*7c478bd9Sstevel@tonic-gate char c; 195*7c478bd9Sstevel@tonic-gate ino_t n; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate dprintf("find: %s\n", path); 198*7c478bd9Sstevel@tonic-gate if (path == NULL || *path == '\0') 199*7c478bd9Sstevel@tonic-gate return (0); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate if (opendir(root_ino, filep)) 202*7c478bd9Sstevel@tonic-gate return (0); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate while (*path) { 205*7c478bd9Sstevel@tonic-gate while (*path == '/') 206*7c478bd9Sstevel@tonic-gate path++; 207*7c478bd9Sstevel@tonic-gate q = path; 208*7c478bd9Sstevel@tonic-gate while (*q != '/' && *q != '\0') 209*7c478bd9Sstevel@tonic-gate q++; 210*7c478bd9Sstevel@tonic-gate c = *q; 211*7c478bd9Sstevel@tonic-gate *q = '\0'; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate if ((n = dlook(path, filep)) != 0) { 214*7c478bd9Sstevel@tonic-gate if (c == '\0') 215*7c478bd9Sstevel@tonic-gate break; 216*7c478bd9Sstevel@tonic-gate if (opendir(n, filep)) 217*7c478bd9Sstevel@tonic-gate return (0); 218*7c478bd9Sstevel@tonic-gate *q = c; 219*7c478bd9Sstevel@tonic-gate path = q; 220*7c478bd9Sstevel@tonic-gate continue; 221*7c478bd9Sstevel@tonic-gate } else { 222*7c478bd9Sstevel@tonic-gate return (0); 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate return ((ino_t)n); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate static ino_t 229*7c478bd9Sstevel@tonic-gate dlook(char *s, fileid_t *filep) 230*7c478bd9Sstevel@tonic-gate { 231*7c478bd9Sstevel@tonic-gate struct hs_direct *hsdep; 232*7c478bd9Sstevel@tonic-gate struct direct *udp; 233*7c478bd9Sstevel@tonic-gate struct inode *ip; 234*7c478bd9Sstevel@tonic-gate struct dirstuff dirp; 235*7c478bd9Sstevel@tonic-gate int len; 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate dprintf("dlook: %s\n", s); 238*7c478bd9Sstevel@tonic-gate ip = filep->fi_inode; 239*7c478bd9Sstevel@tonic-gate if (s == NULL || *s == '\0') 240*7c478bd9Sstevel@tonic-gate return (0); 241*7c478bd9Sstevel@tonic-gate if ((ip->i_smode & IFMT) != IFDIR) { 242*7c478bd9Sstevel@tonic-gate return (0); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate if (ip->i_size == 0) { 245*7c478bd9Sstevel@tonic-gate return (0); 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate len = strlen(s); 248*7c478bd9Sstevel@tonic-gate dirp.loc = 0; 249*7c478bd9Sstevel@tonic-gate dirp.filep = filep; 250*7c478bd9Sstevel@tonic-gate for (hsdep = readdir(&dirp); hsdep != NULL; hsdep = readdir(&dirp)) { 251*7c478bd9Sstevel@tonic-gate udp = &hsdep->hs_ufs_dir; 252*7c478bd9Sstevel@tonic-gate if (udp->d_namlen == 1 && 253*7c478bd9Sstevel@tonic-gate udp->d_name[0] == '.' && 254*7c478bd9Sstevel@tonic-gate udp->d_name[1] == '\0') 255*7c478bd9Sstevel@tonic-gate continue; 256*7c478bd9Sstevel@tonic-gate if (udp->d_namlen == 2 && 257*7c478bd9Sstevel@tonic-gate udp->d_name[0] == '.' && 258*7c478bd9Sstevel@tonic-gate udp->d_name[1] == '.' && 259*7c478bd9Sstevel@tonic-gate udp->d_name[2] == '\0') 260*7c478bd9Sstevel@tonic-gate continue; 261*7c478bd9Sstevel@tonic-gate if (udp->d_namlen == len && (strcmp(s, udp->d_name)) == 0) { 262*7c478bd9Sstevel@tonic-gate struct inode *ip = filep->fi_inode; 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate filep->fi_offset = 0; 265*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(udp->d_ino); 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate bzero(filep->fi_inode, sizeof (struct inode)); 268*7c478bd9Sstevel@tonic-gate ip->i_size = hsdep->hs_dir.ext_size; 269*7c478bd9Sstevel@tonic-gate ip->i_smode = hsdep->hs_dir.mode; 270*7c478bd9Sstevel@tonic-gate ip->i_number = udp->d_ino; 271*7c478bd9Sstevel@tonic-gate return (udp->d_ino); 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate return (0); 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate /* 278*7c478bd9Sstevel@tonic-gate * get next entry in a directory. 279*7c478bd9Sstevel@tonic-gate */ 280*7c478bd9Sstevel@tonic-gate static struct hs_direct * 281*7c478bd9Sstevel@tonic-gate readdir(struct dirstuff *dirp) 282*7c478bd9Sstevel@tonic-gate { 283*7c478bd9Sstevel@tonic-gate static struct hs_direct hsdep; 284*7c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep.hs_ufs_dir; 285*7c478bd9Sstevel@tonic-gate struct inode *ip; 286*7c478bd9Sstevel@tonic-gate fileid_t *filep; 287*7c478bd9Sstevel@tonic-gate daddr_t lbn; 288*7c478bd9Sstevel@tonic-gate int off; 289*7c478bd9Sstevel@tonic-gate 290*7c478bd9Sstevel@tonic-gate dprintf("readdir: start\n"); 291*7c478bd9Sstevel@tonic-gate filep = dirp->filep; 292*7c478bd9Sstevel@tonic-gate ip = filep->fi_inode; 293*7c478bd9Sstevel@tonic-gate for (;;) { 294*7c478bd9Sstevel@tonic-gate if (dirp->loc >= ip->i_size) { 295*7c478bd9Sstevel@tonic-gate return (NULL); 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate off = dirp->loc & ((1 << ISO_SECTOR_SHIFT) - 1); 298*7c478bd9Sstevel@tonic-gate if (off == 0) { 299*7c478bd9Sstevel@tonic-gate lbn = hdbtodb(dirp->loc >> ISO_SECTOR_SHIFT); 300*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = lbn + hdbtodb(ip->i_number); 301*7c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE; 302*7c478bd9Sstevel@tonic-gate filep->fi_memp = 0; 303*7c478bd9Sstevel@tonic-gate if (diskread(filep)) { 304*7c478bd9Sstevel@tonic-gate dprintf("readdir: diskread failed\n"); 305*7c478bd9Sstevel@tonic-gate return (NULL); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate dirp->loc += parse_dir(filep, off, &hsdep); 309*7c478bd9Sstevel@tonic-gate if (udp->d_reclen == 0 && dirp->loc <= ip->i_size) { 310*7c478bd9Sstevel@tonic-gate dirp->loc = roundup(dirp->loc, ISO_SECTOR_SIZE); 311*7c478bd9Sstevel@tonic-gate continue; 312*7c478bd9Sstevel@tonic-gate } 313*7c478bd9Sstevel@tonic-gate return (&hsdep); 314*7c478bd9Sstevel@tonic-gate } 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate static int 318*7c478bd9Sstevel@tonic-gate getblock(fileid_t *filep) 319*7c478bd9Sstevel@tonic-gate { 320*7c478bd9Sstevel@tonic-gate struct inode *ip = filep->fi_inode; 321*7c478bd9Sstevel@tonic-gate int off, size, diff; 322*7c478bd9Sstevel@tonic-gate daddr_t lbn; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate dprintf("getblock: start\n"); 325*7c478bd9Sstevel@tonic-gate diff = ip->i_size - filep->fi_offset; 326*7c478bd9Sstevel@tonic-gate if (diff <= 0) 327*7c478bd9Sstevel@tonic-gate return (-1); 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate /* which block (or frag) in the file do we read? */ 330*7c478bd9Sstevel@tonic-gate lbn = hdbtodb(filep->fi_offset >> ISO_SECTOR_SHIFT); 331*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = lbn + hdbtodb(ip->i_number); 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate off = filep->fi_offset & ((1 << ISO_SECTOR_SHIFT) - 1); 334*7c478bd9Sstevel@tonic-gate size = filep->fi_count = ISO_SECTOR_SIZE; 335*7c478bd9Sstevel@tonic-gate filep->fi_memp = 0; 336*7c478bd9Sstevel@tonic-gate if (diskread(filep)) /* Trap errors */ 337*7c478bd9Sstevel@tonic-gate return (-1); 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate if (filep->fi_offset - off + size >= ip->i_size) 340*7c478bd9Sstevel@tonic-gate filep->fi_count = diff + off; 341*7c478bd9Sstevel@tonic-gate filep->fi_count -= off; 342*7c478bd9Sstevel@tonic-gate filep->fi_memp += off; 343*7c478bd9Sstevel@tonic-gate dprintf("getblock: end\n"); 344*7c478bd9Sstevel@tonic-gate return (0); 345*7c478bd9Sstevel@tonic-gate } 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate static ssize_t 348*7c478bd9Sstevel@tonic-gate bhsfs_read(int fd, caddr_t buf, size_t count) 349*7c478bd9Sstevel@tonic-gate { 350*7c478bd9Sstevel@tonic-gate int i, j; 351*7c478bd9Sstevel@tonic-gate fileid_t *filep; 352*7c478bd9Sstevel@tonic-gate struct inode *ip; 353*7c478bd9Sstevel@tonic-gate caddr_t n; 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate dprintf("bhsfs_read %d, count 0x%lx\n", fd, count); 356*7c478bd9Sstevel@tonic-gate filep = find_fp(fd); 357*7c478bd9Sstevel@tonic-gate if (filep == NULL) 358*7c478bd9Sstevel@tonic-gate return (-1); 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate ip = filep->fi_inode; 361*7c478bd9Sstevel@tonic-gate n = buf; 362*7c478bd9Sstevel@tonic-gate if (filep->fi_offset + count > ip->i_size) 363*7c478bd9Sstevel@tonic-gate count = ip->i_size - filep->fi_offset; 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate if ((i = count) <= 0) 366*7c478bd9Sstevel@tonic-gate return (0); 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate while (i > 0) { 369*7c478bd9Sstevel@tonic-gate if (filep->fi_count <= 0) { 370*7c478bd9Sstevel@tonic-gate if (getblock(filep) == -1) 371*7c478bd9Sstevel@tonic-gate return (0); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate j = MIN(i, filep->fi_count); 374*7c478bd9Sstevel@tonic-gate bcopy(filep->fi_memp, buf, (uint_t)j); 375*7c478bd9Sstevel@tonic-gate buf += j; 376*7c478bd9Sstevel@tonic-gate filep->fi_memp += j; 377*7c478bd9Sstevel@tonic-gate filep->fi_offset += j; 378*7c478bd9Sstevel@tonic-gate filep->fi_count -= j; 379*7c478bd9Sstevel@tonic-gate i -= j; 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate dprintf("bhsfs_read: read 0x%x\n", (int)(buf - n)); 383*7c478bd9Sstevel@tonic-gate return (buf - n); 384*7c478bd9Sstevel@tonic-gate } 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 387*7c478bd9Sstevel@tonic-gate static int 388*7c478bd9Sstevel@tonic-gate bhsfs_mountroot(char *str) 389*7c478bd9Sstevel@tonic-gate { 390*7c478bd9Sstevel@tonic-gate char *bufp; 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate if (hsfsp != NULL) 393*7c478bd9Sstevel@tonic-gate return (0); /* already mounted */ 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate dprintf("mounting ramdisk as hsfs\n"); 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate hsfsp = bkmem_alloc(sizeof (*hsfsp)); 398*7c478bd9Sstevel@tonic-gate bzero(hsfsp, sizeof (*hsfsp)); 399*7c478bd9Sstevel@tonic-gate head = bkmem_alloc(sizeof (*head)); 400*7c478bd9Sstevel@tonic-gate bzero(head, sizeof (*head)); 401*7c478bd9Sstevel@tonic-gate head->fi_back = head->fi_forw = head; 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate /* now read the superblock. */ 404*7c478bd9Sstevel@tonic-gate head->fi_blocknum = hdbtodb(ISO_VOLDESC_SEC); 405*7c478bd9Sstevel@tonic-gate head->fi_offset = 0; 406*7c478bd9Sstevel@tonic-gate head->fi_count = ISO_SECTOR_SIZE; 407*7c478bd9Sstevel@tonic-gate head->fi_memp = head->fi_buf; 408*7c478bd9Sstevel@tonic-gate if (diskread(head)) { 409*7c478bd9Sstevel@tonic-gate printf("failed to read superblock\n"); 410*7c478bd9Sstevel@tonic-gate bhsfs_closeall(); 411*7c478bd9Sstevel@tonic-gate return (-1); 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate /* Since RRIP is based on ISO9660, that's where we start */ 415*7c478bd9Sstevel@tonic-gate bufp = head->fi_buf; 416*7c478bd9Sstevel@tonic-gate if ((ISO_DESC_TYPE(bufp) != ISO_VD_PVD) || 417*7c478bd9Sstevel@tonic-gate (strncmp((const char *)ISO_std_id(bufp), ISO_ID_STRING, 418*7c478bd9Sstevel@tonic-gate ISO_ID_STRLEN) != 0) || (ISO_STD_VER(bufp) != ISO_ID_VER)) { 419*7c478bd9Sstevel@tonic-gate dprintf("volume type does not match\n"); 420*7c478bd9Sstevel@tonic-gate bhsfs_closeall(); 421*7c478bd9Sstevel@tonic-gate return (-1); 422*7c478bd9Sstevel@tonic-gate } 423*7c478bd9Sstevel@tonic-gate 424*7c478bd9Sstevel@tonic-gate /* Now we fill in the volume descriptor */ 425*7c478bd9Sstevel@tonic-gate hsfsp->vol_size = ISO_VOL_SIZE(bufp); 426*7c478bd9Sstevel@tonic-gate hsfsp->lbn_size = ISO_BLK_SIZE(bufp); 427*7c478bd9Sstevel@tonic-gate hsfsp->lbn_shift = ISO_SECTOR_SHIFT; 428*7c478bd9Sstevel@tonic-gate hsfsp->lbn_secshift = ISO_SECTOR_SHIFT; 429*7c478bd9Sstevel@tonic-gate hsfsp->vol_set_size = (ushort_t)ISO_SET_SIZE(bufp); 430*7c478bd9Sstevel@tonic-gate hsfsp->vol_set_seq = (ushort_t)ISO_SET_SEQ(bufp); 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate /* Make sure we have a valid logical block size */ 433*7c478bd9Sstevel@tonic-gate if (hsfsp->lbn_size & ~(1 << hsfsp->lbn_shift)) { 434*7c478bd9Sstevel@tonic-gate printf("%d invalid logical block size\n", hsfsp->lbn_size); 435*7c478bd9Sstevel@tonic-gate bhsfs_closeall(); 436*7c478bd9Sstevel@tonic-gate return (-1); 437*7c478bd9Sstevel@tonic-gate } 438*7c478bd9Sstevel@tonic-gate 439*7c478bd9Sstevel@tonic-gate /* Since an HSFS root could be located anywhere on the media! */ 440*7c478bd9Sstevel@tonic-gate root_ino = IDE_EXT_LBN(ISO_root_dir(bufp)); 441*7c478bd9Sstevel@tonic-gate return (0); 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate 444*7c478bd9Sstevel@tonic-gate static int 445*7c478bd9Sstevel@tonic-gate bhsfs_unmountroot(void) 446*7c478bd9Sstevel@tonic-gate { 447*7c478bd9Sstevel@tonic-gate if (hsfsp == NULL) 448*7c478bd9Sstevel@tonic-gate return (-1); 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate bhsfs_closeall(); 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate return (0); 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate /* 456*7c478bd9Sstevel@tonic-gate * Open a file. 457*7c478bd9Sstevel@tonic-gate */ 458*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 459*7c478bd9Sstevel@tonic-gate int 460*7c478bd9Sstevel@tonic-gate bhsfs_open(char *str, int flags) 461*7c478bd9Sstevel@tonic-gate { 462*7c478bd9Sstevel@tonic-gate static int filedes = 1; 463*7c478bd9Sstevel@tonic-gate 464*7c478bd9Sstevel@tonic-gate fileid_t *filep; 465*7c478bd9Sstevel@tonic-gate ino_t ino; 466*7c478bd9Sstevel@tonic-gate 467*7c478bd9Sstevel@tonic-gate dprintf("open %s\n", str); 468*7c478bd9Sstevel@tonic-gate filep = (fileid_t *)bkmem_alloc(sizeof (fileid_t)); 469*7c478bd9Sstevel@tonic-gate filep->fi_back = head->fi_back; 470*7c478bd9Sstevel@tonic-gate filep->fi_forw = head; 471*7c478bd9Sstevel@tonic-gate head->fi_back->fi_forw = filep; 472*7c478bd9Sstevel@tonic-gate head->fi_back = filep; 473*7c478bd9Sstevel@tonic-gate filep->fi_filedes = filedes++; 474*7c478bd9Sstevel@tonic-gate filep->fi_taken = 1; 475*7c478bd9Sstevel@tonic-gate filep->fi_path = (char *)bkmem_alloc(strlen(str) + 1); 476*7c478bd9Sstevel@tonic-gate (void) strcpy(filep->fi_path, str); 477*7c478bd9Sstevel@tonic-gate filep->fi_inode = NULL; 478*7c478bd9Sstevel@tonic-gate bzero(filep->fi_buf, MAXBSIZE); 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate ino = find(str, filep); 481*7c478bd9Sstevel@tonic-gate if (ino == 0) { 482*7c478bd9Sstevel@tonic-gate (void) bhsfs_close(filep->fi_filedes); 483*7c478bd9Sstevel@tonic-gate return (-1); 484*7c478bd9Sstevel@tonic-gate } 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(ino); 487*7c478bd9Sstevel@tonic-gate filep->fi_offset = 0; 488*7c478bd9Sstevel@tonic-gate filep->fi_count = 0; 489*7c478bd9Sstevel@tonic-gate filep->fi_memp = 0; 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate dprintf("open done\n"); 492*7c478bd9Sstevel@tonic-gate return (filep->fi_filedes); 493*7c478bd9Sstevel@tonic-gate } 494*7c478bd9Sstevel@tonic-gate 495*7c478bd9Sstevel@tonic-gate int 496*7c478bd9Sstevel@tonic-gate bhsfs_close(int fd) 497*7c478bd9Sstevel@tonic-gate { 498*7c478bd9Sstevel@tonic-gate fileid_t *filep; 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate dprintf("close %d\n", fd); 501*7c478bd9Sstevel@tonic-gate if (!(filep = find_fp(fd))) 502*7c478bd9Sstevel@tonic-gate return (-1); 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate if (filep->fi_taken == 0 || filep == head) { 505*7c478bd9Sstevel@tonic-gate printf("File descripter %d no allocated!\n", fd); 506*7c478bd9Sstevel@tonic-gate return (-1); 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate 509*7c478bd9Sstevel@tonic-gate /* unlink and deallocate node */ 510*7c478bd9Sstevel@tonic-gate filep->fi_forw->fi_back = filep->fi_back; 511*7c478bd9Sstevel@tonic-gate filep->fi_back->fi_forw = filep->fi_forw; 512*7c478bd9Sstevel@tonic-gate if (filep->fi_inode) 513*7c478bd9Sstevel@tonic-gate bkmem_free(filep->fi_inode, sizeof (struct inode)); 514*7c478bd9Sstevel@tonic-gate bkmem_free(filep->fi_path, strlen(filep->fi_path) + 1); 515*7c478bd9Sstevel@tonic-gate bkmem_free((char *)filep, sizeof (fileid_t)); 516*7c478bd9Sstevel@tonic-gate dprintf("close done\n"); 517*7c478bd9Sstevel@tonic-gate return (0); 518*7c478bd9Sstevel@tonic-gate } 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate static void 521*7c478bd9Sstevel@tonic-gate bhsfs_closeall(void) 522*7c478bd9Sstevel@tonic-gate { 523*7c478bd9Sstevel@tonic-gate fileid_t *filep; 524*7c478bd9Sstevel@tonic-gate 525*7c478bd9Sstevel@tonic-gate while ((filep = head->fi_forw) != head) 526*7c478bd9Sstevel@tonic-gate if (filep->fi_taken && bhsfs_close(filep->fi_filedes)) 527*7c478bd9Sstevel@tonic-gate printf("Filesystem may be inconsistent.\n"); 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate bkmem_free(hsfsp, sizeof (*hsfsp)); 530*7c478bd9Sstevel@tonic-gate bkmem_free(head, sizeof (fileid_t)); 531*7c478bd9Sstevel@tonic-gate hsfsp = NULL; 532*7c478bd9Sstevel@tonic-gate head = NULL; 533*7c478bd9Sstevel@tonic-gate } 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate /* 536*7c478bd9Sstevel@tonic-gate * This version of seek() only performs absolute seeks (whence == 0). 537*7c478bd9Sstevel@tonic-gate */ 538*7c478bd9Sstevel@tonic-gate static off_t 539*7c478bd9Sstevel@tonic-gate bhsfs_lseek(int fd, off_t addr, int whence) 540*7c478bd9Sstevel@tonic-gate { 541*7c478bd9Sstevel@tonic-gate fileid_t *filep; 542*7c478bd9Sstevel@tonic-gate 543*7c478bd9Sstevel@tonic-gate dprintf("lseek %d, off = %lx\n", fd, addr); 544*7c478bd9Sstevel@tonic-gate if (!(filep = find_fp(fd))) 545*7c478bd9Sstevel@tonic-gate return (-1); 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate switch (whence) { 548*7c478bd9Sstevel@tonic-gate case SEEK_CUR: 549*7c478bd9Sstevel@tonic-gate filep->fi_offset += addr; 550*7c478bd9Sstevel@tonic-gate break; 551*7c478bd9Sstevel@tonic-gate case SEEK_SET: 552*7c478bd9Sstevel@tonic-gate filep->fi_offset = addr; 553*7c478bd9Sstevel@tonic-gate break; 554*7c478bd9Sstevel@tonic-gate default: 555*7c478bd9Sstevel@tonic-gate case SEEK_END: 556*7c478bd9Sstevel@tonic-gate printf("lseek(): invalid whence value %d\n", whence); 557*7c478bd9Sstevel@tonic-gate break; 558*7c478bd9Sstevel@tonic-gate } 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = addr / DEV_BSIZE; 561*7c478bd9Sstevel@tonic-gate filep->fi_count = 0; 562*7c478bd9Sstevel@tonic-gate return (0); 563*7c478bd9Sstevel@tonic-gate } 564*7c478bd9Sstevel@tonic-gate 565*7c478bd9Sstevel@tonic-gate /* 566*7c478bd9Sstevel@tonic-gate * Parse a directory entry. 567*7c478bd9Sstevel@tonic-gate * 568*7c478bd9Sstevel@tonic-gate */ 569*7c478bd9Sstevel@tonic-gate static uint_t 570*7c478bd9Sstevel@tonic-gate parse_dir(fileid_t *filep, int offset, struct hs_direct *hsdep) 571*7c478bd9Sstevel@tonic-gate { 572*7c478bd9Sstevel@tonic-gate char *bufp = (char *)(filep->fi_memp + offset); 573*7c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep->hs_ufs_dir; /* ufs-style dir info */ 574*7c478bd9Sstevel@tonic-gate struct hs_direntry *hdp = &hsdep->hs_dir; /* hsfs-style dir info */ 575*7c478bd9Sstevel@tonic-gate uint_t ce_lbn; 576*7c478bd9Sstevel@tonic-gate uint_t ce_len; 577*7c478bd9Sstevel@tonic-gate uint_t nmlen; 578*7c478bd9Sstevel@tonic-gate uint_t i; 579*7c478bd9Sstevel@tonic-gate uchar_t c; 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate dprintf("parse_dir: offset = %d\n", offset); 582*7c478bd9Sstevel@tonic-gate /* a zero length dir entry terminates the dir block */ 583*7c478bd9Sstevel@tonic-gate udp->d_reclen = IDE_DIR_LEN(bufp); 584*7c478bd9Sstevel@tonic-gate if (udp->d_reclen == 0) 585*7c478bd9Sstevel@tonic-gate return (0); 586*7c478bd9Sstevel@tonic-gate 587*7c478bd9Sstevel@tonic-gate /* fill in some basic hsfs info */ 588*7c478bd9Sstevel@tonic-gate hdp->ext_lbn = IDE_EXT_LBN(bufp); 589*7c478bd9Sstevel@tonic-gate hdp->ext_size = IDE_EXT_SIZE(bufp); 590*7c478bd9Sstevel@tonic-gate hdp->xar_len = IDE_XAR_LEN(bufp); 591*7c478bd9Sstevel@tonic-gate hdp->intlf_sz = IDE_INTRLV_SIZE(bufp); 592*7c478bd9Sstevel@tonic-gate hdp->intlf_sk = IDE_INTRLV_SKIP(bufp); 593*7c478bd9Sstevel@tonic-gate hdp->sym_link = NULL; 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate /* we use lbn of data extent as an inode # equivalent */ 596*7c478bd9Sstevel@tonic-gate udp->d_ino = hdp->ext_lbn; 597*7c478bd9Sstevel@tonic-gate 598*7c478bd9Sstevel@tonic-gate c = IDE_FLAGS(bufp); 599*7c478bd9Sstevel@tonic-gate if (IDE_REGULAR_FILE(c)) { 600*7c478bd9Sstevel@tonic-gate hdp->type = VREG; 601*7c478bd9Sstevel@tonic-gate hdp->mode = IFREG; 602*7c478bd9Sstevel@tonic-gate hdp->nlink = 1; 603*7c478bd9Sstevel@tonic-gate } else if (IDE_REGULAR_DIR(c)) { 604*7c478bd9Sstevel@tonic-gate hdp->type = VDIR; 605*7c478bd9Sstevel@tonic-gate hdp->mode = IFDIR; 606*7c478bd9Sstevel@tonic-gate hdp->nlink = 2; 607*7c478bd9Sstevel@tonic-gate } else { 608*7c478bd9Sstevel@tonic-gate printf("pd(): file type=0x%x unknown.\n", c); 609*7c478bd9Sstevel@tonic-gate } 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate /* 612*7c478bd9Sstevel@tonic-gate * Massage hsfs name, recognizing special entries for . and .. 613*7c478bd9Sstevel@tonic-gate * else lopping off version junk. 614*7c478bd9Sstevel@tonic-gate */ 615*7c478bd9Sstevel@tonic-gate 616*7c478bd9Sstevel@tonic-gate /* Some initial conditions */ 617*7c478bd9Sstevel@tonic-gate nmlen = IDE_NAME_LEN(bufp); 618*7c478bd9Sstevel@tonic-gate c = *IDE_NAME(bufp); 619*7c478bd9Sstevel@tonic-gate /* Special Case: Current Directory */ 620*7c478bd9Sstevel@tonic-gate if (nmlen == 1 && c == '\0') { 621*7c478bd9Sstevel@tonic-gate udp->d_name[0] = '.'; 622*7c478bd9Sstevel@tonic-gate udp->d_name[1] = '\0'; 623*7c478bd9Sstevel@tonic-gate udp->d_namlen = 1; 624*7c478bd9Sstevel@tonic-gate /* Special Case: Parent Directory */ 625*7c478bd9Sstevel@tonic-gate } else if (nmlen == 1 && c == '\001') { 626*7c478bd9Sstevel@tonic-gate udp->d_name[0] = '.'; 627*7c478bd9Sstevel@tonic-gate udp->d_name[1] = '.'; 628*7c478bd9Sstevel@tonic-gate udp->d_name[2] = '\0'; 629*7c478bd9Sstevel@tonic-gate udp->d_namlen = 2; 630*7c478bd9Sstevel@tonic-gate /* Other file name */ 631*7c478bd9Sstevel@tonic-gate } else { 632*7c478bd9Sstevel@tonic-gate udp->d_namlen = 0; 633*7c478bd9Sstevel@tonic-gate for (i = 0; i < nmlen; i++) { 634*7c478bd9Sstevel@tonic-gate c = *(IDE_name(bufp)+i); 635*7c478bd9Sstevel@tonic-gate if (c == ';') 636*7c478bd9Sstevel@tonic-gate break; 637*7c478bd9Sstevel@tonic-gate else if (c == ' ') 638*7c478bd9Sstevel@tonic-gate continue; 639*7c478bd9Sstevel@tonic-gate else 640*7c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen++] = c; 641*7c478bd9Sstevel@tonic-gate } 642*7c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen] = '\0'; 643*7c478bd9Sstevel@tonic-gate } 644*7c478bd9Sstevel@tonic-gate 645*7c478bd9Sstevel@tonic-gate /* System Use Fields */ 646*7c478bd9Sstevel@tonic-gate ce_len = IDE_SUA_LEN(bufp); 647*7c478bd9Sstevel@tonic-gate 648*7c478bd9Sstevel@tonic-gate if (ce_len <= 0) 649*7c478bd9Sstevel@tonic-gate return (udp->d_reclen); 650*7c478bd9Sstevel@tonic-gate 651*7c478bd9Sstevel@tonic-gate /* there is an SUA for this dir entry; go parse it */ 652*7c478bd9Sstevel@tonic-gate ce_lbn = parse_susp((char *)IDE_sys_use_area(bufp), &ce_len, hsdep); 653*7c478bd9Sstevel@tonic-gate 654*7c478bd9Sstevel@tonic-gate if (ce_lbn) { 655*7c478bd9Sstevel@tonic-gate /* 656*7c478bd9Sstevel@tonic-gate * store away current position in dir, 657*7c478bd9Sstevel@tonic-gate * as we will be using the iobuf to reading SUA. 658*7c478bd9Sstevel@tonic-gate */ 659*7c478bd9Sstevel@tonic-gate daddr_t save_bn = filep->fi_blocknum; 660*7c478bd9Sstevel@tonic-gate daddr_t save_offset = filep->fi_offset; 661*7c478bd9Sstevel@tonic-gate caddr_t save_ma = filep->fi_memp; 662*7c478bd9Sstevel@tonic-gate int save_cc = filep->fi_count; 663*7c478bd9Sstevel@tonic-gate do { 664*7c478bd9Sstevel@tonic-gate filep->fi_count = ISO_SECTOR_SIZE; 665*7c478bd9Sstevel@tonic-gate filep->fi_offset = 0; 666*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = hdbtodb(ce_lbn); 667*7c478bd9Sstevel@tonic-gate filep->fi_memp = 0; 668*7c478bd9Sstevel@tonic-gate if (diskread(filep)) { 669*7c478bd9Sstevel@tonic-gate printf("failed to read cont. area\n"); 670*7c478bd9Sstevel@tonic-gate ce_len = 0; 671*7c478bd9Sstevel@tonic-gate ce_lbn = 0; 672*7c478bd9Sstevel@tonic-gate break; 673*7c478bd9Sstevel@tonic-gate } 674*7c478bd9Sstevel@tonic-gate ce_lbn = parse_susp(filep->fi_memp, &ce_len, 675*7c478bd9Sstevel@tonic-gate hsdep); 676*7c478bd9Sstevel@tonic-gate } while (ce_lbn); 677*7c478bd9Sstevel@tonic-gate filep->fi_count = save_cc; 678*7c478bd9Sstevel@tonic-gate filep->fi_offset = save_offset; 679*7c478bd9Sstevel@tonic-gate filep->fi_blocknum = save_bn; 680*7c478bd9Sstevel@tonic-gate filep->fi_memp = save_ma; 681*7c478bd9Sstevel@tonic-gate } 682*7c478bd9Sstevel@tonic-gate return (udp->d_reclen); 683*7c478bd9Sstevel@tonic-gate } 684*7c478bd9Sstevel@tonic-gate 685*7c478bd9Sstevel@tonic-gate /* 686*7c478bd9Sstevel@tonic-gate * Parse the System Use Fields in this System Use Area. 687*7c478bd9Sstevel@tonic-gate * Return blk number of continuation/SUA, or 0 if no continuation/not a SUA. 688*7c478bd9Sstevel@tonic-gate */ 689*7c478bd9Sstevel@tonic-gate static uint_t 690*7c478bd9Sstevel@tonic-gate parse_susp(char *bufp, uint_t *len, struct hs_direct *hsdep) 691*7c478bd9Sstevel@tonic-gate { 692*7c478bd9Sstevel@tonic-gate struct direct *udp = &hsdep->hs_ufs_dir; /* ufs-style info */ 693*7c478bd9Sstevel@tonic-gate char *susp; 694*7c478bd9Sstevel@tonic-gate uint_t cur_off = 0; 695*7c478bd9Sstevel@tonic-gate uint_t blk_len = *len; 696*7c478bd9Sstevel@tonic-gate uint_t susp_len = 0; 697*7c478bd9Sstevel@tonic-gate uint_t ce_lbn = 0; 698*7c478bd9Sstevel@tonic-gate uint_t i; 699*7c478bd9Sstevel@tonic-gate 700*7c478bd9Sstevel@tonic-gate dprintf("parse_susp: len = %d\n", *len); 701*7c478bd9Sstevel@tonic-gate while (cur_off < blk_len) { 702*7c478bd9Sstevel@tonic-gate susp = (char *)(bufp + cur_off); 703*7c478bd9Sstevel@tonic-gate 704*7c478bd9Sstevel@tonic-gate /* 705*7c478bd9Sstevel@tonic-gate * A null entry, or an entry with zero length 706*7c478bd9Sstevel@tonic-gate * terminates the SUSP. 707*7c478bd9Sstevel@tonic-gate */ 708*7c478bd9Sstevel@tonic-gate if (susp[0] == '\0' || susp[1] == '\0' || 709*7c478bd9Sstevel@tonic-gate (susp_len = SUF_LEN(susp)) == 0) 710*7c478bd9Sstevel@tonic-gate break; 711*7c478bd9Sstevel@tonic-gate 712*7c478bd9Sstevel@tonic-gate /* 713*7c478bd9Sstevel@tonic-gate * Compare current entry to all known signatures. 714*7c478bd9Sstevel@tonic-gate */ 715*7c478bd9Sstevel@tonic-gate for (i = 0; i < hsfs_num_sig; i++) 716*7c478bd9Sstevel@tonic-gate if (strncmp(hsfs_sig_tab[i], susp, SUF_SIG_LEN) == 0) 717*7c478bd9Sstevel@tonic-gate break; 718*7c478bd9Sstevel@tonic-gate switch (i) { 719*7c478bd9Sstevel@tonic-gate case SUSP_CE_IX: 720*7c478bd9Sstevel@tonic-gate /* 721*7c478bd9Sstevel@tonic-gate * CE signature: continuation of SUSP. 722*7c478bd9Sstevel@tonic-gate * will want to return new lbn, len. 723*7c478bd9Sstevel@tonic-gate */ 724*7c478bd9Sstevel@tonic-gate ce_lbn = CE_BLK_LOC(susp); 725*7c478bd9Sstevel@tonic-gate *len = CE_CONT_LEN(susp); 726*7c478bd9Sstevel@tonic-gate break; 727*7c478bd9Sstevel@tonic-gate case RRIP_NM_IX: 728*7c478bd9Sstevel@tonic-gate /* NM signature: POSIX-style file name */ 729*7c478bd9Sstevel@tonic-gate if (!RRIP_NAME_FLAGS(susp)) { 730*7c478bd9Sstevel@tonic-gate udp->d_namlen = RRIP_NAME_LEN(susp); 731*7c478bd9Sstevel@tonic-gate bcopy((char *)RRIP_name(susp), 732*7c478bd9Sstevel@tonic-gate udp->d_name, udp->d_namlen); 733*7c478bd9Sstevel@tonic-gate udp->d_name[udp->d_namlen] = '\0'; 734*7c478bd9Sstevel@tonic-gate } 735*7c478bd9Sstevel@tonic-gate break; 736*7c478bd9Sstevel@tonic-gate case HSFS_NUM_SIG: 737*7c478bd9Sstevel@tonic-gate /* couldn't find a legit susp, terminate loop */ 738*7c478bd9Sstevel@tonic-gate case SUSP_ST_IX: 739*7c478bd9Sstevel@tonic-gate /* ST signature: terminates SUSP */ 740*7c478bd9Sstevel@tonic-gate return (ce_lbn); 741*7c478bd9Sstevel@tonic-gate case SUSP_SP_IX: 742*7c478bd9Sstevel@tonic-gate case RRIP_RR_IX: 743*7c478bd9Sstevel@tonic-gate default: 744*7c478bd9Sstevel@tonic-gate break; 745*7c478bd9Sstevel@tonic-gate } 746*7c478bd9Sstevel@tonic-gate cur_off += susp_len; 747*7c478bd9Sstevel@tonic-gate } 748*7c478bd9Sstevel@tonic-gate return (ce_lbn); 749*7c478bd9Sstevel@tonic-gate } 750*7c478bd9Sstevel@tonic-gate 751*7c478bd9Sstevel@tonic-gate struct boot_fs_ops bhsfs_ops = { 752*7c478bd9Sstevel@tonic-gate "boot_hsfs", 753*7c478bd9Sstevel@tonic-gate bhsfs_mountroot, 754*7c478bd9Sstevel@tonic-gate bhsfs_unmountroot, 755*7c478bd9Sstevel@tonic-gate bhsfs_open, 756*7c478bd9Sstevel@tonic-gate bhsfs_close, 757*7c478bd9Sstevel@tonic-gate bhsfs_read, 758*7c478bd9Sstevel@tonic-gate bhsfs_lseek, 759*7c478bd9Sstevel@tonic-gate NULL 760*7c478bd9Sstevel@tonic-gate }; 761