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*5109Spetede * Common Development and Distribution License (the "License").
6*5109Spetede * 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
220Sstevel@tonic-gate /*
23*5109Spetede * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*5109Spetede * 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 * split and splice name
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <meta.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate int
splitname(char * name,md_splitname * spn)360Sstevel@tonic-gate splitname(char *name, md_splitname *spn)
370Sstevel@tonic-gate {
380Sstevel@tonic-gate size_t prefixlen;
390Sstevel@tonic-gate size_t suffixlen;
400Sstevel@tonic-gate char *lastslash;
41*5109Spetede int retval = METASPLIT_SUCCESS;
42*5109Spetede
430Sstevel@tonic-gate lastslash = strrchr(name, '/');
440Sstevel@tonic-gate if (lastslash != NULL) {
450Sstevel@tonic-gate prefixlen = lastslash - name;
460Sstevel@tonic-gate suffixlen = (strlen(name) - prefixlen) - 1; /* slash dropped */
470Sstevel@tonic-gate } else {
480Sstevel@tonic-gate prefixlen = 0;
490Sstevel@tonic-gate suffixlen = strlen(name);
500Sstevel@tonic-gate }
51*5109Spetede if (prefixlen > MD_MAXPREFIX)
52*5109Spetede return (METASPLIT_LONGPREFIX);
53*5109Spetede
54*5109Spetede if (suffixlen > MD_MAXSUFFIX) {
55*5109Spetede lastslash = META_LONGDISKNAME_STR;
56*5109Spetede prefixlen = 0;
57*5109Spetede suffixlen = strlen(lastslash);
58*5109Spetede (void) memcpy(SPN_SUFFIX(spn).suf_data, lastslash, suffixlen);
59*5109Spetede SPN_SUFFIX(spn).suf_len = suffixlen;
60*5109Spetede retval = METASPLIT_LONGDISKNAME;
61*5109Spetede } else {
62*5109Spetede (void) memcpy(SPN_SUFFIX(spn).suf_data, lastslash + 1,
63*5109Spetede suffixlen);
64*5109Spetede SPN_SUFFIX(spn).suf_len = suffixlen;
65*5109Spetede }
66*5109Spetede
670Sstevel@tonic-gate (void) memcpy(SPN_PREFIX(spn).pre_data, name, prefixlen);
680Sstevel@tonic-gate SPN_PREFIX(spn).pre_len = prefixlen;
69*5109Spetede
70*5109Spetede return (retval);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate char *
splicename(md_splitname * spn)740Sstevel@tonic-gate splicename(md_splitname *spn)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate char *name;
770Sstevel@tonic-gate char *suffix;
780Sstevel@tonic-gate size_t prefixlen;
790Sstevel@tonic-gate size_t suffixlen;
800Sstevel@tonic-gate
810Sstevel@tonic-gate prefixlen = SPN_PREFIX(spn).pre_len;
820Sstevel@tonic-gate suffixlen = SPN_SUFFIX(spn).suf_len;
830Sstevel@tonic-gate name = Malloc(prefixlen + suffixlen + 2);
840Sstevel@tonic-gate (void) memcpy(name, SPN_PREFIX(spn).pre_data, prefixlen);
850Sstevel@tonic-gate name[prefixlen] = '/';
860Sstevel@tonic-gate suffix = name + (prefixlen + 1);
870Sstevel@tonic-gate (void) memcpy(suffix, SPN_SUFFIX(spn).suf_data, suffixlen);
880Sstevel@tonic-gate name[prefixlen + suffixlen + 1] = 0;
890Sstevel@tonic-gate return (name);
900Sstevel@tonic-gate }
91