* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 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
* @(#)amq.c 5.3 (Berkeley) 5/12/91
* $Id: amq.c,v 5.2.1.5 91/05/07 22:18:45 jsp Alpha $
@(#)Copyright (c) 1990 Jan-Simon Pendry\n\
@(#)Copyright (c) 1990 Imperial College of Science, Technology & Medicine\n\
@(#)Copyright (c) 1990 The Regents of the University of California.\n\
@(#)All rights reserved.\n";
static char rcsid
[] = "$Id: amq.c,v 5.2.1.5 91/05/07 22:18:45 jsp Alpha $";
static char sccsid
[] = "@(#)amq.c 5.3 (Berkeley) 5/12/91";
static char *xlog_optstr
;
static char localhost
[] = "localhost";
static char *def_server
= localhost
;
static struct timeval tmo
= { 10, 0 };
enum show_opt
{ Full
, Stats
, Calc
, Short
, ShowDone
};
* If (e) is Calc then just calculate the sizes
* Otherwise display the mount node on stdout
static void show_mti(mt
, e
, mwid
, dwid
, twid
)
int mw
= strlen(mt
->mt_mountinfo
);
int dw
= strlen(mt
->mt_directory
);
int tw
= strlen(mt
->mt_type
);
if (mw
> *mwid
) *mwid
= mw
;
if (dw
> *dwid
) *dwid
= dw
;
if (tw
> *twid
) *twid
= tw
;
struct tm
*tp
= localtime((time_t *) &mt
->mt_mounttime
);
printf("%-*.*s %-*.*s %-*.*s %s\n\t%-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n",
*mt
->mt_directory
? mt
->mt_directory
: "/", /* XXX */
tp
->tm_year
> 99 ? tp
->tm_year
- 100 : tp
->tm_year
,
tp
->tm_mon
+1, tp
->tm_mday
,
tp
->tm_hour
, tp
->tm_min
, tp
->tm_sec
);
struct tm
*tp
= localtime((time_t *) &mt
->mt_mounttime
);
printf("%-*.*s %-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n",
*mt
->mt_directory
? mt
->mt_directory
: "/", /* XXX */
tp
->tm_year
> 99 ? tp
->tm_year
- 100 : tp
->tm_year
,
tp
->tm_mon
+1, tp
->tm_mday
,
tp
->tm_hour
, tp
->tm_min
, tp
->tm_sec
);
printf("%-*.*s %-*.*s %-*.*s %s\n",
*mt
->mt_directory
? mt
->mt_directory
: "/",
static void show_mt(mt
, e
, mwid
, dwid
, pwid
)
show_mti(mt
, e
, mwid
, dwid
, pwid
);
show_mt(mt
->mt_next
, e
, mwid
, dwid
, pwid
);
static void show_mi(ml
, e
, mwid
, dwid
, twid
)
for (i
= 0; i
< ml
->amq_mount_info_list_len
; i
++) {
amq_mount_info
*mi
= &ml
->amq_mount_info_list_val
[i
];
int mw
= strlen(mi
->mi_mountinfo
);
int dw
= strlen(mi
->mi_mountpt
);
int tw
= strlen(mi
->mi_type
);
if (mw
> *mwid
) *mwid
= mw
;
if (dw
> *dwid
) *dwid
= dw
;
if (tw
> *twid
) *twid
= tw
;
for (i
= 0; i
< ml
->amq_mount_info_list_len
; i
++) {
amq_mount_info
*mi
= &ml
->amq_mount_info_list_val
[i
];
printf("%-*.*s %-*.*s %-*.*s %-3d %s is %s",
*mwid
, *mwid
, mi
->mi_mountinfo
,
*dwid
, *dwid
, mi
->mi_mountpt
,
*twid
, *twid
, mi
->mi_type
,
mi
->mi_refc
, mi
->mi_fserver
,
mi
->mi_up
< 0 ? "starting" : "down");
extern char *sys_errlist
[];
if (mi
->mi_error
< sys_nerr
)
printf(" (%s)", sys_errlist
[mi
->mi_error
]);
printf(" (Error %d)", mi
->mi_error
);
} else if (mi
->mi_error
< 0) {
fputs(" (in progress)", stdout
);
* Display general mount statistics
requests stale mount mount unmount\n\
deferred fhandles ok failed failed\n\
%-9d %-9d %-9d %-9d %-9d\n",
ms
->as_drops
, ms
->as_stale
, ms
->as_mok
, ms
->as_merr
, ms
->as_uerr
);
xdr_pri_free(xdr_args
, args_ptr
)
return ((*xdr_args
)(&xdr
, args_ptr
));
static char *cluster_server()
if (cp
->cnode_type
== 'r')
struct sockaddr_in server_addr
;
/* In order to pass the Amd security check, we must use a priv port. */
progname
= strrchr(argv
[0], '/');
if (progname
&& progname
[1])
while ((opt_ch
= getopt(argc
, argv
, "fh:l:msuvx:D:M:")) != EOF
)
Usage: %s [-h host] [[-f] [-m] [-v] [-s]] | [[-u] directory ...]] |\n\
\t[-l logfile|\"syslog\"] [-x log_flags] [-D dbg_opts] [-M mapent]\n", progname
);
* Figure out root server of cluster
if (def_server
== localhost
)
server
= cluster_server();
if ((hp
= gethostbyname(server
)) == 0 && strcmp(server
, localhost
) != 0) {
fprintf(stderr
, "%s: Can't get address of %s\n", progname
, server
);
bzero(&server_addr
, sizeof server_addr
);
server_addr
.sin_family
= AF_INET
;
bcopy((voidp
) hp
->h_addr
, (voidp
) &server_addr
.sin_addr
,
sizeof(server_addr
.sin_addr
));
server_addr
.sin_addr
.s_addr
= htonl(0x7f000001);
clnt
= clntudp_create(&server_addr
, AMQ_PROGRAM
, AMQ_VERSION
, TIMEOUT
, &s
);
fprintf(stderr
, "%s: ", progname
);
clnt_pcreateerror(server
);
opt
.as_opt
= AMOPT_DEBUG
;
rc
= amqproc_setopt_1(&opt
, clnt
);
fprintf(stderr
, "%s: daemon not compiled for debug", progname
);
} else if (!rc
|| *rc
> 0) {
fprintf(stderr
, "%s: debug setting for \"%s\" failed\n", progname
, debug_opts
);
opt
.as_str
= xlog_optstr
;
rc
= amqproc_setopt_1(&opt
, clnt
);
fprintf(stderr
, "%s: setting log level to \"%s\" failed\n", progname
, xlog_optstr
);
opt
.as_opt
= AMOPT_LOGFILE
;
rc
= amqproc_setopt_1(&opt
, clnt
);
fprintf(stderr
, "%s: setting logfile to \"%s\" failed\n", progname
, logfile
);
opt
.as_opt
= AMOPT_FLUSHMAPC
;
rc
= amqproc_setopt_1(&opt
, clnt
);
fprintf(stderr
, "%s: amd on %s cannot flush the map cache\n", progname
, server
);
amq_mount_info_list
*ml
= amqproc_getmntfs_1(&dummy
, clnt
);
int mwid
= 0, dwid
= 0, twid
= 0;
show_mi(ml
, Calc
, &mwid
, &dwid
, &twid
);
show_mi(ml
, Full
, &mwid
, &dwid
, &twid
);
fprintf(stderr
, "%s: amd on %s cannot provide mount info\n", progname
, server
);
rc
= amqproc_mount_1(&mount_map
, clnt
);
fprintf(stderr
, "%s: could not start new ", progname
);
perror("autmount point");
amq_string
*spp
= amqproc_getvers_1((voidp
) 0, clnt
);
fprintf(stderr
, "%s: failed to get version information\n", progname
);
* Apply required operation to all remaining arguments
char *fs
= argv
[optind
++];
amqproc_umnt_1(&fs
, clnt
);
amq_mount_tree_p
*mtp
= amqproc_mnttree_1(&fs
, clnt
);
amq_mount_tree
*mt
= *mtp
;
int mwid
= 0, dwid
= 0, twid
= 0;
show_mt(mt
, Calc
, &mwid
, &dwid
, &twid
);
printf("%-*.*s Uid Getattr Lookup RdDir RdLnk Statfs Mounted@\n",
show_mt(mt
, Stats
, &mwid
, &dwid
, &twid
);
fprintf(stderr
, "%s: %s not automounted\n", progname
, fs
);
xdr_pri_free(xdr_amq_mount_tree_p
, (caddr_t
) mtp
);
fprintf(stderr
, "%s: ", progname
);
clnt_perror(clnt
, server
);
} else if (unmount_flag
) {
amq_mount_stats
*ms
= amqproc_stats_1((voidp
) 0, clnt
);
fprintf(stderr
, "%s: ", progname
);
clnt_perror(clnt
, server
);
amq_mount_tree_list
*mlp
= amqproc_export_1((voidp
) 0, clnt
);
int mwid
= 0, dwid
= 0, pwid
= 0;
for (i
= 0; i
< mlp
->amq_mount_tree_list_len
; i
++) {
show_mt(mlp
->amq_mount_tree_list_val
[i
],
if (e
== Calc
) e
= Short
;
else if (e
== Short
) e
= ShowDone
;
fprintf(stderr
, "%s: ", progname
);
clnt_perror(clnt
, server
);
* udpresport creates a datagram socket and attempts to bind it to a
* returns: The bound socket, or -1 to indicate an error.
/* Use internet address family */
addr
.sin_family
= AF_INET
;
addr
.sin_addr
.s_addr
= INADDR_ANY
;
if ((sock
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
)) < 0)
for (alport
= IPPORT_RESERVED
-1; alport
> IPPORT_RESERVED
/2 + 1; alport
--) {
addr
.sin_port
= htons((u_short
)alport
);
if (bind(sock
, (struct sockaddr
*)&addr
, sizeof (addr
)) >= 0)
if (errno
!= EADDRINUSE
) {
* Privsock() calls udpresport() to attempt to bind a socket to a secure
* port. If udpresport() fails, privsock returns a magic socket number which
* indicates to RPC that it should make its own socket.
* returns: A privileged socket # or RPC_ANYSOCK.
/* Couldn't get a secure port, let RPC make an insecure one */