4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 1989 Jan-Simon Pendry
6 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1989 The Regents of the University of California.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * File: am-utils/fsinfo/wr_fstab.c
48 #endif /* HAVE_CONFIG_H */
53 #define GENERIC_OS_NAME "generic"
55 /* forward definitions */
56 static void write_aix1_dkfstab(FILE *ef
, disk_fs
*dp
);
57 static void write_aix1_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
);
58 static void write_aix3_dkfstab(FILE *ef
, disk_fs
*dp
);
59 static void write_aix3_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
);
60 static int write_dkfstab(FILE *ef
, qelem
*q
, void (*output
) (FILE *, disk_fs
*));
61 static int write_dkrmount(FILE *ef
, qelem
*q
, char *hn
, void (*output
) (FILE *, char *, fsmount
*));
62 static void write_generic_dkfstab(FILE *ef
, disk_fs
*dp
);
63 static void write_generic_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
);
64 static void write_ultrix_dkfstab(FILE *ef
, disk_fs
*dp
);
65 static void write_ultrix_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
);
67 /* ----------------------------------------------- */
69 static struct os_fstab_type
{
71 void (*op_fstab
) (FILE *ef
, disk_fs
*dp
);
72 void (*op_mount
) (FILE *ef
, char *hn
, fsmount
*fp
);
76 "aix1", write_aix1_dkfstab
, write_aix1_dkrmount
79 "aix3", write_aix3_dkfstab
, write_aix3_dkrmount
82 "generic", write_generic_dkfstab
, write_generic_dkrmount
85 "u2_0", write_ultrix_dkfstab
, write_ultrix_dkrmount
88 "u3_0", write_ultrix_dkfstab
, write_ultrix_dkrmount
91 "u4_0", write_ultrix_dkfstab
, write_ultrix_dkrmount
99 /* ---------- AIX 1 ------------------------------ */
105 write_aix1_dkfstab(FILE *ef
, disk_fs
*dp
)
107 char *hp
= strdup(dp
->d_host
->h_hostname
);
108 char *p
= strchr(hp
, '.');
113 fprintf(ef
, "\n%s:\n\tdev = %s\n\tvfs = %s\n\ttype = %s\n\tlog = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
126 write_aix1_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
)
128 char *h
= strdup(fp
->f_ref
->m_dk
->d_host
->h_hostname
);
129 char *hp
= strdup(h
);
130 char *p
= strchr(hp
, '.');
135 fprintf(ef
, "\n%s:\n\tsite = %s\n\tdev = %s:%s\n\tvfs = %s\n\ttype = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
150 /* ---------- AIX 3 ------------------------------ */
156 write_aix3_dkfstab(FILE *ef
, disk_fs
*dp
)
158 if (STREQ(dp
->d_fstype
, "jfs") &&
159 NSTREQ(dp
->d_dev
, "/dev/", 5) &&
161 error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
163 fprintf(ef
, "\n%s:\n\tdev = %s\n\tvfs = %s\n\ttype = %s\n\tlog = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
175 write_aix3_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
)
177 char *h
= strdup(fp
->f_ref
->m_dk
->d_host
->h_hostname
);
180 fprintf(ef
, "\n%s:\n\tdev = %s:%s\n\tvfs = %s\n\ttype = %s\n\tvol = %s\n\topts = %s\n\tmount = true\n\tcheck = true\n\tfree = false\n",
193 /* ---------- Ultrix ----------------------------- */
196 write_ultrix_dkfstab(FILE *ef
, disk_fs
*dp
)
198 fprintf(ef
, "%s:%s:%s:%s:%d:%d\n",
209 write_ultrix_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
)
211 char *h
= strdup(fp
->f_ref
->m_dk
->d_host
->h_hostname
);
214 fprintf(ef
, "%s@%s:%s:%s:%s:0:0\n",
224 /* ---------- Generic ---------------------------- */
227 * Generic (BSD, SunOS, HPUX) format
230 write_generic_dkfstab(FILE *ef
, disk_fs
*dp
)
232 fprintf(ef
, "%s %s %s %s %d %d\n",
243 write_generic_dkrmount(FILE *ef
, char *hn
, fsmount
*fp
)
248 h
= strdup(fp
->f_ref
->m_dk
->d_host
->h_hostname
);
250 h
= strdup(fp
->f_from
);
253 fprintf(ef
, "%s:%s %s %s %s 0 0\n",
263 static struct os_fstab_type
*
264 find_fstab_type(host
*hp
)
266 struct os_fstab_type
*op
= NULL
;
267 char *os_name
= NULL
;
271 if (ISSET(hp
->h_mask
, HF_OS
))
274 os_name
= GENERIC_OS_NAME
;
276 for (op
= os_tabs
; op
->os_name
; op
++)
277 if (STREQ(os_name
, op
->os_name
))
280 os_name
= GENERIC_OS_NAME
;
286 write_dkfstab(FILE *ef
, qelem
*q
, void (*output
) (FILE *, disk_fs
*))
292 if (!STREQ(dp
->d_fstype
, "export"))
300 write_dkrmount(FILE *ef
, qelem
*q
, char *hn
, void (*output
) (FILE *, char *, fsmount
*))
306 (*output
) (ef
, hn
, fp
);
313 write_fstab(qelem
*q
)
320 show_area_being_processed("write fstab", 4);
322 if (hp
->h_disk_fs
|| hp
->h_mount
) {
323 FILE *ef
= pref_open(fstab_pref
, hp
->h_hostname
, gen_hdr
, hp
->h_hostname
);
325 struct os_fstab_type
*op
= find_fstab_type(hp
);
326 show_new(hp
->h_hostname
);
328 errors
+= write_dkfstab(ef
, hp
->h_disk_fs
, op
->op_fstab
);
330 fsi_log("No local disk mounts on %s", hp
->h_hostname
);
333 errors
+= write_dkrmount(ef
, hp
->h_mount
, hp
->h_hostname
, op
->op_mount
);
338 error("no disk mounts on %s", hp
->h_hostname
);