xref: /onnv-gate/usr/src/uts/common/fs/hsfs/hsfs_rrip.c (revision 9031:569640c630f9)
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 /*
22*9031SFrank.Batschulat@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23494Sfrankho  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * Rock Ridge extensions to the System Use Sharing protocol
280Sstevel@tonic-gate  * for the High Sierra filesystem
290Sstevel@tonic-gate  */
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/kmem.h>
360Sstevel@tonic-gate #include <sys/signal.h>
370Sstevel@tonic-gate #include <sys/user.h>
380Sstevel@tonic-gate #include <sys/proc.h>
390Sstevel@tonic-gate #include <sys/disp.h>
400Sstevel@tonic-gate #include <sys/buf.h>
410Sstevel@tonic-gate #include <sys/pathname.h>
420Sstevel@tonic-gate #include <sys/vfs.h>
430Sstevel@tonic-gate #include <sys/vnode.h>
440Sstevel@tonic-gate #include <sys/file.h>
450Sstevel@tonic-gate #include <sys/uio.h>
460Sstevel@tonic-gate #include <sys/conf.h>
470Sstevel@tonic-gate #include <sys/stat.h>
480Sstevel@tonic-gate #include <sys/mode.h>
490Sstevel@tonic-gate #include <sys/mkdev.h>
500Sstevel@tonic-gate #include <sys/ddi.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #include <vm/page.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
550Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
560Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
570Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
580Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
590Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #include <sys/statvfs.h>
620Sstevel@tonic-gate #include <sys/mount.h>
630Sstevel@tonic-gate #include <sys/swap.h>
640Sstevel@tonic-gate #include <sys/errno.h>
650Sstevel@tonic-gate #include <sys/debug.h>
660Sstevel@tonic-gate #include "fs/fs_subr.h"
670Sstevel@tonic-gate #include <sys/cmn_err.h>
680Sstevel@tonic-gate 
690Sstevel@tonic-gate static void form_time(int, uchar_t *, struct timeval *);
700Sstevel@tonic-gate static void name_parse(int, uchar_t *, size_t, uchar_t *, int *,
710Sstevel@tonic-gate     ulong_t *, int);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  *  Signature table for RRIP
750Sstevel@tonic-gate  */
760Sstevel@tonic-gate ext_signature_t  rrip_signature_table[ ] = {
770Sstevel@tonic-gate 	RRIP_CL,	rrip_child_link,
780Sstevel@tonic-gate 	RRIP_NM,	rrip_name,
790Sstevel@tonic-gate 	RRIP_PL,	rrip_parent_link,
800Sstevel@tonic-gate 	RRIP_PN,	rrip_dev_nodes,
810Sstevel@tonic-gate 	RRIP_PX,	rrip_file_attr,
820Sstevel@tonic-gate 	RRIP_RE,	rrip_reloc_dir,
830Sstevel@tonic-gate 	RRIP_RR,	rrip_rock_ridge,
840Sstevel@tonic-gate 	RRIP_SL,	rrip_sym_link,
850Sstevel@tonic-gate 	RRIP_TF,	rrip_file_time,
860Sstevel@tonic-gate 	(char *)NULL,   NULL
870Sstevel@tonic-gate };
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * rrip_dev_nodes()
920Sstevel@tonic-gate  *
930Sstevel@tonic-gate  * sig_handler() for RRIP signature "PN"
940Sstevel@tonic-gate  *
950Sstevel@tonic-gate  * This function parses out the major and minor numbers from the "PN
960Sstevel@tonic-gate  * " SUF.
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate uchar_t *
rrip_dev_nodes(sig_args_t * sig_args_p)990Sstevel@tonic-gate rrip_dev_nodes(sig_args_t *sig_args_p)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate 	uchar_t *pn_ptr = sig_args_p->SUF_ptr;
1020Sstevel@tonic-gate 	major_t	major_dev = (major_t)RRIP_MAJOR(pn_ptr);
1030Sstevel@tonic-gate 	minor_t	minor_dev = (minor_t)RRIP_MINOR(pn_ptr);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	sig_args_p->hdp->r_dev = makedevice(major_dev, minor_dev);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	return (pn_ptr + SUF_LEN(pn_ptr));
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate  * rrip_file_attr()
1120Sstevel@tonic-gate  *
1130Sstevel@tonic-gate  * sig_handler() for RRIP signature "PX"
1140Sstevel@tonic-gate  *
1150Sstevel@tonic-gate  * This function parses out the file attributes of a file from the "PX"
1160Sstevel@tonic-gate  * SUF.  The attributes is finds are : st_mode, st_nlink, st_uid,
1170Sstevel@tonic-gate  * and st_gid.
1180Sstevel@tonic-gate  */
1190Sstevel@tonic-gate uchar_t *
rrip_file_attr(sig_args_t * sig_args_p)1200Sstevel@tonic-gate rrip_file_attr(sig_args_t *sig_args_p)
1210Sstevel@tonic-gate {
1220Sstevel@tonic-gate 	uchar_t *px_ptr = sig_args_p->SUF_ptr;
1230Sstevel@tonic-gate 	struct hs_direntry *hdp    = sig_args_p->hdp;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	hdp->mode  = RRIP_MODE(px_ptr);
1260Sstevel@tonic-gate 	hdp->nlink = RRIP_NLINK(px_ptr);
1270Sstevel@tonic-gate 	hdp->uid   = RRIP_UID(px_ptr);
1280Sstevel@tonic-gate 	hdp->gid   = RRIP_GID(px_ptr);
1290Sstevel@tonic-gate 
1304866Sfrankho 	if (SUF_LEN(px_ptr) >= RRIP_PX_SIZE)
1314866Sfrankho 		hdp->inode = (ino64_t)RRIP_INO(px_ptr);
1324866Sfrankho 	else
1334866Sfrankho 		hdp->inode = 0;
1344866Sfrankho 
1350Sstevel@tonic-gate 	hdp->type = IFTOVT(hdp->mode);
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	return (px_ptr + SUF_LEN(px_ptr));
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate  * rrip_file_time()
1420Sstevel@tonic-gate  *
1430Sstevel@tonic-gate  * support function for rrip_file_time()
1440Sstevel@tonic-gate  *
1450Sstevel@tonic-gate  * This function decides whether to parse the times in a long time form
1460Sstevel@tonic-gate  * (17 bytes) or a short time form (7 bytes).  These time formats are
1470Sstevel@tonic-gate  * defined in the ISO 9660 specification.
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate static void
form_time(int time_length,uchar_t * file_time,struct timeval * tvp)1500Sstevel@tonic-gate form_time(int time_length, uchar_t *file_time, struct timeval *tvp)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	if (time_length == ISO_DATE_LEN)
1530Sstevel@tonic-gate 		hs_parse_longdate(file_time, tvp);
1540Sstevel@tonic-gate 	else
1550Sstevel@tonic-gate 		hs_parse_dirdate(file_time, tvp);
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * rrip_file_time()
1610Sstevel@tonic-gate  *
1620Sstevel@tonic-gate  * sig_handler() for RRIP signature RRIP_TF
1630Sstevel@tonic-gate  *
1640Sstevel@tonic-gate  * This function parses out the file time attributes of a file from the
1650Sstevel@tonic-gate  * "TI" SUF.  The times it parses are : st_mtime, st_atime and st_ctime.
1660Sstevel@tonic-gate  *
1670Sstevel@tonic-gate  * The function form_time is a support function only used in this
1680Sstevel@tonic-gate  * function.
1690Sstevel@tonic-gate  */
1700Sstevel@tonic-gate uchar_t *
rrip_file_time(sig_args_t * sig_args_p)1710Sstevel@tonic-gate rrip_file_time(sig_args_t *sig_args_p)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate 	uchar_t *tf_ptr = sig_args_p->SUF_ptr;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_ACCESS_BIT)) {
1760Sstevel@tonic-gate 		form_time(RRIP_TF_TIME_LENGTH(tf_ptr),
1770Sstevel@tonic-gate 		    RRIP_tf_access(tf_ptr),
1780Sstevel@tonic-gate 		    &sig_args_p->hdp->adate);
1790Sstevel@tonic-gate 	}
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_MODIFY_BIT)) {
1820Sstevel@tonic-gate 		form_time(RRIP_TF_TIME_LENGTH(tf_ptr), RRIP_tf_modify(tf_ptr),
1830Sstevel@tonic-gate 		    &sig_args_p->hdp->mdate);
1840Sstevel@tonic-gate 	}
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_ATTRIBUTES_BIT)) {
1870Sstevel@tonic-gate 		form_time(RRIP_TF_TIME_LENGTH(tf_ptr),
1880Sstevel@tonic-gate 		    RRIP_tf_attributes(tf_ptr),
1890Sstevel@tonic-gate 		    &sig_args_p->hdp->cdate);
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	return (tf_ptr + SUF_LEN(tf_ptr));
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate  * name_parse()
1990Sstevel@tonic-gate  *
2000Sstevel@tonic-gate  * This is a generic fuction used for sym links and filenames.  The
2010Sstevel@tonic-gate  * flags passed to it effect the way the name/component field is parsed.
2020Sstevel@tonic-gate  *
2030Sstevel@tonic-gate  * The return value will be the NAME_CONTINUE or NAME_CHANGE value.
2040Sstevel@tonic-gate  *
2050Sstevel@tonic-gate  */
2060Sstevel@tonic-gate static void
name_parse(int rrip_flags,uchar_t * SUA_string,size_t SUA_string_len,uchar_t * dst,int * dst_lenp,ulong_t * name_flags_p,int dst_size)2070Sstevel@tonic-gate name_parse(
2080Sstevel@tonic-gate 	int		rrip_flags,	/* component/name flag */
2090Sstevel@tonic-gate 	uchar_t		*SUA_string,	/* string from SUA */
2100Sstevel@tonic-gate 	size_t		SUA_string_len, /* length of SUA string */
211494Sfrankho 	uchar_t		*dst,		/* string to copy to */
212494Sfrankho 	int		*dst_lenp,	/* ptr to cur. str len */
2130Sstevel@tonic-gate 	ulong_t		*name_flags_p,	/* internal name flags */
214494Sfrankho 	int		dst_size)	/* limit dest string to */
2150Sstevel@tonic-gate 						/* this value */
2160Sstevel@tonic-gate {
2174866Sfrankho 	size_t	off;
2184866Sfrankho 	size_t	len;
2194866Sfrankho 
220494Sfrankho 	if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_ROOT))
221*9031SFrank.Batschulat@Sun.COM 		dst[0] = 0;
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_CURRENT)) {
2240Sstevel@tonic-gate 		SUA_string = (uchar_t *)".";
2250Sstevel@tonic-gate 		SUA_string_len = 1;
2260Sstevel@tonic-gate 	}
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_PARENT)) {
2290Sstevel@tonic-gate 		SUA_string = (uchar_t *)"..";
2300Sstevel@tonic-gate 		SUA_string_len = 2;
2310Sstevel@tonic-gate 	}
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	/*
2340Sstevel@tonic-gate 	 * XXX
2350Sstevel@tonic-gate 	 * For now, ignore the following flags and return.
2360Sstevel@tonic-gate 	 * have to figure out how to get host name in kernel.
2370Sstevel@tonic-gate 	 * Unsure if this even should be done.
2380Sstevel@tonic-gate 	 */
2390Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_VOLROOT) ||
2400Sstevel@tonic-gate 	    IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_HOST)) {
2410Sstevel@tonic-gate 		cmn_err(CE_NOTE,
2420Sstevel@tonic-gate 			"VOLUME ROOT and NAME_HOST currently unsupported\n");
2430Sstevel@tonic-gate 		return;
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	/*
2471025Sfrankho 	 * strlcat() has two nice properties:
2481025Sfrankho 	 * - the size of the output buffer includes the trailing '\0'
2491025Sfrankho 	 * - we pass "total size" not "remaining size"
2501025Sfrankho 	 * It'd be the ideal candidate for this codeblock - make it:
2511025Sfrankho 	 *
2521025Sfrankho 	 *	strlcat(dst, SUA_string,
2531025Sfrankho 	 *	    MIN(dstsize, strlen(dst) + SUA_string_len + 1));
2541025Sfrankho 	 *
2551025Sfrankho 	 * Unfortunately, strlcat() cannot deal with input strings
2561025Sfrankho 	 * that are not NULL-terminated - like SUA_string can be in
2571025Sfrankho 	 * our case here. So we can't use it :(
2584866Sfrankho 	 * Now strncat() doesn't work either - because it doesn't deal
2594866Sfrankho 	 * with strings for which the 'potential NULL-termination' isn't
2604866Sfrankho 	 * accessible - strncat(dst, NULL, 0) crashes although it copies
2614866Sfrankho 	 * nothing in any case. If the SUA ends on a mapping boundary,
2624866Sfrankho 	 * then telling strncat() to copy no more than the remaining bytes
2634866Sfrankho 	 * in the buffer is of no avail if there's no NULL byte in them.
2644866Sfrankho 	 *
2654866Sfrankho 	 * Hence - binary copy. What are all these str* funcs for ??
2660Sstevel@tonic-gate 	 */
2671025Sfrankho 	dst_size--;	/* trailing '\0' */
2681025Sfrankho 
2694866Sfrankho 	off = strlen((char *)dst);
2704866Sfrankho 	len = MIN(dst_size - off, SUA_string_len);
2714866Sfrankho 	bcopy((char *)SUA_string, (char *)(dst + off), len);
2724866Sfrankho 	dst[off + len] = '\0';
2731025Sfrankho 	*dst_lenp = strlen((char *)dst);
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_CONTINUE))
2760Sstevel@tonic-gate 		SET_NAME_BIT(*(name_flags_p), RRIP_NAME_CONTINUE);
2770Sstevel@tonic-gate 	else
2780Sstevel@tonic-gate 		SET_NAME_BIT(*(name_flags_p), RRIP_NAME_CHANGE);
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate }
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate  * rrip_name()
2840Sstevel@tonic-gate  *
2850Sstevel@tonic-gate  * sig_handler() for RRIP signature RRIP_NM
2860Sstevel@tonic-gate  *
2870Sstevel@tonic-gate  * This function handles the name of the current file.  It is case
2880Sstevel@tonic-gate  * sensitive to whatever was put into the field and does NO
2890Sstevel@tonic-gate  * translation. It will take whatever characters were in the field.
2900Sstevel@tonic-gate  *
2910Sstevel@tonic-gate  * Because the flags effect the way the name is parsed the same way
2920Sstevel@tonic-gate  * that the sym_link component parsing is done, we will use the same
2930Sstevel@tonic-gate  * function to do the actual parsing.
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate uchar_t  *
rrip_name(sig_args_t * sig_args_p)2960Sstevel@tonic-gate rrip_name(sig_args_t *sig_args_p)
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate 	uchar_t *nm_ptr = sig_args_p->SUF_ptr;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	if ((sig_args_p->name_p == (uchar_t *)NULL) ||
3010Sstevel@tonic-gate 	    (sig_args_p->name_len_p == (int *)NULL))
3020Sstevel@tonic-gate 		goto end;
3030Sstevel@tonic-gate 	/*
3040Sstevel@tonic-gate 	 * If we have a "." or ".." directory, we should not look for
3050Sstevel@tonic-gate 	 * an alternate name
3060Sstevel@tonic-gate 	 */
3070Sstevel@tonic-gate 	if (HDE_NAME_LEN(sig_args_p->dirp) == 1) {
3080Sstevel@tonic-gate 		if (*((char *)HDE_name(sig_args_p->dirp)) == '\0') {
3090Sstevel@tonic-gate 			(void) strcpy((char *)sig_args_p->name_p, ".");
3100Sstevel@tonic-gate 			*sig_args_p->name_len_p = 1;
3110Sstevel@tonic-gate 			goto end;
3120Sstevel@tonic-gate 		} else if (*((char *)HDE_name(sig_args_p->dirp)) == '\1') {
3130Sstevel@tonic-gate 			(void) strcpy((char *)sig_args_p->name_p, "..");
3140Sstevel@tonic-gate 			*sig_args_p->name_len_p = 2;
3150Sstevel@tonic-gate 			goto end;
3160Sstevel@tonic-gate 		}
3170Sstevel@tonic-gate 	}
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	name_parse((int)RRIP_NAME_FLAGS(nm_ptr), RRIP_name(nm_ptr),
3200Sstevel@tonic-gate 	    (size_t)RRIP_NAME_LEN(nm_ptr), sig_args_p->name_p,
3210Sstevel@tonic-gate 	    sig_args_p->name_len_p, &(sig_args_p->name_flags),
3220Sstevel@tonic-gate 	    MAXNAMELEN);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate end:
3250Sstevel@tonic-gate 	return (nm_ptr + SUF_LEN(nm_ptr));
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate /*
3300Sstevel@tonic-gate  * rrip_sym_link()
3310Sstevel@tonic-gate  *
3320Sstevel@tonic-gate  * sig_handler() for RRIP signature RRIP_SL
3330Sstevel@tonic-gate  *
3340Sstevel@tonic-gate  * creates a symlink buffer to simulate sym_links.
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate uchar_t *
rrip_sym_link(sig_args_t * sig_args_p)3370Sstevel@tonic-gate rrip_sym_link(sig_args_t *sig_args_p)
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate 	uchar_t	*sl_ptr = sig_args_p->SUF_ptr;
3400Sstevel@tonic-gate 	uchar_t	*comp_ptr;
3410Sstevel@tonic-gate 	char 	*tmp_sym_link;
3420Sstevel@tonic-gate 	struct hs_direntry *hdp = sig_args_p->hdp;
3430Sstevel@tonic-gate 	int	sym_link_len;
3440Sstevel@tonic-gate 	char	*sym_link;
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	if (hdp->type != VLNK)
3470Sstevel@tonic-gate 		goto end;
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	/*
3500Sstevel@tonic-gate 	 * If the sym link has already been created, don't recreate it
3510Sstevel@tonic-gate 	 */
3520Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(sig_args_p->name_flags, RRIP_SYM_LINK_COMPLETE))
3530Sstevel@tonic-gate 		goto end;
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	sym_link = kmem_alloc(MAXPATHLEN + 1, KM_SLEEP);
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	/*
3580Sstevel@tonic-gate 	 * If there is an original string put it into sym_link[], otherwise
3590Sstevel@tonic-gate 	 * initialize sym_link[] to the empty string.
3600Sstevel@tonic-gate 	 */
3610Sstevel@tonic-gate 	if (hdp->sym_link != (char *)NULL) {
3620Sstevel@tonic-gate 		sym_link_len = (int)strlen(strcpy(sym_link, hdp->sym_link));
3630Sstevel@tonic-gate 	} else {
3640Sstevel@tonic-gate 		sym_link[0] = '\0';
3650Sstevel@tonic-gate 		sym_link_len = 0;
3660Sstevel@tonic-gate 	}
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	/* for all components */
3690Sstevel@tonic-gate 	for (comp_ptr = RRIP_sl_comp(sl_ptr);
3704866Sfrankho 	    comp_ptr < (sl_ptr + SUF_LEN(sl_ptr));
3714866Sfrankho 	    comp_ptr += RRIP_COMP_LEN(comp_ptr)) {
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 		name_parse((int)RRIP_COMP_FLAGS(comp_ptr),
3740Sstevel@tonic-gate 		    RRIP_comp(comp_ptr),
3750Sstevel@tonic-gate 		    (size_t)RRIP_COMP_NAME_LEN(comp_ptr), (uchar_t *)sym_link,
3760Sstevel@tonic-gate 		    &sym_link_len, &(sig_args_p->name_flags),
3770Sstevel@tonic-gate 		    MAXPATHLEN);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 		/*
380*9031SFrank.Batschulat@Sun.COM 		 * If the component is continued don't put a '/' in
381*9031SFrank.Batschulat@Sun.COM 		 * the pathname, but do NULL terminate it.
3820Sstevel@tonic-gate 		 */
3830Sstevel@tonic-gate 		if (IS_NAME_BIT_SET(RRIP_COMP_FLAGS(comp_ptr),
384*9031SFrank.Batschulat@Sun.COM 		    RRIP_NAME_CONTINUE)) {
3850Sstevel@tonic-gate 			sym_link[sym_link_len] = '\0';
3860Sstevel@tonic-gate 		} else {
3870Sstevel@tonic-gate 			sym_link[sym_link_len] = '/';
3880Sstevel@tonic-gate 			sym_link[sym_link_len + 1] = '\0';
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 			/* add 1 to sym_link_len for '/' */
3910Sstevel@tonic-gate 			sym_link_len++;
3920Sstevel@tonic-gate 		}
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	}
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate 	/*
397*9031SFrank.Batschulat@Sun.COM 	 * If we reached the end of the symbolic link, take out the
398*9031SFrank.Batschulat@Sun.COM 	 * last slash, but don't change ROOT "/" to an empty string.
3990Sstevel@tonic-gate 	 */
400*9031SFrank.Batschulat@Sun.COM 	if (!IS_NAME_BIT_SET(RRIP_SL_FLAGS(sl_ptr), RRIP_NAME_CONTINUE) &&
401*9031SFrank.Batschulat@Sun.COM 	    sym_link_len > 1 && sym_link[sym_link_len - 1] == '/')
4020Sstevel@tonic-gate 		sym_link[--sym_link_len] = '\0';
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 	/*
4050Sstevel@tonic-gate 	 * if no memory has been allocated, get some, otherwise, append
4060Sstevel@tonic-gate 	 * to the current allocation
4070Sstevel@tonic-gate 	 */
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	tmp_sym_link = kmem_alloc(SYM_LINK_LEN(sym_link), KM_SLEEP);
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 	(void) strcpy(tmp_sym_link, sym_link);
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 	if (hdp->sym_link != (char *)NULL)
4140Sstevel@tonic-gate 		kmem_free(hdp->sym_link, (size_t)(hdp->ext_size + 1));
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	hdp->sym_link = (char *)&tmp_sym_link[0];
4170Sstevel@tonic-gate 	/* the size of a symlink is its length */
4180Sstevel@tonic-gate 	hdp->ext_size = (uint_t)strlen(tmp_sym_link);
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	if (!IS_NAME_BIT_SET(RRIP_SL_FLAGS(sl_ptr), RRIP_NAME_CONTINUE)) {
4210Sstevel@tonic-gate 		/* reached the end of the symbolic link */
4220Sstevel@tonic-gate 		SET_NAME_BIT(sig_args_p->name_flags, RRIP_SYM_LINK_COMPLETE);
4230Sstevel@tonic-gate 	}
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate 	kmem_free(sym_link, MAXPATHLEN + 1);
4260Sstevel@tonic-gate end:
4270Sstevel@tonic-gate 	return (sl_ptr + SUF_LEN(sl_ptr));
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate /*
4310Sstevel@tonic-gate  * rrip_namecopy()
4320Sstevel@tonic-gate  *
4330Sstevel@tonic-gate  * This function will copy the rrip name to the "to" buffer, if it
4340Sstevel@tonic-gate  * exists.
4350Sstevel@tonic-gate  *
4360Sstevel@tonic-gate  * XXX -  We should speed this up by implementing the search in
4370Sstevel@tonic-gate  * parse_sua().  It works right now, so I don't want to mess with it.
4380Sstevel@tonic-gate  */
4390Sstevel@tonic-gate int
rrip_namecopy(char * from,char * to,char * tmp_name,uchar_t * dirp,uint_t last_offset,struct hsfs * fsp,struct hs_direntry * hdp)4400Sstevel@tonic-gate rrip_namecopy(
4410Sstevel@tonic-gate 	char 	*from,			/* name to copy */
4420Sstevel@tonic-gate 	char 	*to,			/* string to copy "from" to */
4430Sstevel@tonic-gate 	char  	*tmp_name,		/* temp storage for original name */
4440Sstevel@tonic-gate 	uchar_t	*dirp,			/* directory entry pointer */
4454866Sfrankho 	uint_t	last_offset,		/* last index into current dir block */
4460Sstevel@tonic-gate 	struct 	hsfs *fsp,		/* filesystem pointer */
4470Sstevel@tonic-gate 	struct 	hs_direntry *hdp)	/* directory entry pointer to put */
4480Sstevel@tonic-gate 					/* all that good info in */
4490Sstevel@tonic-gate {
4500Sstevel@tonic-gate 	int	size = 0;
4510Sstevel@tonic-gate 	int	change_flag = 0;
4520Sstevel@tonic-gate 	int	ret_val;
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	if ((to == (char *)NULL) ||
4550Sstevel@tonic-gate 	    (from == (char *)NULL) ||
4560Sstevel@tonic-gate 	    (dirp == (uchar_t *)NULL)) {
4570Sstevel@tonic-gate 		return (0);
4580Sstevel@tonic-gate 	}
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	/* special handling for '.' and '..' */
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 	if (HDE_NAME_LEN(dirp) == 1) {
4630Sstevel@tonic-gate 		if (*((char *)HDE_name(dirp)) == '\0') {
4640Sstevel@tonic-gate 			(void) strcpy(to, ".");
4650Sstevel@tonic-gate 			return (1);
4660Sstevel@tonic-gate 		} else if (*((char *)HDE_name(dirp)) == '\1') {
4670Sstevel@tonic-gate 			(void) strcpy(to, "..");
4680Sstevel@tonic-gate 			return (2);
4690Sstevel@tonic-gate 		}
4700Sstevel@tonic-gate 	}
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 
4734866Sfrankho 	ret_val = parse_sua((uchar_t *)to, &size, &change_flag,
4744866Sfrankho 			dirp, last_offset,
4750Sstevel@tonic-gate 			hdp, fsp, (uchar_t *)NULL, NULL);
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate 	if (IS_NAME_BIT_SET(change_flag, RRIP_NAME_CHANGE) && !ret_val)
4780Sstevel@tonic-gate 		return (size);
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate 	/*
4810Sstevel@tonic-gate 	 * Well, the name was not found
4820Sstevel@tonic-gate 	 *
4830Sstevel@tonic-gate 	 * make rripname an upper case "nm" (to), so that
4840Sstevel@tonic-gate 	 * we can compare it the current HDE_DIR_NAME()
4850Sstevel@tonic-gate 	 * without nuking the original "nm", for future case
4860Sstevel@tonic-gate 	 * sensitive name comparing
4870Sstevel@tonic-gate 	 */
4880Sstevel@tonic-gate 	(void) strcpy(tmp_name, from);		/* keep original */
4890Sstevel@tonic-gate 	size = hs_uppercase_copy(tmp_name, from, (int)strlen(from));
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	return (-1);
4920Sstevel@tonic-gate }
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate /*
4970Sstevel@tonic-gate  * rrip_reloc_dir()
4980Sstevel@tonic-gate  *
4990Sstevel@tonic-gate  * This function is fairly bogus.  All it does is cause a failure of
5000Sstevel@tonic-gate  * the hs_parsedir, so that no vnode will be made for it and
5010Sstevel@tonic-gate  * essentially, the directory will no longer be seen.  This is part
5020Sstevel@tonic-gate  * of the directory hierarchy mess, where the relocated directory will
5030Sstevel@tonic-gate  * be hidden as far as ISO 9660 is concerned.  When we hit the child
5040Sstevel@tonic-gate  * link "CL" SUF, then we will read the new directory.
5050Sstevel@tonic-gate  */
5060Sstevel@tonic-gate uchar_t *
rrip_reloc_dir(sig_args_t * sig_args_p)5070Sstevel@tonic-gate rrip_reloc_dir(sig_args_t *sig_args_p)
5080Sstevel@tonic-gate {
5090Sstevel@tonic-gate 	uchar_t *re_ptr = sig_args_p->SUF_ptr;
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 	sig_args_p->flags = RELOC_DIR;
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	return (re_ptr + SUF_LEN(re_ptr));
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate /*
5190Sstevel@tonic-gate  * rrip_child_link()
5200Sstevel@tonic-gate  *
5210Sstevel@tonic-gate  * This is the child link part of the directory hierarchy stuff and
5220Sstevel@tonic-gate  * this does not really do much anyway.  All it does is read the
5230Sstevel@tonic-gate  * directory entry that the child link SUF contains.  All should be
5240Sstevel@tonic-gate  * fine then.
5250Sstevel@tonic-gate  */
5260Sstevel@tonic-gate uchar_t *
rrip_child_link(sig_args_t * sig_args_p)5270Sstevel@tonic-gate rrip_child_link(sig_args_t *sig_args_p)
5280Sstevel@tonic-gate {
5290Sstevel@tonic-gate 	uchar_t *cl_ptr = sig_args_p->SUF_ptr;
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 	sig_args_p->hdp->ext_lbn = RRIP_CHILD_LBN(cl_ptr);
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	hs_filldirent(sig_args_p->fsp->hsfs_rootvp, sig_args_p->hdp);
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate 	sig_args_p->flags = 0;
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	return (cl_ptr + SUF_LEN(cl_ptr));
5380Sstevel@tonic-gate }
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate /*
5420Sstevel@tonic-gate  * rrip_parent_link()
5430Sstevel@tonic-gate  *
5440Sstevel@tonic-gate  * This is the parent link part of the directory hierarchy stuff and
5450Sstevel@tonic-gate  * this does not really do much anyway.  All it does is read the
5460Sstevel@tonic-gate  * directory entry that the parent link SUF contains.  All should be
5470Sstevel@tonic-gate  * fine then.
5480Sstevel@tonic-gate  */
5490Sstevel@tonic-gate uchar_t *
rrip_parent_link(sig_args_t * sig_args_p)5500Sstevel@tonic-gate rrip_parent_link(sig_args_t *sig_args_p)
5510Sstevel@tonic-gate {
5520Sstevel@tonic-gate 	uchar_t *pl_ptr = sig_args_p->SUF_ptr;
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 	sig_args_p->hdp->ext_lbn = RRIP_PARENT_LBN(pl_ptr);
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	hs_filldirent(sig_args_p->fsp->hsfs_rootvp, sig_args_p->hdp);
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate 	sig_args_p->flags = 0;
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 	return (pl_ptr + SUF_LEN(pl_ptr));
5610Sstevel@tonic-gate }
5620Sstevel@tonic-gate 
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate /*
5650Sstevel@tonic-gate  * rrip_rock_ridge()
5660Sstevel@tonic-gate  *
5670Sstevel@tonic-gate  * This function is supposed to aid in speed of the filesystem.
5680Sstevel@tonic-gate  *
5690Sstevel@tonic-gate  * XXX - It is only here as a place holder so far.
5700Sstevel@tonic-gate  */
5710Sstevel@tonic-gate uchar_t *
rrip_rock_ridge(sig_args_t * sig_args_p)5720Sstevel@tonic-gate rrip_rock_ridge(sig_args_t *sig_args_p)
5730Sstevel@tonic-gate {
5740Sstevel@tonic-gate 	uchar_t *rr_ptr = sig_args_p->SUF_ptr;
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	return (rr_ptr + SUF_LEN(rr_ptr));
5770Sstevel@tonic-gate }
578