* $Id: amq.c,v 5.2 90/06/23 22:20:07 jsp Rel $
* 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.
* %sccs.include.redist.c%
@(#)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 90/06/23 22:20:07 jsp Rel $";
static char sccsid
[] = "@(#)amq.c 5.1 (Berkeley) %G%";
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(&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(&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
;
progname
= strrchr(argv
[0], '/');
if (progname
&& progname
[1])
while ((opt_ch
= getopt(argc
, argv
, "fh:l:msux:D:")) != EOF
)
Usage: %s [-h host] [[-f] [-m] | | [-s] | [[-u] directory ...]] |\n\
\t[-l logfile|\"syslog\"] [-x log_flags] [-D dbg_opts]\n", progname
);
* Figure out root server of cluster
if (def_server
== localhost
)
server
= cluster_server();
if ((hp
= gethostbyname(server
)) == 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
;
server_addr
.sin_addr
= *(struct in_addr
*) hp
->h_addr
;
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
);
rc
= amqproc_setopt_1(&opt
, clnt
);
fprintf(stderr
, "%s: setting log level to \"%s\" failed\n", progname
, xlog_opt
);
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
);
* 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("\t%s\n%-*.*s %-*.*s %-*.*s %s\n",
"Uid Getattr Lookup RdDir RdLnk Statfs Mounted@",
dwid
, dwid
, "What", twid
, twid
, "Type", mwid
, mwid
, "Info", "Where");
show_mt(mt
, Full
, &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
);