147491Spendry /* 247491Spendry * $Id: wr_fstab.c,v 5.2.1.2 90/12/21 16:46:52 jsp Alpha $ 347491Spendry * 447491Spendry * Copyright (c) 1989 Jan-Simon Pendry 547491Spendry * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 647491Spendry * Copyright (c) 1989 The Regents of the University of California. 747491Spendry * All rights reserved. 847491Spendry * 947491Spendry * This code is derived from software contributed to Berkeley by 1047491Spendry * Jan-Simon Pendry at Imperial College, London. 1147491Spendry * 12*47530Spendry * %sccs.include.redist.c% 1347491Spendry * 14*47530Spendry * @(#)wr_fstab.c 5.2 (Berkeley) 03/17/91 1547491Spendry */ 1647491Spendry 1747491Spendry #include "../fsinfo/fsinfo.h" 1847491Spendry 1947491Spendry /* ---------- AIX 1 ------------------------------ */ 2047491Spendry 2147491Spendry /* 2247491Spendry * AIX 1 format 2347491Spendry */ 2447491Spendry static void write_aix1_dkfstab(ef, dp) 2547491Spendry FILE *ef; 2647491Spendry disk_fs *dp; 2747491Spendry { 2847491Spendry char *hp = strdup(dp->d_host->h_hostname); 2947491Spendry char *p = strchr(hp, '.'); 3047491Spendry if (p) 3147491Spendry *p = '\0'; 3247491Spendry 3347491Spendry 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", 3447491Spendry dp->d_mountpt, 3547491Spendry dp->d_dev, 3647491Spendry dp->d_fstype, 3747491Spendry dp->d_fstype, 3847491Spendry dp->d_log, 3947491Spendry dp->d_mountpt, 4047491Spendry dp->d_opts); 4147491Spendry free(hp); 4247491Spendry } 4347491Spendry 4447491Spendry static void write_aix1_dkrmount(ef, hn, fp) 4547491Spendry FILE *ef; 4647491Spendry char *hn; 4747491Spendry fsmount *fp; 4847491Spendry { 4947491Spendry char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 5047491Spendry char *hp = strdup(h); 5147491Spendry char *p = strchr(hp, '.'); 5247491Spendry if (p) 5347491Spendry *p = '\0'; 5447491Spendry domain_strip(h, hn); 5547491Spendry 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", 5647491Spendry fp->f_localname, 5747491Spendry hp, 5847491Spendry h, 5947491Spendry fp->f_volname, 6047491Spendry fp->f_fstype, 6147491Spendry fp->f_fstype, 6247491Spendry fp->f_localname, 6347491Spendry fp->f_opts); 6447491Spendry 6547491Spendry free(hp); 6647491Spendry free(h); 6747491Spendry } 6847491Spendry 6947491Spendry /* ---------- AIX 3 ------------------------------ */ 7047491Spendry 7147491Spendry /* 7247491Spendry * AIX 3 format 7347491Spendry */ 7447491Spendry static void write_aix3_dkfstab(ef, dp) 7547491Spendry FILE *ef; 7647491Spendry disk_fs *dp; 7747491Spendry { 7847491Spendry if (strcmp(dp->d_fstype, "jfs") == 0 && strncmp(dp->d_dev, "/dev/", 5) == 0 && !dp->d_log) 7947491Spendry error("aix 3 needs a log device for journalled filesystem (jfs) mounts"); 8047491Spendry 8147491Spendry 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", 8247491Spendry dp->d_mountpt, 8347491Spendry dp->d_dev, 8447491Spendry dp->d_fstype, 8547491Spendry dp->d_fstype, 8647491Spendry dp->d_log, 8747491Spendry dp->d_mountpt, 8847491Spendry dp->d_opts); 8947491Spendry } 9047491Spendry 9147491Spendry static void write_aix3_dkrmount(ef, hn, fp) 9247491Spendry FILE *ef; 9347491Spendry char *hn; 9447491Spendry fsmount *fp; 9547491Spendry { 9647491Spendry char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 9747491Spendry domain_strip(h, hn); 9847491Spendry 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", 9947491Spendry fp->f_localname, 10047491Spendry h, 10147491Spendry fp->f_volname, 10247491Spendry fp->f_fstype, 10347491Spendry fp->f_fstype, 10447491Spendry fp->f_localname, 10547491Spendry fp->f_opts); 10647491Spendry 10747491Spendry free(h); 10847491Spendry } 10947491Spendry 11047491Spendry /* ---------- Ultrix ----------------------------- */ 11147491Spendry 11247491Spendry static void write_ultrix_dkfstab(ef, dp) 11347491Spendry FILE *ef; 11447491Spendry disk_fs *dp; 11547491Spendry { 11647491Spendry fprintf(ef, "%s:%s:%s:%s:%d:%d\n", 11747491Spendry dp->d_dev, 11847491Spendry dp->d_mountpt, 11947491Spendry dp->d_fstype, 12047491Spendry dp->d_opts, 12147491Spendry dp->d_freq, 12247491Spendry dp->d_passno); 12347491Spendry } 12447491Spendry 12547491Spendry static void write_ultrix_dkrmount(ef, hn, fp) 12647491Spendry FILE *ef; 12747491Spendry char *hn; 12847491Spendry fsmount *fp; 12947491Spendry { 13047491Spendry char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 13147491Spendry domain_strip(h, hn); 13247491Spendry fprintf(ef, "%s@%s:%s:%s:%s:0:0\n", 13347491Spendry fp->f_volname, 13447491Spendry h, 13547491Spendry fp->f_localname, 13647491Spendry fp->f_fstype, 13747491Spendry fp->f_opts); 13847491Spendry free(h); 13947491Spendry } 14047491Spendry 14147491Spendry /* ---------- Generic ---------------------------- */ 14247491Spendry 14347491Spendry /* 14447491Spendry * Generic (BSD, SunOS, HPUX) format 14547491Spendry */ 14647491Spendry static void write_generic_dkfstab(ef, dp) 14747491Spendry FILE *ef; 14847491Spendry disk_fs *dp; 14947491Spendry { 15047491Spendry fprintf(ef, "%s %s %s %s %d %d\n", 15147491Spendry dp->d_dev, 15247491Spendry dp->d_mountpt, 15347491Spendry dp->d_fstype, 15447491Spendry dp->d_opts, 15547491Spendry dp->d_freq, 15647491Spendry dp->d_passno); 15747491Spendry } 15847491Spendry 15947491Spendry static void write_generic_dkrmount(ef, hn, fp) 16047491Spendry FILE *ef; 16147491Spendry char *hn; 16247491Spendry fsmount *fp; 16347491Spendry { 16447491Spendry char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname); 16547491Spendry domain_strip(h, hn); 16647491Spendry fprintf(ef, "%s:%s %s %s %s 0 0\n", 16747491Spendry h, 16847491Spendry fp->f_volname, 16947491Spendry fp->f_localname, 17047491Spendry fp->f_fstype, 17147491Spendry fp->f_opts); 17247491Spendry free(h); 17347491Spendry } 17447491Spendry 17547491Spendry /* ----------------------------------------------- */ 17647491Spendry 17747491Spendry static struct os_fstab_type { 17847491Spendry char *os_name; 17947491Spendry void (*op_fstab)(); 18047491Spendry void (*op_mount)(); 18147491Spendry } os_tabs[] = { 18247491Spendry { "aix1", write_aix1_dkfstab, write_aix1_dkrmount }, /* AIX 1 */ 18347491Spendry { "aix3", write_aix3_dkfstab, write_aix3_dkrmount }, /* AIX 3 */ 18447491Spendry { "generic", write_generic_dkfstab, write_generic_dkrmount }, /* Generic */ 18547491Spendry { "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 18647491Spendry { "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 18747491Spendry { "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount }, /* Ultrix */ 18847491Spendry { 0, 0, 0 } 18947491Spendry }; 19047491Spendry 19147491Spendry #define GENERIC_OS_NAME "generic" 19247491Spendry 19347491Spendry static struct os_fstab_type *find_fstab_type(hp) 19447491Spendry host *hp; 19547491Spendry { 19647491Spendry struct os_fstab_type *op = 0; 19747491Spendry char *os_name = 0; 19847491Spendry 19947491Spendry again:; 20047491Spendry if (os_name == 0) { 20147491Spendry if (ISSET(hp->h_mask, HF_OS)) 20247491Spendry os_name = hp->h_os; 20347491Spendry else 20447491Spendry os_name = GENERIC_OS_NAME; 20547491Spendry } 20647491Spendry 20747491Spendry for (op = os_tabs; op->os_name; op++) 20847491Spendry if (strcmp(os_name, op->os_name) == 0) 20947491Spendry return op; 21047491Spendry 21147491Spendry os_name = GENERIC_OS_NAME; 21247491Spendry goto again; 21347491Spendry } 21447491Spendry 21547491Spendry static int write_dkfstab(ef, q, output) 21647491Spendry FILE *ef; 21747491Spendry qelem *q; 21847491Spendry void (*output)(); 21947491Spendry { 22047491Spendry int errors = 0; 22147491Spendry disk_fs *dp; 22247491Spendry 22347491Spendry ITER(dp, disk_fs, q) 22447491Spendry if (strcmp(dp->d_fstype, "export") != 0) 22547491Spendry (*output)(ef, dp); 22647491Spendry 22747491Spendry return errors; 22847491Spendry } 22947491Spendry 23047491Spendry static int write_dkrmount(ef, q, hn, output) 23147491Spendry FILE *ef; 23247491Spendry qelem *q; 23347491Spendry char *hn; 23447491Spendry void (*output)(); 23547491Spendry { 23647491Spendry int errors = 0; 23747491Spendry fsmount *fp; 23847491Spendry 23947491Spendry ITER(fp, fsmount, q) 24047491Spendry (*output)(ef, hn, fp); 24147491Spendry 24247491Spendry return errors; 24347491Spendry } 24447491Spendry 24547491Spendry int write_fstab(q) 24647491Spendry qelem *q; 24747491Spendry { 24847491Spendry int errors = 0; 24947491Spendry 25047491Spendry if (fstab_pref) { 25147491Spendry host *hp; 25247491Spendry show_area_being_processed("write fstab", 4); 25347491Spendry ITER(hp, host, q) { 25447491Spendry if (hp->h_disk_fs || hp->h_mount) { 25547491Spendry FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname); 25647491Spendry if (ef) { 25747491Spendry struct os_fstab_type *op = find_fstab_type(hp); 25847491Spendry show_new(hp->h_hostname); 25947491Spendry if (hp->h_disk_fs) 26047491Spendry errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab); 26147491Spendry else 26247491Spendry log("No local disk mounts on %s", hp->h_hostname); 26347491Spendry 26447491Spendry if (hp->h_mount) 26547491Spendry errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount); 26647491Spendry 26747491Spendry pref_close(ef); 26847491Spendry } 26947491Spendry } else { 27047491Spendry error("no disk mounts on %s", hp->h_hostname); 27147491Spendry } 27247491Spendry } 27347491Spendry } 27447491Spendry 27547491Spendry return errors; 27647491Spendry } 277