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*4866Sfrankho * Copyright 2007 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 132*4866Sfrankho if (SUF_LEN(px_ptr) >= RRIP_PX_SIZE) 133*4866Sfrankho hdp->inode = (ino64_t)RRIP_INO(px_ptr); 134*4866Sfrankho else 135*4866Sfrankho hdp->inode = 0; 136*4866Sfrankho 1370Sstevel@tonic-gate hdp->type = IFTOVT(hdp->mode); 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate return (px_ptr + SUF_LEN(px_ptr)); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * rrip_file_time() 1440Sstevel@tonic-gate * 1450Sstevel@tonic-gate * support function for rrip_file_time() 1460Sstevel@tonic-gate * 1470Sstevel@tonic-gate * This function decides whether to parse the times in a long time form 1480Sstevel@tonic-gate * (17 bytes) or a short time form (7 bytes). These time formats are 1490Sstevel@tonic-gate * defined in the ISO 9660 specification. 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate static void 1520Sstevel@tonic-gate form_time(int time_length, uchar_t *file_time, struct timeval *tvp) 1530Sstevel@tonic-gate { 1540Sstevel@tonic-gate if (time_length == ISO_DATE_LEN) 1550Sstevel@tonic-gate hs_parse_longdate(file_time, tvp); 1560Sstevel@tonic-gate else 1570Sstevel@tonic-gate hs_parse_dirdate(file_time, tvp); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate /* 1620Sstevel@tonic-gate * rrip_file_time() 1630Sstevel@tonic-gate * 1640Sstevel@tonic-gate * sig_handler() for RRIP signature RRIP_TF 1650Sstevel@tonic-gate * 1660Sstevel@tonic-gate * This function parses out the file time attributes of a file from the 1670Sstevel@tonic-gate * "TI" SUF. The times it parses are : st_mtime, st_atime and st_ctime. 1680Sstevel@tonic-gate * 1690Sstevel@tonic-gate * The function form_time is a support function only used in this 1700Sstevel@tonic-gate * function. 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate uchar_t * 1730Sstevel@tonic-gate rrip_file_time(sig_args_t *sig_args_p) 1740Sstevel@tonic-gate { 1750Sstevel@tonic-gate uchar_t *tf_ptr = sig_args_p->SUF_ptr; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_ACCESS_BIT)) { 1780Sstevel@tonic-gate form_time(RRIP_TF_TIME_LENGTH(tf_ptr), 1790Sstevel@tonic-gate RRIP_tf_access(tf_ptr), 1800Sstevel@tonic-gate &sig_args_p->hdp->adate); 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_MODIFY_BIT)) { 1840Sstevel@tonic-gate form_time(RRIP_TF_TIME_LENGTH(tf_ptr), RRIP_tf_modify(tf_ptr), 1850Sstevel@tonic-gate &sig_args_p->hdp->mdate); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if (IS_TIME_BIT_SET(RRIP_TF_FLAGS(tf_ptr), RRIP_TF_ATTRIBUTES_BIT)) { 1890Sstevel@tonic-gate form_time(RRIP_TF_TIME_LENGTH(tf_ptr), 1900Sstevel@tonic-gate RRIP_tf_attributes(tf_ptr), 1910Sstevel@tonic-gate &sig_args_p->hdp->cdate); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate return (tf_ptr + SUF_LEN(tf_ptr)); 1950Sstevel@tonic-gate } 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate /* 2000Sstevel@tonic-gate * name_parse() 2010Sstevel@tonic-gate * 2020Sstevel@tonic-gate * This is a generic fuction used for sym links and filenames. The 2030Sstevel@tonic-gate * flags passed to it effect the way the name/component field is parsed. 2040Sstevel@tonic-gate * 2050Sstevel@tonic-gate * The return value will be the NAME_CONTINUE or NAME_CHANGE value. 2060Sstevel@tonic-gate * 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate static void 2090Sstevel@tonic-gate name_parse( 2100Sstevel@tonic-gate int rrip_flags, /* component/name flag */ 2110Sstevel@tonic-gate uchar_t *SUA_string, /* string from SUA */ 2120Sstevel@tonic-gate size_t SUA_string_len, /* length of SUA string */ 213494Sfrankho uchar_t *dst, /* string to copy to */ 214494Sfrankho int *dst_lenp, /* ptr to cur. str len */ 2150Sstevel@tonic-gate ulong_t *name_flags_p, /* internal name flags */ 216494Sfrankho int dst_size) /* limit dest string to */ 2170Sstevel@tonic-gate /* this value */ 2180Sstevel@tonic-gate { 219*4866Sfrankho size_t off; 220*4866Sfrankho size_t len; 221*4866Sfrankho 222494Sfrankho if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_ROOT)) 223494Sfrankho (void) strcpy((char *)dst, "/"); 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_CURRENT)) { 2260Sstevel@tonic-gate SUA_string = (uchar_t *)"."; 2270Sstevel@tonic-gate SUA_string_len = 1; 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_PARENT)) { 2310Sstevel@tonic-gate SUA_string = (uchar_t *)".."; 2320Sstevel@tonic-gate SUA_string_len = 2; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate /* 2360Sstevel@tonic-gate * XXX 2370Sstevel@tonic-gate * For now, ignore the following flags and return. 2380Sstevel@tonic-gate * have to figure out how to get host name in kernel. 2390Sstevel@tonic-gate * Unsure if this even should be done. 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_VOLROOT) || 2420Sstevel@tonic-gate IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_HOST)) { 2430Sstevel@tonic-gate cmn_err(CE_NOTE, 2440Sstevel@tonic-gate "VOLUME ROOT and NAME_HOST currently unsupported\n"); 2450Sstevel@tonic-gate return; 2460Sstevel@tonic-gate } 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2491025Sfrankho * strlcat() has two nice properties: 2501025Sfrankho * - the size of the output buffer includes the trailing '\0' 2511025Sfrankho * - we pass "total size" not "remaining size" 2521025Sfrankho * It'd be the ideal candidate for this codeblock - make it: 2531025Sfrankho * 2541025Sfrankho * strlcat(dst, SUA_string, 2551025Sfrankho * MIN(dstsize, strlen(dst) + SUA_string_len + 1)); 2561025Sfrankho * 2571025Sfrankho * Unfortunately, strlcat() cannot deal with input strings 2581025Sfrankho * that are not NULL-terminated - like SUA_string can be in 2591025Sfrankho * our case here. So we can't use it :( 260*4866Sfrankho * Now strncat() doesn't work either - because it doesn't deal 261*4866Sfrankho * with strings for which the 'potential NULL-termination' isn't 262*4866Sfrankho * accessible - strncat(dst, NULL, 0) crashes although it copies 263*4866Sfrankho * nothing in any case. If the SUA ends on a mapping boundary, 264*4866Sfrankho * then telling strncat() to copy no more than the remaining bytes 265*4866Sfrankho * in the buffer is of no avail if there's no NULL byte in them. 266*4866Sfrankho * 267*4866Sfrankho * Hence - binary copy. What are all these str* funcs for ?? 2680Sstevel@tonic-gate */ 2691025Sfrankho dst_size--; /* trailing '\0' */ 2701025Sfrankho 271*4866Sfrankho off = strlen((char *)dst); 272*4866Sfrankho len = MIN(dst_size - off, SUA_string_len); 273*4866Sfrankho bcopy((char *)SUA_string, (char *)(dst + off), len); 274*4866Sfrankho dst[off + len] = '\0'; 2751025Sfrankho *dst_lenp = strlen((char *)dst); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate if (IS_NAME_BIT_SET(rrip_flags, RRIP_NAME_CONTINUE)) 2780Sstevel@tonic-gate SET_NAME_BIT(*(name_flags_p), RRIP_NAME_CONTINUE); 2790Sstevel@tonic-gate else 2800Sstevel@tonic-gate SET_NAME_BIT(*(name_flags_p), RRIP_NAME_CHANGE); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* 2850Sstevel@tonic-gate * rrip_name() 2860Sstevel@tonic-gate * 2870Sstevel@tonic-gate * sig_handler() for RRIP signature RRIP_NM 2880Sstevel@tonic-gate * 2890Sstevel@tonic-gate * This function handles the name of the current file. It is case 2900Sstevel@tonic-gate * sensitive to whatever was put into the field and does NO 2910Sstevel@tonic-gate * translation. It will take whatever characters were in the field. 2920Sstevel@tonic-gate * 2930Sstevel@tonic-gate * Because the flags effect the way the name is parsed the same way 2940Sstevel@tonic-gate * that the sym_link component parsing is done, we will use the same 2950Sstevel@tonic-gate * function to do the actual parsing. 2960Sstevel@tonic-gate */ 2970Sstevel@tonic-gate uchar_t * 2980Sstevel@tonic-gate rrip_name(sig_args_t *sig_args_p) 2990Sstevel@tonic-gate { 3000Sstevel@tonic-gate uchar_t *nm_ptr = sig_args_p->SUF_ptr; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate if ((sig_args_p->name_p == (uchar_t *)NULL) || 3030Sstevel@tonic-gate (sig_args_p->name_len_p == (int *)NULL)) 3040Sstevel@tonic-gate goto end; 3050Sstevel@tonic-gate /* 3060Sstevel@tonic-gate * If we have a "." or ".." directory, we should not look for 3070Sstevel@tonic-gate * an alternate name 3080Sstevel@tonic-gate */ 3090Sstevel@tonic-gate if (HDE_NAME_LEN(sig_args_p->dirp) == 1) { 3100Sstevel@tonic-gate if (*((char *)HDE_name(sig_args_p->dirp)) == '\0') { 3110Sstevel@tonic-gate (void) strcpy((char *)sig_args_p->name_p, "."); 3120Sstevel@tonic-gate *sig_args_p->name_len_p = 1; 3130Sstevel@tonic-gate goto end; 3140Sstevel@tonic-gate } else if (*((char *)HDE_name(sig_args_p->dirp)) == '\1') { 3150Sstevel@tonic-gate (void) strcpy((char *)sig_args_p->name_p, ".."); 3160Sstevel@tonic-gate *sig_args_p->name_len_p = 2; 3170Sstevel@tonic-gate goto end; 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate name_parse((int)RRIP_NAME_FLAGS(nm_ptr), RRIP_name(nm_ptr), 3220Sstevel@tonic-gate (size_t)RRIP_NAME_LEN(nm_ptr), sig_args_p->name_p, 3230Sstevel@tonic-gate sig_args_p->name_len_p, &(sig_args_p->name_flags), 3240Sstevel@tonic-gate MAXNAMELEN); 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate end: 3270Sstevel@tonic-gate return (nm_ptr + SUF_LEN(nm_ptr)); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate /* 3320Sstevel@tonic-gate * rrip_sym_link() 3330Sstevel@tonic-gate * 3340Sstevel@tonic-gate * sig_handler() for RRIP signature RRIP_SL 3350Sstevel@tonic-gate * 3360Sstevel@tonic-gate * creates a symlink buffer to simulate sym_links. 3370Sstevel@tonic-gate */ 3380Sstevel@tonic-gate uchar_t * 3390Sstevel@tonic-gate rrip_sym_link(sig_args_t *sig_args_p) 3400Sstevel@tonic-gate { 3410Sstevel@tonic-gate uchar_t *sl_ptr = sig_args_p->SUF_ptr; 3420Sstevel@tonic-gate uchar_t *comp_ptr; 3430Sstevel@tonic-gate char *tmp_sym_link; 3440Sstevel@tonic-gate struct hs_direntry *hdp = sig_args_p->hdp; 3450Sstevel@tonic-gate int sym_link_len; 3460Sstevel@tonic-gate char *sym_link; 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate if (hdp->type != VLNK) 3490Sstevel@tonic-gate goto end; 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * If the sym link has already been created, don't recreate it 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate if (IS_NAME_BIT_SET(sig_args_p->name_flags, RRIP_SYM_LINK_COMPLETE)) 3550Sstevel@tonic-gate goto end; 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate sym_link = kmem_alloc(MAXPATHLEN + 1, KM_SLEEP); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate /* 3600Sstevel@tonic-gate * If there is an original string put it into sym_link[], otherwise 3610Sstevel@tonic-gate * initialize sym_link[] to the empty string. 3620Sstevel@tonic-gate */ 3630Sstevel@tonic-gate if (hdp->sym_link != (char *)NULL) { 3640Sstevel@tonic-gate sym_link_len = (int)strlen(strcpy(sym_link, hdp->sym_link)); 3650Sstevel@tonic-gate } else { 3660Sstevel@tonic-gate sym_link[0] = '\0'; 3670Sstevel@tonic-gate sym_link_len = 0; 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate /* for all components */ 3710Sstevel@tonic-gate for (comp_ptr = RRIP_sl_comp(sl_ptr); 372*4866Sfrankho comp_ptr < (sl_ptr + SUF_LEN(sl_ptr)); 373*4866Sfrankho comp_ptr += RRIP_COMP_LEN(comp_ptr)) { 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate name_parse((int)RRIP_COMP_FLAGS(comp_ptr), 3760Sstevel@tonic-gate RRIP_comp(comp_ptr), 3770Sstevel@tonic-gate (size_t)RRIP_COMP_NAME_LEN(comp_ptr), (uchar_t *)sym_link, 3780Sstevel@tonic-gate &sym_link_len, &(sig_args_p->name_flags), 3790Sstevel@tonic-gate MAXPATHLEN); 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate /* 3820Sstevel@tonic-gate * If the component is continued, Don't put a 3830Sstevel@tonic-gate * '/' in the pathname, but do NULL terminate it. 3840Sstevel@tonic-gate * And avoid 2 '//' in a row, or if '/' was wanted 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate if (IS_NAME_BIT_SET(RRIP_COMP_FLAGS(comp_ptr), 387*4866Sfrankho RRIP_NAME_CONTINUE) || 3880Sstevel@tonic-gate (sym_link[sym_link_len - 1] == '/')) { 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate sym_link[sym_link_len] = '\0'; 3910Sstevel@tonic-gate } else { 3920Sstevel@tonic-gate sym_link[sym_link_len] = '/'; 3930Sstevel@tonic-gate sym_link[sym_link_len + 1] = '\0'; 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* add 1 to sym_link_len for '/' */ 3960Sstevel@tonic-gate sym_link_len++; 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * take out the last slash 4030Sstevel@tonic-gate */ 4040Sstevel@tonic-gate if (sym_link[sym_link_len - 1] == '/') 4050Sstevel@tonic-gate sym_link[--sym_link_len] = '\0'; 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * if no memory has been allocated, get some, otherwise, append 4090Sstevel@tonic-gate * to the current allocation 4100Sstevel@tonic-gate */ 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate tmp_sym_link = kmem_alloc(SYM_LINK_LEN(sym_link), KM_SLEEP); 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate (void) strcpy(tmp_sym_link, sym_link); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate if (hdp->sym_link != (char *)NULL) 4170Sstevel@tonic-gate kmem_free(hdp->sym_link, (size_t)(hdp->ext_size + 1)); 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate hdp->sym_link = (char *)&tmp_sym_link[0]; 4200Sstevel@tonic-gate /* the size of a symlink is its length */ 4210Sstevel@tonic-gate hdp->ext_size = (uint_t)strlen(tmp_sym_link); 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate if (!IS_NAME_BIT_SET(RRIP_SL_FLAGS(sl_ptr), RRIP_NAME_CONTINUE)) { 4240Sstevel@tonic-gate /* reached the end of the symbolic link */ 4250Sstevel@tonic-gate SET_NAME_BIT(sig_args_p->name_flags, RRIP_SYM_LINK_COMPLETE); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate kmem_free(sym_link, MAXPATHLEN + 1); 4290Sstevel@tonic-gate end: 4300Sstevel@tonic-gate return (sl_ptr + SUF_LEN(sl_ptr)); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate /* 4340Sstevel@tonic-gate * rrip_namecopy() 4350Sstevel@tonic-gate * 4360Sstevel@tonic-gate * This function will copy the rrip name to the "to" buffer, if it 4370Sstevel@tonic-gate * exists. 4380Sstevel@tonic-gate * 4390Sstevel@tonic-gate * XXX - We should speed this up by implementing the search in 4400Sstevel@tonic-gate * parse_sua(). It works right now, so I don't want to mess with it. 4410Sstevel@tonic-gate */ 4420Sstevel@tonic-gate int 4430Sstevel@tonic-gate rrip_namecopy( 4440Sstevel@tonic-gate char *from, /* name to copy */ 4450Sstevel@tonic-gate char *to, /* string to copy "from" to */ 4460Sstevel@tonic-gate char *tmp_name, /* temp storage for original name */ 4470Sstevel@tonic-gate uchar_t *dirp, /* directory entry pointer */ 448*4866Sfrankho uint_t last_offset, /* last index into current dir block */ 4490Sstevel@tonic-gate struct hsfs *fsp, /* filesystem pointer */ 4500Sstevel@tonic-gate struct hs_direntry *hdp) /* directory entry pointer to put */ 4510Sstevel@tonic-gate /* all that good info in */ 4520Sstevel@tonic-gate { 4530Sstevel@tonic-gate int size = 0; 4540Sstevel@tonic-gate int change_flag = 0; 4550Sstevel@tonic-gate int ret_val; 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate if ((to == (char *)NULL) || 4580Sstevel@tonic-gate (from == (char *)NULL) || 4590Sstevel@tonic-gate (dirp == (uchar_t *)NULL)) { 4600Sstevel@tonic-gate return (0); 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* special handling for '.' and '..' */ 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (HDE_NAME_LEN(dirp) == 1) { 4660Sstevel@tonic-gate if (*((char *)HDE_name(dirp)) == '\0') { 4670Sstevel@tonic-gate (void) strcpy(to, "."); 4680Sstevel@tonic-gate return (1); 4690Sstevel@tonic-gate } else if (*((char *)HDE_name(dirp)) == '\1') { 4700Sstevel@tonic-gate (void) strcpy(to, ".."); 4710Sstevel@tonic-gate return (2); 4720Sstevel@tonic-gate } 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate 476*4866Sfrankho ret_val = parse_sua((uchar_t *)to, &size, &change_flag, 477*4866Sfrankho dirp, last_offset, 4780Sstevel@tonic-gate hdp, fsp, (uchar_t *)NULL, NULL); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate if (IS_NAME_BIT_SET(change_flag, RRIP_NAME_CHANGE) && !ret_val) 4810Sstevel@tonic-gate return (size); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * Well, the name was not found 4850Sstevel@tonic-gate * 4860Sstevel@tonic-gate * make rripname an upper case "nm" (to), so that 4870Sstevel@tonic-gate * we can compare it the current HDE_DIR_NAME() 4880Sstevel@tonic-gate * without nuking the original "nm", for future case 4890Sstevel@tonic-gate * sensitive name comparing 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate (void) strcpy(tmp_name, from); /* keep original */ 4920Sstevel@tonic-gate size = hs_uppercase_copy(tmp_name, from, (int)strlen(from)); 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate return (-1); 4950Sstevel@tonic-gate } 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate /* 5000Sstevel@tonic-gate * rrip_reloc_dir() 5010Sstevel@tonic-gate * 5020Sstevel@tonic-gate * This function is fairly bogus. All it does is cause a failure of 5030Sstevel@tonic-gate * the hs_parsedir, so that no vnode will be made for it and 5040Sstevel@tonic-gate * essentially, the directory will no longer be seen. This is part 5050Sstevel@tonic-gate * of the directory hierarchy mess, where the relocated directory will 5060Sstevel@tonic-gate * be hidden as far as ISO 9660 is concerned. When we hit the child 5070Sstevel@tonic-gate * link "CL" SUF, then we will read the new directory. 5080Sstevel@tonic-gate */ 5090Sstevel@tonic-gate uchar_t * 5100Sstevel@tonic-gate rrip_reloc_dir(sig_args_t *sig_args_p) 5110Sstevel@tonic-gate { 5120Sstevel@tonic-gate uchar_t *re_ptr = sig_args_p->SUF_ptr; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate sig_args_p->flags = RELOC_DIR; 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate return (re_ptr + SUF_LEN(re_ptr)); 5170Sstevel@tonic-gate } 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* 5220Sstevel@tonic-gate * rrip_child_link() 5230Sstevel@tonic-gate * 5240Sstevel@tonic-gate * This is the child link part of the directory hierarchy stuff and 5250Sstevel@tonic-gate * this does not really do much anyway. All it does is read the 5260Sstevel@tonic-gate * directory entry that the child link SUF contains. All should be 5270Sstevel@tonic-gate * fine then. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate uchar_t * 5300Sstevel@tonic-gate rrip_child_link(sig_args_t *sig_args_p) 5310Sstevel@tonic-gate { 5320Sstevel@tonic-gate uchar_t *cl_ptr = sig_args_p->SUF_ptr; 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate sig_args_p->hdp->ext_lbn = RRIP_CHILD_LBN(cl_ptr); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate hs_filldirent(sig_args_p->fsp->hsfs_rootvp, sig_args_p->hdp); 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate sig_args_p->flags = 0; 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate return (cl_ptr + SUF_LEN(cl_ptr)); 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate /* 5450Sstevel@tonic-gate * rrip_parent_link() 5460Sstevel@tonic-gate * 5470Sstevel@tonic-gate * This is the parent link part of the directory hierarchy stuff and 5480Sstevel@tonic-gate * this does not really do much anyway. All it does is read the 5490Sstevel@tonic-gate * directory entry that the parent link SUF contains. All should be 5500Sstevel@tonic-gate * fine then. 5510Sstevel@tonic-gate */ 5520Sstevel@tonic-gate uchar_t * 5530Sstevel@tonic-gate rrip_parent_link(sig_args_t *sig_args_p) 5540Sstevel@tonic-gate { 5550Sstevel@tonic-gate uchar_t *pl_ptr = sig_args_p->SUF_ptr; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate sig_args_p->hdp->ext_lbn = RRIP_PARENT_LBN(pl_ptr); 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate hs_filldirent(sig_args_p->fsp->hsfs_rootvp, sig_args_p->hdp); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate sig_args_p->flags = 0; 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate return (pl_ptr + SUF_LEN(pl_ptr)); 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate /* 5680Sstevel@tonic-gate * rrip_rock_ridge() 5690Sstevel@tonic-gate * 5700Sstevel@tonic-gate * This function is supposed to aid in speed of the filesystem. 5710Sstevel@tonic-gate * 5720Sstevel@tonic-gate * XXX - It is only here as a place holder so far. 5730Sstevel@tonic-gate */ 5740Sstevel@tonic-gate uchar_t * 5750Sstevel@tonic-gate rrip_rock_ridge(sig_args_t *sig_args_p) 5760Sstevel@tonic-gate { 5770Sstevel@tonic-gate uchar_t *rr_ptr = sig_args_p->SUF_ptr; 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate return (rr_ptr + SUF_LEN(rr_ptr)); 5800Sstevel@tonic-gate } 581