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 /*
28*7c478bd9Sstevel@tonic-gate * Traverses /etc/vfstab in order to find default mount information about
29*7c478bd9Sstevel@tonic-gate * file systems on the current host.
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate #include <errno.h>
32*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/vfstab.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include <strings.h>
37*7c478bd9Sstevel@tonic-gate #include <thread.h>
38*7c478bd9Sstevel@tonic-gate #include <synch.h>
39*7c478bd9Sstevel@tonic-gate #include "libfsmgt.h"
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate * Private constants
43*7c478bd9Sstevel@tonic-gate */
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate static const char sepstr[] = "\t\n";
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate * Private variables
49*7c478bd9Sstevel@tonic-gate */
50*7c478bd9Sstevel@tonic-gate static mutex_t vfstab_lock = DEFAULTMUTEX;
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate * Private method declarations
55*7c478bd9Sstevel@tonic-gate */
56*7c478bd9Sstevel@tonic-gate static int cmp_fields(char *, char *, int);
57*7c478bd9Sstevel@tonic-gate static fs_mntdefaults_t *create_mntdefaults_entry(struct vfstab vfstab_entry,
58*7c478bd9Sstevel@tonic-gate int *errp);
59*7c478bd9Sstevel@tonic-gate static struct vfstab *create_vfstab_filter(fs_mntdefaults_t *filter,
60*7c478bd9Sstevel@tonic-gate int *errp);
61*7c478bd9Sstevel@tonic-gate static void free_vfstab_entry(struct vfstab *vfstab_entry);
62*7c478bd9Sstevel@tonic-gate static char *create_vfstab_entry_line(struct vfstab *, int *);
63*7c478bd9Sstevel@tonic-gate static int vfstab_line_cmp(fs_mntdefaults_t *, struct vfstab *);
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate * Public methods
67*7c478bd9Sstevel@tonic-gate */
68*7c478bd9Sstevel@tonic-gate
fs_free_mntdefaults_list(fs_mntdefaults_t * headp)69*7c478bd9Sstevel@tonic-gate void fs_free_mntdefaults_list(fs_mntdefaults_t *headp) {
70*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *tmp;
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate while (headp != NULL) {
73*7c478bd9Sstevel@tonic-gate tmp = headp->next;
74*7c478bd9Sstevel@tonic-gate free(headp->resource);
75*7c478bd9Sstevel@tonic-gate free(headp->fsckdevice);
76*7c478bd9Sstevel@tonic-gate free(headp->mountp);
77*7c478bd9Sstevel@tonic-gate free(headp->fstype);
78*7c478bd9Sstevel@tonic-gate free(headp->fsckpass);
79*7c478bd9Sstevel@tonic-gate free(headp->mountatboot);
80*7c478bd9Sstevel@tonic-gate free(headp->mntopts);
81*7c478bd9Sstevel@tonic-gate headp->next = NULL;
82*7c478bd9Sstevel@tonic-gate free(headp);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate headp = tmp;
85*7c478bd9Sstevel@tonic-gate }
86*7c478bd9Sstevel@tonic-gate } /* fs_free_mntdefaults_list */
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * Filter by the fields that are filled in on the filter parameter.
90*7c478bd9Sstevel@tonic-gate * Fields that aren't used in filtering the defaults will be NULL.
91*7c478bd9Sstevel@tonic-gate */
fs_get_filtered_mount_defaults(fs_mntdefaults_t * filter,int * errp)92*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *fs_get_filtered_mount_defaults(fs_mntdefaults_t *filter,
93*7c478bd9Sstevel@tonic-gate int *errp) {
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *newp;
96*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *headp;
97*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *tailp;
98*7c478bd9Sstevel@tonic-gate FILE *fp;
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate headp = NULL;
101*7c478bd9Sstevel@tonic-gate tailp = NULL;
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) != NULL) {
105*7c478bd9Sstevel@tonic-gate struct vfstab vfstab_entry;
106*7c478bd9Sstevel@tonic-gate struct vfstab *search_entry;
107*7c478bd9Sstevel@tonic-gate (void) mutex_lock(&vfstab_lock);
108*7c478bd9Sstevel@tonic-gate search_entry = create_vfstab_filter(filter, errp);
109*7c478bd9Sstevel@tonic-gate if (search_entry == NULL) {
110*7c478bd9Sstevel@tonic-gate /*
111*7c478bd9Sstevel@tonic-gate * Out of memory, the error pointer (errp) gets
112*7c478bd9Sstevel@tonic-gate * set in create_vfstab_filter.
113*7c478bd9Sstevel@tonic-gate */
114*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(headp);
115*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
116*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
117*7c478bd9Sstevel@tonic-gate return (NULL);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate while (getvfsany(fp, &vfstab_entry, search_entry) == 0) {
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate * Add to list to be returned
123*7c478bd9Sstevel@tonic-gate */
124*7c478bd9Sstevel@tonic-gate newp = create_mntdefaults_entry(vfstab_entry, errp);
125*7c478bd9Sstevel@tonic-gate if (newp == NULL) {
126*7c478bd9Sstevel@tonic-gate /*
127*7c478bd9Sstevel@tonic-gate * Out of memory, the error pointer (errp)
128*7c478bd9Sstevel@tonic-gate * gets set in create_mntdefaults_entry.
129*7c478bd9Sstevel@tonic-gate */
130*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(headp);
131*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
132*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
133*7c478bd9Sstevel@tonic-gate return (NULL);
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate if (headp == NULL) {
137*7c478bd9Sstevel@tonic-gate headp = newp;
138*7c478bd9Sstevel@tonic-gate tailp = newp;
139*7c478bd9Sstevel@tonic-gate } else {
140*7c478bd9Sstevel@tonic-gate tailp->next = newp;
141*7c478bd9Sstevel@tonic-gate tailp = newp;
142*7c478bd9Sstevel@tonic-gate }
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
145*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
146*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate } else {
149*7c478bd9Sstevel@tonic-gate *errp = errno;
150*7c478bd9Sstevel@tonic-gate } /* if ((fp = fopen(VFSTAB, "r")) != NULL) */
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate return (headp);
153*7c478bd9Sstevel@tonic-gate } /* fs_get_filtered_mount_defaults */
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *
fs_get_mount_defaults(int * errp)157*7c478bd9Sstevel@tonic-gate fs_get_mount_defaults(int *errp)
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *newp;
160*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *headp;
161*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *tailp;
162*7c478bd9Sstevel@tonic-gate FILE *fp;
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate headp = NULL;
165*7c478bd9Sstevel@tonic-gate tailp = NULL;
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) != NULL) {
168*7c478bd9Sstevel@tonic-gate struct vfstab vfstab_entry;
169*7c478bd9Sstevel@tonic-gate (void) mutex_lock(&vfstab_lock);
170*7c478bd9Sstevel@tonic-gate while (getvfsent(fp, &vfstab_entry) == 0) {
171*7c478bd9Sstevel@tonic-gate /*
172*7c478bd9Sstevel@tonic-gate * Add entry to list
173*7c478bd9Sstevel@tonic-gate */
174*7c478bd9Sstevel@tonic-gate newp = create_mntdefaults_entry(vfstab_entry, errp);
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate if (newp == NULL) {
177*7c478bd9Sstevel@tonic-gate /*
178*7c478bd9Sstevel@tonic-gate * Out of memory, the error pointer (errp)
179*7c478bd9Sstevel@tonic-gate * gets set in create_mntdefaults_entry.
180*7c478bd9Sstevel@tonic-gate */
181*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
182*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
183*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(headp);
184*7c478bd9Sstevel@tonic-gate return (NULL);
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate if (headp == NULL) {
188*7c478bd9Sstevel@tonic-gate headp = newp;
189*7c478bd9Sstevel@tonic-gate tailp = newp;
190*7c478bd9Sstevel@tonic-gate } else {
191*7c478bd9Sstevel@tonic-gate tailp->next = newp;
192*7c478bd9Sstevel@tonic-gate tailp = newp;
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate }
195*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
196*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
197*7c478bd9Sstevel@tonic-gate } else {
198*7c478bd9Sstevel@tonic-gate *errp = errno;
199*7c478bd9Sstevel@tonic-gate } /* if ((fp = fopen(VFSTAB, "r")) != NULL) */
200*7c478bd9Sstevel@tonic-gate
201*7c478bd9Sstevel@tonic-gate /*
202*7c478bd9Sstevel@tonic-gate * Caller must free the returned list
203*7c478bd9Sstevel@tonic-gate */
204*7c478bd9Sstevel@tonic-gate return (headp);
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate } /* fs_get_mount_defaults */
207*7c478bd9Sstevel@tonic-gate
208*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *
fs_add_mount_default(fs_mntdefaults_t * newp,int * errp)209*7c478bd9Sstevel@tonic-gate fs_add_mount_default(fs_mntdefaults_t *newp, int *errp) {
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate FILE *fp;
212*7c478bd9Sstevel@tonic-gate struct vfstab *new_entry;
213*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *ret_val;
214*7c478bd9Sstevel@tonic-gate
215*7c478bd9Sstevel@tonic-gate new_entry = create_vfstab_filter(newp, errp);
216*7c478bd9Sstevel@tonic-gate if (new_entry != NULL) {
217*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "a")) != NULL) {
218*7c478bd9Sstevel@tonic-gate (void) mutex_lock(&vfstab_lock);
219*7c478bd9Sstevel@tonic-gate putvfsent(fp, new_entry);
220*7c478bd9Sstevel@tonic-gate free_vfstab_entry(new_entry);
221*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
222*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
223*7c478bd9Sstevel@tonic-gate ret_val = fs_get_mount_defaults(errp);
224*7c478bd9Sstevel@tonic-gate } else {
225*7c478bd9Sstevel@tonic-gate *errp = errno;
226*7c478bd9Sstevel@tonic-gate free_vfstab_entry(new_entry);
227*7c478bd9Sstevel@tonic-gate ret_val = NULL;
228*7c478bd9Sstevel@tonic-gate }
229*7c478bd9Sstevel@tonic-gate } else {
230*7c478bd9Sstevel@tonic-gate ret_val = NULL;
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate return (ret_val);
233*7c478bd9Sstevel@tonic-gate } /* fs_add_mount_default */
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *
fs_edit_mount_defaults(fs_mntdefaults_t * old_vfstab_ent,fs_mntdefaults_t * new_vfstab_ent,int * errp)237*7c478bd9Sstevel@tonic-gate fs_edit_mount_defaults(
238*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *old_vfstab_ent,
239*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *new_vfstab_ent,
240*7c478bd9Sstevel@tonic-gate int *errp)
241*7c478bd9Sstevel@tonic-gate {
242*7c478bd9Sstevel@tonic-gate FILE *fp;
243*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *ret_val;
244*7c478bd9Sstevel@tonic-gate char vfstab_line[VFS_LINE_MAX];
245*7c478bd9Sstevel@tonic-gate char **temp_vfstab = NULL;
246*7c478bd9Sstevel@tonic-gate char *new_line;
247*7c478bd9Sstevel@tonic-gate struct vfstab vfstabp, *new_vfstab;
248*7c478bd9Sstevel@tonic-gate int line_found = 0;
249*7c478bd9Sstevel@tonic-gate
250*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) != NULL) {
251*7c478bd9Sstevel@tonic-gate char *tmp;
252*7c478bd9Sstevel@tonic-gate int count = 0;
253*7c478bd9Sstevel@tonic-gate (void) mutex_lock(&vfstab_lock);
254*7c478bd9Sstevel@tonic-gate while (fgets(vfstab_line, VFS_LINE_MAX, fp) != NULL) {
255*7c478bd9Sstevel@tonic-gate char *charp;
256*7c478bd9Sstevel@tonic-gate struct vfstab *vp;
257*7c478bd9Sstevel@tonic-gate char *orig_line = strdup(vfstab_line);
258*7c478bd9Sstevel@tonic-gate if (orig_line == NULL) {
259*7c478bd9Sstevel@tonic-gate *errp = ENOMEM;
260*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
261*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
262*7c478bd9Sstevel@tonic-gate return (NULL);
263*7c478bd9Sstevel@tonic-gate }
264*7c478bd9Sstevel@tonic-gate vp = &vfstabp;
265*7c478bd9Sstevel@tonic-gate for (charp = vfstab_line;
266*7c478bd9Sstevel@tonic-gate *charp == ' ' || *charp == '\t'; charp++);
267*7c478bd9Sstevel@tonic-gate if (*charp == '#' || *charp == '\n') {
268*7c478bd9Sstevel@tonic-gate /*
269*7c478bd9Sstevel@tonic-gate * Write comments out to temp vfstab
270*7c478bd9Sstevel@tonic-gate * image
271*7c478bd9Sstevel@tonic-gate */
272*7c478bd9Sstevel@tonic-gate if (!fileutil_add_string_to_array(
273*7c478bd9Sstevel@tonic-gate &temp_vfstab, vfstab_line, &count, errp)) {
274*7c478bd9Sstevel@tonic-gate ret_val = NULL;
275*7c478bd9Sstevel@tonic-gate line_found = 0;
276*7c478bd9Sstevel@tonic-gate break;
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate continue;
279*7c478bd9Sstevel@tonic-gate }
280*7c478bd9Sstevel@tonic-gate vp->vfs_special = (char *)strtok_r(
281*7c478bd9Sstevel@tonic-gate vfstab_line, sepstr, &tmp);
282*7c478bd9Sstevel@tonic-gate vp->vfs_fsckdev = (char *)strtok_r(
283*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
284*7c478bd9Sstevel@tonic-gate vp->vfs_mountp = (char *)strtok_r(
285*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
286*7c478bd9Sstevel@tonic-gate vp->vfs_fstype = (char *)strtok_r(
287*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
288*7c478bd9Sstevel@tonic-gate vp->vfs_fsckpass = (char *)strtok_r(
289*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
290*7c478bd9Sstevel@tonic-gate vp->vfs_automnt = (char *)strtok_r(
291*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
292*7c478bd9Sstevel@tonic-gate vp->vfs_mntopts = (char *)strtok_r(
293*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
294*7c478bd9Sstevel@tonic-gate if (strtok_r(NULL, sepstr, &tmp) != NULL) {
295*7c478bd9Sstevel@tonic-gate /*
296*7c478bd9Sstevel@tonic-gate * Invalid vfstab line.
297*7c478bd9Sstevel@tonic-gate */
298*7c478bd9Sstevel@tonic-gate *errp = EINVAL;
299*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
300*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
301*7c478bd9Sstevel@tonic-gate return (NULL);
302*7c478bd9Sstevel@tonic-gate }
303*7c478bd9Sstevel@tonic-gate
304*7c478bd9Sstevel@tonic-gate if (vfstab_line_cmp(old_vfstab_ent, vp)) {
305*7c478bd9Sstevel@tonic-gate line_found = 1;
306*7c478bd9Sstevel@tonic-gate new_vfstab =
307*7c478bd9Sstevel@tonic-gate create_vfstab_filter(
308*7c478bd9Sstevel@tonic-gate new_vfstab_ent, errp);
309*7c478bd9Sstevel@tonic-gate new_line =
310*7c478bd9Sstevel@tonic-gate create_vfstab_entry_line(new_vfstab, errp);
311*7c478bd9Sstevel@tonic-gate if (!fileutil_add_string_to_array(
312*7c478bd9Sstevel@tonic-gate &temp_vfstab, new_line, &count, errp)) {
313*7c478bd9Sstevel@tonic-gate ret_val = NULL;
314*7c478bd9Sstevel@tonic-gate line_found = 0;
315*7c478bd9Sstevel@tonic-gate free(new_line);
316*7c478bd9Sstevel@tonic-gate break;
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate free(new_line);
319*7c478bd9Sstevel@tonic-gate } else {
320*7c478bd9Sstevel@tonic-gate if (!fileutil_add_string_to_array(
321*7c478bd9Sstevel@tonic-gate &temp_vfstab, orig_line, &count, errp)) {
322*7c478bd9Sstevel@tonic-gate ret_val = NULL;
323*7c478bd9Sstevel@tonic-gate line_found = 0;
324*7c478bd9Sstevel@tonic-gate break;
325*7c478bd9Sstevel@tonic-gate }
326*7c478bd9Sstevel@tonic-gate }
327*7c478bd9Sstevel@tonic-gate free(orig_line);
328*7c478bd9Sstevel@tonic-gate }
329*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gate if (line_found && temp_vfstab != NULL) {
332*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "w")) != NULL) {
333*7c478bd9Sstevel@tonic-gate int i;
334*7c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
335*7c478bd9Sstevel@tonic-gate fprintf(fp, "%s", temp_vfstab[i]);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
338*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
339*7c478bd9Sstevel@tonic-gate ret_val = fs_get_mount_defaults(errp);
340*7c478bd9Sstevel@tonic-gate fileutil_free_string_array(temp_vfstab, count);
341*7c478bd9Sstevel@tonic-gate } else {
342*7c478bd9Sstevel@tonic-gate *errp = errno;
343*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
344*7c478bd9Sstevel@tonic-gate ret_val = NULL;
345*7c478bd9Sstevel@tonic-gate }
346*7c478bd9Sstevel@tonic-gate } else {
347*7c478bd9Sstevel@tonic-gate *errp = errno;
348*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
349*7c478bd9Sstevel@tonic-gate ret_val = NULL;
350*7c478bd9Sstevel@tonic-gate }
351*7c478bd9Sstevel@tonic-gate } else {
352*7c478bd9Sstevel@tonic-gate *errp = errno;
353*7c478bd9Sstevel@tonic-gate ret_val = NULL;
354*7c478bd9Sstevel@tonic-gate }
355*7c478bd9Sstevel@tonic-gate return (ret_val);
356*7c478bd9Sstevel@tonic-gate } /* fs_edit_mount_defaults */
357*7c478bd9Sstevel@tonic-gate
358*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *
fs_del_mount_default_ent(fs_mntdefaults_t * old_vfstab_ent,int * errp)359*7c478bd9Sstevel@tonic-gate fs_del_mount_default_ent(fs_mntdefaults_t *old_vfstab_ent, int *errp)
360*7c478bd9Sstevel@tonic-gate {
361*7c478bd9Sstevel@tonic-gate FILE *fp;
362*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *ret_val;
363*7c478bd9Sstevel@tonic-gate char vfstab_line[VFS_LINE_MAX];
364*7c478bd9Sstevel@tonic-gate struct vfstab vfstabp;
365*7c478bd9Sstevel@tonic-gate int line_found = 0;
366*7c478bd9Sstevel@tonic-gate
367*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "r")) != NULL) {
368*7c478bd9Sstevel@tonic-gate struct vfstab *vp;
369*7c478bd9Sstevel@tonic-gate char *tmp;
370*7c478bd9Sstevel@tonic-gate char *charp;
371*7c478bd9Sstevel@tonic-gate char *orig_line = NULL;
372*7c478bd9Sstevel@tonic-gate char **temp_vfstab = NULL;
373*7c478bd9Sstevel@tonic-gate int count = 0;
374*7c478bd9Sstevel@tonic-gate vp = &vfstabp;
375*7c478bd9Sstevel@tonic-gate (void) mutex_lock(&vfstab_lock);
376*7c478bd9Sstevel@tonic-gate while (fgets(vfstab_line, VFS_LINE_MAX, fp) != NULL) {
377*7c478bd9Sstevel@tonic-gate
378*7c478bd9Sstevel@tonic-gate orig_line = strdup(vfstab_line);
379*7c478bd9Sstevel@tonic-gate if (orig_line == NULL) {
380*7c478bd9Sstevel@tonic-gate *errp = ENOMEM;
381*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
382*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
383*7c478bd9Sstevel@tonic-gate return (NULL);
384*7c478bd9Sstevel@tonic-gate }
385*7c478bd9Sstevel@tonic-gate
386*7c478bd9Sstevel@tonic-gate for (charp = vfstab_line;
387*7c478bd9Sstevel@tonic-gate *charp == ' ' || *charp == '\t'; charp++);
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gate if (*charp == '#' || *charp == '\n') {
390*7c478bd9Sstevel@tonic-gate /*
391*7c478bd9Sstevel@tonic-gate * Write comments out to temp vfstab
392*7c478bd9Sstevel@tonic-gate * image
393*7c478bd9Sstevel@tonic-gate */
394*7c478bd9Sstevel@tonic-gate if (!fileutil_add_string_to_array(
395*7c478bd9Sstevel@tonic-gate &temp_vfstab, vfstab_line, &count, errp)) {
396*7c478bd9Sstevel@tonic-gate ret_val = NULL;
397*7c478bd9Sstevel@tonic-gate line_found = 0;
398*7c478bd9Sstevel@tonic-gate free(orig_line);
399*7c478bd9Sstevel@tonic-gate break;
400*7c478bd9Sstevel@tonic-gate }
401*7c478bd9Sstevel@tonic-gate continue;
402*7c478bd9Sstevel@tonic-gate }
403*7c478bd9Sstevel@tonic-gate
404*7c478bd9Sstevel@tonic-gate vp->vfs_special = (char *)strtok_r(
405*7c478bd9Sstevel@tonic-gate vfstab_line, sepstr, &tmp);
406*7c478bd9Sstevel@tonic-gate vp->vfs_fsckdev = (char *)strtok_r(
407*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
408*7c478bd9Sstevel@tonic-gate vp->vfs_mountp = (char *)strtok_r(
409*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
410*7c478bd9Sstevel@tonic-gate vp->vfs_fstype = (char *)strtok_r(
411*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
412*7c478bd9Sstevel@tonic-gate vp->vfs_fsckpass = (char *)strtok_r(
413*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
414*7c478bd9Sstevel@tonic-gate vp->vfs_automnt = (char *)strtok_r(
415*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
416*7c478bd9Sstevel@tonic-gate vp->vfs_mntopts = (char *)strtok_r(
417*7c478bd9Sstevel@tonic-gate NULL, sepstr, &tmp);
418*7c478bd9Sstevel@tonic-gate
419*7c478bd9Sstevel@tonic-gate if (strtok_r(NULL, sepstr, &tmp) != NULL) {
420*7c478bd9Sstevel@tonic-gate /*
421*7c478bd9Sstevel@tonic-gate * Invalid vfstab line.
422*7c478bd9Sstevel@tonic-gate */
423*7c478bd9Sstevel@tonic-gate *errp = EINVAL;
424*7c478bd9Sstevel@tonic-gate free(orig_line);
425*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
426*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
427*7c478bd9Sstevel@tonic-gate return (NULL);
428*7c478bd9Sstevel@tonic-gate }
429*7c478bd9Sstevel@tonic-gate
430*7c478bd9Sstevel@tonic-gate if (vfstab_line_cmp(old_vfstab_ent, vp)) {
431*7c478bd9Sstevel@tonic-gate line_found = 1;
432*7c478bd9Sstevel@tonic-gate } else {
433*7c478bd9Sstevel@tonic-gate if (!fileutil_add_string_to_array(
434*7c478bd9Sstevel@tonic-gate &temp_vfstab, orig_line, &count, errp)) {
435*7c478bd9Sstevel@tonic-gate ret_val = NULL;
436*7c478bd9Sstevel@tonic-gate line_found = 0;
437*7c478bd9Sstevel@tonic-gate free(orig_line);
438*7c478bd9Sstevel@tonic-gate break;
439*7c478bd9Sstevel@tonic-gate }
440*7c478bd9Sstevel@tonic-gate }
441*7c478bd9Sstevel@tonic-gate free(orig_line);
442*7c478bd9Sstevel@tonic-gate }
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
445*7c478bd9Sstevel@tonic-gate
446*7c478bd9Sstevel@tonic-gate if (line_found && temp_vfstab != NULL) {
447*7c478bd9Sstevel@tonic-gate if ((fp = fopen(VFSTAB, "w")) != NULL) {
448*7c478bd9Sstevel@tonic-gate int i;
449*7c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
450*7c478bd9Sstevel@tonic-gate fprintf(fp, "%s", temp_vfstab[i]);
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
453*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
454*7c478bd9Sstevel@tonic-gate ret_val = fs_get_mount_defaults(errp);
455*7c478bd9Sstevel@tonic-gate fileutil_free_string_array(temp_vfstab, count);
456*7c478bd9Sstevel@tonic-gate } else {
457*7c478bd9Sstevel@tonic-gate *errp = errno;
458*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
459*7c478bd9Sstevel@tonic-gate fileutil_free_string_array(temp_vfstab, count);
460*7c478bd9Sstevel@tonic-gate ret_val = NULL;
461*7c478bd9Sstevel@tonic-gate }
462*7c478bd9Sstevel@tonic-gate } else {
463*7c478bd9Sstevel@tonic-gate (void) mutex_unlock(&vfstab_lock);
464*7c478bd9Sstevel@tonic-gate if (temp_vfstab != NULL) {
465*7c478bd9Sstevel@tonic-gate fileutil_free_string_array(temp_vfstab, count);
466*7c478bd9Sstevel@tonic-gate }
467*7c478bd9Sstevel@tonic-gate ret_val = NULL;
468*7c478bd9Sstevel@tonic-gate }
469*7c478bd9Sstevel@tonic-gate } else {
470*7c478bd9Sstevel@tonic-gate *errp = errno;
471*7c478bd9Sstevel@tonic-gate ret_val = NULL;
472*7c478bd9Sstevel@tonic-gate }
473*7c478bd9Sstevel@tonic-gate return (ret_val);
474*7c478bd9Sstevel@tonic-gate }
475*7c478bd9Sstevel@tonic-gate
476*7c478bd9Sstevel@tonic-gate /*
477*7c478bd9Sstevel@tonic-gate * Private methods
478*7c478bd9Sstevel@tonic-gate */
479*7c478bd9Sstevel@tonic-gate
480*7c478bd9Sstevel@tonic-gate static fs_mntdefaults_t *
create_mntdefaults_entry(struct vfstab vfstab_entry,int * errp)481*7c478bd9Sstevel@tonic-gate create_mntdefaults_entry(struct vfstab vfstab_entry, int *errp) {
482*7c478bd9Sstevel@tonic-gate fs_mntdefaults_t *newp;
483*7c478bd9Sstevel@tonic-gate
484*7c478bd9Sstevel@tonic-gate newp = (fs_mntdefaults_t *)calloc((size_t)1,
485*7c478bd9Sstevel@tonic-gate (size_t)sizeof (fs_mntdefaults_t));
486*7c478bd9Sstevel@tonic-gate
487*7c478bd9Sstevel@tonic-gate if (newp == NULL) {
488*7c478bd9Sstevel@tonic-gate /*
489*7c478bd9Sstevel@tonic-gate * Out of memory
490*7c478bd9Sstevel@tonic-gate */
491*7c478bd9Sstevel@tonic-gate *errp = errno;
492*7c478bd9Sstevel@tonic-gate return (NULL);
493*7c478bd9Sstevel@tonic-gate }
494*7c478bd9Sstevel@tonic-gate
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_special != NULL) {
497*7c478bd9Sstevel@tonic-gate newp->resource = strdup(vfstab_entry.vfs_special);
498*7c478bd9Sstevel@tonic-gate if (newp->resource == NULL) {
499*7c478bd9Sstevel@tonic-gate /*
500*7c478bd9Sstevel@tonic-gate * Out of memory
501*7c478bd9Sstevel@tonic-gate */
502*7c478bd9Sstevel@tonic-gate *errp = errno;
503*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
504*7c478bd9Sstevel@tonic-gate return (NULL);
505*7c478bd9Sstevel@tonic-gate }
506*7c478bd9Sstevel@tonic-gate }
507*7c478bd9Sstevel@tonic-gate
508*7c478bd9Sstevel@tonic-gate
509*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_fsckdev != NULL) {
510*7c478bd9Sstevel@tonic-gate newp->fsckdevice = strdup(vfstab_entry.vfs_fsckdev);
511*7c478bd9Sstevel@tonic-gate if (newp->fsckdevice == NULL) {
512*7c478bd9Sstevel@tonic-gate /*
513*7c478bd9Sstevel@tonic-gate * Out of memory
514*7c478bd9Sstevel@tonic-gate */
515*7c478bd9Sstevel@tonic-gate *errp = errno;
516*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
517*7c478bd9Sstevel@tonic-gate return (NULL);
518*7c478bd9Sstevel@tonic-gate }
519*7c478bd9Sstevel@tonic-gate }
520*7c478bd9Sstevel@tonic-gate
521*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_mountp != NULL) {
522*7c478bd9Sstevel@tonic-gate newp->mountp = strdup(vfstab_entry.vfs_mountp);
523*7c478bd9Sstevel@tonic-gate if (newp->mountp == NULL) {
524*7c478bd9Sstevel@tonic-gate /*
525*7c478bd9Sstevel@tonic-gate * Out of memory
526*7c478bd9Sstevel@tonic-gate */
527*7c478bd9Sstevel@tonic-gate *errp = errno;
528*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
529*7c478bd9Sstevel@tonic-gate return (NULL);
530*7c478bd9Sstevel@tonic-gate }
531*7c478bd9Sstevel@tonic-gate }
532*7c478bd9Sstevel@tonic-gate
533*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_fstype != NULL) {
534*7c478bd9Sstevel@tonic-gate newp->fstype = strdup(vfstab_entry.vfs_fstype);
535*7c478bd9Sstevel@tonic-gate if (newp->fstype == NULL) {
536*7c478bd9Sstevel@tonic-gate /*
537*7c478bd9Sstevel@tonic-gate * Out of memory
538*7c478bd9Sstevel@tonic-gate */
539*7c478bd9Sstevel@tonic-gate *errp = errno;
540*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
541*7c478bd9Sstevel@tonic-gate return (NULL);
542*7c478bd9Sstevel@tonic-gate }
543*7c478bd9Sstevel@tonic-gate }
544*7c478bd9Sstevel@tonic-gate
545*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_fsckpass != NULL) {
546*7c478bd9Sstevel@tonic-gate newp->fsckpass = strdup(vfstab_entry.vfs_fsckpass);
547*7c478bd9Sstevel@tonic-gate if (newp->fsckpass == NULL) {
548*7c478bd9Sstevel@tonic-gate /*
549*7c478bd9Sstevel@tonic-gate * Out of memory
550*7c478bd9Sstevel@tonic-gate */
551*7c478bd9Sstevel@tonic-gate *errp = errno;
552*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
553*7c478bd9Sstevel@tonic-gate return (NULL);
554*7c478bd9Sstevel@tonic-gate }
555*7c478bd9Sstevel@tonic-gate }
556*7c478bd9Sstevel@tonic-gate
557*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_automnt != NULL) {
558*7c478bd9Sstevel@tonic-gate newp->mountatboot = strdup(vfstab_entry.vfs_automnt);
559*7c478bd9Sstevel@tonic-gate if (newp->mountatboot == NULL) {
560*7c478bd9Sstevel@tonic-gate /*
561*7c478bd9Sstevel@tonic-gate * Out of memory
562*7c478bd9Sstevel@tonic-gate */
563*7c478bd9Sstevel@tonic-gate *errp = errno;
564*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
565*7c478bd9Sstevel@tonic-gate return (NULL);
566*7c478bd9Sstevel@tonic-gate }
567*7c478bd9Sstevel@tonic-gate }
568*7c478bd9Sstevel@tonic-gate
569*7c478bd9Sstevel@tonic-gate if (vfstab_entry.vfs_mntopts != NULL) {
570*7c478bd9Sstevel@tonic-gate newp->mntopts = strdup(vfstab_entry.vfs_mntopts);
571*7c478bd9Sstevel@tonic-gate if (newp->mntopts == NULL) {
572*7c478bd9Sstevel@tonic-gate /*
573*7c478bd9Sstevel@tonic-gate * Out of memory
574*7c478bd9Sstevel@tonic-gate */
575*7c478bd9Sstevel@tonic-gate *errp = errno;
576*7c478bd9Sstevel@tonic-gate fs_free_mntdefaults_list(newp);
577*7c478bd9Sstevel@tonic-gate return (NULL);
578*7c478bd9Sstevel@tonic-gate }
579*7c478bd9Sstevel@tonic-gate }
580*7c478bd9Sstevel@tonic-gate newp->next = NULL;
581*7c478bd9Sstevel@tonic-gate
582*7c478bd9Sstevel@tonic-gate return (newp);
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate } /* create_mntdefaults_entry */
585*7c478bd9Sstevel@tonic-gate
586*7c478bd9Sstevel@tonic-gate static struct vfstab *
create_vfstab_filter(fs_mntdefaults_t * filter,int * errp)587*7c478bd9Sstevel@tonic-gate create_vfstab_filter(fs_mntdefaults_t *filter, int *errp) {
588*7c478bd9Sstevel@tonic-gate struct vfstab *search_entry;
589*7c478bd9Sstevel@tonic-gate
590*7c478bd9Sstevel@tonic-gate search_entry = (struct vfstab *)calloc((size_t)1,
591*7c478bd9Sstevel@tonic-gate (size_t)sizeof (struct vfstab));
592*7c478bd9Sstevel@tonic-gate if (search_entry == NULL) {
593*7c478bd9Sstevel@tonic-gate /*
594*7c478bd9Sstevel@tonic-gate * Out of memory
595*7c478bd9Sstevel@tonic-gate */
596*7c478bd9Sstevel@tonic-gate *errp = errno;
597*7c478bd9Sstevel@tonic-gate return (NULL);
598*7c478bd9Sstevel@tonic-gate }
599*7c478bd9Sstevel@tonic-gate
600*7c478bd9Sstevel@tonic-gate /*
601*7c478bd9Sstevel@tonic-gate * Populate the filter criteria
602*7c478bd9Sstevel@tonic-gate */
603*7c478bd9Sstevel@tonic-gate if (filter->resource != NULL) {
604*7c478bd9Sstevel@tonic-gate search_entry->vfs_special = strdup(filter->resource);
605*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_special == NULL) {
606*7c478bd9Sstevel@tonic-gate /*
607*7c478bd9Sstevel@tonic-gate * Out of memory
608*7c478bd9Sstevel@tonic-gate */
609*7c478bd9Sstevel@tonic-gate *errp = errno;
610*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
611*7c478bd9Sstevel@tonic-gate return (NULL);
612*7c478bd9Sstevel@tonic-gate }
613*7c478bd9Sstevel@tonic-gate
614*7c478bd9Sstevel@tonic-gate }
615*7c478bd9Sstevel@tonic-gate
616*7c478bd9Sstevel@tonic-gate if (filter->fsckdevice != NULL) {
617*7c478bd9Sstevel@tonic-gate search_entry->vfs_fsckdev = strdup(filter->fsckdevice);
618*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_fsckdev == NULL) {
619*7c478bd9Sstevel@tonic-gate /*
620*7c478bd9Sstevel@tonic-gate * Out of memory
621*7c478bd9Sstevel@tonic-gate */
622*7c478bd9Sstevel@tonic-gate *errp = errno;
623*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
624*7c478bd9Sstevel@tonic-gate return (NULL);
625*7c478bd9Sstevel@tonic-gate }
626*7c478bd9Sstevel@tonic-gate }
627*7c478bd9Sstevel@tonic-gate
628*7c478bd9Sstevel@tonic-gate if (filter->mountp != NULL) {
629*7c478bd9Sstevel@tonic-gate search_entry->vfs_mountp = strdup(filter->mountp);
630*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_mountp == NULL) {
631*7c478bd9Sstevel@tonic-gate /*
632*7c478bd9Sstevel@tonic-gate * Out of memory
633*7c478bd9Sstevel@tonic-gate */
634*7c478bd9Sstevel@tonic-gate *errp = errno;
635*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
636*7c478bd9Sstevel@tonic-gate return (NULL);
637*7c478bd9Sstevel@tonic-gate }
638*7c478bd9Sstevel@tonic-gate }
639*7c478bd9Sstevel@tonic-gate
640*7c478bd9Sstevel@tonic-gate if (filter->fstype != NULL) {
641*7c478bd9Sstevel@tonic-gate search_entry->vfs_fstype = strdup(filter->fstype);
642*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_fstype == NULL) {
643*7c478bd9Sstevel@tonic-gate /*
644*7c478bd9Sstevel@tonic-gate * Out of memory
645*7c478bd9Sstevel@tonic-gate */
646*7c478bd9Sstevel@tonic-gate *errp = errno;
647*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
648*7c478bd9Sstevel@tonic-gate return (NULL);
649*7c478bd9Sstevel@tonic-gate }
650*7c478bd9Sstevel@tonic-gate }
651*7c478bd9Sstevel@tonic-gate
652*7c478bd9Sstevel@tonic-gate if (filter->fsckpass != NULL) {
653*7c478bd9Sstevel@tonic-gate search_entry->vfs_fsckpass = strdup(filter->fsckpass);
654*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_fsckpass == NULL) {
655*7c478bd9Sstevel@tonic-gate /*
656*7c478bd9Sstevel@tonic-gate * Out of memory
657*7c478bd9Sstevel@tonic-gate */
658*7c478bd9Sstevel@tonic-gate *errp = errno;
659*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
660*7c478bd9Sstevel@tonic-gate return (NULL);
661*7c478bd9Sstevel@tonic-gate }
662*7c478bd9Sstevel@tonic-gate }
663*7c478bd9Sstevel@tonic-gate
664*7c478bd9Sstevel@tonic-gate if (filter->mountatboot != NULL) {
665*7c478bd9Sstevel@tonic-gate search_entry->vfs_automnt = strdup(filter->mountatboot);
666*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_automnt == NULL) {
667*7c478bd9Sstevel@tonic-gate /*
668*7c478bd9Sstevel@tonic-gate * Out of memory
669*7c478bd9Sstevel@tonic-gate */
670*7c478bd9Sstevel@tonic-gate *errp = errno;
671*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
672*7c478bd9Sstevel@tonic-gate return (NULL);
673*7c478bd9Sstevel@tonic-gate }
674*7c478bd9Sstevel@tonic-gate }
675*7c478bd9Sstevel@tonic-gate
676*7c478bd9Sstevel@tonic-gate if (filter->mntopts != NULL) {
677*7c478bd9Sstevel@tonic-gate search_entry->vfs_mntopts = strdup(filter->mntopts);
678*7c478bd9Sstevel@tonic-gate if (search_entry->vfs_mntopts == NULL) {
679*7c478bd9Sstevel@tonic-gate /*
680*7c478bd9Sstevel@tonic-gate * Out of memory
681*7c478bd9Sstevel@tonic-gate */
682*7c478bd9Sstevel@tonic-gate *errp = errno;
683*7c478bd9Sstevel@tonic-gate free_vfstab_entry(search_entry);
684*7c478bd9Sstevel@tonic-gate return (NULL);
685*7c478bd9Sstevel@tonic-gate }
686*7c478bd9Sstevel@tonic-gate }
687*7c478bd9Sstevel@tonic-gate
688*7c478bd9Sstevel@tonic-gate return (search_entry);
689*7c478bd9Sstevel@tonic-gate } /* create_vfstab_filter */
690*7c478bd9Sstevel@tonic-gate
free_vfstab_entry(struct vfstab * vfstab_entry)691*7c478bd9Sstevel@tonic-gate static void free_vfstab_entry(struct vfstab *vfstab_entry) {
692*7c478bd9Sstevel@tonic-gate
693*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_special);
694*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_fsckdev);
695*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_mountp);
696*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_fstype);
697*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_fsckpass);
698*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_automnt);
699*7c478bd9Sstevel@tonic-gate free(vfstab_entry->vfs_mntopts);
700*7c478bd9Sstevel@tonic-gate
701*7c478bd9Sstevel@tonic-gate free(vfstab_entry);
702*7c478bd9Sstevel@tonic-gate } /* free_vfstab_entry */
703*7c478bd9Sstevel@tonic-gate
704*7c478bd9Sstevel@tonic-gate static int
vfstab_line_cmp(fs_mntdefaults_t * mntdftp,struct vfstab * vp)705*7c478bd9Sstevel@tonic-gate vfstab_line_cmp(fs_mntdefaults_t *mntdftp, struct vfstab *vp) {
706*7c478bd9Sstevel@tonic-gate
707*7c478bd9Sstevel@tonic-gate int ret_val = 1;
708*7c478bd9Sstevel@tonic-gate
709*7c478bd9Sstevel@tonic-gate ret_val = cmp_fields(mntdftp->resource, vp->vfs_special, ret_val);
710*7c478bd9Sstevel@tonic-gate ret_val = cmp_fields(mntdftp->mountp, vp->vfs_mountp, ret_val);
711*7c478bd9Sstevel@tonic-gate
712*7c478bd9Sstevel@tonic-gate return (ret_val);
713*7c478bd9Sstevel@tonic-gate } /* vfstab_line_cmp */
714*7c478bd9Sstevel@tonic-gate
715*7c478bd9Sstevel@tonic-gate /*
716*7c478bd9Sstevel@tonic-gate * Helper function for comparing fields in a fs_mntdefaults_t to a
717*7c478bd9Sstevel@tonic-gate * vfstab structure. Used in vfstab_line_cmp().
718*7c478bd9Sstevel@tonic-gate */
719*7c478bd9Sstevel@tonic-gate static int
cmp_fields(char * mntdflt_str,char * vfstab_str,int ret_val)720*7c478bd9Sstevel@tonic-gate cmp_fields(char *mntdflt_str, char *vfstab_str, int ret_val) {
721*7c478bd9Sstevel@tonic-gate if (ret_val != 0) {
722*7c478bd9Sstevel@tonic-gate if (mntdflt_str != NULL && vfstab_str != NULL) {
723*7c478bd9Sstevel@tonic-gate if (strcmp(mntdflt_str, vfstab_str) != 0) {
724*7c478bd9Sstevel@tonic-gate ret_val = 0;
725*7c478bd9Sstevel@tonic-gate }
726*7c478bd9Sstevel@tonic-gate } else if (mntdflt_str == NULL || vfstab_str == NULL) {
727*7c478bd9Sstevel@tonic-gate ret_val = 0;
728*7c478bd9Sstevel@tonic-gate }
729*7c478bd9Sstevel@tonic-gate }
730*7c478bd9Sstevel@tonic-gate return (ret_val);
731*7c478bd9Sstevel@tonic-gate } /* cmp_fields */
732*7c478bd9Sstevel@tonic-gate
733*7c478bd9Sstevel@tonic-gate /*
734*7c478bd9Sstevel@tonic-gate * Helper fuction used by del_vfstab_ent() and edit_vfstab_ent() to
735*7c478bd9Sstevel@tonic-gate * create a vfstab line for writing out to the vfstab file.
736*7c478bd9Sstevel@tonic-gate */
737*7c478bd9Sstevel@tonic-gate char *
create_vfstab_entry_line(struct vfstab * vfstab_ent,int * errp)738*7c478bd9Sstevel@tonic-gate create_vfstab_entry_line(struct vfstab *vfstab_ent, int *errp) {
739*7c478bd9Sstevel@tonic-gate char *line;
740*7c478bd9Sstevel@tonic-gate int line_length;
741*7c478bd9Sstevel@tonic-gate line_length = (
742*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_special ?
743*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_special) +1) : 2) +
744*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_fsckdev ?
745*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_fsckdev) +1) : 2) +
746*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_mountp ?
747*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_mountp) +1) : 2) +
748*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_fstype ?
749*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_fstype) +1) : 2) +
750*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_fsckpass ?
751*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_fsckpass) +1) : 2) +
752*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_automnt ?
753*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_automnt) +1) : 2) +
754*7c478bd9Sstevel@tonic-gate (vfstab_ent->vfs_mntopts ?
755*7c478bd9Sstevel@tonic-gate (strlen(vfstab_ent->vfs_mntopts) +1) : 2));
756*7c478bd9Sstevel@tonic-gate line = (char *)malloc(line_length + 1);
757*7c478bd9Sstevel@tonic-gate if (line != NULL) {
758*7c478bd9Sstevel@tonic-gate sprintf(line, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
759*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_special ? vfstab_ent->vfs_special : "-",
760*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_fsckdev ? vfstab_ent->vfs_fsckdev : "-",
761*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_mountp ? vfstab_ent->vfs_mountp : "-",
762*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_fstype ? vfstab_ent->vfs_fstype : "-",
763*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_fsckpass ? vfstab_ent->vfs_fsckpass : "-",
764*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_automnt ? vfstab_ent->vfs_automnt : "-",
765*7c478bd9Sstevel@tonic-gate vfstab_ent->vfs_mntopts ? vfstab_ent->vfs_mntopts : "-");
766*7c478bd9Sstevel@tonic-gate } else {
767*7c478bd9Sstevel@tonic-gate *errp = errno;
768*7c478bd9Sstevel@tonic-gate }
769*7c478bd9Sstevel@tonic-gate return (line);
770*7c478bd9Sstevel@tonic-gate } /* create_vfstab_entry_line */
771