home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / amd / fsinfo / wr_fstab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-12  |  7.3 KB  |  304 lines

  1. /*
  2.  * Copyright (c) 1989 Jan-Simon Pendry
  3.  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
  4.  * Copyright (c) 1989 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Jan-Simon Pendry at Imperial College, London.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)wr_fstab.c    5.3 (Berkeley) 5/12/91
  39.  *
  40.  * $Id: wr_fstab.c,v 5.2.1.3 91/05/07 22:19:14 jsp Alpha $
  41.  *
  42.  */
  43.  
  44. #include "../fsinfo/fsinfo.h"
  45.  
  46. /* ---------- AIX 1 ------------------------------ */
  47.  
  48. /*
  49.  * AIX 1 format
  50.  */
  51. static void write_aix1_dkfstab(ef, dp)
  52. FILE *ef;
  53. disk_fs *dp;
  54. {
  55.     char *hp = strdup(dp->d_host->h_hostname);
  56.     char *p = strchr(hp, '.');
  57.     if (p)
  58.         *p = '\0';
  59.  
  60.     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",
  61.         dp->d_mountpt,
  62.         dp->d_dev,
  63.         dp->d_fstype,
  64.         dp->d_fstype,
  65.         dp->d_log,
  66.         dp->d_mountpt,
  67.         dp->d_opts);
  68.     free(hp);
  69. }
  70.  
  71. static void write_aix1_dkrmount(ef, hn, fp)
  72. FILE *ef;
  73. char *hn;
  74. fsmount *fp;
  75. {
  76.     char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
  77.     char *hp = strdup(h);
  78.     char *p = strchr(hp, '.');
  79.     if (p)
  80.         *p = '\0';
  81.     domain_strip(h, hn);
  82.     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",
  83.         fp->f_localname,
  84.         hp,
  85.         h,
  86.         fp->f_volname,
  87.         fp->f_fstype,
  88.         fp->f_fstype,
  89.         fp->f_localname,
  90.         fp->f_opts);
  91.  
  92.     free(hp);
  93.     free(h);
  94. }
  95.  
  96. /* ---------- AIX 3 ------------------------------ */
  97.  
  98. /*
  99.  * AIX 3 format
  100.  */
  101. static void write_aix3_dkfstab(ef, dp)
  102. FILE *ef;
  103. disk_fs *dp;
  104. {
  105.     if (strcmp(dp->d_fstype, "jfs") == 0 && strncmp(dp->d_dev, "/dev/", 5) == 0 && !dp->d_log)
  106.         error("aix 3 needs a log device for journalled filesystem (jfs) mounts");
  107.  
  108.     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",
  109.         dp->d_mountpt,
  110.         dp->d_dev,
  111.         dp->d_fstype,
  112.         dp->d_fstype,
  113.         dp->d_log,
  114.         dp->d_mountpt,
  115.         dp->d_opts);
  116. }
  117.  
  118. static void write_aix3_dkrmount(ef, hn, fp)
  119. FILE *ef;
  120. char *hn;
  121. fsmount *fp;
  122. {
  123.     char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
  124.     domain_strip(h, hn);
  125.     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",
  126.         fp->f_localname,
  127.         h,
  128.         fp->f_volname,
  129.         fp->f_fstype,
  130.         fp->f_fstype,
  131.         fp->f_localname,
  132.         fp->f_opts);
  133.  
  134.     free(h);
  135. }
  136.  
  137. /* ---------- Ultrix ----------------------------- */
  138.  
  139. static void write_ultrix_dkfstab(ef, dp)
  140. FILE *ef;
  141. disk_fs *dp;
  142. {
  143.     fprintf(ef, "%s:%s:%s:%s:%d:%d\n",
  144.         dp->d_dev,
  145.         dp->d_mountpt,
  146.         dp->d_fstype,
  147.         dp->d_opts,
  148.         dp->d_freq,
  149.         dp->d_passno);
  150. }
  151.  
  152. static void write_ultrix_dkrmount(ef, hn, fp)
  153. FILE *ef;
  154. char *hn;
  155. fsmount *fp;
  156. {
  157.     char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
  158.     domain_strip(h, hn);
  159.     fprintf(ef, "%s@%s:%s:%s:%s:0:0\n",
  160.         fp->f_volname,
  161.         h,
  162.         fp->f_localname,
  163.         fp->f_fstype,
  164.         fp->f_opts);
  165.     free(h);
  166. }
  167.  
  168. /* ---------- Generic ---------------------------- */
  169.  
  170. /*
  171.  * Generic (BSD, SunOS, HPUX) format
  172.  */
  173. static void write_generic_dkfstab(ef, dp)
  174. FILE *ef;
  175. disk_fs *dp;
  176. {
  177.     fprintf(ef, "%s %s %s %s %d %d\n",
  178.         dp->d_dev,
  179.         dp->d_mountpt,
  180.         dp->d_fstype,
  181.         dp->d_opts,
  182.         dp->d_freq,
  183.         dp->d_passno);
  184. }
  185.  
  186. static void write_generic_dkrmount(ef, hn, fp)
  187. FILE *ef;
  188. char *hn;
  189. fsmount *fp;
  190. {
  191.     char *h = strdup(fp->f_ref->m_dk->d_host->h_hostname);
  192.     domain_strip(h, hn);
  193.     fprintf(ef, "%s:%s %s %s %s 0 0\n",
  194.         h,
  195.         fp->f_volname,
  196.         fp->f_localname,
  197.         fp->f_fstype,
  198.         fp->f_opts);
  199.     free(h);
  200. }
  201.  
  202. /* ----------------------------------------------- */
  203.  
  204. static struct os_fstab_type {
  205.     char *os_name;
  206.     void (*op_fstab)();
  207.     void (*op_mount)();
  208. } os_tabs[] = {
  209.     { "aix1", write_aix1_dkfstab, write_aix1_dkrmount },        /* AIX 1 */
  210.     { "aix3", write_aix3_dkfstab, write_aix3_dkrmount },        /* AIX 3 */
  211.     { "generic", write_generic_dkfstab, write_generic_dkrmount },    /* Generic */
  212.     { "u2_0", write_ultrix_dkfstab, write_ultrix_dkrmount },    /* Ultrix */
  213.     { "u3_0", write_ultrix_dkfstab, write_ultrix_dkrmount },    /* Ultrix */
  214.     { "u4_0", write_ultrix_dkfstab, write_ultrix_dkrmount },    /* Ultrix */
  215.     { 0, 0, 0 }
  216. };
  217.  
  218. #define    GENERIC_OS_NAME "generic"
  219.  
  220. static struct os_fstab_type *find_fstab_type(hp)
  221. host *hp;
  222. {
  223.     struct os_fstab_type *op = 0;
  224.     char *os_name = 0;
  225.  
  226. again:;
  227.     if (os_name == 0) {
  228.         if (ISSET(hp->h_mask, HF_OS))
  229.             os_name = hp->h_os;
  230.         else
  231.             os_name = GENERIC_OS_NAME;
  232.     }
  233.  
  234.     for (op = os_tabs; op->os_name; op++)
  235.         if (strcmp(os_name, op->os_name) == 0)
  236.             return op;
  237.  
  238.     os_name = GENERIC_OS_NAME;
  239.     goto again;
  240. }
  241.  
  242. static int write_dkfstab(ef, q, output)
  243. FILE *ef;
  244. qelem *q;
  245. void (*output)();
  246. {
  247.     int errors = 0;
  248.     disk_fs *dp;
  249.  
  250.     ITER(dp, disk_fs, q)
  251.         if (strcmp(dp->d_fstype, "export") != 0)
  252.             (*output)(ef, dp);
  253.  
  254.     return errors;
  255. }
  256.  
  257. static int write_dkrmount(ef, q, hn, output)
  258. FILE *ef;
  259. qelem *q;
  260. char *hn;
  261. void (*output)();
  262. {
  263.     int errors = 0;
  264.     fsmount *fp;
  265.  
  266.     ITER(fp, fsmount, q)
  267.         (*output)(ef, hn, fp);
  268.  
  269.     return errors;
  270. }
  271.  
  272. int write_fstab(q)
  273. qelem *q;
  274. {
  275.     int errors = 0;
  276.  
  277.     if (fstab_pref) {
  278.         host *hp;
  279.         show_area_being_processed("write fstab", 4);
  280.         ITER(hp, host, q) {
  281.             if (hp->h_disk_fs || hp->h_mount) {
  282.                 FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
  283.                 if (ef) {
  284.                     struct os_fstab_type *op = find_fstab_type(hp);
  285.                     show_new(hp->h_hostname);
  286.                     if (hp->h_disk_fs)
  287.                         errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
  288.                     else
  289.                         log("No local disk mounts on %s", hp->h_hostname);
  290.  
  291.                     if (hp->h_mount)
  292.                         errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);
  293.  
  294.                     pref_close(ef);
  295.                 }
  296.             } else {
  297.                 error("no disk mounts on %s", hp->h_hostname);
  298.             }
  299.         }
  300.     }
  301.  
  302.     return errors;
  303. }
  304.