/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/stds.h>
+#include <roken.h>
+#include <ctype.h>
+#include <assert.h>
#include <afs/afs_consts.h>
#include <afs/afs_args.h>
#include <rx/xdr.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <errno.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <netinet/in.h>
-#include <sys/stat.h>
-#include <afs/stds.h>
#include <afs/vice.h>
#include <afs/venus.h>
#include <afs/com_err.h>
#include <afs/afs_consts.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
-
-#include <string.h>
#undef VIRTUE
#undef VICE
#include <afs/volser.h>
#include <afs/vlserver.h>
#include <afs/cmd.h>
-#include <afs/afsutil.h>
#include <afs/com_err.h>
-#include <stdlib.h>
-#include <assert.h>
#include <afs/ptclient.h>
#include <afs/ptuser.h>
#include <afs/afsutil.h>
return tspace;
}
-enum rtype { add, destroy, deny };
+ /* added relative add resp. delete */
+ /* (so old add really means to set) */
+enum rtype { add, destroy, deny, reladd, reldel };
static afs_int32
Convert(char *arights, int dfs, enum rtype *rtypep)
{
- int i, len;
afs_int32 mode;
char tc;
+ char *tcp; /* to walk through the rights string */
*rtypep = add; /* add rights, by default */
+ /* analyze last character of string */
+ tcp = arights + strlen(arights);
+ if ( tcp-- > arights ) { /* assure non-empty string */
+ if ( *tcp == '+' )
+ *rtypep = reladd; /* '+' indicates more rights */
+ else if ( *tcp == '-' )
+ *rtypep = reldel; /* '-' indicates less rights */
+ else if ( *tcp == '=' )
+ *rtypep = add; /* '=' also allows old behaviour */
+ else
+ tcp++; /* back to original null byte */
+ *tcp = '\0'; /* do not disturb old strcmp-s */
+ }
+
if (dfs) {
if (!strcmp(arights, "null")) {
*rtypep = deny;
*rtypep = destroy; /* Remove entire entry */
return 0;
}
- len = strlen(arights);
mode = 0;
- for (i = 0; i < len; i++) {
- tc = *arights++;
+ tcp = arights;
+ while ((tc = *tcp++ )) {
if (dfs) {
if (tc == '-')
continue;
}
static void
-ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
+ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights,
+ enum rtype *artypep)
{
struct AclEntry *tlist;
tlist = (plus ? al->pluslist : al->minuslist);
tlist = FindList(tlist, aname);
if (tlist) {
- /* Found the item already in the list. */
- tlist->rights = arights;
+ /* Found the item already in the list.
+ * modify rights in case of reladd and reladd only,
+ * use standard - add, ie. set - otherwise
+ */
+ if ( artypep == NULL )
+ tlist->rights = arights;
+ else if ( *artypep == reladd )
+ tlist->rights |= arights;
+ else if ( *artypep == reldel )
+ tlist->rights &= ~arights;
+ else
+ tlist->rights = arights;
+
if (plus)
al->nplus -= PruneList(&al->pluslist, al->dfs);
else
al->nminus -= PruneList(&al->minuslist, al->dfs);
return;
}
+ if ( artypep != NULL && *artypep == reldel )
+ return; /* can't reduce non-existing rights */
+
/* Otherwise we make a new item and plug in the new data. */
tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
assert(tlist);
return 0;
}
+static const char power_letter[] = {
+ 'K', /* kibi */
+ 'M', /* mebi */
+ 'G', /* gibi */
+ 'T', /* tebi */
+ 'P', /* pebi */
+};
+
+static void
+HumanPrintSpace(afs_int32 int_space)
+{
+ int exponent = 0;
+ int exponent_max = sizeof(power_letter) - 1;
+ float space = int_space;
+
+ while (space >= 1024 && exponent < exponent_max) {
+ exponent++;
+ space /= 1024;
+ }
+ printf("%9.1f%c", space, power_letter[exponent]);
+}
+
static int
-QuickPrintStatus(VolumeStatus * status, char *name)
+QuickPrintStatus(VolumeStatus * status, char *name, int human)
{
double QuotaUsed = 0.0;
double PartUsed = 0.0;
printf("%-25.25s", name);
if (status->MaxQuota != 0) {
- printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
+ if (human) {
+ printf(" ");
+ HumanPrintSpace(status->MaxQuota);
+ printf(" ");
+ HumanPrintSpace(status->BlocksInUse);
+ }
+ else
+ printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
QuotaUsed =
((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
} else {
- printf(" no limit %10d", status->BlocksInUse);
+ printf(" no limit ");
+ if (human)
+ HumanPrintSpace(status->BlocksInUse);
+ else
+ printf("%10d", status->BlocksInUse);
}
if (QuotaUsed > 90.0) {
printf("%5.0f%%<<", QuotaUsed);
}
static int
-QuickPrintSpace(VolumeStatus * status, char *name)
+QuickPrintSpace(VolumeStatus * status, char *name, int human)
{
double PartUsed = 0.0;
int WARN = 0;
printf("%-25.25s", name);
- printf("%10d%10d%10d", status->PartMaxBlocks,
- status->PartMaxBlocks - status->PartBlocksAvail,
- status->PartBlocksAvail);
+ if (human) {
+ HumanPrintSpace(status->PartMaxBlocks);
+ HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
+ HumanPrintSpace(status->PartBlocksAvail);
+ }
+ else
+ printf("%10d%10d%10d", status->PartMaxBlocks,
+ status->PartMaxBlocks - status->PartBlocksAvail,
+ status->PartBlocksAvail);
PartUsed =
(100.0 -
plusp = 0;
if (rtype == destroy && ta->dfs)
rights = -1;
- ChangeList(ta, plusp, ui->data, rights);
+ ChangeList(ta, plusp, ui->data, rights, &rtype);
}
blob.in = AclToString(ta);
blob.out_size = 0;
}
strcpy(ta->cell, fa->cell);
}
+ /* NULL rtype for standard handling */
for (tp = fa->pluslist; tp; tp = tp->next)
- ChangeList(ta, 1, tp->name, tp->rights);
+ ChangeList(ta, 1, tp->name, tp->rights, NULL);
for (tp = fa->minuslist; tp; tp = tp->next)
- ChangeList(ta, 0, tp->name, tp->rights);
+ ChangeList(ta, 0, tp->name, tp->rights, NULL);
blob.in = AclToString(ta);
blob.out_size = 0;
blob.in_size = 1 + strlen(blob.in);
return error;
}
-/*
+/*
* The Windows version of UuidCmd displays the UUID.
* When the UNIX version is updated to do the same
* be sure to replace the CMD_REQUIRED flag with
- * CMD_OPTIONAL in the cmd_AddParam(-generate) call
+ * CMD_OPTIONAL in the cmd_AddParam(-generate) call
*/
static int
UuidCmd(struct cmd_syndesc *as, void *arock)
blob.in_size = 0;
blob.out_size = 0;
-
+
if (as->parms[0].items) {
if (geteuid()) {
fprintf (stderr, "Permission denied: requires root access.\n");
* With a threshold of 0, the cache is always bypassed. With a threshold of -1,
* cache bypass is disabled.
*/
-
+
static int
BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
{
afs_int32 code;
struct ViceIoctl blob;
afs_int32 threshold_i, threshold_o;
- char *tp;
-
+ char *tp;
+
/* if new threshold supplied, then set and confirm, else,
* get current threshold and print
*/
-
+
if(as->parms[0].items) {
int digit, ix, len;
-
+
tp = as->parms[0].items->data;
len = strlen(tp);
- digit = 1;
- for(ix = 0; ix < len; ++ix) {
- if(!isdigit(tp[0])) {
- digit = 0;
- break;
- }
- }
- if (digit == 0) {
- fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
- return EINVAL;
- }
- threshold_i = atoi(tp);
- if(ix > 9 && threshold_i < 2147483647)
- threshold_i = 2147483647;
- blob.in = (char *) &threshold_i;
- blob.in_size = sizeof(threshold_i);
+
+ if (!strcmp(tp,"-1")) {
+ threshold_i = -1;
+ } else {
+ digit = 1;
+ for(ix = 0; ix < len; ++ix) {
+ if(!isdigit(tp[0])) {
+ digit = 0;
+ break;
+ }
+ }
+ if (digit == 0) {
+ fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
+ return EINVAL;
+ }
+ threshold_i = atoi(tp);
+ if(ix > 9 && threshold_i < 2147483647)
+ threshold_i = 2147483647;
+ }
+ blob.in = (char *) &threshold_i;
+ blob.in_size = sizeof(threshold_i);
} else {
blob.in = NULL;
blob.in_size = 0;
if (code) {
Die(errno, NULL);
return 1;
- } else {
+ } else {
printf("Cache bypass threshold %d", threshold_o);
if(threshold_o == -1)
printf(" (disabled)");
struct VolumeStatus *status;
char *name;
int error = 0;
+ int human = 0;
+
+ if (as->parms[1].items)
+ human = 1;
printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
" Used", " %Used", " Partition");
}
status = (VolumeStatus *) space;
name = (char *)status + sizeof(*status);
- QuickPrintStatus(status, name);
+ QuickPrintStatus(status, name, human);
}
return error;
}
char *name;
struct VolumeStatus *status;
int error = 0;
+ int human = 0;
+
+ if (as->parms[1].items)
+ human = 1;
- printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
- " used", " avail", " %used");
+ printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
+ human ? "total" : "kbytes", "used", "avail", "%used");
SetDotDefault(&as->parms[0].items);
for (ti = as->parms[0].items; ti; ti = ti->next) {
/* once per file */
}
status = (VolumeStatus *) space;
name = (char *)status + sizeof(*status);
- QuickPrintSpace(status, name);
+ QuickPrintSpace(status, name, human);
}
return error;
}
}
static int
-ListMountCmd(struct cmd_syndesc *as, void *arock)
+GetLastComponent(const char *data, char **outdir, char **outbase,
+ int *thru_symlink)
{
- afs_int32 code;
- struct ViceIoctl blob;
- struct cmd_item *ti;
char orig_name[1024]; /*Original name, may be modified */
char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
- char parent_dir[1024]; /*Parent directory of true name */
- char *last_component; /*Last component of true name */
+ char *lastSlash;
struct stat statbuff; /*Buffer for status info */
int link_chars_read; /*Num chars read in readlink() */
- int thru_symlink; /*Did we get to a mount point via a symlink? */
- int error = 0;
+ char *dirname = NULL;
+ char *basename = NULL;
- for (ti = as->parms[0].items; ti; ti = ti->next) {
- /* once per file */
- thru_symlink = 0;
- sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
- ti->data);
+ if (thru_symlink)
+ *thru_symlink = 0;
- if (lstat(orig_name, &statbuff) < 0) {
- /* if lstat fails, we should still try the pioctl, since it
- * may work (for example, lstat will fail, but pioctl will
- * work if the volume of offline (returning ENODEV). */
- statbuff.st_mode = S_IFDIR; /* lie like pros */
+ snprintf(orig_name, sizeof(orig_name), "%s%s",
+ (data[0] == '/') ? "" : "./", data);
+
+ if (lstat(orig_name, &statbuff) < 0) {
+ /* if lstat fails, we should still try the pioctl, since it
+ * may work (for example, lstat will fail, but pioctl will
+ * work if the volume of offline (returning ENODEV). */
+ statbuff.st_mode = S_IFDIR; /* lie like pros */
+ }
+
+ /*
+ * The lstat succeeded. If the given file is a symlink, substitute
+ * the file name with the link name.
+ */
+ if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
+ if (thru_symlink)
+ *thru_symlink = 1;
+
+ /* Read name of resolved file */
+ link_chars_read = readlink(orig_name, true_name, 1024);
+ if (link_chars_read <= 0) {
+ fprintf(stderr,
+ "%s: Can't read target name for '%s' symbolic link!\n",
+ pn, orig_name);
+ goto out;
}
+ /* Add a trailing null to what was read, bump the length. */
+ true_name[link_chars_read++] = 0;
+
/*
- * The lstat succeeded. If the given file is a symlink, substitute
- * the file name with the link name.
+ * If the symlink is an absolute pathname, we're fine. Otherwise, we
+ * have to create a full pathname using the original name and the
+ * relative symlink name. Find the rightmost slash in the original
+ * name (we know there is one) and splice in the symlink value.
*/
- if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
- thru_symlink = 1;
- /*
- * Read name of resolved file.
- */
- link_chars_read = readlink(orig_name, true_name, 1024);
- if (link_chars_read <= 0) {
- fprintf(stderr,
- "%s: Can't read target name for '%s' symbolic link!\n",
- pn, orig_name);
- error = 1;
- continue;
- }
-
- /*
- * Add a trailing null to what was read, bump the length.
- */
- true_name[link_chars_read++] = 0;
-
- /*
- * If the symlink is an absolute pathname, we're fine. Otherwise, we
- * have to create a full pathname using the original name and the
- * relative symlink name. Find the rightmost slash in the original
- * name (we know there is one) and splice in the symlink value.
- */
- if (true_name[0] != '/') {
- last_component = (char *)strrchr(orig_name, '/');
- strcpy(++last_component, true_name);
- strcpy(true_name, orig_name);
- }
- } else
+ if (true_name[0] != '/') {
+ lastSlash = strrchr(orig_name, '/');
+ strcpy(++lastSlash, true_name);
strcpy(true_name, orig_name);
-
+ }
+ } else {
+ strcpy(true_name, orig_name);
+ }
+
+ /* Find rightmost slash, if any. */
+ lastSlash = strrchr(true_name, '/');
+ if (lastSlash == true_name) {
+ dirname = strdup("/");
+ basename = strdup(lastSlash+1);
+ } else if (lastSlash != NULL) {
/*
- * Find rightmost slash, if any.
+ * Found it. Designate everything before it as the parent directory,
+ * everything after it as the final component.
*/
- last_component = (char *)strrchr(true_name, '/');
- if (last_component == (char *)true_name) {
- strcpy(parent_dir, "/");
- last_component++;
- }
- else if (last_component != (char *)NULL) {
- /*
- * Found it. Designate everything before it as the parent directory,
- * everything after it as the final component.
- */
- strncpy(parent_dir, true_name, last_component - true_name);
- parent_dir[last_component - true_name] = 0;
- last_component++; /*Skip the slash */
- } else {
- /*
- * No slash appears in the given file name. Set parent_dir to the current
- * directory, and the last component as the given name.
- */
- strcpy(parent_dir, ".");
- last_component = true_name;
- }
+ *lastSlash = '\0';
+ dirname = strdup(true_name);
+ basename = strdup(lastSlash+1);
+ } else {
+ /*
+ * No slash appears in the given file name. Set parent_dir to the current
+ * directory, and the last component as the given name.
+ */
+ dirname = strdup(".");
+ basename = strdup(true_name);
+ }
- if (strcmp(last_component, ".") == 0
- || strcmp(last_component, "..") == 0) {
- fprintf(stderr,
- "%s: you may not use '.' or '..' as the last component\n",
- pn);
- fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
- pn);
+ if (strcmp(basename, ".") == 0
+ || strcmp(basename, "..") == 0) {
+ fprintf(stderr,
+ "%s: you may not use '.' or '..' as the last component\n", pn);
+ fprintf(stderr, "%s: of a name in this fs command.\n", pn);
+ goto out;
+ }
+
+ *outdir = dirname;
+ *outbase = basename;
+
+ return 0;
+
+out:
+ if (outdir)
+ free(outdir);
+ if (outbase)
+ free(outbase);
+ return -1;
+}
+
+
+static int
+ListMountCmd(struct cmd_syndesc *as, void *arock)
+{
+ afs_int32 code;
+ struct ViceIoctl blob;
+ struct cmd_item *ti;
+ char *last_component;
+ char *parent_dir;
+ int thru_symlink = 0;
+ int error = 0;
+
+ for (ti = as->parms[0].items; ti; ti = ti->next) {
+ if (GetLastComponent(ti->data, &parent_dir,
+ &last_component, &thru_symlink) != 0) {
error = 1;
continue;
}
memset(space, 0, AFS_PIOCTL_MAXSIZE);
code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
+ free(last_component);
+ free(parent_dir);
if (code == 0) {
printf("'%s' is a %smount point for volume '%s'\n", ti->data,
blob.in_size = strlen(tp) + 1;
blob.out = lsbuffer;
blob.out_size = sizeof(lsbuffer);
- code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
+ code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
if (code) {
if (errno == EINVAL) {
fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
blob.out_size = 0;
blob.in = tp;
blob.in_size = strlen(tp) + 1;
- code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
+ code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
if (code) {
Die(errno, ti->data);
error = 1;
afs_int32 code;
struct ViceIoctl blob;
afs_int32 temp;
-
+
if (!as->parms[0].items && !as->parms[1].items) {
fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
return 1;
Die(errno, NULL);
return 1;
}
-
+
printf("New precache size set.\n");
return 0;
}
percentFiles, filesUsed, parms[2]);
if (flags == 2){
printf(" afs_cacheFiles: %10d\n", parms[2]);
- printf(" IFFree: %10d\n", parms[3]);
- printf(" IFEverUsed: %10d\n", parms[4]);
- printf(" IFDataMod: %10d\n", parms[5]);
+ printf(" IFFree: %10d\n", parms[3]);
+ printf(" IFEverUsed: %10d\n", parms[4]);
+ printf(" IFDataMod: %10d\n", parms[5]);
printf(" IFDirtyPages: %10d\n", parms[6]);
- printf(" IFAnyPages: %10d\n", parms[7]);
+ printf(" IFAnyPages: %10d\n", parms[7]);
printf(" IFDiscarded: %10d\n", parms[8]);
printf(" DCentries: %10d\n", parms[9]);
- printf(" 0k- 4K: %10d\n", parms[10]);
- printf(" 4k- 16k: %10d\n", parms[11]);
- printf(" 16k- 64k: %10d\n", parms[12]);
- printf(" 64k- 256k: %10d\n", parms[13]);
- printf(" 256k- 1M: %10d\n", parms[14]);
- printf(" >=1M: %10d\n", parms[15]);
+ printf(" 0k- 4K: %10d\n", parms[10]);
+ printf(" 4k- 16k: %10d\n", parms[11]);
+ printf(" 16k- 64k: %10d\n", parms[12]);
+ printf(" 64k- 256k: %10d\n", parms[13]);
+ printf(" 256k- 1M: %10d\n", parms[14]);
+ printf(" >=1M: %10d\n", parms[15]);
}
if (percentBlocks > 90)
printf("[cache size usage over 90%%, consider increasing cache size]\n");
if (percentFiles > 90)
printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
-
+
return 0;
}
struct cmd_item *ti;
afs_int32 hostAddr;
struct hostent *thp;
- int setp;
-
+
ti = as->parms[0].items;
- setp = 1;
if (ti) {
thp = hostutil_GetHostByName(ti->data);
if (!thp) {
else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
} else {
hostAddr = 0; /* means don't set host */
- setp = 0; /* aren't setting host */
}
-
+
/* now do operation */
blob.in_size = sizeof(afs_int32);
blob.out_size = sizeof(afs_int32);
blob.in = (char *) &hostAddr;
blob.out = (char *) &hostAddr;
-
+
code = pioctl(0, VIOC_CBADDR, &blob, 1);
if (code < 0) {
Die(errno, 0);
struct cmd_item *ti;
afs_int32 hostAddr;
struct hostent *thp;
-
+
ti = as->parms[0].items;
thp = hostutil_GetHostByName(ti->data);
if (!thp) {
return 1;
}
else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
-
+
/* now do operation */
blob.in_size = sizeof(afs_int32);
blob.out_size = sizeof(afs_int32);
blob.in = (char *) &hostAddr;
blob.out = (char *) &hostAddr;
-
+
code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
if (code < 0) {
Die(errno, 0);
afs_int32 code;
struct ViceIoctl blob;
struct cmd_item *ti;
- int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
+ int export = 0, type = 0, mode = 0, exportcall, pwsync =
0, smounts = 0, clipags = 0, pagcb = 0;
ti = as->parms[0].items;
fprintf(stderr, "Illegal argument %s\n", ti->data);
return 1;
}
- exp = 1;
}
if ((ti = as->parms[2].items)) { /* -noconvert */
if (strcmp(ti->data, "on") == 0)
afs_int32 code;
code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
- info->name, 0, &uclient,
+ info->name, 0, &uclient,
NULL, pn, rxkad_clear,
VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
0, 0, USER_SERVICE_ID);
static struct ViceIoctl gblob;
static int debug = 0;
/*
- * here follow some routines in suport of the setserverprefs and
+ * here follow some routines in support of the setserverprefs and
* getserverprefs commands. They are:
* SetPrefCmd "top-level" routine
* addServer adds a server to the list of servers to be poked into the
afs_int32 code;
struct cmd_item *ti;
char name[80];
- afs_int32 rank;
+ int rank;
struct setspref *ssp;
int error = 0; /* -1 means error message printed,
* >0 means errno value for unprinted message */
perror(ti->data);
error = -1;
} else {
- while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
+ while (fscanf(infd, "%79s%d", name, &rank) != EOF) {
code = addServer(name, (unsigned short)rank);
if (code)
error = code;
ti = as->parms[3].items; /* -stdin */
if (ti) {
- while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
+ while (scanf("%79s%d", name, &rank) != EOF) {
code = addServer(name, (unsigned short)rank);
if (code)
error = code;
(AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
in->flags = vlservers;
- code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
- if (code) {
- perror("getserverprefs pioctl");
- return 1;
- }
+ do {
+ code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
+ if (code) {
+ if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
+ perror("getserverprefs pioctl");
+ return 1;
+ }
+ blob.out_size *= 2;
+ if (blob.out == space)
+ blob.out = malloc(blob.out_size);
+ else
+ blob.out = realloc(blob.out, blob.out_size);
+ }
+ } while (code != 0);
out = (struct sprefinfo *)blob.out;
in->offset = out->next_offset;
} while (out->next_offset > 0);
+ if (blob.out != space)
+ free(blob.out);
+
return 0;
}
}
/* Having no arguments also reports the default store asynchrony */
- if (verbose && (blob.out_size == sizeof(tsb2))) {
+ if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
(tsb2.sb_default / 1024));
}
return 0;
}
-#ifdef AFS_DISCON_ENV
static char *modenames[] = {
"offline",
"online",
char *modename;
char *policyname;
int modelen, policylen;
- afs_int32 mode, policy, code;
+ afs_int32 mode, policy, code, unixuid = 0;
struct ViceIoctl blob;
blob.in = NULL;
blob.in_size = 0;
- space[0] = space[1] = space[2] = 0;
+ space[0] = space[1] = space[2] = space[3] = 0;
ti = as->parms[0].items;
if (ti) {
printf("force on\n");
}
+ ti = as->parms[3].items;
+ if (ti) {
+ code = util_GetInt32(ti->data, &unixuid);
+ if (code) {
+ fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
+ return 1;
+ }
+ space[3] = unixuid;
+ } else
+ space[3] = 0;
+
blob.in = space;
- blob.in_size = 3 * sizeof(afs_int32);
+ blob.in_size = 4 * sizeof(afs_int32);
blob.out_size = sizeof(mode);
blob.out = space;
return 0;
}
-#endif
#include "AFS_component_version_number.c"
ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+ cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
cmd_CreateAlias(ts, "lq");
ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
"show server disk space usage");
cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+ cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
cmd_CreateAlias(ts, "df");
ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
"get fid for file(s)");
cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
-#ifdef AFS_DISCON_ENV
ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
"disconnection mode");
cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
-#endif
+ cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
afs_int32 code;
struct ViceIoctl blob;
struct cmd_item *ti;
- char orig_name[1024]; /*Original name, may be modified */
- char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
- char parent_dir[1024]; /*Parent directory of true name */
- char *last_component; /*Last component of true name */
- struct stat statbuff; /*Buffer for status info */
- int link_chars_read; /*Num chars read in readlink() */
- int thru_symlink; /*Did we get to a mount point via a symlink? */
+ char *last_component;
+ char *parent_dir;
int error = 0;
for (ti = as->parms[0].items; ti; ti = ti->next) {
- /* once per file */
- thru_symlink = 0;
- sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
- ti->data);
-
- if (lstat(orig_name, &statbuff) < 0) {
- /* if lstat fails, we should still try the pioctl, since it
- * may work (for example, lstat will fail, but pioctl will
- * work if the volume of offline (returning ENODEV). */
- statbuff.st_mode = S_IFDIR; /* lie like pros */
- }
-
- /*
- * The lstat succeeded. If the given file is a symlink, substitute
- * the file name with the link name.
- */
- if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
- thru_symlink = 1;
- /*
- * Read name of resolved file.
- */
- link_chars_read = readlink(orig_name, true_name, 1024);
- if (link_chars_read <= 0) {
- fprintf(stderr,
- "%s: Can't read target name for '%s' symbolic link!\n",
- pn, orig_name);
- error = 1;
- continue;
- }
-
- /*
- * Add a trailing null to what was read, bump the length.
- */
- true_name[link_chars_read++] = 0;
-
- /*
- * If the symlink is an absolute pathname, we're fine. Otherwise, we
- * have to create a full pathname using the original name and the
- * relative symlink name. Find the rightmost slash in the original
- * name (we know there is one) and splice in the symlink value.
- */
- if (true_name[0] != '/') {
- last_component = (char *)strrchr(orig_name, '/');
- strcpy(++last_component, true_name);
- strcpy(true_name, orig_name);
- }
- } else
- strcpy(true_name, orig_name);
-
- /*
- * Find rightmost slash, if any.
- */
- last_component = (char *)strrchr(true_name, '/');
- if (last_component == (char *)true_name) {
- strcpy(parent_dir, "/");
- last_component++;
- }
- else if (last_component != (char *)NULL) {
- /*
- * Found it. Designate everything before it as the parent directory,
- * everything after it as the final component.
- */
- strncpy(parent_dir, true_name, last_component - true_name);
- parent_dir[last_component - true_name] = 0;
- last_component++; /*Skip the slash */
- } else {
- /*
- * No slash appears in the given file name. Set parent_dir to the current
- * directory, and the last component as the given name.
- */
- strcpy(parent_dir, ".");
- last_component = true_name;
- }
-
- if (strcmp(last_component, ".") == 0
- || strcmp(last_component, "..") == 0) {
- fprintf(stderr,
- "%s: you may not use '.' or '..' as the last component\n",
- pn);
- fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
- pn);
+ if (GetLastComponent(ti->data, &parent_dir,
+ &last_component, NULL) != 0) {
error = 1;
continue;
}
blob.in = last_component;
blob.in_size = strlen(last_component) + 1;
blob.out_size = 0;
- memset(space, 0, AFS_PIOCTL_MAXSIZE);
code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
+ free(last_component);
+ free(parent_dir);
+
if (code != 0) {
if (errno == EINVAL) {
fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
{
struct ViceIoctl blob;
struct cmd_item *ti;
+
+ afs_int32 code;
+ int error = 0;
+ char cell[MAXCELLCHARS];
+
+ SetDotDefault(&as->parms[0].items);
for (ti = as->parms[0].items; ti; ti = ti->next) {
- struct VenusFid vfid;
-
- blob.out_size = sizeof(struct VenusFid);
- blob.out = (char *) &vfid;
- blob.in_size = 0;
-
- if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
- printf("File %s (%u.%u.%u) contained in volume %u\n",
- ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
- vfid.Fid.Volume);
- }
+ struct VenusFid vfid;
+
+ blob.out_size = sizeof(struct VenusFid);
+ blob.out = (char *) &vfid;
+ blob.in_size = 0;
+
+ code = pioctl(ti->data, VIOCGETFID, &blob, 1);
+ if (code) {
+ Die(errno,ti->data);
+ error = 1;
+ continue;
+ }
+
+ code = GetCell(ti->data, cell);
+ if (code) {
+ if (errno == ENOENT)
+ fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
+ else
+ Die(errno, ti->data);
+ error = 1;
+ continue;
+ }
+
+ printf("File %s (%u.%u.%u) located in cell %s\n",
+ ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
+ cell);
+
}
- return 0;
+ return error;
}