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
554e0249cSfrankho * Common Development and Distribution License (the "License").
654e0249cSfrankho * 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 /*
227c478bd9Sstevel@tonic-gate * System Use Sharing protocol subroutines for High Sierra filesystem
23fc1c62b8Sfrankho */
24fc1c62b8Sfrankho /*
25*d10b6702Sfrankho * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
26cf83459aSfrankho * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
357c478bd9Sstevel@tonic-gate #include <sys/signal.h>
367c478bd9Sstevel@tonic-gate #include <sys/user.h>
377c478bd9Sstevel@tonic-gate #include <sys/proc.h>
387c478bd9Sstevel@tonic-gate #include <sys/disp.h>
397c478bd9Sstevel@tonic-gate #include <sys/buf.h>
407c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
417c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
427c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
437c478bd9Sstevel@tonic-gate #include <sys/file.h>
447c478bd9Sstevel@tonic-gate #include <sys/uio.h>
457c478bd9Sstevel@tonic-gate #include <sys/conf.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #include <vm/page.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
507c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
517c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
527c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
537c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
547c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
577c478bd9Sstevel@tonic-gate #include <sys/mount.h>
587c478bd9Sstevel@tonic-gate #include <sys/swap.h>
597c478bd9Sstevel@tonic-gate #include <sys/errno.h>
607c478bd9Sstevel@tonic-gate #include <sys/debug.h>
617c478bd9Sstevel@tonic-gate #include "fs/fs_subr.h"
627c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /* static declarations */
657c478bd9Sstevel@tonic-gate static void free_cont_area(uchar_t *);
667c478bd9Sstevel@tonic-gate static int get_cont_area(struct hsfs *, uchar_t **, cont_info_t *);
6754e0249cSfrankho static int parse_signatures(sig_args_t *, int, uchar_t *, int);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate * parse_sua()
717c478bd9Sstevel@tonic-gate *
727c478bd9Sstevel@tonic-gate * This is the main SUSP routine, that gets all the SUA areas and
737c478bd9Sstevel@tonic-gate * continuations. It calls parse_signatures() to actually interpret
747c478bd9Sstevel@tonic-gate * the signature fields.
757c478bd9Sstevel@tonic-gate *
767c478bd9Sstevel@tonic-gate * XXX - need to implement signature searching to speed things up and
777c478bd9Sstevel@tonic-gate * which is needed for the api, which isn't done yet.
787c478bd9Sstevel@tonic-gate */
797c478bd9Sstevel@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)807c478bd9Sstevel@tonic-gate parse_sua(
817c478bd9Sstevel@tonic-gate uchar_t *name_p, /* location to copy name */
827c478bd9Sstevel@tonic-gate int *name_len_p, /* location to put name len */
837c478bd9Sstevel@tonic-gate int *name_change_p, /* flags to signal name chg */
847c478bd9Sstevel@tonic-gate uchar_t *dirp, /* pointer to ISO dir entry */
85*d10b6702Sfrankho uint_t last_offset, /* last ind. in cur. dirblock */
867c478bd9Sstevel@tonic-gate struct hs_direntry *hdp, /* loc to store dir info */
877c478bd9Sstevel@tonic-gate struct hsfs *fsp, /* filesystem pointer */
887c478bd9Sstevel@tonic-gate uchar_t *search_sig, /* signature to search for */
897c478bd9Sstevel@tonic-gate int search_num) /* n^th sig to search for */
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate uchar_t *SUA_p = IDE_sys_use_area(dirp);
927c478bd9Sstevel@tonic-gate int SUA_len = IDE_SUA_LEN(dirp);
937c478bd9Sstevel@tonic-gate uchar_t *tmp_SUA_p = (SUA_p + fsp->hsfs_sua_off);
947c478bd9Sstevel@tonic-gate int tmp_SUA_len = (SUA_len - fsp->hsfs_sua_off);
957c478bd9Sstevel@tonic-gate short ret_val = -1;
967c478bd9Sstevel@tonic-gate uchar_t *cont_p = (uchar_t *)NULL;
977c478bd9Sstevel@tonic-gate sig_args_t sig_args;
987c478bd9Sstevel@tonic-gate cont_info_t cont_info;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * If there is no SUA, just return, no error
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate if (SUA_len == 0)
1057c478bd9Sstevel@tonic-gate return (0);
1067c478bd9Sstevel@tonic-gate
10754e0249cSfrankho /*
10854e0249cSfrankho * Underflow on the length field means there's a mismatch
10954e0249cSfrankho * between sizes of SUA and ISO directory entry. This entry
11054e0249cSfrankho * is corrupted, return an appropriate error.
11154e0249cSfrankho */
112*d10b6702Sfrankho if (SUA_len < 0) {
113*d10b6702Sfrankho hs_log_bogus_disk_warning(fsp, HSFS_ERR_NEG_SUA_LEN, 0);
1149694f18aSfrankho return (SUA_EINVAL);
115*d10b6702Sfrankho }
116*d10b6702Sfrankho
117*d10b6702Sfrankho if ((tmp_SUA_p + tmp_SUA_len) > (dirp + last_offset)) {
118*d10b6702Sfrankho hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_SUA_LEN, 0);
119*d10b6702Sfrankho return (SUA_EINVAL);
120*d10b6702Sfrankho }
12154e0249cSfrankho
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate * Make sure that the continuation lenth is zero, as that is
1247c478bd9Sstevel@tonic-gate * the way to tell if we must grab another continuation area.
1257c478bd9Sstevel@tonic-gate */
1267c478bd9Sstevel@tonic-gate bzero((char *)&cont_info, sizeof (cont_info));
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate sig_args.dirp = dirp;
1297c478bd9Sstevel@tonic-gate sig_args.name_p = name_p;
1307c478bd9Sstevel@tonic-gate sig_args.name_len_p = name_len_p;
1317c478bd9Sstevel@tonic-gate sig_args.SUF_ptr = tmp_SUA_p;
1327c478bd9Sstevel@tonic-gate sig_args.hdp = hdp;
1337c478bd9Sstevel@tonic-gate sig_args.fsp = fsp;
1347c478bd9Sstevel@tonic-gate sig_args.cont_info_p = &cont_info;
1357c478bd9Sstevel@tonic-gate sig_args.flags = 0;
1367c478bd9Sstevel@tonic-gate sig_args.name_flags = 0;
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * Get ready to put in a new name. If no "NM" is found, then
1407c478bd9Sstevel@tonic-gate * hs_namecopy will come to the rescue. Make sure you don't
1417c478bd9Sstevel@tonic-gate * have NULL names, also.
1427c478bd9Sstevel@tonic-gate */
1437c478bd9Sstevel@tonic-gate if (name_p)
1447c478bd9Sstevel@tonic-gate *(name_p) = '\0';
1457c478bd9Sstevel@tonic-gate if (name_len_p)
1467c478bd9Sstevel@tonic-gate *(name_len_p) = 0;
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate while (ret_val == -1) {
1497c478bd9Sstevel@tonic-gate switch (parse_signatures(&sig_args, tmp_SUA_len, search_sig,
150*d10b6702Sfrankho search_num)) {
1517c478bd9Sstevel@tonic-gate case END_OF_SUA :
1527c478bd9Sstevel@tonic-gate if (cont_info.cont_len) {
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if (get_cont_area(fsp, &cont_p, &cont_info)) {
1557c478bd9Sstevel@tonic-gate ret_val = 1;
1567c478bd9Sstevel@tonic-gate goto clean_up;
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
159*d10b6702Sfrankho sig_args.SUF_ptr =
160*d10b6702Sfrankho cont_p + cont_info.cont_offset;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate tmp_SUA_len = cont_info.cont_len;
1637c478bd9Sstevel@tonic-gate cont_info.cont_len = 0;
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate continue;
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate sig_args.flags = 0; /* reset */
1687c478bd9Sstevel@tonic-gate ret_val = 0; /* keep going */
1697c478bd9Sstevel@tonic-gate break;
1707c478bd9Sstevel@tonic-gate case SUA_NULL_POINTER:
1717c478bd9Sstevel@tonic-gate ret_val = SUA_NULL_POINTER;
1727c478bd9Sstevel@tonic-gate goto clean_up;
1737c478bd9Sstevel@tonic-gate case SUA_ENOMEM:
1747c478bd9Sstevel@tonic-gate ret_val = SUA_ENOMEM;
1757c478bd9Sstevel@tonic-gate goto clean_up;
1767c478bd9Sstevel@tonic-gate case SUA_EINVAL:
1777c478bd9Sstevel@tonic-gate ret_val = SUA_EINVAL;
1787c478bd9Sstevel@tonic-gate goto clean_up;
1797c478bd9Sstevel@tonic-gate case RELOC_DIR:
1807c478bd9Sstevel@tonic-gate ret_val = RELOC_DIR;
1817c478bd9Sstevel@tonic-gate goto clean_up;
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate if (ret_val != 0)
1867c478bd9Sstevel@tonic-gate goto clean_up;
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if (IS_NAME_BIT_SET(sig_args.name_flags, RRIP_NAME_CHANGE))
1897c478bd9Sstevel@tonic-gate SET_NAME_BIT(*(name_change_p), RRIP_NAME_CHANGE);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate clean_up:
1927c478bd9Sstevel@tonic-gate free_cont_area(cont_p);
1937c478bd9Sstevel@tonic-gate return (ret_val);
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate * parse_signatures()
1997c478bd9Sstevel@tonic-gate *
200cf83459aSfrankho * Find the correct handling function for the signature string that is
201cf83459aSfrankho * passed to this function.
2027c478bd9Sstevel@tonic-gate *
2037c478bd9Sstevel@tonic-gate * signature searching:
2047c478bd9Sstevel@tonic-gate *
2057c478bd9Sstevel@tonic-gate * The two arguments of search_sig and search_num are for finding the
2067c478bd9Sstevel@tonic-gate * search_num^th occurance of the signature search_sig. This will come
2077c478bd9Sstevel@tonic-gate * in handy with searching for the "NM" field and is part of the api
2087c478bd9Sstevel@tonic-gate * for rrip (which really can be used for any extension).
2097c478bd9Sstevel@tonic-gate */
2107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2117c478bd9Sstevel@tonic-gate static int
parse_signatures(sig_args_t * sig_args_p,int SUA_len,uchar_t * search_sig,int search_num)2127c478bd9Sstevel@tonic-gate parse_signatures(
2137c478bd9Sstevel@tonic-gate sig_args_t *sig_args_p,
21454e0249cSfrankho int SUA_len,
2157c478bd9Sstevel@tonic-gate uchar_t *search_sig, /* possible signature to search for */
2167c478bd9Sstevel@tonic-gate int search_num) /* n^th occurance of search_sig to */
2177c478bd9Sstevel@tonic-gate /* search for */
2187c478bd9Sstevel@tonic-gate {
2197c478bd9Sstevel@tonic-gate uchar_t *sig_string = sig_args_p->SUF_ptr;
2207c478bd9Sstevel@tonic-gate extension_name_t *extnp;
2217c478bd9Sstevel@tonic-gate ext_signature_t *ext_sigp;
2227c478bd9Sstevel@tonic-gate int impl_bit_num = 0;
22354e0249cSfrankho int SUA_rem = SUA_len; /* SUA length */
2247c478bd9Sstevel@tonic-gate /* remaining to be parsed */
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /* This should never happen ... just so we don't panic, literally */
2277c478bd9Sstevel@tonic-gate if (sig_string == (uchar_t *)NULL)
2287c478bd9Sstevel@tonic-gate return (SUA_NULL_POINTER);
2297c478bd9Sstevel@tonic-gate
23054e0249cSfrankho if (SUA_len < 0)
23154e0249cSfrankho return (SUA_EINVAL);
23254e0249cSfrankho
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate * Until the end of SUA, search for the signatures
2357c478bd9Sstevel@tonic-gate * (check for end of SUA (2 consecutive NULL bytes)) or the
2367c478bd9Sstevel@tonic-gate * remaining length of the SUA is <= 3. The minimum signature
2377c478bd9Sstevel@tonic-gate * field is 4.
2387c478bd9Sstevel@tonic-gate */
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate while ((SUA_rem >= SUF_MIN_LEN) && (*sig_string != '\0') &&
2417c478bd9Sstevel@tonic-gate (*(sig_string + 1) != '\0')) {
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate * Find appropriate extension and signature table
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate for (extnp = extension_name_table, impl_bit_num = 0;
2477c478bd9Sstevel@tonic-gate extnp->extension_name != (char *)NULL;
2487c478bd9Sstevel@tonic-gate extnp++, impl_bit_num++) {
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate * look at an extension only if it is implemented
2527c478bd9Sstevel@tonic-gate * on the CD-ROM
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate if (!IS_IMPL_BIT_SET(sig_args_p->fsp, impl_bit_num))
2557c478bd9Sstevel@tonic-gate continue;
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate * Find the appropriate signature
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate for (ext_sigp = extnp->signature_table;
2617c478bd9Sstevel@tonic-gate ext_sigp->ext_signature != (char *)NULL;
2627c478bd9Sstevel@tonic-gate ext_sigp++) {
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (strncmp((char *)sig_string,
2657c478bd9Sstevel@tonic-gate ext_sigp->ext_signature,
2667c478bd9Sstevel@tonic-gate SUF_SIG_LEN) == 0) {
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate SUA_rem -= SUF_LEN(sig_string);
26954e0249cSfrankho if (SUA_rem < 0)
27054e0249cSfrankho return (END_OF_SUA);
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate /*
2737c478bd9Sstevel@tonic-gate * The SUA_len parameter specifies the
2747c478bd9Sstevel@tonic-gate * length of the SUA that the kernel
2757c478bd9Sstevel@tonic-gate * expects. There is also a length
2767c478bd9Sstevel@tonic-gate * encoded in the SUA data. If they
2777c478bd9Sstevel@tonic-gate * do not agree, bail out.
2787c478bd9Sstevel@tonic-gate */
2797c478bd9Sstevel@tonic-gate if (SUA_len < SUF_LEN(sig_string)) {
2807c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
2817c478bd9Sstevel@tonic-gate "parse_signatures: SUA length too big: "
2827c478bd9Sstevel@tonic-gate "expected=%d, found=%d",
2837c478bd9Sstevel@tonic-gate SUA_len,
2847c478bd9Sstevel@tonic-gate SUF_LEN(sig_string));
2857c478bd9Sstevel@tonic-gate return (SUA_EINVAL);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate sig_args_p->SUF_ptr = sig_string;
2897c478bd9Sstevel@tonic-gate sig_string =
2907c478bd9Sstevel@tonic-gate (ext_sigp->sig_handler)(sig_args_p);
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate switch (sig_args_p->flags) {
2937c478bd9Sstevel@tonic-gate case END_OF_SUA :
2947c478bd9Sstevel@tonic-gate return (END_OF_SUA);
2957c478bd9Sstevel@tonic-gate case SUA_ENOMEM :
2967c478bd9Sstevel@tonic-gate return (SUA_ENOMEM);
2977c478bd9Sstevel@tonic-gate case SUA_EINVAL :
2987c478bd9Sstevel@tonic-gate return (SUA_EINVAL);
2997c478bd9Sstevel@tonic-gate case RELOC_DIR :
3007c478bd9Sstevel@tonic-gate return (RELOC_DIR);
3017c478bd9Sstevel@tonic-gate default :
3027c478bd9Sstevel@tonic-gate #if NAME_SEARCH
3037c478bd9Sstevel@tonic-gate case NAME_CONTINUE :
3047c478bd9Sstevel@tonic-gate /* nothing for now */
3057c478bd9Sstevel@tonic-gate case NAME_CHANGE :
3067c478bd9Sstevel@tonic-gate /* nothing for now */
3077c478bd9Sstevel@tonic-gate #endif
3087c478bd9Sstevel@tonic-gate break;
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate /* reset to be zero */
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate sig_args_p->flags = 0;
3147c478bd9Sstevel@tonic-gate goto next_signature;
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate /* off to the next signature .... */
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate } /* for ext_sigp */
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate } /* for extnp (extension parsing) */
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate /*
324cf83459aSfrankho * Opps, did not find this signature. We must
325cf83459aSfrankho * advance on the the next signature in the SUA
326cf83459aSfrankho * and pray to persumedly omniscient, omnipresent,
327cf83459aSfrankho * almighty transcendental being(s) that the next
328cf83459aSfrankho * record is in the susp format, or we get hosed.
3297c478bd9Sstevel@tonic-gate */
3307c478bd9Sstevel@tonic-gate if (SUA_rem < SUF_MIN_LEN)
3317c478bd9Sstevel@tonic-gate return (END_OF_SUA);
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate SUA_rem -= SUF_LEN(sig_string);
3347c478bd9Sstevel@tonic-gate sig_string += SUF_LEN(sig_string);
3357c478bd9Sstevel@tonic-gate
336cf83459aSfrankho next_signature:
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate * Failsafe
3397c478bd9Sstevel@tonic-gate */
340c0f937daSfrankho if (SUA_rem < SUF_MIN_LEN ||
341c0f937daSfrankho sig_string == NULL || SUF_LEN(sig_string) <= 0) {
3427c478bd9Sstevel@tonic-gate return (END_OF_SUA);
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate } /* while */
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate return (END_OF_SUA);
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * hs_fill_root_dirent()
3527c478bd9Sstevel@tonic-gate *
3537c478bd9Sstevel@tonic-gate *
3547c478bd9Sstevel@tonic-gate * This function reads the root directory extent to get to the SUA of
3557c478bd9Sstevel@tonic-gate * the "." entry of the root directory. It the checks to see if the
3567c478bd9Sstevel@tonic-gate * susp is implemented.
3577c478bd9Sstevel@tonic-gate */
3587c478bd9Sstevel@tonic-gate void
hs_check_root_dirent(struct vnode * vp,struct hs_direntry * hdp)3597c478bd9Sstevel@tonic-gate hs_check_root_dirent(struct vnode *vp, struct hs_direntry *hdp)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate struct buf *secbp;
3627c478bd9Sstevel@tonic-gate uchar_t *root_ptr;
3637c478bd9Sstevel@tonic-gate uchar_t *secp;
3647c478bd9Sstevel@tonic-gate uint_t secno;
3657c478bd9Sstevel@tonic-gate offset_t secoff;
3667c478bd9Sstevel@tonic-gate sig_args_t sig_args;
3677c478bd9Sstevel@tonic-gate struct hsfs *fsp;
3687c478bd9Sstevel@tonic-gate int error;
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate if (vp->v_type != VDIR) {
3717c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
3727c478bd9Sstevel@tonic-gate "hs_check_root_dirent: vp (0x%p) not a directory",
3737c478bd9Sstevel@tonic-gate (void *)vp);
3747c478bd9Sstevel@tonic-gate return;
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate bzero((caddr_t)&sig_args, sizeof (sig_args));
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate fsp = VFS_TO_HSFS(vp->v_vfsp);
3807c478bd9Sstevel@tonic-gate secno = LBN_TO_SEC(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp);
3817c478bd9Sstevel@tonic-gate secoff = LBN_TO_BYTE(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp) &
382*d10b6702Sfrankho MAXHSOFFSET;
3837c478bd9Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
3847c478bd9Sstevel@tonic-gate error = geterror(secbp);
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate if (error != 0) {
3877c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
388*d10b6702Sfrankho "hs_check_root_dirent: bread: error=(%d)", error);
3897c478bd9Sstevel@tonic-gate goto end;
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate secp = (uchar_t *)secbp->b_un.b_addr;
3937c478bd9Sstevel@tonic-gate root_ptr = &secp[secoff];
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate /* quick check */
3967c478bd9Sstevel@tonic-gate if (hdp->ext_lbn != HDE_EXT_LBN(root_ptr)) {
3977c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "hs_check_root_dirent: dirent not match\n");
3987c478bd9Sstevel@tonic-gate /* keep on going */
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate * Here, we know that the "." entry is the first in the sector
4037c478bd9Sstevel@tonic-gate * just read (ISO 9660). Let's now check for the sharing
4047c478bd9Sstevel@tonic-gate * protocol and set call the susp sig_handler() if we should.
4057c478bd9Sstevel@tonic-gate * Then we run through the hs_parsedir() function to catch all
4067c478bd9Sstevel@tonic-gate * the other possibilities of SUSP fields and continuations.
4077c478bd9Sstevel@tonic-gate *
40854e0249cSfrankho * If there is no SUA area, just return, and assume ISO.
40954e0249cSfrankho *
41054e0249cSfrankho * If the SUA area length is invalid (negative, due to a mismatch
41154e0249cSfrankho * between dirent size and SUA size), return and hope for the best.
4127c478bd9Sstevel@tonic-gate */
4137c478bd9Sstevel@tonic-gate
41454e0249cSfrankho if (IDE_SUA_LEN(root_ptr) <= 0)
4157c478bd9Sstevel@tonic-gate goto end;
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate if (strncmp(SUSP_SP, (char *)IDE_sys_use_area(root_ptr),
418*d10b6702Sfrankho SUF_SIG_LEN) == 0) {
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate * We have a match of the sharing signature, so let's
4217c478bd9Sstevel@tonic-gate * call the sig_handler to do what is necessary. We can
4227c478bd9Sstevel@tonic-gate * ignore the return value, as implemented bits are set.
4237c478bd9Sstevel@tonic-gate */
4247c478bd9Sstevel@tonic-gate sig_args.SUF_ptr = IDE_sys_use_area(root_ptr);
4257c478bd9Sstevel@tonic-gate sig_args.fsp = fsp;
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate if ((susp_sp->sig_handler)(&sig_args) == (uchar_t *)NULL) {
4287c478bd9Sstevel@tonic-gate goto end;
4297c478bd9Sstevel@tonic-gate }
430*d10b6702Sfrankho } else {
4317c478bd9Sstevel@tonic-gate goto end;
432*d10b6702Sfrankho }
4337c478bd9Sstevel@tonic-gate
434*d10b6702Sfrankho /*
435*d10b6702Sfrankho * If the "ER" signature in the root directory is past any non SU
436*d10b6702Sfrankho * signature, the Rock Ridge signatures will be ignored. This happens
437*d10b6702Sfrankho * e.g. for filesystems created by mkisofs. In this case,
438*d10b6702Sfrankho * IS_RRIP_IMPLEMENTED(fsp) will return 0 when the "ER" signature is
439*d10b6702Sfrankho * parsed. Unfortunately, the results of this run will be cached for
440*d10b6702Sfrankho * the root vnode. The solution is to run hs_parsedir() a second time
441*d10b6702Sfrankho * for the root directory.
442*d10b6702Sfrankho */
443*d10b6702Sfrankho if (hs_parsedir(fsp, root_ptr, hdp, (char *)NULL, (int *)NULL,
444*d10b6702Sfrankho HS_SECTOR_SIZE - secoff) == 0) {
445*d10b6702Sfrankho (void) hs_parsedir(fsp, root_ptr, hdp, (char *)NULL,
446*d10b6702Sfrankho (int *)NULL, HS_SECTOR_SIZE - secoff);
447*d10b6702Sfrankho }
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate * If we did not get at least 1 extension, let's assume ISO and
4517c478bd9Sstevel@tonic-gate * NULL out the implementation bits.
4527c478bd9Sstevel@tonic-gate */
4537c478bd9Sstevel@tonic-gate if (fsp->hsfs_ext_impl <= 1L)
4547c478bd9Sstevel@tonic-gate fsp->hsfs_ext_impl = 0L;
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate end:
4577c478bd9Sstevel@tonic-gate brelse(secbp);
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate /*
4627c478bd9Sstevel@tonic-gate * get_cont_area()
4637c478bd9Sstevel@tonic-gate *
4647c478bd9Sstevel@tonic-gate * This function allocates a memory block, if necessary, and reads the
4657c478bd9Sstevel@tonic-gate * continuation area into the allocated space.
4667c478bd9Sstevel@tonic-gate *
4677c478bd9Sstevel@tonic-gate * Return value : 0 if the read and allocation went OK.
4687c478bd9Sstevel@tonic-gate * 1 if there was an error.
4697c478bd9Sstevel@tonic-gate */
4707c478bd9Sstevel@tonic-gate static int
get_cont_area(struct hsfs * fsp,uchar_t ** buf_pp,cont_info_t * cont_info_p)4717c478bd9Sstevel@tonic-gate get_cont_area(struct hsfs *fsp, uchar_t **buf_pp, cont_info_t *cont_info_p)
4727c478bd9Sstevel@tonic-gate {
4737c478bd9Sstevel@tonic-gate struct buf *secbp;
4747c478bd9Sstevel@tonic-gate int error;
4757c478bd9Sstevel@tonic-gate uint_t secno;
4767c478bd9Sstevel@tonic-gate
477cf83459aSfrankho /*
478cf83459aSfrankho * Guard against invalid continuation area records.
479cf83459aSfrankho * Both cont_offset and cont_len must be no longer than
480cf83459aSfrankho * HS_SECTOR_SIZE. If they are, return an error.
481cf83459aSfrankho */
482cf83459aSfrankho if (cont_info_p->cont_offset > HS_SECTOR_SIZE ||
483cf83459aSfrankho cont_info_p->cont_len > HS_SECTOR_SIZE) {
484cf83459aSfrankho cmn_err(CE_NOTE, "get_cont_area: invalid offset/length");
485cf83459aSfrankho return (1);
486cf83459aSfrankho }
487cf83459aSfrankho
4887c478bd9Sstevel@tonic-gate if (*buf_pp == (uchar_t *)NULL)
4897c478bd9Sstevel@tonic-gate *buf_pp = kmem_alloc((size_t)HS_SECTOR_SIZE, KM_SLEEP);
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate secno = (uint_t)LBN_TO_SEC(cont_info_p->cont_lbn, fsp->hsfs_vfs);
4927c478bd9Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
4937c478bd9Sstevel@tonic-gate error = geterror(secbp);
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate if (error != 0) {
4967c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "get_cont_area: bread: error=(%d)", error);
4977c478bd9Sstevel@tonic-gate brelse(secbp);
4987c478bd9Sstevel@tonic-gate return (1);
4997c478bd9Sstevel@tonic-gate }
5007c478bd9Sstevel@tonic-gate
5017c478bd9Sstevel@tonic-gate /*
5027c478bd9Sstevel@tonic-gate * This continuation area does not extend into the next sector
5037c478bd9Sstevel@tonic-gate * so just copy the data to the buffer.
5047c478bd9Sstevel@tonic-gate */
5057c478bd9Sstevel@tonic-gate if ((cont_info_p->cont_offset + cont_info_p->cont_len) <=
5067c478bd9Sstevel@tonic-gate HS_SECTOR_SIZE) {
5077c478bd9Sstevel@tonic-gate bcopy(secbp->b_un.b_addr, (char *)*buf_pp, HS_SECTOR_SIZE);
5087c478bd9Sstevel@tonic-gate }
5097c478bd9Sstevel@tonic-gate /*
5107c478bd9Sstevel@tonic-gate * This continuation area extends into the next sector so we
5117c478bd9Sstevel@tonic-gate * need to do some dancing:
5127c478bd9Sstevel@tonic-gate *
5137c478bd9Sstevel@tonic-gate * - zero the return buffer so nothing random is returned
5147c478bd9Sstevel@tonic-gate * - copy the partial data to the *beginning* of the return buffer
5157c478bd9Sstevel@tonic-gate * - release the first sector's buffer
5167c478bd9Sstevel@tonic-gate * - read the next sector
5177c478bd9Sstevel@tonic-gate * - copy the remainder of the data to the return buffer
5187c478bd9Sstevel@tonic-gate */
5197c478bd9Sstevel@tonic-gate else {
5207c478bd9Sstevel@tonic-gate uint_t partial_size;
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate bzero((char *)*buf_pp, HS_SECTOR_SIZE);
5237c478bd9Sstevel@tonic-gate partial_size = HS_SECTOR_SIZE - cont_info_p->cont_offset;
5247c478bd9Sstevel@tonic-gate bcopy(&secbp->b_un.b_addr[cont_info_p->cont_offset],
525*d10b6702Sfrankho (char *)*buf_pp, partial_size);
5267c478bd9Sstevel@tonic-gate cont_info_p->cont_offset = 0;
5277c478bd9Sstevel@tonic-gate brelse(secbp);
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate secbp = bread(fsp->hsfs_devvp->v_rdev, (secno + 1) * 4,
530*d10b6702Sfrankho HS_SECTOR_SIZE);
5317c478bd9Sstevel@tonic-gate error = geterror(secbp);
5327c478bd9Sstevel@tonic-gate if (error != 0) {
5337c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "get_cont_area: bread(2): error=(%d)",
534*d10b6702Sfrankho error);
5357c478bd9Sstevel@tonic-gate brelse(secbp);
5367c478bd9Sstevel@tonic-gate return (1);
5377c478bd9Sstevel@tonic-gate }
5387c478bd9Sstevel@tonic-gate bcopy(secbp->b_un.b_addr, (char *)&(*buf_pp)[partial_size],
539*d10b6702Sfrankho cont_info_p->cont_len - partial_size);
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate brelse(secbp);
5437c478bd9Sstevel@tonic-gate return (0);
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate * free_cont_area
5497c478bd9Sstevel@tonic-gate *
5507c478bd9Sstevel@tonic-gate * simple function to just free up memory, if it exists
5517c478bd9Sstevel@tonic-gate *
5527c478bd9Sstevel@tonic-gate */
5537c478bd9Sstevel@tonic-gate static void
free_cont_area(uchar_t * cont_p)5547c478bd9Sstevel@tonic-gate free_cont_area(uchar_t *cont_p)
5557c478bd9Sstevel@tonic-gate {
5567c478bd9Sstevel@tonic-gate if (cont_p)
5577c478bd9Sstevel@tonic-gate (void) kmem_free((caddr_t)cont_p, (size_t)HS_SECTOR_SIZE);
5587c478bd9Sstevel@tonic-gate cont_p = (uchar_t *)NULL;
5597c478bd9Sstevel@tonic-gate }
560