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