10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51025Sfrankho * Common Development and Distribution License (the "License").
61025Sfrankho * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate * System Use Sharing protocol subroutines for High Sierra filesystem
232900Sfrankho */
242900Sfrankho /*
25*4866Sfrankho * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
26494Sfrankho * Use is subject to license terms.
270Sstevel@tonic-gate */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/t_lock.h>
330Sstevel@tonic-gate #include <sys/param.h>
340Sstevel@tonic-gate #include <sys/systm.h>
350Sstevel@tonic-gate #include <sys/sysmacros.h>
360Sstevel@tonic-gate #include <sys/kmem.h>
370Sstevel@tonic-gate #include <sys/signal.h>
380Sstevel@tonic-gate #include <sys/user.h>
390Sstevel@tonic-gate #include <sys/proc.h>
400Sstevel@tonic-gate #include <sys/disp.h>
410Sstevel@tonic-gate #include <sys/buf.h>
420Sstevel@tonic-gate #include <sys/pathname.h>
430Sstevel@tonic-gate #include <sys/vfs.h>
440Sstevel@tonic-gate #include <sys/vnode.h>
450Sstevel@tonic-gate #include <sys/file.h>
460Sstevel@tonic-gate #include <sys/uio.h>
470Sstevel@tonic-gate #include <sys/conf.h>
480Sstevel@tonic-gate
490Sstevel@tonic-gate #include <vm/page.h>
500Sstevel@tonic-gate
510Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
520Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
530Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
540Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
550Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
560Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
570Sstevel@tonic-gate
580Sstevel@tonic-gate #include <sys/statvfs.h>
590Sstevel@tonic-gate #include <sys/mount.h>
600Sstevel@tonic-gate #include <sys/swap.h>
610Sstevel@tonic-gate #include <sys/errno.h>
620Sstevel@tonic-gate #include <sys/debug.h>
630Sstevel@tonic-gate #include "fs/fs_subr.h"
640Sstevel@tonic-gate #include <sys/cmn_err.h>
650Sstevel@tonic-gate
660Sstevel@tonic-gate /* static declarations */
670Sstevel@tonic-gate static void free_cont_area(uchar_t *);
680Sstevel@tonic-gate static int get_cont_area(struct hsfs *, uchar_t **, cont_info_t *);
691025Sfrankho static int parse_signatures(sig_args_t *, int, uchar_t *, int);
700Sstevel@tonic-gate
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate * parse_sua()
730Sstevel@tonic-gate *
740Sstevel@tonic-gate * This is the main SUSP routine, that gets all the SUA areas and
750Sstevel@tonic-gate * continuations. It calls parse_signatures() to actually interpret
760Sstevel@tonic-gate * the signature fields.
770Sstevel@tonic-gate *
780Sstevel@tonic-gate * XXX - need to implement signature searching to speed things up and
790Sstevel@tonic-gate * which is needed for the api, which isn't done yet.
800Sstevel@tonic-gate */
810Sstevel@tonic-gate int
parse_sua(uchar_t * name_p,int * name_len_p,int * name_change_p,uchar_t * dirp,uint_t last_offset,struct hs_direntry * hdp,struct hsfs * fsp,uchar_t * search_sig,int search_num)820Sstevel@tonic-gate parse_sua(
830Sstevel@tonic-gate uchar_t *name_p, /* location to copy name */
840Sstevel@tonic-gate int *name_len_p, /* location to put name len */
850Sstevel@tonic-gate int *name_change_p, /* flags to signal name chg */
860Sstevel@tonic-gate uchar_t *dirp, /* pointer to ISO dir entry */
87*4866Sfrankho uint_t last_offset, /* last ind. in cur. dirblock */
880Sstevel@tonic-gate struct hs_direntry *hdp, /* loc to store dir info */
890Sstevel@tonic-gate struct hsfs *fsp, /* filesystem pointer */
900Sstevel@tonic-gate uchar_t *search_sig, /* signature to search for */
910Sstevel@tonic-gate int search_num) /* n^th sig to search for */
920Sstevel@tonic-gate {
930Sstevel@tonic-gate uchar_t *SUA_p = IDE_sys_use_area(dirp);
940Sstevel@tonic-gate int SUA_len = IDE_SUA_LEN(dirp);
950Sstevel@tonic-gate uchar_t *tmp_SUA_p = (SUA_p + fsp->hsfs_sua_off);
960Sstevel@tonic-gate int tmp_SUA_len = (SUA_len - fsp->hsfs_sua_off);
970Sstevel@tonic-gate short ret_val = -1;
980Sstevel@tonic-gate uchar_t *cont_p = (uchar_t *)NULL;
990Sstevel@tonic-gate sig_args_t sig_args;
1000Sstevel@tonic-gate cont_info_t cont_info;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate * If there is no SUA, just return, no error
1040Sstevel@tonic-gate */
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate if (SUA_len == 0)
1070Sstevel@tonic-gate return (0);
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate /*
1101025Sfrankho * Underflow on the length field means there's a mismatch
1111025Sfrankho * between sizes of SUA and ISO directory entry. This entry
1121025Sfrankho * is corrupted, return an appropriate error.
1131025Sfrankho */
114*4866Sfrankho if (SUA_len < 0) {
115*4866Sfrankho hs_log_bogus_disk_warning(fsp, HSFS_ERR_NEG_SUA_LEN, 0);
1161025Sfrankho return (SUA_EINVAL);
117*4866Sfrankho }
118*4866Sfrankho
119*4866Sfrankho if ((tmp_SUA_p + tmp_SUA_len) > (dirp + last_offset)) {
120*4866Sfrankho hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_SUA_LEN, 0);
121*4866Sfrankho return (SUA_EINVAL);
122*4866Sfrankho }
1231025Sfrankho
1241025Sfrankho /*
1250Sstevel@tonic-gate * Make sure that the continuation lenth is zero, as that is
1260Sstevel@tonic-gate * the way to tell if we must grab another continuation area.
1270Sstevel@tonic-gate */
1280Sstevel@tonic-gate bzero((char *)&cont_info, sizeof (cont_info));
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate sig_args.dirp = dirp;
1310Sstevel@tonic-gate sig_args.name_p = name_p;
1320Sstevel@tonic-gate sig_args.name_len_p = name_len_p;
1330Sstevel@tonic-gate sig_args.SUF_ptr = tmp_SUA_p;
1340Sstevel@tonic-gate sig_args.hdp = hdp;
1350Sstevel@tonic-gate sig_args.fsp = fsp;
1360Sstevel@tonic-gate sig_args.cont_info_p = &cont_info;
1370Sstevel@tonic-gate sig_args.flags = 0;
1380Sstevel@tonic-gate sig_args.name_flags = 0;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate * Get ready to put in a new name. If no "NM" is found, then
1420Sstevel@tonic-gate * hs_namecopy will come to the rescue. Make sure you don't
1430Sstevel@tonic-gate * have NULL names, also.
1440Sstevel@tonic-gate */
1450Sstevel@tonic-gate if (name_p)
1460Sstevel@tonic-gate *(name_p) = '\0';
1470Sstevel@tonic-gate if (name_len_p)
1480Sstevel@tonic-gate *(name_len_p) = 0;
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate while (ret_val == -1) {
1510Sstevel@tonic-gate switch (parse_signatures(&sig_args, tmp_SUA_len, search_sig,
152*4866Sfrankho search_num)) {
1530Sstevel@tonic-gate case END_OF_SUA :
1540Sstevel@tonic-gate if (cont_info.cont_len) {
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate if (get_cont_area(fsp, &cont_p, &cont_info)) {
1570Sstevel@tonic-gate ret_val = 1;
1580Sstevel@tonic-gate goto clean_up;
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate
161*4866Sfrankho sig_args.SUF_ptr =
162*4866Sfrankho cont_p + cont_info.cont_offset;
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate tmp_SUA_len = cont_info.cont_len;
1650Sstevel@tonic-gate cont_info.cont_len = 0;
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate continue;
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate sig_args.flags = 0; /* reset */
1700Sstevel@tonic-gate ret_val = 0; /* keep going */
1710Sstevel@tonic-gate break;
1720Sstevel@tonic-gate case SUA_NULL_POINTER:
1730Sstevel@tonic-gate ret_val = SUA_NULL_POINTER;
1740Sstevel@tonic-gate goto clean_up;
1750Sstevel@tonic-gate case SUA_ENOMEM:
1760Sstevel@tonic-gate ret_val = SUA_ENOMEM;
1770Sstevel@tonic-gate goto clean_up;
1780Sstevel@tonic-gate case SUA_EINVAL:
1790Sstevel@tonic-gate ret_val = SUA_EINVAL;
1800Sstevel@tonic-gate goto clean_up;
1810Sstevel@tonic-gate case RELOC_DIR:
1820Sstevel@tonic-gate ret_val = RELOC_DIR;
1830Sstevel@tonic-gate goto clean_up;
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate if (ret_val != 0)
1880Sstevel@tonic-gate goto clean_up;
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate if (IS_NAME_BIT_SET(sig_args.name_flags, RRIP_NAME_CHANGE))
1910Sstevel@tonic-gate SET_NAME_BIT(*(name_change_p), RRIP_NAME_CHANGE);
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate clean_up:
1940Sstevel@tonic-gate free_cont_area(cont_p);
1950Sstevel@tonic-gate return (ret_val);
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate * parse_signatures()
2010Sstevel@tonic-gate *
202494Sfrankho * Find the correct handling function for the signature string that is
203494Sfrankho * passed to this function.
2040Sstevel@tonic-gate *
2050Sstevel@tonic-gate * signature searching:
2060Sstevel@tonic-gate *
2070Sstevel@tonic-gate * The two arguments of search_sig and search_num are for finding the
2080Sstevel@tonic-gate * search_num^th occurance of the signature search_sig. This will come
2090Sstevel@tonic-gate * in handy with searching for the "NM" field and is part of the api
2100Sstevel@tonic-gate * for rrip (which really can be used for any extension).
2110Sstevel@tonic-gate */
2120Sstevel@tonic-gate /*ARGSUSED*/
2130Sstevel@tonic-gate static int
parse_signatures(sig_args_t * sig_args_p,int SUA_len,uchar_t * search_sig,int search_num)2140Sstevel@tonic-gate parse_signatures(
2150Sstevel@tonic-gate sig_args_t *sig_args_p,
2161025Sfrankho int SUA_len,
2170Sstevel@tonic-gate uchar_t *search_sig, /* possible signature to search for */
2180Sstevel@tonic-gate int search_num) /* n^th occurance of search_sig to */
2190Sstevel@tonic-gate /* search for */
2200Sstevel@tonic-gate {
2210Sstevel@tonic-gate uchar_t *sig_string = sig_args_p->SUF_ptr;
2220Sstevel@tonic-gate extension_name_t *extnp;
2230Sstevel@tonic-gate ext_signature_t *ext_sigp;
2240Sstevel@tonic-gate int impl_bit_num = 0;
2251025Sfrankho int SUA_rem = SUA_len; /* SUA length */
2260Sstevel@tonic-gate /* remaining to be parsed */
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate /* This should never happen ... just so we don't panic, literally */
2290Sstevel@tonic-gate if (sig_string == (uchar_t *)NULL)
2300Sstevel@tonic-gate return (SUA_NULL_POINTER);
2310Sstevel@tonic-gate
2321025Sfrankho if (SUA_len < 0)
2331025Sfrankho return (SUA_EINVAL);
2341025Sfrankho
2350Sstevel@tonic-gate /*
2360Sstevel@tonic-gate * Until the end of SUA, search for the signatures
2370Sstevel@tonic-gate * (check for end of SUA (2 consecutive NULL bytes)) or the
2380Sstevel@tonic-gate * remaining length of the SUA is <= 3. The minimum signature
2390Sstevel@tonic-gate * field is 4.
2400Sstevel@tonic-gate */
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate while ((SUA_rem >= SUF_MIN_LEN) && (*sig_string != '\0') &&
2430Sstevel@tonic-gate (*(sig_string + 1) != '\0')) {
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate * Find appropriate extension and signature table
2470Sstevel@tonic-gate */
2480Sstevel@tonic-gate for (extnp = extension_name_table, impl_bit_num = 0;
2490Sstevel@tonic-gate extnp->extension_name != (char *)NULL;
2500Sstevel@tonic-gate extnp++, impl_bit_num++) {
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate /*
2530Sstevel@tonic-gate * look at an extension only if it is implemented
2540Sstevel@tonic-gate * on the CD-ROM
2550Sstevel@tonic-gate */
2560Sstevel@tonic-gate if (!IS_IMPL_BIT_SET(sig_args_p->fsp, impl_bit_num))
2570Sstevel@tonic-gate continue;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate * Find the appropriate signature
2610Sstevel@tonic-gate */
2620Sstevel@tonic-gate for (ext_sigp = extnp->signature_table;
2630Sstevel@tonic-gate ext_sigp->ext_signature != (char *)NULL;
2640Sstevel@tonic-gate ext_sigp++) {
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate if (strncmp((char *)sig_string,
2670Sstevel@tonic-gate ext_sigp->ext_signature,
2680Sstevel@tonic-gate SUF_SIG_LEN) == 0) {
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate SUA_rem -= SUF_LEN(sig_string);
2711025Sfrankho if (SUA_rem < 0)
2721025Sfrankho return (END_OF_SUA);
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate /*
2750Sstevel@tonic-gate * The SUA_len parameter specifies the
2760Sstevel@tonic-gate * length of the SUA that the kernel
2770Sstevel@tonic-gate * expects. There is also a length
2780Sstevel@tonic-gate * encoded in the SUA data. If they
2790Sstevel@tonic-gate * do not agree, bail out.
2800Sstevel@tonic-gate */
2810Sstevel@tonic-gate if (SUA_len < SUF_LEN(sig_string)) {
2820Sstevel@tonic-gate cmn_err(CE_NOTE,
2830Sstevel@tonic-gate "parse_signatures: SUA length too big: "
2840Sstevel@tonic-gate "expected=%d, found=%d",
2850Sstevel@tonic-gate SUA_len,
2860Sstevel@tonic-gate SUF_LEN(sig_string));
2870Sstevel@tonic-gate return (SUA_EINVAL);
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate sig_args_p->SUF_ptr = sig_string;
2910Sstevel@tonic-gate sig_string =
2920Sstevel@tonic-gate (ext_sigp->sig_handler)(sig_args_p);
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate switch (sig_args_p->flags) {
2950Sstevel@tonic-gate case END_OF_SUA :
2960Sstevel@tonic-gate return (END_OF_SUA);
2970Sstevel@tonic-gate case SUA_ENOMEM :
2980Sstevel@tonic-gate return (SUA_ENOMEM);
2990Sstevel@tonic-gate case SUA_EINVAL :
3000Sstevel@tonic-gate return (SUA_EINVAL);
3010Sstevel@tonic-gate case RELOC_DIR :
3020Sstevel@tonic-gate return (RELOC_DIR);
3030Sstevel@tonic-gate default :
3040Sstevel@tonic-gate #if NAME_SEARCH
3050Sstevel@tonic-gate case NAME_CONTINUE :
3060Sstevel@tonic-gate /* nothing for now */
3070Sstevel@tonic-gate case NAME_CHANGE :
3080Sstevel@tonic-gate /* nothing for now */
3090Sstevel@tonic-gate #endif
3100Sstevel@tonic-gate break;
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate /* reset to be zero */
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate sig_args_p->flags = 0;
3160Sstevel@tonic-gate goto next_signature;
3170Sstevel@tonic-gate }
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate /* off to the next signature .... */
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate } /* for ext_sigp */
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate } /* for extnp (extension parsing) */
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate /*
326494Sfrankho * Opps, did not find this signature. We must
327494Sfrankho * advance on the the next signature in the SUA
328494Sfrankho * and pray to persumedly omniscient, omnipresent,
329494Sfrankho * almighty transcendental being(s) that the next
330494Sfrankho * record is in the susp format, or we get hosed.
3310Sstevel@tonic-gate */
3320Sstevel@tonic-gate if (SUA_rem < SUF_MIN_LEN)
3330Sstevel@tonic-gate return (END_OF_SUA);
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate SUA_rem -= SUF_LEN(sig_string);
3360Sstevel@tonic-gate sig_string += SUF_LEN(sig_string);
3370Sstevel@tonic-gate
338494Sfrankho next_signature:
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate * Failsafe
3410Sstevel@tonic-gate */
342700Sfrankho if (SUA_rem < SUF_MIN_LEN ||
343700Sfrankho sig_string == NULL || SUF_LEN(sig_string) <= 0) {
3440Sstevel@tonic-gate return (END_OF_SUA);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate } /* while */
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate return (END_OF_SUA);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate /*
3530Sstevel@tonic-gate * hs_fill_root_dirent()
3540Sstevel@tonic-gate *
3550Sstevel@tonic-gate *
3560Sstevel@tonic-gate * This function reads the root directory extent to get to the SUA of
3570Sstevel@tonic-gate * the "." entry of the root directory. It the checks to see if the
3580Sstevel@tonic-gate * susp is implemented.
3590Sstevel@tonic-gate */
3600Sstevel@tonic-gate void
hs_check_root_dirent(struct vnode * vp,struct hs_direntry * hdp)3610Sstevel@tonic-gate hs_check_root_dirent(struct vnode *vp, struct hs_direntry *hdp)
3620Sstevel@tonic-gate {
3630Sstevel@tonic-gate struct buf *secbp;
3640Sstevel@tonic-gate uchar_t *root_ptr;
3650Sstevel@tonic-gate uchar_t *secp;
3660Sstevel@tonic-gate uint_t secno;
3670Sstevel@tonic-gate offset_t secoff;
3680Sstevel@tonic-gate sig_args_t sig_args;
3690Sstevel@tonic-gate struct hsfs *fsp;
3700Sstevel@tonic-gate int error;
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate if (vp->v_type != VDIR) {
3730Sstevel@tonic-gate cmn_err(CE_NOTE,
3740Sstevel@tonic-gate "hs_check_root_dirent: vp (0x%p) not a directory",
3750Sstevel@tonic-gate (void *)vp);
3760Sstevel@tonic-gate return;
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate bzero((caddr_t)&sig_args, sizeof (sig_args));
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate fsp = VFS_TO_HSFS(vp->v_vfsp);
3820Sstevel@tonic-gate secno = LBN_TO_SEC(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp);
3830Sstevel@tonic-gate secoff = LBN_TO_BYTE(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp) &
384*4866Sfrankho MAXHSOFFSET;
3850Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
3860Sstevel@tonic-gate error = geterror(secbp);
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate if (error != 0) {
3890Sstevel@tonic-gate cmn_err(CE_NOTE,
390*4866Sfrankho "hs_check_root_dirent: bread: error=(%d)", error);
3910Sstevel@tonic-gate goto end;
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate secp = (uchar_t *)secbp->b_un.b_addr;
3950Sstevel@tonic-gate root_ptr = &secp[secoff];
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate /* quick check */
3980Sstevel@tonic-gate if (hdp->ext_lbn != HDE_EXT_LBN(root_ptr)) {
3990Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_check_root_dirent: dirent not match\n");
4000Sstevel@tonic-gate /* keep on going */
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate /*
4040Sstevel@tonic-gate * Here, we know that the "." entry is the first in the sector
4050Sstevel@tonic-gate * just read (ISO 9660). Let's now check for the sharing
4060Sstevel@tonic-gate * protocol and set call the susp sig_handler() if we should.
4070Sstevel@tonic-gate * Then we run through the hs_parsedir() function to catch all
4080Sstevel@tonic-gate * the other possibilities of SUSP fields and continuations.
4090Sstevel@tonic-gate *
4101025Sfrankho * If there is no SUA area, just return, and assume ISO.
4111025Sfrankho *
4121025Sfrankho * If the SUA area length is invalid (negative, due to a mismatch
4131025Sfrankho * between dirent size and SUA size), return and hope for the best.
4140Sstevel@tonic-gate */
4150Sstevel@tonic-gate
4161025Sfrankho if (IDE_SUA_LEN(root_ptr) <= 0)
4170Sstevel@tonic-gate goto end;
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate if (strncmp(SUSP_SP, (char *)IDE_sys_use_area(root_ptr),
420*4866Sfrankho SUF_SIG_LEN) == 0) {
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate * We have a match of the sharing signature, so let's
4230Sstevel@tonic-gate * call the sig_handler to do what is necessary. We can
4240Sstevel@tonic-gate * ignore the return value, as implemented bits are set.
4250Sstevel@tonic-gate */
4260Sstevel@tonic-gate sig_args.SUF_ptr = IDE_sys_use_area(root_ptr);
4270Sstevel@tonic-gate sig_args.fsp = fsp;
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate if ((susp_sp->sig_handler)(&sig_args) == (uchar_t *)NULL) {
4300Sstevel@tonic-gate goto end;
4310Sstevel@tonic-gate }
432*4866Sfrankho } else {
4330Sstevel@tonic-gate goto end;
434*4866Sfrankho }
4350Sstevel@tonic-gate
436*4866Sfrankho /*
437*4866Sfrankho * If the "ER" signature in the root directory is past any non SU
438*4866Sfrankho * signature, the Rock Ridge signatures will be ignored. This happens
439*4866Sfrankho * e.g. for filesystems created by mkisofs. In this case,
440*4866Sfrankho * IS_RRIP_IMPLEMENTED(fsp) will return 0 when the "ER" signature is
441*4866Sfrankho * parsed. Unfortunately, the results of this run will be cached for
442*4866Sfrankho * the root vnode. The solution is to run hs_parsedir() a second time
443*4866Sfrankho * for the root directory.
444*4866Sfrankho */
445*4866Sfrankho if (hs_parsedir(fsp, root_ptr, hdp, (char *)NULL, (int *)NULL,
446*4866Sfrankho HS_SECTOR_SIZE - secoff) == 0) {
447*4866Sfrankho (void) hs_parsedir(fsp, root_ptr, hdp, (char *)NULL,
448*4866Sfrankho (int *)NULL, HS_SECTOR_SIZE - secoff);
449*4866Sfrankho }
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate /*
4520Sstevel@tonic-gate * If we did not get at least 1 extension, let's assume ISO and
4530Sstevel@tonic-gate * NULL out the implementation bits.
4540Sstevel@tonic-gate */
4550Sstevel@tonic-gate if (fsp->hsfs_ext_impl <= 1L)
4560Sstevel@tonic-gate fsp->hsfs_ext_impl = 0L;
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate end:
4590Sstevel@tonic-gate brelse(secbp);
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate /*
4640Sstevel@tonic-gate * get_cont_area()
4650Sstevel@tonic-gate *
4660Sstevel@tonic-gate * This function allocates a memory block, if necessary, and reads the
4670Sstevel@tonic-gate * continuation area into the allocated space.
4680Sstevel@tonic-gate *
4690Sstevel@tonic-gate * Return value : 0 if the read and allocation went OK.
4700Sstevel@tonic-gate * 1 if there was an error.
4710Sstevel@tonic-gate */
4720Sstevel@tonic-gate static int
get_cont_area(struct hsfs * fsp,uchar_t ** buf_pp,cont_info_t * cont_info_p)4730Sstevel@tonic-gate get_cont_area(struct hsfs *fsp, uchar_t **buf_pp, cont_info_t *cont_info_p)
4740Sstevel@tonic-gate {
4750Sstevel@tonic-gate struct buf *secbp;
4760Sstevel@tonic-gate int error;
4770Sstevel@tonic-gate uint_t secno;
4780Sstevel@tonic-gate
479494Sfrankho /*
480494Sfrankho * Guard against invalid continuation area records.
481494Sfrankho * Both cont_offset and cont_len must be no longer than
482494Sfrankho * HS_SECTOR_SIZE. If they are, return an error.
483494Sfrankho */
484494Sfrankho if (cont_info_p->cont_offset > HS_SECTOR_SIZE ||
485494Sfrankho cont_info_p->cont_len > HS_SECTOR_SIZE) {
486494Sfrankho cmn_err(CE_NOTE, "get_cont_area: invalid offset/length");
487494Sfrankho return (1);
488494Sfrankho }
489494Sfrankho
4900Sstevel@tonic-gate if (*buf_pp == (uchar_t *)NULL)
4910Sstevel@tonic-gate *buf_pp = kmem_alloc((size_t)HS_SECTOR_SIZE, KM_SLEEP);
4920Sstevel@tonic-gate
4930Sstevel@tonic-gate secno = (uint_t)LBN_TO_SEC(cont_info_p->cont_lbn, fsp->hsfs_vfs);
4940Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
4950Sstevel@tonic-gate error = geterror(secbp);
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate if (error != 0) {
4980Sstevel@tonic-gate cmn_err(CE_NOTE, "get_cont_area: bread: error=(%d)", error);
4990Sstevel@tonic-gate brelse(secbp);
5000Sstevel@tonic-gate return (1);
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate
5030Sstevel@tonic-gate /*
5040Sstevel@tonic-gate * This continuation area does not extend into the next sector
5050Sstevel@tonic-gate * so just copy the data to the buffer.
5060Sstevel@tonic-gate */
5070Sstevel@tonic-gate if ((cont_info_p->cont_offset + cont_info_p->cont_len) <=
5080Sstevel@tonic-gate HS_SECTOR_SIZE) {
5090Sstevel@tonic-gate bcopy(secbp->b_un.b_addr, (char *)*buf_pp, HS_SECTOR_SIZE);
5100Sstevel@tonic-gate }
5110Sstevel@tonic-gate /*
5120Sstevel@tonic-gate * This continuation area extends into the next sector so we
5130Sstevel@tonic-gate * need to do some dancing:
5140Sstevel@tonic-gate *
5150Sstevel@tonic-gate * - zero the return buffer so nothing random is returned
5160Sstevel@tonic-gate * - copy the partial data to the *beginning* of the return buffer
5170Sstevel@tonic-gate * - release the first sector's buffer
5180Sstevel@tonic-gate * - read the next sector
5190Sstevel@tonic-gate * - copy the remainder of the data to the return buffer
5200Sstevel@tonic-gate */
5210Sstevel@tonic-gate else {
5220Sstevel@tonic-gate uint_t partial_size;
5230Sstevel@tonic-gate
5240Sstevel@tonic-gate bzero((char *)*buf_pp, HS_SECTOR_SIZE);
5250Sstevel@tonic-gate partial_size = HS_SECTOR_SIZE - cont_info_p->cont_offset;
5260Sstevel@tonic-gate bcopy(&secbp->b_un.b_addr[cont_info_p->cont_offset],
527*4866Sfrankho (char *)*buf_pp, partial_size);
5280Sstevel@tonic-gate cont_info_p->cont_offset = 0;
5290Sstevel@tonic-gate brelse(secbp);
5300Sstevel@tonic-gate
5310Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, (secno + 1) * 4,
532*4866Sfrankho HS_SECTOR_SIZE);
5330Sstevel@tonic-gate error = geterror(secbp);
5340Sstevel@tonic-gate if (error != 0) {
5350Sstevel@tonic-gate cmn_err(CE_NOTE, "get_cont_area: bread(2): error=(%d)",
536*4866Sfrankho error);
5370Sstevel@tonic-gate brelse(secbp);
5380Sstevel@tonic-gate return (1);
5390Sstevel@tonic-gate }
5400Sstevel@tonic-gate bcopy(secbp->b_un.b_addr, (char *)&(*buf_pp)[partial_size],
541*4866Sfrankho cont_info_p->cont_len - partial_size);
5420Sstevel@tonic-gate }
5430Sstevel@tonic-gate
5440Sstevel@tonic-gate brelse(secbp);
5450Sstevel@tonic-gate return (0);
5460Sstevel@tonic-gate }
5470Sstevel@tonic-gate
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate /*
5500Sstevel@tonic-gate * free_cont_area
5510Sstevel@tonic-gate *
5520Sstevel@tonic-gate * simple function to just free up memory, if it exists
5530Sstevel@tonic-gate *
5540Sstevel@tonic-gate */
5550Sstevel@tonic-gate static void
free_cont_area(uchar_t * cont_p)5560Sstevel@tonic-gate free_cont_area(uchar_t *cont_p)
5570Sstevel@tonic-gate {
5580Sstevel@tonic-gate if (cont_p)
5590Sstevel@tonic-gate (void) kmem_free((caddr_t)cont_p, (size_t)HS_SECTOR_SIZE);
5600Sstevel@tonic-gate cont_p = (uchar_t *)NULL;
5610Sstevel@tonic-gate }
562