4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
35 * Portions of this source code were derived from Berkeley 4.3 BSD
36 * under license from the Regents of the University of California.
43 #include <sharefs/share.h>
47 * Get an entry from the share table.
48 * There should be at least 4 fields:
50 * pathname resource fstype options [ description ]
52 * A fifth field (description) is optional.
60 getshare(FILE *fd
, share_t
**shp
)
62 static char *line
= NULL
;
63 static share_t
*sh
= NULL
;
69 line
= (char *)malloc(MAXBUFSIZE
+1);
74 sh
= (share_t
*)malloc(sizeof (*sh
));
79 p
= fgets(line
, MAXBUFSIZE
, fd
);
82 line
[strlen(line
) - 1] = '\0';
84 sh
->sh_path
= (char *)strtok_r(p
, w
, &lasts
);
85 if (sh
->sh_path
== NULL
)
87 sh
->sh_res
= (char *)strtok_r(NULL
, w
, &lasts
);
88 if (sh
->sh_res
== NULL
)
90 sh
->sh_fstype
= (char *)strtok_r(NULL
, w
, &lasts
);
91 if (sh
->sh_fstype
== NULL
)
93 sh
->sh_opts
= (char *)strtok_r(NULL
, w
, &lasts
);
94 if (sh
->sh_opts
== NULL
)
96 sh
->sh_descr
= (char *)strtok_r(NULL
, "", &lasts
);
97 if (sh
->sh_descr
== NULL
)
105 sharedup(share_t
*sh
)
109 nsh
= (share_t
*)calloc(1, sizeof (*nsh
));
114 nsh
->sh_path
= strdup(sh
->sh_path
);
115 if (nsh
->sh_path
== NULL
)
120 nsh
->sh_res
= strdup(sh
->sh_res
);
121 if (nsh
->sh_res
== NULL
)
125 nsh
->sh_fstype
= strdup(sh
->sh_fstype
);
126 if (nsh
->sh_fstype
== NULL
)
130 nsh
->sh_opts
= strdup(sh
->sh_opts
);
131 if (nsh
->sh_opts
== NULL
)
135 nsh
->sh_descr
= strdup(sh
->sh_descr
);
136 if (nsh
->sh_descr
== NULL
)
147 sharefree(share_t
*sh
)
158 * Return the value after "=" for option "opt"
159 * in option string "optlist". Caller must
160 * free returned value.
163 getshareopt(char *optlist
, char *opt
)
171 b
= bb
= strdup(optlist
);
175 while ((p
= strtok_r(b
, ",", &lasts
)) != NULL
) {
177 if ((pe
= strchr(p
, '=')) != NULL
) {
179 if (strcmp(opt
, p
) == 0) {
180 val
= strdup(pe
+ 1);
184 if (strcmp(opt
, p
) == 0) {