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