1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <stdio.h>
28*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
29*7c478bd9Sstevel@tonic-gate #include <errno.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate #include <ctype.h>
32*7c478bd9Sstevel@tonic-gate #include <string.h>
33*7c478bd9Sstevel@tonic-gate #include <strings.h>
34*7c478bd9Sstevel@tonic-gate #include <thread.h>
35*7c478bd9Sstevel@tonic-gate #include <synch.h>
36*7c478bd9Sstevel@tonic-gate #include "libfsmgt.h"
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * Private datastructures.
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate typedef struct dfstab_entry {
42*7c478bd9Sstevel@tonic-gate 	struct dfstab_entry *next;
43*7c478bd9Sstevel@tonic-gate 	char    *path;
44*7c478bd9Sstevel@tonic-gate 	char    *resource;
45*7c478bd9Sstevel@tonic-gate 	char    *fstype;
46*7c478bd9Sstevel@tonic-gate 	char    *options;
47*7c478bd9Sstevel@tonic-gate 	char    *description;
48*7c478bd9Sstevel@tonic-gate } dfstab_entry_t;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static const char *whitespace = " \t";
51*7c478bd9Sstevel@tonic-gate static mutex_t dfstab_lock = DEFAULTMUTEX;
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * Private functions
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *get_dfstab_ents(int *);
57*7c478bd9Sstevel@tonic-gate static void free_dfstab_list(dfstab_entry_t *);
58*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *dfstab_line_to_dfstab_entry(char *, int *);
59*7c478bd9Sstevel@tonic-gate static char *create_share_cmd(dfstab_entry_t *, char *, int *);
60*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *change_dfstab_ent(dfstab_entry_t *,
61*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *, int *);
62*7c478bd9Sstevel@tonic-gate static void add_entry_to_dfstab(dfstab_entry_t *, int *);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *
get_dfstab_ents(int * err)66*7c478bd9Sstevel@tonic-gate get_dfstab_ents(int *err)
67*7c478bd9Sstevel@tonic-gate {
68*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *dfstablist, *headptr, *tailptr = NULL;
69*7c478bd9Sstevel@tonic-gate 	FILE *dfp;		/* fp for dfs list */
70*7c478bd9Sstevel@tonic-gate 	static char cmd[BUFSIZE];
71*7c478bd9Sstevel@tonic-gate 	*err = 0;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	if ((dfp = fopen(DFSTAB, "r")) != NULL) {
74*7c478bd9Sstevel@tonic-gate 		char *share_cmd;
75*7c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&dfstab_lock);
76*7c478bd9Sstevel@tonic-gate 		while ((share_cmd =
77*7c478bd9Sstevel@tonic-gate 		    fileutil_getline(dfp, cmd, BUFSIZE)) != NULL) {
78*7c478bd9Sstevel@tonic-gate 			if ((dfstablist =
79*7c478bd9Sstevel@tonic-gate 			    dfstab_line_to_dfstab_entry(share_cmd, err)) !=
80*7c478bd9Sstevel@tonic-gate 			    NULL) {
81*7c478bd9Sstevel@tonic-gate 				if (tailptr == NULL) {
82*7c478bd9Sstevel@tonic-gate 					headptr = dfstablist;
83*7c478bd9Sstevel@tonic-gate 					tailptr = dfstablist;
84*7c478bd9Sstevel@tonic-gate 				} else {
85*7c478bd9Sstevel@tonic-gate 					tailptr->next = dfstablist;
86*7c478bd9Sstevel@tonic-gate 					tailptr = dfstablist;
87*7c478bd9Sstevel@tonic-gate 				}
88*7c478bd9Sstevel@tonic-gate 				dfstablist = dfstablist->next;
89*7c478bd9Sstevel@tonic-gate 			} else {
90*7c478bd9Sstevel@tonic-gate 				free(share_cmd);
91*7c478bd9Sstevel@tonic-gate 				break;
92*7c478bd9Sstevel@tonic-gate 			}
93*7c478bd9Sstevel@tonic-gate 			free(share_cmd);
94*7c478bd9Sstevel@tonic-gate 		}
95*7c478bd9Sstevel@tonic-gate 		if (tailptr == NULL) {
96*7c478bd9Sstevel@tonic-gate 			headptr = tailptr;
97*7c478bd9Sstevel@tonic-gate 		}
98*7c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&dfstab_lock);
99*7c478bd9Sstevel@tonic-gate 		fclose(dfp);
100*7c478bd9Sstevel@tonic-gate 	} else {
101*7c478bd9Sstevel@tonic-gate 		*err = errno;
102*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: cannot open %s\n", cmd, DFSTAB);
103*7c478bd9Sstevel@tonic-gate 		headptr = NULL;
104*7c478bd9Sstevel@tonic-gate 	}
105*7c478bd9Sstevel@tonic-gate 	return (headptr);
106*7c478bd9Sstevel@tonic-gate } /* get_dfstab_ents */
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate static void
add_entry_to_dfstab(dfstab_entry_t * list,int * err)109*7c478bd9Sstevel@tonic-gate add_entry_to_dfstab(dfstab_entry_t *list, int *err)
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate 	FILE *dfp;		/* fp for dfs list */
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	if ((dfp = fopen(DFSTAB, "a")) != NULL) {
114*7c478bd9Sstevel@tonic-gate 		char *share_cmd;
115*7c478bd9Sstevel@tonic-gate 		if ((share_cmd = create_share_cmd(list, NULL, err)) != NULL) {
116*7c478bd9Sstevel@tonic-gate 			(void) mutex_lock(&dfstab_lock);
117*7c478bd9Sstevel@tonic-gate 			fprintf(dfp, "%s", share_cmd);
118*7c478bd9Sstevel@tonic-gate 			fclose(dfp);
119*7c478bd9Sstevel@tonic-gate 			(void) mutex_unlock(&dfstab_lock);
120*7c478bd9Sstevel@tonic-gate 			free(share_cmd);
121*7c478bd9Sstevel@tonic-gate 		} else {
122*7c478bd9Sstevel@tonic-gate 			*err = errno;
123*7c478bd9Sstevel@tonic-gate 		}
124*7c478bd9Sstevel@tonic-gate 	} else {
125*7c478bd9Sstevel@tonic-gate 		*err = errno;
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate } /* add_entry_to_dfstab */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate static void
free_dfstab_list(dfstab_entry_t * headp)131*7c478bd9Sstevel@tonic-gate free_dfstab_list(dfstab_entry_t *headp)
132*7c478bd9Sstevel@tonic-gate {
133*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *tmp = headp;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	while (headp != NULL) {
136*7c478bd9Sstevel@tonic-gate 		tmp = headp->next;
137*7c478bd9Sstevel@tonic-gate 		if (headp->path != NULL) {
138*7c478bd9Sstevel@tonic-gate 			free(headp->path);
139*7c478bd9Sstevel@tonic-gate 		}
140*7c478bd9Sstevel@tonic-gate 		if (headp->resource != NULL) {
141*7c478bd9Sstevel@tonic-gate 			free(headp->resource);
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 		if (headp->fstype != NULL) {
144*7c478bd9Sstevel@tonic-gate 			free(headp->fstype);
145*7c478bd9Sstevel@tonic-gate 		}
146*7c478bd9Sstevel@tonic-gate 		if (headp->options != NULL) {
147*7c478bd9Sstevel@tonic-gate 			free(headp->options);
148*7c478bd9Sstevel@tonic-gate 		}
149*7c478bd9Sstevel@tonic-gate 		if (headp->description != NULL) {
150*7c478bd9Sstevel@tonic-gate 			free(headp->description);
151*7c478bd9Sstevel@tonic-gate 		}
152*7c478bd9Sstevel@tonic-gate 		headp->next = NULL;
153*7c478bd9Sstevel@tonic-gate 		free(headp);
154*7c478bd9Sstevel@tonic-gate 		headp = tmp;
155*7c478bd9Sstevel@tonic-gate 	}
156*7c478bd9Sstevel@tonic-gate } /* free_dfstab_list */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate static char *
create_share_cmd(dfstab_entry_t * new_entry,char * temp_line,int * err)159*7c478bd9Sstevel@tonic-gate create_share_cmd(dfstab_entry_t *new_entry, char *temp_line, int *err)
160*7c478bd9Sstevel@tonic-gate {
161*7c478bd9Sstevel@tonic-gate 	char tempstr[BUFSIZE];
162*7c478bd9Sstevel@tonic-gate 	char *cmd, *ret_val;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	cmd = (char *)calloc((size_t)1, BUFSIZE);
165*7c478bd9Sstevel@tonic-gate 	if (cmd == NULL) {
166*7c478bd9Sstevel@tonic-gate 		*err = errno;
167*7c478bd9Sstevel@tonic-gate 		return (NULL);
168*7c478bd9Sstevel@tonic-gate 	}
169*7c478bd9Sstevel@tonic-gate 	sprintf(cmd, "share ");
170*7c478bd9Sstevel@tonic-gate 	if (new_entry->fstype) {
171*7c478bd9Sstevel@tonic-gate 		sprintf(tempstr, "-F %s ", new_entry->fstype);
172*7c478bd9Sstevel@tonic-gate 		strlcat(cmd, tempstr, BUFSIZE);
173*7c478bd9Sstevel@tonic-gate 	}
174*7c478bd9Sstevel@tonic-gate 	if (new_entry->options) {
175*7c478bd9Sstevel@tonic-gate 		sprintf(tempstr, "-o %s ", new_entry->options);
176*7c478bd9Sstevel@tonic-gate 		strlcat(cmd, tempstr, BUFSIZE);
177*7c478bd9Sstevel@tonic-gate 	}
178*7c478bd9Sstevel@tonic-gate 	if (new_entry->description) {
179*7c478bd9Sstevel@tonic-gate 		sprintf(tempstr, "-d %s ",
180*7c478bd9Sstevel@tonic-gate 		    new_entry->description);
181*7c478bd9Sstevel@tonic-gate 		strlcat(cmd, tempstr, BUFSIZE);
182*7c478bd9Sstevel@tonic-gate 	}
183*7c478bd9Sstevel@tonic-gate 	sprintf(tempstr, "%s\n", new_entry->path);
184*7c478bd9Sstevel@tonic-gate 	strlcat(cmd, tempstr, BUFSIZE);
185*7c478bd9Sstevel@tonic-gate 	if (temp_line != NULL && strchr(temp_line, '#')) {
186*7c478bd9Sstevel@tonic-gate 		sprintf(tempstr, " %s", strchr(temp_line, '#'));
187*7c478bd9Sstevel@tonic-gate 		strlcat(cmd, tempstr, BUFSIZE);
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate 	ret_val = strdup(cmd);
190*7c478bd9Sstevel@tonic-gate 	free(cmd);
191*7c478bd9Sstevel@tonic-gate 	return (ret_val);
192*7c478bd9Sstevel@tonic-gate } /* create_share_cmd */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate  * dfstab_line_to_dfstab_entry - parses a line from dfstab and fills in
196*7c478bd9Sstevel@tonic-gate  * the fields of a dfstab_entry_t structure
197*7c478bd9Sstevel@tonic-gate  * Parameters:
198*7c478bd9Sstevel@tonic-gate  * char *cmd - the share command or dfstab line to be parsed
199*7c478bd9Sstevel@tonic-gate  * int *err - a pointer for returning any error codes encountered
200*7c478bd9Sstevel@tonic-gate  */
201*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *
dfstab_line_to_dfstab_entry(char * cmd,int * err)202*7c478bd9Sstevel@tonic-gate dfstab_line_to_dfstab_entry(char *cmd, int *err)
203*7c478bd9Sstevel@tonic-gate {
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *dfstablist;
206*7c478bd9Sstevel@tonic-gate 	extern char *optarg;
207*7c478bd9Sstevel@tonic-gate 	extern int optind;
208*7c478bd9Sstevel@tonic-gate 	int c, argcount = 0;
209*7c478bd9Sstevel@tonic-gate 	char *temp_str;
210*7c478bd9Sstevel@tonic-gate 	char *arglist[LINESZ];
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	c = 0;
213*7c478bd9Sstevel@tonic-gate 	optind = 1;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	temp_str = strdup(cmd);
216*7c478bd9Sstevel@tonic-gate 	if (temp_str == NULL) {
217*7c478bd9Sstevel@tonic-gate 		*err = ENOMEM;
218*7c478bd9Sstevel@tonic-gate 		return (NULL);
219*7c478bd9Sstevel@tonic-gate 	}
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	for (arglist[argcount] = strtok(temp_str, whitespace);
222*7c478bd9Sstevel@tonic-gate 	    arglist[argcount] != NULL; /* CSTYLED */) {
223*7c478bd9Sstevel@tonic-gate 		arglist[++argcount] = strtok(NULL, whitespace);
224*7c478bd9Sstevel@tonic-gate 	}
225*7c478bd9Sstevel@tonic-gate 	argcount--;
226*7c478bd9Sstevel@tonic-gate 	dfstablist =
227*7c478bd9Sstevel@tonic-gate 	    (dfstab_entry_t *)calloc((size_t)1,
228*7c478bd9Sstevel@tonic-gate 	    sizeof (dfstab_entry_t));
229*7c478bd9Sstevel@tonic-gate 	if (dfstablist == NULL) {
230*7c478bd9Sstevel@tonic-gate 		*err = ENOMEM;
231*7c478bd9Sstevel@tonic-gate 		free(temp_str);
232*7c478bd9Sstevel@tonic-gate 		return (NULL);
233*7c478bd9Sstevel@tonic-gate 	}
234*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argcount, arglist, "F:d:o:")) != -1) {
235*7c478bd9Sstevel@tonic-gate 		switch (c) {
236*7c478bd9Sstevel@tonic-gate 		case 'F':
237*7c478bd9Sstevel@tonic-gate 					/* file system type */
238*7c478bd9Sstevel@tonic-gate 					/* at most one -F */
239*7c478bd9Sstevel@tonic-gate 			*err |= (dfstablist->fstype != NULL);
240*7c478bd9Sstevel@tonic-gate 			dfstablist->fstype = strdup(optarg);
241*7c478bd9Sstevel@tonic-gate 			if (dfstablist->fstype == NULL) {
242*7c478bd9Sstevel@tonic-gate 				*err = ENOMEM;
243*7c478bd9Sstevel@tonic-gate 				free_dfstab_list(dfstablist);
244*7c478bd9Sstevel@tonic-gate 				free(temp_str);
245*7c478bd9Sstevel@tonic-gate 				return (NULL);
246*7c478bd9Sstevel@tonic-gate 			}
247*7c478bd9Sstevel@tonic-gate 			break;
248*7c478bd9Sstevel@tonic-gate 		case 'd':		/* description */
249*7c478bd9Sstevel@tonic-gate 					/* at most one -d */
250*7c478bd9Sstevel@tonic-gate 			*err |= (dfstablist->description != NULL);
251*7c478bd9Sstevel@tonic-gate 			dfstablist->description = strdup(optarg);
252*7c478bd9Sstevel@tonic-gate 			if (dfstablist->description == NULL) {
253*7c478bd9Sstevel@tonic-gate 				*err = ENOMEM;
254*7c478bd9Sstevel@tonic-gate 				free_dfstab_list(dfstablist);
255*7c478bd9Sstevel@tonic-gate 				free(temp_str);
256*7c478bd9Sstevel@tonic-gate 				return (NULL);
257*7c478bd9Sstevel@tonic-gate 			}
258*7c478bd9Sstevel@tonic-gate 			break;
259*7c478bd9Sstevel@tonic-gate 		case 'o':		/* fs specific options */
260*7c478bd9Sstevel@tonic-gate 					/* at most one - o */
261*7c478bd9Sstevel@tonic-gate 			*err |= (dfstablist->options != NULL);
262*7c478bd9Sstevel@tonic-gate 			dfstablist->options = strdup(optarg);
263*7c478bd9Sstevel@tonic-gate 			if (dfstablist->options == NULL) {
264*7c478bd9Sstevel@tonic-gate 				*err = ENOMEM;
265*7c478bd9Sstevel@tonic-gate 				free_dfstab_list(dfstablist);
266*7c478bd9Sstevel@tonic-gate 				free(temp_str);
267*7c478bd9Sstevel@tonic-gate 				return (NULL);
268*7c478bd9Sstevel@tonic-gate 			}
269*7c478bd9Sstevel@tonic-gate 			break;
270*7c478bd9Sstevel@tonic-gate 		case '?':
271*7c478bd9Sstevel@tonic-gate 			*err = 1;
272*7c478bd9Sstevel@tonic-gate 			break;
273*7c478bd9Sstevel@tonic-gate 		}
274*7c478bd9Sstevel@tonic-gate 	}
275*7c478bd9Sstevel@tonic-gate 	if (dfstablist->fstype == NULL) {
276*7c478bd9Sstevel@tonic-gate 		FILE *fp;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 		if ((fp = fopen(DFSTYPES, "r")) == NULL) {
279*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: cannot open %s\n",
280*7c478bd9Sstevel@tonic-gate 			    cmd, DFSTYPES);
281*7c478bd9Sstevel@tonic-gate 			free_dfstab_list(dfstablist);
282*7c478bd9Sstevel@tonic-gate 			free(temp_str);
283*7c478bd9Sstevel@tonic-gate 			return (NULL);
284*7c478bd9Sstevel@tonic-gate 		}
285*7c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&dfstab_lock);
286*7c478bd9Sstevel@tonic-gate 		dfstablist->fstype = strdup(fileutil_getfs(fp));
287*7c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&dfstab_lock);
288*7c478bd9Sstevel@tonic-gate 		fclose(fp);
289*7c478bd9Sstevel@tonic-gate 	}
290*7c478bd9Sstevel@tonic-gate 	dfstablist->path = strdup(arglist[argcount]);
291*7c478bd9Sstevel@tonic-gate 	if (dfstablist->path == NULL) {
292*7c478bd9Sstevel@tonic-gate 		*err = ENOMEM;
293*7c478bd9Sstevel@tonic-gate 		free_dfstab_list(dfstablist);
294*7c478bd9Sstevel@tonic-gate 		free(temp_str);
295*7c478bd9Sstevel@tonic-gate 		return (NULL);
296*7c478bd9Sstevel@tonic-gate 	}
297*7c478bd9Sstevel@tonic-gate 	free(temp_str);
298*7c478bd9Sstevel@tonic-gate 	return (dfstablist);
299*7c478bd9Sstevel@tonic-gate } /* dfstab_line_to_dfstab_entry */
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate static dfstab_entry_t *
change_dfstab_ent(dfstab_entry_t * old_entry,dfstab_entry_t * new_entry,int * err)302*7c478bd9Sstevel@tonic-gate change_dfstab_ent(
303*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *old_entry,
304*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *new_entry,
305*7c478bd9Sstevel@tonic-gate 	int *err)
306*7c478bd9Sstevel@tonic-gate {
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 	FILE *fp;
309*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *temp_list, *ret_val;
310*7c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZE];
311*7c478bd9Sstevel@tonic-gate 	char **temp_dfstab = NULL;
312*7c478bd9Sstevel@tonic-gate 	int line_found = 0;
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	if ((fp = fopen(DFSTAB, "r")) != NULL) {
315*7c478bd9Sstevel@tonic-gate 		char *share_cmd;
316*7c478bd9Sstevel@tonic-gate 		int count = 0;
317*7c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&dfstab_lock);
318*7c478bd9Sstevel@tonic-gate 		while (fgets(cmd, BUFSIZE, fp) != NULL) {
319*7c478bd9Sstevel@tonic-gate 			if ((share_cmd =
320*7c478bd9Sstevel@tonic-gate 			    fileutil_get_cmd_from_string(cmd)) == NULL) {
321*7c478bd9Sstevel@tonic-gate 				if (!fileutil_add_string_to_array(
322*7c478bd9Sstevel@tonic-gate 				    &temp_dfstab, cmd, &count, err)) {
323*7c478bd9Sstevel@tonic-gate 					ret_val = NULL;
324*7c478bd9Sstevel@tonic-gate 					line_found = 0;
325*7c478bd9Sstevel@tonic-gate 					break;
326*7c478bd9Sstevel@tonic-gate 				}
327*7c478bd9Sstevel@tonic-gate 				continue;
328*7c478bd9Sstevel@tonic-gate 			}
329*7c478bd9Sstevel@tonic-gate 			if ((temp_list =
330*7c478bd9Sstevel@tonic-gate 			    dfstab_line_to_dfstab_entry(share_cmd, err)) ==
331*7c478bd9Sstevel@tonic-gate 			    NULL) {
332*7c478bd9Sstevel@tonic-gate 				free(share_cmd);
333*7c478bd9Sstevel@tonic-gate 				ret_val = NULL;
334*7c478bd9Sstevel@tonic-gate 				break;
335*7c478bd9Sstevel@tonic-gate 			}
336*7c478bd9Sstevel@tonic-gate 			if (strcmp(old_entry->path,
337*7c478bd9Sstevel@tonic-gate 			    temp_list->path) == 0) {
338*7c478bd9Sstevel@tonic-gate 				char *new_cmd = NULL;
339*7c478bd9Sstevel@tonic-gate 				line_found = 1;
340*7c478bd9Sstevel@tonic-gate 				if (new_entry != NULL && (new_cmd =
341*7c478bd9Sstevel@tonic-gate 				    create_share_cmd(new_entry, cmd,
342*7c478bd9Sstevel@tonic-gate 				    err)) != NULL) {
343*7c478bd9Sstevel@tonic-gate 					if (!fileutil_add_string_to_array(
344*7c478bd9Sstevel@tonic-gate 					    &temp_dfstab, new_cmd, &count,
345*7c478bd9Sstevel@tonic-gate 					    err)) {
346*7c478bd9Sstevel@tonic-gate 						ret_val = NULL;
347*7c478bd9Sstevel@tonic-gate 						line_found = 0;
348*7c478bd9Sstevel@tonic-gate 						free(share_cmd);
349*7c478bd9Sstevel@tonic-gate 						free(new_cmd);
350*7c478bd9Sstevel@tonic-gate 						break;
351*7c478bd9Sstevel@tonic-gate 					}
352*7c478bd9Sstevel@tonic-gate 					free(new_cmd);
353*7c478bd9Sstevel@tonic-gate 				}
354*7c478bd9Sstevel@tonic-gate 			} else {
355*7c478bd9Sstevel@tonic-gate 				if (!fileutil_add_string_to_array(
356*7c478bd9Sstevel@tonic-gate 				    &temp_dfstab, cmd, &count, err)) {
357*7c478bd9Sstevel@tonic-gate 					free(share_cmd);
358*7c478bd9Sstevel@tonic-gate 					ret_val = NULL;
359*7c478bd9Sstevel@tonic-gate 					line_found = 0;
360*7c478bd9Sstevel@tonic-gate 					break;
361*7c478bd9Sstevel@tonic-gate 				}
362*7c478bd9Sstevel@tonic-gate 			}
363*7c478bd9Sstevel@tonic-gate 			free_dfstab_list(temp_list);
364*7c478bd9Sstevel@tonic-gate 			free(share_cmd);
365*7c478bd9Sstevel@tonic-gate 		}
366*7c478bd9Sstevel@tonic-gate 		fclose(fp);
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 		if (line_found && temp_dfstab != NULL) {
369*7c478bd9Sstevel@tonic-gate 			if ((fp = fopen(DFSTAB, "w")) != NULL) {
370*7c478bd9Sstevel@tonic-gate 				int i;
371*7c478bd9Sstevel@tonic-gate 				for (i = 0; i < count; i++) {
372*7c478bd9Sstevel@tonic-gate 					fprintf(fp, "%s", temp_dfstab[i]);
373*7c478bd9Sstevel@tonic-gate 				}
374*7c478bd9Sstevel@tonic-gate 				fclose(fp);
375*7c478bd9Sstevel@tonic-gate 				(void) mutex_unlock(&dfstab_lock);
376*7c478bd9Sstevel@tonic-gate 				ret_val = get_dfstab_ents(err);
377*7c478bd9Sstevel@tonic-gate 				fileutil_free_string_array(temp_dfstab, count);
378*7c478bd9Sstevel@tonic-gate 			} else {
379*7c478bd9Sstevel@tonic-gate 				*err = errno;
380*7c478bd9Sstevel@tonic-gate 				(void) mutex_unlock(&dfstab_lock);
381*7c478bd9Sstevel@tonic-gate 				fileutil_free_string_array(temp_dfstab, count);
382*7c478bd9Sstevel@tonic-gate 				ret_val = NULL;
383*7c478bd9Sstevel@tonic-gate 			}
384*7c478bd9Sstevel@tonic-gate 		} else {
385*7c478bd9Sstevel@tonic-gate 			(void) mutex_unlock(&dfstab_lock);
386*7c478bd9Sstevel@tonic-gate 			if (temp_dfstab != NULL) {
387*7c478bd9Sstevel@tonic-gate 				fileutil_free_string_array(temp_dfstab, count);
388*7c478bd9Sstevel@tonic-gate 			}
389*7c478bd9Sstevel@tonic-gate 			ret_val = NULL;
390*7c478bd9Sstevel@tonic-gate 		}
391*7c478bd9Sstevel@tonic-gate 	} else {
392*7c478bd9Sstevel@tonic-gate 		*err = errno;
393*7c478bd9Sstevel@tonic-gate 		ret_val = NULL;
394*7c478bd9Sstevel@tonic-gate 	}
395*7c478bd9Sstevel@tonic-gate 	return (ret_val);
396*7c478bd9Sstevel@tonic-gate } /* change_dfstab_ent */
397*7c478bd9Sstevel@tonic-gate 
398*7c478bd9Sstevel@tonic-gate /*
399*7c478bd9Sstevel@tonic-gate  * Public accessor functions.
400*7c478bd9Sstevel@tonic-gate  */
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate /*
403*7c478bd9Sstevel@tonic-gate  * fs_add_DFStab_ent - adds an entry to dfstab and to the list of dfstab
404*7c478bd9Sstevel@tonic-gate  * entries. Returns a pointer to the head of the dfstab entry list.
405*7c478bd9Sstevel@tonic-gate  * Parameters:
406*7c478bd9Sstevel@tonic-gate  * char *cmd - the same command to be added to dstab
407*7c478bd9Sstevel@tonic-gate  * int *err - an error pointer for retruning any errors
408*7c478bd9Sstevel@tonic-gate  */
409*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_add_DFStab_ent(char * cmd,int * err)410*7c478bd9Sstevel@tonic-gate fs_add_DFStab_ent(char *cmd, int *err)
411*7c478bd9Sstevel@tonic-gate {
412*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *dfstab_ent;
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate 	dfstab_ent = dfstab_line_to_dfstab_entry(cmd, err);
415*7c478bd9Sstevel@tonic-gate 	if (dfstab_ent == NULL) {
416*7c478bd9Sstevel@tonic-gate 		*err = errno;
417*7c478bd9Sstevel@tonic-gate 		return (NULL);
418*7c478bd9Sstevel@tonic-gate 	}
419*7c478bd9Sstevel@tonic-gate 	add_entry_to_dfstab(dfstab_ent, err);
420*7c478bd9Sstevel@tonic-gate 	if (*err != 0) {
421*7c478bd9Sstevel@tonic-gate 		free_dfstab_list(dfstab_ent);
422*7c478bd9Sstevel@tonic-gate 		return (NULL);
423*7c478bd9Sstevel@tonic-gate 	}
424*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(dfstab_ent);
425*7c478bd9Sstevel@tonic-gate 	return (get_dfstab_ents(err));
426*7c478bd9Sstevel@tonic-gate }
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate /*
429*7c478bd9Sstevel@tonic-gate  * set_DFStab_ent - adds an entry to dfstab and to the list of dfstab entries.
430*7c478bd9Sstevel@tonic-gate  * returns a pointer to the head of the dfstab entry list.
431*7c478bd9Sstevel@tonic-gate  */
432*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_set_DFStab_ent(char * path,char * fstype,char * options,char * description,int * err)433*7c478bd9Sstevel@tonic-gate fs_set_DFStab_ent(
434*7c478bd9Sstevel@tonic-gate 	char *path,
435*7c478bd9Sstevel@tonic-gate 	char *fstype,
436*7c478bd9Sstevel@tonic-gate 	char *options,
437*7c478bd9Sstevel@tonic-gate 	char *description,
438*7c478bd9Sstevel@tonic-gate 	int *err)
439*7c478bd9Sstevel@tonic-gate {
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *new_entry;
442*7c478bd9Sstevel@tonic-gate 	new_entry = (dfstab_entry_t *)calloc((size_t)1,
443*7c478bd9Sstevel@tonic-gate 	    sizeof (dfstab_entry_t));
444*7c478bd9Sstevel@tonic-gate 	if (new_entry == NULL) {
445*7c478bd9Sstevel@tonic-gate 		*err = ENOMEM;
446*7c478bd9Sstevel@tonic-gate 		return (NULL);
447*7c478bd9Sstevel@tonic-gate 	}
448*7c478bd9Sstevel@tonic-gate 	if (path != NULL) {
449*7c478bd9Sstevel@tonic-gate 		new_entry->path = strdup(path);
450*7c478bd9Sstevel@tonic-gate 	} else {
451*7c478bd9Sstevel@tonic-gate 		*err = EINVAL;
452*7c478bd9Sstevel@tonic-gate 		free_dfstab_list(new_entry);
453*7c478bd9Sstevel@tonic-gate 		return (NULL);
454*7c478bd9Sstevel@tonic-gate 	}
455*7c478bd9Sstevel@tonic-gate 	if (fstype != NULL) {
456*7c478bd9Sstevel@tonic-gate 		new_entry->fstype = strdup(fstype);
457*7c478bd9Sstevel@tonic-gate 	} else {
458*7c478bd9Sstevel@tonic-gate 		FILE *fp;
459*7c478bd9Sstevel@tonic-gate 
460*7c478bd9Sstevel@tonic-gate 		if ((fp = fopen(DFSTYPES, "r")) == NULL) {
461*7c478bd9Sstevel@tonic-gate 			/* change this to error handler */
462*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "cannot open %s\n",
463*7c478bd9Sstevel@tonic-gate 			    DFSTYPES);
464*7c478bd9Sstevel@tonic-gate 			free_dfstab_list(new_entry);
465*7c478bd9Sstevel@tonic-gate 			return (NULL);
466*7c478bd9Sstevel@tonic-gate 		}
467*7c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&dfstab_lock);
468*7c478bd9Sstevel@tonic-gate 		new_entry->fstype = strdup(fileutil_getfs(fp));
469*7c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&dfstab_lock);
470*7c478bd9Sstevel@tonic-gate 		fclose(fp);
471*7c478bd9Sstevel@tonic-gate 	}
472*7c478bd9Sstevel@tonic-gate 	if (options != NULL) {
473*7c478bd9Sstevel@tonic-gate 		new_entry->options = strdup(options);
474*7c478bd9Sstevel@tonic-gate 	}
475*7c478bd9Sstevel@tonic-gate 	if (description != NULL) {
476*7c478bd9Sstevel@tonic-gate 		new_entry->description = strdup(description);
477*7c478bd9Sstevel@tonic-gate 	}
478*7c478bd9Sstevel@tonic-gate 	add_entry_to_dfstab(new_entry, err);
479*7c478bd9Sstevel@tonic-gate 	if (*err != 0) {
480*7c478bd9Sstevel@tonic-gate 		free_dfstab_list(new_entry);
481*7c478bd9Sstevel@tonic-gate 		return (NULL);
482*7c478bd9Sstevel@tonic-gate 	}
483*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(new_entry);
484*7c478bd9Sstevel@tonic-gate 	return (get_dfstab_ents(err));
485*7c478bd9Sstevel@tonic-gate } /* set_DFStab_ent */
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate /*
488*7c478bd9Sstevel@tonic-gate  * Accessor function for path element of dfstab entry.
489*7c478bd9Sstevel@tonic-gate  */
490*7c478bd9Sstevel@tonic-gate char *
fs_get_DFStab_ent_Path(void * entry)491*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Path(void *entry)
492*7c478bd9Sstevel@tonic-gate {
493*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *entryptr = (dfstab_entry_t *)entry;
494*7c478bd9Sstevel@tonic-gate 	if (entryptr == NULL) {
495*7c478bd9Sstevel@tonic-gate 		return (NULL);
496*7c478bd9Sstevel@tonic-gate 	}
497*7c478bd9Sstevel@tonic-gate 	return (entryptr->path);
498*7c478bd9Sstevel@tonic-gate } /* get_DFStab_ent_Path */
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate /*
501*7c478bd9Sstevel@tonic-gate  * Accessor function for fstype element of dfstab entry.
502*7c478bd9Sstevel@tonic-gate  */
503*7c478bd9Sstevel@tonic-gate char *
fs_get_DFStab_ent_Fstype(void * entry)504*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Fstype(void *entry)
505*7c478bd9Sstevel@tonic-gate {
506*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *entryptr = (dfstab_entry_t *)entry;
507*7c478bd9Sstevel@tonic-gate 	if (entryptr == NULL) {
508*7c478bd9Sstevel@tonic-gate 		return (NULL);
509*7c478bd9Sstevel@tonic-gate 	}
510*7c478bd9Sstevel@tonic-gate 	return (entryptr->fstype);
511*7c478bd9Sstevel@tonic-gate }
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate /*
514*7c478bd9Sstevel@tonic-gate  * Accessor function for options element of dfstab entry.
515*7c478bd9Sstevel@tonic-gate  */
516*7c478bd9Sstevel@tonic-gate char *
fs_get_DFStab_ent_Options(void * entry)517*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Options(void *entry)
518*7c478bd9Sstevel@tonic-gate {
519*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *entryptr = (dfstab_entry_t *)entry;
520*7c478bd9Sstevel@tonic-gate 	if (entryptr == NULL) {
521*7c478bd9Sstevel@tonic-gate 		return (NULL);
522*7c478bd9Sstevel@tonic-gate 	}
523*7c478bd9Sstevel@tonic-gate 	return (entryptr->options);
524*7c478bd9Sstevel@tonic-gate }
525*7c478bd9Sstevel@tonic-gate 
526*7c478bd9Sstevel@tonic-gate /*
527*7c478bd9Sstevel@tonic-gate  * Accessor function for description element of dfstab entry.
528*7c478bd9Sstevel@tonic-gate  */
529*7c478bd9Sstevel@tonic-gate char *
fs_get_DFStab_ent_Desc(void * entry)530*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Desc(void *entry)
531*7c478bd9Sstevel@tonic-gate {
532*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *entryptr = (dfstab_entry_t *)entry;
533*7c478bd9Sstevel@tonic-gate 	if (entryptr == NULL) {
534*7c478bd9Sstevel@tonic-gate 		return (NULL);
535*7c478bd9Sstevel@tonic-gate 	}
536*7c478bd9Sstevel@tonic-gate 	return (entryptr->description);
537*7c478bd9Sstevel@tonic-gate }
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate /*
540*7c478bd9Sstevel@tonic-gate  * Accessor function for resource element of dfstab entry.
541*7c478bd9Sstevel@tonic-gate  */
542*7c478bd9Sstevel@tonic-gate char *
fs_get_DFStab_ent_Res(void * entry)543*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Res(void *entry)
544*7c478bd9Sstevel@tonic-gate {
545*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *entryptr = (dfstab_entry_t *)entry;
546*7c478bd9Sstevel@tonic-gate 	if (entryptr == NULL) {
547*7c478bd9Sstevel@tonic-gate 		return (NULL);
548*7c478bd9Sstevel@tonic-gate 	}
549*7c478bd9Sstevel@tonic-gate 	return (entryptr->resource);
550*7c478bd9Sstevel@tonic-gate }
551*7c478bd9Sstevel@tonic-gate 
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate /*
554*7c478bd9Sstevel@tonic-gate  * Calls get_dfstab_ents to create the list of dfstab
555*7c478bd9Sstevel@tonic-gate  * entries and returns that list.
556*7c478bd9Sstevel@tonic-gate  */
557*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_get_DFStab_ents(int * err)558*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ents(int *err)
559*7c478bd9Sstevel@tonic-gate {
560*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *list;
561*7c478bd9Sstevel@tonic-gate 	list = get_dfstab_ents(err);
562*7c478bd9Sstevel@tonic-gate 	return (list);
563*7c478bd9Sstevel@tonic-gate }
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate /*
566*7c478bd9Sstevel@tonic-gate  * Retrives and returns the next entry in the list.
567*7c478bd9Sstevel@tonic-gate  */
568*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_get_DFStab_ent_Next(void * list)569*7c478bd9Sstevel@tonic-gate fs_get_DFStab_ent_Next(void *list)
570*7c478bd9Sstevel@tonic-gate {
571*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *listptr = (dfstab_entry_t *)list;
572*7c478bd9Sstevel@tonic-gate 	if (listptr == NULL) {
573*7c478bd9Sstevel@tonic-gate 		return (NULL);
574*7c478bd9Sstevel@tonic-gate 	}
575*7c478bd9Sstevel@tonic-gate 	return (listptr->next);
576*7c478bd9Sstevel@tonic-gate }
577*7c478bd9Sstevel@tonic-gate 
578*7c478bd9Sstevel@tonic-gate /*
579*7c478bd9Sstevel@tonic-gate  * Retrives and returns a share command based on the dfstab entry passed in.
580*7c478bd9Sstevel@tonic-gate  */
581*7c478bd9Sstevel@tonic-gate char *
fs_get_Dfstab_share_cmd(fs_dfstab_entry_t dfstab_ent,int * err)582*7c478bd9Sstevel@tonic-gate fs_get_Dfstab_share_cmd(fs_dfstab_entry_t dfstab_ent, int *err)
583*7c478bd9Sstevel@tonic-gate {
584*7c478bd9Sstevel@tonic-gate 	char *share_cmd;
585*7c478bd9Sstevel@tonic-gate 	if (dfstab_ent == NULL) {
586*7c478bd9Sstevel@tonic-gate 		return (NULL);
587*7c478bd9Sstevel@tonic-gate 	}
588*7c478bd9Sstevel@tonic-gate 	share_cmd = create_share_cmd((dfstab_entry_t *)dfstab_ent, NULL, err);
589*7c478bd9Sstevel@tonic-gate 	return (share_cmd);
590*7c478bd9Sstevel@tonic-gate } /* fs_get_Dfstab_share_cmd */
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate /*
593*7c478bd9Sstevel@tonic-gate  * edit_DFStab_ent - changes an entry in dfstab.
594*7c478bd9Sstevel@tonic-gate  */
595*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_edit_DFStab_ent(char * old_cmd,char * new_cmd,int * err)596*7c478bd9Sstevel@tonic-gate fs_edit_DFStab_ent(char *old_cmd, char *new_cmd, int *err)
597*7c478bd9Sstevel@tonic-gate {
598*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *old_dfstabent, *new_dfstabent, *ret_val;
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate 	if ((old_dfstabent =
601*7c478bd9Sstevel@tonic-gate 	    dfstab_line_to_dfstab_entry(old_cmd, err)) == NULL) {
602*7c478bd9Sstevel@tonic-gate 		return (NULL);
603*7c478bd9Sstevel@tonic-gate 	}
604*7c478bd9Sstevel@tonic-gate 	if ((new_dfstabent =
605*7c478bd9Sstevel@tonic-gate 	    dfstab_line_to_dfstab_entry(new_cmd, err)) == NULL) {
606*7c478bd9Sstevel@tonic-gate 		return (NULL);
607*7c478bd9Sstevel@tonic-gate 	}
608*7c478bd9Sstevel@tonic-gate 	if ((ret_val =
609*7c478bd9Sstevel@tonic-gate 	    change_dfstab_ent(old_dfstabent, new_dfstabent, err)) == NULL) {
610*7c478bd9Sstevel@tonic-gate 		return (NULL);
611*7c478bd9Sstevel@tonic-gate 	}
612*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(old_dfstabent);
613*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(new_dfstabent);
614*7c478bd9Sstevel@tonic-gate 	return (ret_val);
615*7c478bd9Sstevel@tonic-gate }
616*7c478bd9Sstevel@tonic-gate 
617*7c478bd9Sstevel@tonic-gate /*
618*7c478bd9Sstevel@tonic-gate  * del_DFStab_ent - deletes an entry in dfstab.
619*7c478bd9Sstevel@tonic-gate  */
620*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_del_DFStab_ent(char * del_cmd,int * err)621*7c478bd9Sstevel@tonic-gate fs_del_DFStab_ent(char *del_cmd, int *err)
622*7c478bd9Sstevel@tonic-gate {
623*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *del_dfstabent, *ret_val;
624*7c478bd9Sstevel@tonic-gate 
625*7c478bd9Sstevel@tonic-gate 	if ((del_dfstabent =
626*7c478bd9Sstevel@tonic-gate 	    dfstab_line_to_dfstab_entry(del_cmd, err)) == NULL) {
627*7c478bd9Sstevel@tonic-gate 		return (NULL);
628*7c478bd9Sstevel@tonic-gate 	}
629*7c478bd9Sstevel@tonic-gate 	if ((ret_val =
630*7c478bd9Sstevel@tonic-gate 	    change_dfstab_ent(del_dfstabent, NULL, err)) == NULL) {
631*7c478bd9Sstevel@tonic-gate 		return (NULL);
632*7c478bd9Sstevel@tonic-gate 	}
633*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(del_dfstabent);
634*7c478bd9Sstevel@tonic-gate 	return (ret_val);
635*7c478bd9Sstevel@tonic-gate }
636*7c478bd9Sstevel@tonic-gate 
637*7c478bd9Sstevel@tonic-gate /*
638*7c478bd9Sstevel@tonic-gate  * del_All_DFStab_ents_with_Path - deletes all duplicate entries with
639*7c478bd9Sstevel@tonic-gate  * the specified path.
640*7c478bd9Sstevel@tonic-gate  */
641*7c478bd9Sstevel@tonic-gate fs_dfstab_entry_t
fs_del_All_DFStab_ents_with_Path(char * path,int * err)642*7c478bd9Sstevel@tonic-gate fs_del_All_DFStab_ents_with_Path(char *path, int *err)
643*7c478bd9Sstevel@tonic-gate {
644*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t del_dfstabent, *ret_val;
645*7c478bd9Sstevel@tonic-gate 
646*7c478bd9Sstevel@tonic-gate 	if (path != NULL) {
647*7c478bd9Sstevel@tonic-gate 		if ((del_dfstabent.path = strdup(path)) != NULL) {
648*7c478bd9Sstevel@tonic-gate 			if ((ret_val = change_dfstab_ent(&del_dfstabent,
649*7c478bd9Sstevel@tonic-gate 			    NULL, err)) == NULL) {
650*7c478bd9Sstevel@tonic-gate 				ret_val = NULL;
651*7c478bd9Sstevel@tonic-gate 			}
652*7c478bd9Sstevel@tonic-gate 			free(del_dfstabent.path);
653*7c478bd9Sstevel@tonic-gate 		} else {
654*7c478bd9Sstevel@tonic-gate 			*err = ENOMEM;
655*7c478bd9Sstevel@tonic-gate 			ret_val = NULL;
656*7c478bd9Sstevel@tonic-gate 		}
657*7c478bd9Sstevel@tonic-gate 	} else {
658*7c478bd9Sstevel@tonic-gate 		*err = EINVAL;
659*7c478bd9Sstevel@tonic-gate 		ret_val = NULL;
660*7c478bd9Sstevel@tonic-gate 	}
661*7c478bd9Sstevel@tonic-gate 	return (ret_val);
662*7c478bd9Sstevel@tonic-gate }
663*7c478bd9Sstevel@tonic-gate 
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate int
fs_check_for_duplicate_DFStab_paths(char * path,int * err)666*7c478bd9Sstevel@tonic-gate fs_check_for_duplicate_DFStab_paths(char *path, int *err)
667*7c478bd9Sstevel@tonic-gate {
668*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *dfstablist;
669*7c478bd9Sstevel@tonic-gate 	int count = 0;
670*7c478bd9Sstevel@tonic-gate 
671*7c478bd9Sstevel@tonic-gate 	*err = 0;
672*7c478bd9Sstevel@tonic-gate 	if (path == NULL) {
673*7c478bd9Sstevel@tonic-gate 		count = -1;
674*7c478bd9Sstevel@tonic-gate 	}
675*7c478bd9Sstevel@tonic-gate 	dfstablist = get_dfstab_ents(err);
676*7c478bd9Sstevel@tonic-gate 	if (dfstablist != NULL) {
677*7c478bd9Sstevel@tonic-gate 		while (dfstablist != NULL) {
678*7c478bd9Sstevel@tonic-gate 			if (strcmp(dfstablist->path, path) == 0) {
679*7c478bd9Sstevel@tonic-gate 				count++;
680*7c478bd9Sstevel@tonic-gate 			}
681*7c478bd9Sstevel@tonic-gate 			dfstablist = dfstablist->next;
682*7c478bd9Sstevel@tonic-gate 		}
683*7c478bd9Sstevel@tonic-gate 
684*7c478bd9Sstevel@tonic-gate 		free_dfstab_list(dfstablist);
685*7c478bd9Sstevel@tonic-gate 	} else {
686*7c478bd9Sstevel@tonic-gate 		if (err != 0)
687*7c478bd9Sstevel@tonic-gate 			count = *err;
688*7c478bd9Sstevel@tonic-gate 		else
689*7c478bd9Sstevel@tonic-gate 			count = 0;
690*7c478bd9Sstevel@tonic-gate 	}
691*7c478bd9Sstevel@tonic-gate 	return (count);
692*7c478bd9Sstevel@tonic-gate }
693*7c478bd9Sstevel@tonic-gate 
694*7c478bd9Sstevel@tonic-gate void
fs_free_DFStab_ents(void * list)695*7c478bd9Sstevel@tonic-gate fs_free_DFStab_ents(void *list)
696*7c478bd9Sstevel@tonic-gate {
697*7c478bd9Sstevel@tonic-gate 	dfstab_entry_t *headp = (dfstab_entry_t *)list;
698*7c478bd9Sstevel@tonic-gate 	free_dfstab_list(headp);
699*7c478bd9Sstevel@tonic-gate }
700*7c478bd9Sstevel@tonic-gate 
701*7c478bd9Sstevel@tonic-gate /*
702*7c478bd9Sstevel@tonic-gate  * used for debugging only
703*7c478bd9Sstevel@tonic-gate  */
704*7c478bd9Sstevel@tonic-gate void
fs_print_dfstab_entries(void * list)705*7c478bd9Sstevel@tonic-gate fs_print_dfstab_entries(void *list)
706*7c478bd9Sstevel@tonic-gate {
707*7c478bd9Sstevel@tonic-gate 	while (list != NULL) {
708*7c478bd9Sstevel@tonic-gate 
709*7c478bd9Sstevel@tonic-gate 		if (fs_get_DFStab_ent_Fstype(list) != NULL)
710*7c478bd9Sstevel@tonic-gate 			printf("fstype: %s", fs_get_DFStab_ent_Fstype(list));
711*7c478bd9Sstevel@tonic-gate 		if (fs_get_DFStab_ent_Desc(list) != NULL)
712*7c478bd9Sstevel@tonic-gate 			printf(" description: %s",
713*7c478bd9Sstevel@tonic-gate 			    fs_get_DFStab_ent_Desc(list));
714*7c478bd9Sstevel@tonic-gate 		if (fs_get_DFStab_ent_Options(list) != NULL)
715*7c478bd9Sstevel@tonic-gate 			printf(" options: %s",
716*7c478bd9Sstevel@tonic-gate 			    fs_get_DFStab_ent_Options(list));
717*7c478bd9Sstevel@tonic-gate 		if (fs_get_DFStab_ent_Path(list) != NULL)
718*7c478bd9Sstevel@tonic-gate 			printf(" shared path is: %s\n",
719*7c478bd9Sstevel@tonic-gate 			    fs_get_DFStab_ent_Path(list));
720*7c478bd9Sstevel@tonic-gate 		list = (void *)fs_get_DFStab_ent_Next(list);
721*7c478bd9Sstevel@tonic-gate 	}
722*7c478bd9Sstevel@tonic-gate 
723*7c478bd9Sstevel@tonic-gate }
724