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