#include <moira.h>
#include <moira_site.h>
#include <menu.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
#include "mit-copyright.h"
#include "defs.h"
#define DEFAULT_OWNERS (user)
#define DEFAULT_CREATE DEFAULT_YES
#define DEFAULT_L_TYPE ("PROJECT")
+#define DEFAULT_CELL ("athena.mit.edu")
/* Function Name: SetDefaults
* Description: sets the default values for filesystem additions.
sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
info[FS_OWNER], info[FS_OWNERS]);
Put_message(print_buf);
- sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
+ sprintf(print_buf, "Update Fileserver: %-27s Locker Type: %s",
atoi(info[FS_CREATE]) ? "ON" : "OFF",
info[FS_L_TYPE]);
Put_message(print_buf);
return(info[FS_NAME]);
}
+
+char *canonicalize_cell(c)
+char *c;
+{
+ struct stat stbuf;
+ char path[512];
+ int count;
+
+ sprintf(path, "/afs/%s", c);
+ if (lstat(path, &stbuf) || !stbuf.st_mode&S_IFLNK)
+ return(c);
+ count = readlink(path, path, sizeof(path));
+ if (count < 1) return(c);
+ path[count] = 0;
+ free(c);
+ return(strsave(path));
+}
+
+
+int GetAliasValue(argc, argv, retval)
+int argc;
+char **argv;
+char **retval;
+{
+ *retval = strsave(argv[2]);
+ return(MR_CONT);
+}
+
/* Function Name: AskFSInfo.
* Description: This function askes the user for information about a
* machine and saves it into a structure.
Bool name;
{
char temp_buf[BUFSIZ], *newname, access_type[32];
- int fsgroup = 0;
+ int fsgroup = 0, newdefaults = 0;
Put_message("");
sprintf(temp_buf, "Changing Attributes of filesystem %s.",
return(NULL);
}
+ strcpy(temp_buf, info[FS_TYPE]);
if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) ==
SUB_ERROR)
return(NULL);
if (!strcasecmp(info[FS_TYPE], "FSGROUP") ||
!strcasecmp(info[FS_TYPE], "MUL"))
fsgroup++;
- if (fsgroup || !strcasecmp(info[FS_TYPE], "AFS")) {
+ if (strcasecmp(info[FS_TYPE], temp_buf))
+ newdefaults++;
+ if (fsgroup) {
free(info[FS_MACHINE]);
info[FS_MACHINE] = Strsave(NO_MACHINE);
} else {
free(info[FS_MACHINE]);
info[FS_MACHINE] = Strsave(NO_MACHINE);
}
- if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) ==
- SUB_ERROR)
- return(NULL);
- info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
+ if (!strcasecmp(info[FS_TYPE], "AFS")) {
+ if (!name || newdefaults) {
+ free(info[FS_MACHINE]);
+ info[FS_MACHINE] = strsave(DEFAULT_CELL);
+ }
+ if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) ==
+ SUB_ERROR)
+ return(NULL);
+ info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]);
+ } else {
+ if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) ==
+ SUB_ERROR)
+ return(NULL);
+ info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
+ }
}
if (!fsgroup) {
+ if (!strcasecmp(info[FS_TYPE], "AFS")) {
+ char *path, *args[3], *p;
+ int status, depth, i;
+ if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
+ &info[FS_L_TYPE]) == SUB_ERROR)
+ return(NULL);
+ if (!name || newdefaults) {
+ free(info[FS_PACK]);
+ lowercase(info[FS_MACHINE]);
+ sprintf(temp_buf, "%s:%s", info[FS_MACHINE], info[FS_L_TYPE]);
+ args[0] = temp_buf;
+ args[1] = "AFSPATH";
+ args[2] = "*";
+ path = "???";
+ status = do_mr_query("get_alias", 3, args,
+ GetAliasValue, &path);
+ if (status == MR_SUCCESS) {
+ p = index(path, ':');
+ if (p) {
+ *p = 0;
+ depth = atoi(++p);
+ } else
+ depth = 0;
+ sprintf(temp_buf, "/afs/%s/%s", info[FS_MACHINE], path);
+ if (depth >= 0) {
+ for (p=info[FS_NAME]; *p&&(p-info[FS_NAME])<depth; p++) {
+ if (islower(*p)) {
+ strcat(temp_buf, "/x");
+ temp_buf[strlen(temp_buf)-1] = *p;
+ } else {
+ sprintf(temp_buf, "/afs/%s/%s/other", info[FS_MACHINE], path);
+ break;
+ }
+ }
+ } else if (depth = -1) {
+ if (isdigit(info[FS_NAME][0])) {
+ strcat(temp_buf, "/");
+ depth = strlen(temp_buf);
+ for (p = info[FS_NAME]; *p && isdigit(*p); p++) {
+ temp_buf[depth++] = *p;
+ temp_buf[depth] = 0;
+ }
+ } else
+ strcat(temp_buf, "/other");
+ } else {
+ /* no default */
+ }
+ strcat(temp_buf, "/");
+ strcat(temp_buf, info[FS_NAME]);
+ free(path);
+ } else {
+ sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE],
+ lowercase(info[FS_L_TYPE]), info[FS_NAME]);
+ }
+ info[FS_PACK] = strsave(temp_buf);
+ }
+ }
if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) ==
SUB_ERROR)
return(NULL);
SUB_ERROR)
return(NULL);
if (!fsgroup)
- if (GetYesNoValueFromUser("Automatically create this filesystem",
+ if (GetYesNoValueFromUser("Propagate changes to fileserver",
&info[FS_CREATE]) == SUB_ERROR)
return(NULL);
- if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
- &info[FS_L_TYPE]) == SUB_ERROR)
- return(NULL);
+ if (strcasecmp(info[FS_TYPE], "AFS")) {
+ if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
+ &info[FS_L_TYPE]) == SUB_ERROR)
+ return(NULL);
+ }
FreeAndClear(&info[FS_MODTIME], TRUE);
FreeAndClear(&info[FS_MODBY], TRUE);
return(info);
}
+
/* --------------- Filesystem Menu ------------- */
/* Function Name: GetFS
{
struct qelem *top;
- argv[1] = canonicalize_hostname(argv[1]);
+ argv[1] = canonicalize_hostname(strsave(argv[1]));
top = GetFSInfo(MACHINE, argv[1]); /* get info. */
Loop(top, (void *) PrintFSInfo);
FreeQueue(top); /* clean the queue. */
info[FS_NAME], def_quota, info[FS_NAME]);
if (YesNoQuestion(buf, 1) == TRUE) {
argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
- argv[Q_TYPE] = "USER";
+ if (!strcmp(info[FS_TYPE], "NFS"))
+ argv[Q_TYPE] = "USER";
+ else
+ argv[Q_TYPE] = "ANY";
argv[Q_QUOTA] = def_quota;
if ((stat = do_mr_query("add_quota", Q_QUOTA+1, argv, Scream,
(char *) NULL)) != MR_SUCCESS) {
}
}
}
+ } else if (stat == MR_SUCCESS) {
+ if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1)
+ == TRUE) {
+ parsed_argc = 1;
+ parsed_argv[0] = info[FS_NAME];
+ AddQuota();
+ }
}
FreeInfo(info);