* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)wr_atab.c 5.3 (Berkeley) 5/12/91
* $Id: wr_atab.c,v 5.2.1.3 91/05/07 22:19:09 jsp Alpha $
#include "../fsinfo/fsinfo.h"
* Write a sequence of automount mount map entries
static int write_amount_info(af
, ap
, sk
)
* This can also be a top-level directory, in which
* case the type:=auto is not wanted...
* type:=auto;fs:=${map};pref:=whatever/
if (strlen(ap
->a_name
) > sk
) {
fprintf(af
, "%s type:=auto;fs:=${map};pref:=%s/\n",
ap
->a_name
+ sk
, ap
->a_name
+ sk
);
ITER(ap2
, automount
, ap
->a_mount
)
errors
+= write_amount_info(af
, ap2
, sk
);
} else if (ap
->a_mounted
) {
* type:=link [ link entries ] type:=nfs [ nfs entries ]
dict_ent
*de
= ap
->a_mounted
;
char *key
= ap
->a_name
+ sk
;
* First output any Link locations that would not
* otherwise be correctly mounted. These refer
* to filesystem which are not mounted in the same
* place which the automounter would use.
ITER(dd
, dict_data
, &de
->de_q
) {
mount
*mp
= (mount
*) dd
->dd_data
;
* If the mount point and the exported volname are the
* same then this filesystem will be recognised by
* the restart code - so we don't need to put out a
if (mp
->m_dk
->d_host
->h_lochost
) {
compute_automount_point(amountpt
, mp
->m_dk
->d_host
, mp
->m_exported
->m_volname
);
if (strcmp(mp
->m_dk
->d_mountpt
, amountpt
) != 0) {
* ap->a_volname is the name of the aliased volume
* mp->m_name is the mount point of the filesystem
* mp->m_volname is the volume name of the filesystems
* Find length of key and volume names
int avlen
= strlen(ap
->a_volname
);
int mnlen
= strlen(mp
->m_volname
);
* Make sure a -type:=link is output once
fputs(" -type:=link", af
);
* Output a selector for the hostname,
* the device from which to mount and
* where to mount. This will correspond
* to the values output for the fstab.
if (mp
->m_dk
->d_host
->h_lochost
)
fprintf(af
, " host==%s", mp
->m_dk
->d_host
->h_lochost
);
fprintf(af
, " hostd==%s", mp
->m_dk
->d_host
->h_hostname
);
fprintf(af
, ";fs:=%s", mp
->m_name
);
* ... and a sublink if needed
char *sublink
= ap
->a_volname
+ mnlen
+ 1;
fprintf(af
, "/%s", sublink
);
* Next do the NFS locations
ITER(dd
, dict_data
, &de
->de_q
) {
mount
*mp
= (mount
*) dd
->dd_data
;
int namelen
= mp
->m_name_len
;
int exp_namelen
= mp
->m_exported
->m_name_len
;
int volnlen
= strlen(ap
->a_volname
);
int mvolnlen
= strlen(mp
->m_volname
);
fprintf(af
, "\\\n /* avolname = %s, mname = %s,\n * mvolname = %s, mexp_name = %s,\n * mexp_volname = %s\n */\\\n",
ap
->a_volname
, mp
->m_name
, mp
->m_volname
, mp
->m_exported
->m_name
, mp
->m_exported
->m_volname
);
fprintf(af
, "%s;", mp
->m_sel
);
* Print host and volname of exported filesystem
mp
->m_dk
->d_host
->h_lochost
?
mp
->m_dk
->d_host
->h_lochost
:
mp
->m_dk
->d_host
->h_hostname
);
fprintf(af
, ";rfs:=%s", mp
->m_exported
->m_volname
);
* Now determine whether a sublink is required.
if (exp_namelen
< namelen
|| mvolnlen
< volnlen
) {
if (exp_namelen
< namelen
) {
strcat(sublink
, mp
->m_name
+ exp_namelen
+ 1);
strcat(sublink
, ap
->a_volname
+ mvolnlen
+ 1);
fprintf(af
, ";sublink:=%s", sublink
);
} else if (ap
->a_symlink
) {
* type:=link;fs:=whatever
fprintf(af
, "%s type:=link;fs:=%s\n", ap
->a_name
+ sk
, ap
->a_symlink
);
* Write a single automount configuration file
static int write_amount(q
, def
)
* Output all indirect maps
* If there is no a_mount node then this is really
* a direct mount, so just keep a count and continue.
* Direct mounts are output into a special file during
p
= strrchr(ap
->a_name
, '/');
af
= pref_open(mount_pref
, p
, gen_hdr
, ap
->a_name
);
fputs("type:=nfs\n", af
);
errors
+= write_amount_info(af
, ap
, strlen(ap
->a_name
) + 1);
errors
+= pref_close(af
);
* Output any direct map entries which were found during the
* previous pass over the data.
FILE *af
= pref_open(mount_pref
, "direct.map", info_hdr
, "direct mount");
show_new("direct mounts");
fputs("type:=nfs\n", af
);
errors
+= write_amount_info(af
, ap
, 1);
errors
+= pref_close(af
);
* Write all the needed automount configuration files
show_area_being_processed("write automount", "");
errors
+= write_amount(tp
->t_mount
, tp
->t_defaults
);