3 * This is the file attach.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: Functions for maintaining data used by Hesiod
6 * to map courses/projects/users to their file systems,
7 * and maintain filesys info.
10 * By: Chris D. Peterson
12 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
13 * For copying and distribution information, please see the file
17 #include <mit-copyright.h>
19 #include <moira_site.h>
33 #endif /* HAVE_UNISTD_H */
37 char *canonicalize_cell(char *c);
38 int GetAliasValue(int argc, char **argv, void *retval);
39 void RealDeleteFS(char **info, Bool one_item);
40 char *SortAfter(struct mqelem *elem, int count);
41 void RealDeleteFSAlias(char **info, Bool one_item);
43 #define FS_ALIAS_TYPE "FILESYS"
52 #define NO_MACHINE ("[NONE]")
54 #define DEFAULT_TYPE ("AFS")
55 #define DEFAULT_MACHINE DEFAULT_NONE
56 #define DEFAULT_PACK DEFAULT_NONE
57 #define DEFAULT_ACCESS ("w")
58 #define DEFAULT_COMMENTS DEFAULT_COMMENT
59 #define DEFAULT_OWNER (user)
60 #define DEFAULT_OWNERS (user)
61 #define DEFAULT_CREATE DEFAULT_YES
62 #define DEFAULT_L_TYPE ("PROJECT")
63 #define DEFAULT_CELL ("athena.mit.edu")
65 /* Function Name: SetDefaults
66 * Description: sets the default values for filesystem additions.
67 * Arguments: info - an array of char pointers to recieve defaults.
68 * Returns: char ** (this array, now filled).
71 static char **SetDefaults(char **info, char *name)
75 info[FS_NAME] = strdup(name);
76 info[FS_TYPE] = strdup(DEFAULT_TYPE);
77 info[FS_MACHINE] = strdup(DEFAULT_MACHINE);
78 info[FS_PACK] = strdup(DEFAULT_PACK);
79 sprintf(buf, "/mit/%s", name);
80 info[FS_M_POINT] = strdup(buf);
81 info[FS_ACCESS] = strdup(DEFAULT_ACCESS);
82 info[FS_COMMENTS] = strdup(DEFAULT_COMMENTS);
83 info[FS_OWNER] = strdup(DEFAULT_OWNER);
84 info[FS_OWNERS] = strdup(DEFAULT_OWNERS);
85 info[FS_CREATE] = strdup(DEFAULT_CREATE);
86 info[FS_L_TYPE] = strdup(DEFAULT_L_TYPE);
87 info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
91 /* Function Name: GetFSInfo
92 * Description: Stores the info in a queue.
93 * Arguments: type - type of information to get.
94 * name - name of the item to get information on.
95 * Returns: a pointer to the first element in the queue.
98 static struct mqelem *GetFSInfo(int type, char *name)
101 struct mqelem *elem = NULL;
107 if ((stat = do_mr_query("get_filesys_by_label", 1, &name,
110 com_err(program_name, stat, " in GetFSInfo");
115 if ((stat = do_mr_query("get_filesys_by_machine", 1, &name,
118 com_err(program_name, stat, " in GetFSInfo");
123 if ((stat = do_mr_query("get_filesys_by_group", 1, &name,
126 com_err(program_name, stat, " in GetFSInfo");
132 args[ALIAS_NAME] = name;
133 args[ALIAS_TYPE] = FS_ALIAS_TYPE;
134 args[ALIAS_TRANS] = "*";
135 if ((stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem)))
137 if (type != ALIAS_CHECK || stat != MR_NO_MATCH)
138 com_err(program_name, stat, " in get_alias.");
143 args[ALIAS_NAME] = "*";
144 args[ALIAS_TYPE] = FS_ALIAS_TYPE;
145 args[ALIAS_TRANS] = name;
146 if ((stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem)))
148 if (stat != MR_NO_MATCH)
149 com_err(program_name, stat, " in get_alias.");
155 return QueueTop(elem);
158 /* Function Name: PrintFSAlias
159 * Description: Prints a filesystem alias
160 * Arguments: info - an array contains the strings of info.
161 * Returns: the name of the filesys - used be QueryLoop().
164 static char *PrintFSAlias(char **info)
168 sprintf(buf, "Alias: %-25s Filesystem: %s", info[ALIAS_NAME],
171 return info[ALIAS_NAME];
174 static char aliasbuf[256];
176 static char *PrintFSAliasList(char **info)
178 if (strlen(aliasbuf) == 0)
179 snprintf(aliasbuf, sizeof(aliasbuf), "Aliases: %s", info[ALIAS_NAME]);
182 strncat(aliasbuf, ", ", sizeof(aliasbuf));
183 strncat(aliasbuf, info[ALIAS_NAME], sizeof(aliasbuf));
187 static char labelbuf[256];
189 static char *GetFSLabel(char **info)
191 snprintf(labelbuf, sizeof(labelbuf), info[ALIAS_TRANS]);
194 static int fsgCount = 1;
196 static void PrintFSGMembers(char **info)
198 char print_buf[BUFSIZ];
200 sprintf(print_buf, " %d. Filesystem: %-32s (sort key: %s)",
201 fsgCount++, info[0], info[1]);
202 Put_message(print_buf);
206 /* Function Name: PrintFSInfo
207 * Description: Prints the filesystem information.
208 * Arguments: info - a pointer to the filesystem information.
212 static char *PrintFSInfo(char **info)
214 char print_buf[BUFSIZ];
219 if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL"))
222 struct mqelem *elem = NULL;
224 if (!strcmp(info[FS_TYPE], "MUL"))
225 sprintf(print_buf, "%20s Multiple Filesystem: %s", " ", info[FS_NAME]);
227 sprintf(print_buf, "%20s Filesystem Group: %s", " ", info[FS_NAME]);
228 Put_message(print_buf);
230 top = GetFSInfo(FS_ALIASES, info[FS_NAME]);
233 Loop(top, (void (*)(char **))PrintFSAliasList);
234 Put_message(aliasbuf);
235 FreeQueue(top); /* clean the queue. */
238 sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]);
239 Put_message(print_buf);
240 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
242 Put_message(print_buf);
243 Put_message("Containing the filesystems (in order):");
244 if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME],
247 if (stat == MR_NO_MATCH)
248 Put_message(" [no members]");
250 com_err(program_name, stat, " in PrintFSInfo");
255 Loop(QueueTop(elem), PrintFSGMembers);
261 sprintf(print_buf, "%20s Filesystem: %s", " ", info[FS_NAME]);
262 Put_message(print_buf);
264 top = GetFSInfo(FS_ALIASES, info[FS_NAME]);
267 Loop(top, (void (*)(char **))PrintFSAliasList);
268 Put_message(aliasbuf);
269 FreeQueue(top); /* clean the queue. */
272 sprintf(print_buf, "Type: %-40s Machine: %-15s",
273 info[FS_TYPE], info[FS_MACHINE]);
274 Put_message(print_buf);
275 sprintf(print_buf, "Default Access: %-2s Packname: %-17s Mountpoint %s ",
276 info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
277 Put_message(print_buf);
278 sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]);
279 Put_message(print_buf);
280 sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
281 info[FS_OWNER], info[FS_OWNERS]);
282 Put_message(print_buf);
283 sprintf(print_buf, "Update Fileserver: %-27s Locker Type: %s",
284 atoi(info[FS_CREATE]) ? "ON" : "OFF", info[FS_L_TYPE]);
285 Put_message(print_buf);
286 sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
288 Put_message(print_buf);
290 return info[FS_NAME];
293 char *canonicalize_cell(char *c)
302 sprintf(path, "/afs/%s", c);
303 if (lstat(path, &stbuf) || !stbuf.st_mode & S_IFLNK)
305 count = readlink(path, path, sizeof(path));
315 int GetAliasValue(int argc, char **argv, void *retval)
317 *(char **)retval = strdup(argv[2]);
321 /* Function Name: AskFSInfo.
322 * Description: This function askes the user for information about a
323 * machine and saves it into a structure.
324 * Arguments: info - a pointer the the structure to put the
326 * name - add a newname field? (T/F)
330 static char **AskFSInfo(char **info, Bool name)
332 char temp_buf[BUFSIZ], *newname, access_type[32];
333 int fsgroup = 0, newdefaults = 0;
336 sprintf(temp_buf, "Changing Attributes of filesystem %s.", info[FS_NAME]);
337 Put_message(temp_buf);
342 newname = strdup(info[FS_NAME]);
343 if (GetValueFromUser("The new name for this filesystem",
344 &newname) == SUB_ERROR)
348 strcpy(temp_buf, info[FS_TYPE]);
349 if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) ==
352 if (!strcasecmp(info[FS_TYPE], "FSGROUP") ||
353 !strcasecmp(info[FS_TYPE], "MUL"))
355 if (strcasecmp(info[FS_TYPE], temp_buf))
359 free(info[FS_MACHINE]);
360 info[FS_MACHINE] = strdup(NO_MACHINE);
364 if (!strcasecmp(info[FS_TYPE], "AFS"))
366 if (!name || newdefaults)
368 free(info[FS_MACHINE]);
369 info[FS_MACHINE] = strdup(DEFAULT_CELL);
371 if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) ==
374 info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]);
378 if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) ==
381 info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
386 if (!strcasecmp(info[FS_TYPE], "AFS"))
388 char *path, *args[3], *p;
390 if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
391 &info[FS_L_TYPE]) == SUB_ERROR)
393 if (!name || newdefaults)
396 lowercase(info[FS_MACHINE]);
397 sprintf(temp_buf, "%s:%s", info[FS_MACHINE], info[FS_L_TYPE]);
402 status = do_mr_query("get_alias", 3, args, GetAliasValue, &path);
403 if (status == MR_SUCCESS)
405 p = strchr(path, ':');
413 sprintf(temp_buf, "/afs/%s/%s", info[FS_MACHINE], path);
416 for (p = info[FS_NAME];
417 *p && (p - info[FS_NAME]) < depth; p++)
421 strcat(temp_buf, "/x");
422 temp_buf[strlen(temp_buf) - 1] = *p;
426 sprintf(temp_buf, "/afs/%s/%s/other",
427 info[FS_MACHINE], path);
432 else if (depth == -1)
434 if (isdigit(info[FS_NAME][0]))
436 strcat(temp_buf, "/");
437 depth = strlen(temp_buf);
438 for (p = info[FS_NAME]; *p && isdigit(*p); p++)
440 temp_buf[depth++] = *p;
445 strcat(temp_buf, "/other");
451 strcat(temp_buf, "/");
452 strcat(temp_buf, info[FS_NAME]);
457 sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE],
458 lowercase(info[FS_L_TYPE]), info[FS_NAME]);
460 info[FS_PACK] = strdup(temp_buf);
463 if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) ==
466 if (GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]) ==
469 sprintf(access_type, "fs_access_%s", info[FS_TYPE]);
470 if (GetTypeFromUser("Filesystem's Default Access", access_type,
471 &info[FS_ACCESS]) == SUB_ERROR)
474 if (GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS])
477 if (GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]) ==
480 if (GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]) ==
484 if (GetYesNoValueFromUser("Propagate changes to fileserver",
485 &info[FS_CREATE]) == SUB_ERROR)
487 if (strcasecmp(info[FS_TYPE], "AFS"))
489 if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
490 &info[FS_L_TYPE]) == SUB_ERROR)
494 FreeAndClear(&info[FS_MODTIME], TRUE);
495 FreeAndClear(&info[FS_MODBY], TRUE);
496 FreeAndClear(&info[FS_MODWITH], TRUE);
498 if (name) /* slide the newname into the #2 slot. */
499 SlipInNewName(info, newname);
505 /* --------------- Filesystem Menu ------------- */
507 /* Function Name: GetFS
508 * Description: Get Filesystem information by name.
509 * Arguments: argc, argv - name of filsys in argv[1].
510 * Returns: DM_NORMAL.
513 int GetFS(int argc, char **argv)
520 top = GetFSInfo(ALIAS_CHECK, argv[1]);
522 Loop(top, (void (*)(char **))GetFSLabel);
526 top = GetFSInfo(LABEL, fs_label); /* get info. */
527 Loop(top, (void (*)(char **))PrintFSInfo);
528 FreeQueue(top); /* clean the queue. */
532 /* Function Name: GetFSM
533 * Description: Get Filesystem information by machine.
534 * Arguments: argc, argv - name of server in argv[1].
535 * Returns: DM_NORMAL.
538 int GetFSM(int argc, char **argv)
542 argv[1] = canonicalize_hostname(strdup(argv[1]));
543 top = GetFSInfo(MACHINE, argv[1]); /* get info. */
544 Loop(top, (void (*)(char **))PrintFSInfo);
545 FreeQueue(top); /* clean the queue. */
549 /* Function Name: RealDeleteFS
550 * Description: Does the real deletion work.
551 * Arguments: info - array of char *'s containing all useful info.
552 * one_item - a Boolean that is true if only one item
553 * in queue that dumped us here.
557 void RealDeleteFS(char **info, Bool one_item)
560 char temp_buf[BUFSIZ];
563 * Deletions are performed if the user hits 'y' on a list of multiple
564 * filesystem, or if the user confirms on a unique alias.
566 sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
568 if (!one_item || Confirm(temp_buf))
570 if ((stat = do_mr_query("delete_filesys", 1,
571 &info[FS_NAME], NULL, NULL)))
572 com_err(program_name, stat, " filesystem not deleted.");
574 Put_message("Filesystem deleted.");
577 Put_message("Filesystem not deleted.");
580 /* Function Name: DeleteFS
581 * Description: Delete a filesystem give its name.
582 * Arguments: argc, argv - argv[1] is the name of the filesystem.
586 int DeleteFS(int argc, char **argv)
588 struct mqelem *elem = GetFSInfo(LABEL, argv[1]);
589 QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
595 /* Function Name: RealChangeFS
596 * Description: performs the actual change to the filesys.
597 * Arguments: info - the information
598 * junk - an unused boolean.
602 static void RealChangeFS(char **info, Bool junk)
606 extern Menu nfsphys_menu;
608 args = AskFSInfo(info, TRUE);
611 Put_message("Aborted.");
614 stat = do_mr_query("update_filesys", CountArgs(args), args, NULL, NULL);
618 Put_message("That NFS filesystem is not exported.");
619 if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE)
621 Do_menu(&nfsphys_menu, 0, NULL);
622 if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE) == TRUE)
624 if ((stat = do_mr_query("update_filesys", CountArgs(args), args,
626 com_err(program_name, stat, " filesystem not updated");
628 Put_message("filesystem sucessfully updated.");
635 com_err(program_name, stat, " in UpdateFS");
639 /* Function Name: ChangeFS
640 * Description: change the information in a filesys record.
641 * Arguments: arc, argv - value of filsys in argv[1].
642 * Returns: DM_NORMAL.
645 int ChangeFS(int argc, char **argv)
647 struct mqelem *elem = GetFSInfo(LABEL, argv[1]);
648 QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
654 /* Function Name: AddFS
655 * Description: change the information in a filesys record.
656 * Arguments: arc, argv - name of filsys in argv[1].
657 * Returns: DM_NORMAL.
660 int AddFS(int argc, char **argv)
662 char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ];
664 extern Menu nfsphys_menu;
666 if (!ValidName(argv[1]))
669 if (!(stat = do_mr_query("get_filesys_by_label", 1, argv + 1,
672 Put_message ("A Filesystem by that name already exists.");
675 else if (stat != MR_NO_MATCH)
677 com_err(program_name, stat, " in AddFS");
681 if (!(args = AskFSInfo(SetDefaults(info, argv[1]), FALSE)))
683 Put_message("Aborted.");
687 stat = do_mr_query("add_filesys", CountArgs(args), args, NULL, NULL);
691 Put_message("That NFS filesystem is not exported.");
692 if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE)
694 Do_menu(&nfsphys_menu, 0, NULL);
695 if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE)
697 if ((stat = do_mr_query("add_filesys", CountArgs(args), args,
699 com_err(program_name, stat, " in AddFS");
701 Put_message("Created.");
708 com_err(program_name, stat, " in AddFS");
711 if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR"))
713 static char *val[] = {"def_quota", NULL};
714 static char *def_quota = NULL;
715 char *argv[Q_QUOTA + 1];
716 struct mqelem *top = NULL;
720 stat = do_mr_query("get_value", CountArgs(val), val,
722 if (stat != MR_SUCCESS)
723 com_err(program_name, stat, " getting default quota");
727 def_quota = strdup(((char **)top->q_data)[0]);
733 sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)",
734 info[FS_NAME], def_quota, info[FS_NAME]);
735 if (YesNoQuestion(buf, 1) == TRUE)
737 argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
738 if (!strcmp(info[FS_TYPE], "NFS"))
739 argv[Q_TYPE] = "USER";
741 argv[Q_TYPE] = "ANY";
742 argv[Q_QUOTA] = def_quota;
743 if ((stat = do_mr_query("add_quota", Q_QUOTA + 1, argv, NULL,
745 com_err(program_name, stat, " while adding quota");
749 else if (stat == MR_SUCCESS)
751 if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1) == TRUE)
754 parsed_argv[0] = info[FS_NAME];
755 AddQuota(parsed_argc, parsed_argv);
763 /* Function Name: SortAfter
764 * Description: choose a sortkey to cause an item to be added after
765 * the count element in the queue
766 * Arguments: queue of filesys names & sortkeys, queue count pointer
767 * Returns: sort key to use.
770 char *SortAfter(struct mqelem *elem, int count)
772 char *prev, *next, prevnext, *key, keybuf[9];
774 /* first find the two keys we need to insert between */
776 for (; count > 0; count--)
778 prev = ((char **)elem->q_data)[1];
787 next = ((char **)elem->q_data)[1];
789 /* now copy the matching characters */
790 for (key = keybuf; *prev && *prev == *next; next++)
793 /* and set the last character */
795 *prev = prevnext = 'A';
802 if (*next - *prev > 1)
803 *key++ = (*next + *prev) / 2;
807 *key++ = (prevnext + 'Z') / 2;
810 return strdup(keybuf);
813 /* Function Name: AddFSToGroup
814 * Description: add a filesystem to an FS group
815 * Arguments: arc, argv - name of group in argv[1], filesys in argv[2].
816 * Returns: DM_NORMAL.
819 int AddFSToGroup(int argc, char **argv)
822 struct mqelem *elem = NULL;
823 char buf[BUFSIZ], *args[5], *bufp;
825 if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo,
828 if (stat != MR_NO_MATCH)
829 com_err(program_name, stat, " in AddFSToGroup");
836 stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL);
838 com_err(program_name, stat, " in AddFSToGroup");
841 elem = QueueTop(elem);
843 Loop(elem, PrintFSGMembers);
844 sprintf(buf, "%d", QueueCount(elem));
846 if (GetValueFromUser("Enter number of filesystem it should follow "
847 "(0 to make it first):", &bufp) == SUB_ERROR)
851 args[2] = SortAfter(elem, count);
853 FreeQueue(QueueTop(elem));
856 stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL);
857 if (stat == MR_EXISTS)
859 Put_message("That filesystem is already a member of the group.");
860 Put_message("Use the order command if you want to change the "
864 com_err(program_name, stat, " in AddFSToGroup");
869 /* Function Name: RemoveFSFromGroup
870 * Description: delete a filesystem from an FS group
871 * Arguments: arc, argv - name of group in argv[1].
872 * Returns: DM_NORMAL.
875 int RemoveFSFromGroup(int argc, char **argv)
880 sprintf(buf, "Delete filesystem %s from FS group %s", argv[2], argv[1]);
883 if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, argv + 1,
885 com_err(program_name, stat, ", not removed.");
889 /* Function Name: ChangeFSGroupOrder
890 * Description: change the sortkey on a filesys in an FSgroup
891 * Arguments: arc, argv - name of group in argv[1].
892 * Returns: DM_NORMAL.
895 int ChangeFSGroupOrder(int argc, char **argv)
897 int stat, src, dst, i;
898 struct mqelem *elem = NULL, *top, *tmpelem;
899 char buf[BUFSIZ], *bufp, *args[3];
901 if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo,
904 if (stat == MR_NO_MATCH)
907 "Ether %s is not a filesystem group or it has no members",
912 com_err(program_name, stat, " in ChangeFSGroupOrder");
915 top = QueueTop(elem);
917 Loop(top, PrintFSGMembers);
921 if (GetValueFromUser("Enter number of the filesystem to move:",
928 Put_message("You must enter a positive number (or 0 to abort).");
933 Put_message("Aborted.");
936 for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw)
940 Put_message("You entered a number that is too high");
948 if (GetValueFromUser("Enter number of filesystem it should follow "
949 "(0 to make it first):", &bufp) == SUB_ERROR)
953 if (src == dst || src == dst + 1)
955 Put_message("That has no effect on the sorting order!");
960 Put_message("You must enter a non-negative number.");
963 for (tmpelem = top, i = dst; i-- > 1 && tmpelem->q_forw;
964 tmpelem = tmpelem->q_forw)
968 Put_message("You entered a number that is too high");
973 args[2] = SortAfter(top, dst);
975 args[1] = ((char **)elem->q_data)[0];
976 if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args,
979 com_err(program_name, stat, " in ChangeFSGroupOrder");
982 if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args,
984 com_err(program_name, stat, " in ChangeFSGroupOrder");
989 /* -------------- Top Level Menu ---------------- */
991 /* Function Name: GetFSAlias
992 * Description: Gets the value for a Filesystem Alias.
993 * Arguments: argc, argv - name of alias in argv[1].
994 * Returns: DM_NORMAL.
995 * NOTES: There should only be one filesystem per alias, thus
996 * this will work correctly.
999 int GetFSAlias(int argc, char **argv)
1003 top = GetFSInfo(ALIAS, argv[1]);
1004 Put_message(" "); /* blank line. */
1005 Loop(top, (void (*)(char **))PrintFSAlias);
1010 /* Function Name: CreateFSAlias
1011 * Description: Create an alias name for a filesystem
1012 * Arguments: argc, argv - name of alias in argv[1].
1013 * Returns: DM_NORMAL.
1014 * NOTES: This requires (name, type, transl) I get {name, translation}
1015 * from the user. I provide type, which is well-known.
1018 int CreateFSAlias(int argc, char **argv)
1021 struct mqelem *elem, *top;
1022 char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;
1026 if (!ValidName(argv[1]))
1029 args[ALIAS_NAME] = strdup(argv[1]);
1030 args[ALIAS_TYPE] = strdup(FS_ALIAS_TYPE);
1031 args[ALIAS_TRANS] = strdup("*");
1034 * Check to see if this alias already exists in the database, if so then
1035 * print out values, free memory used and then exit.
1038 if (!(stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem)))
1040 top = elem = QueueTop(elem);
1043 info = elem->q_data;
1044 sprintf(buf, "The alias: %s currently describes the filesystem %s",
1045 info[ALIAS_NAME], info[ALIAS_TRANS]);
1047 elem = elem->q_forw;
1052 else if (stat != MR_NO_MATCH)
1054 com_err(program_name, stat, " in CreateFSAlias.");
1058 args[ALIAS_TRANS] = strdup("");
1059 args[ALIAS_END] = NULL;
1060 if (GetValueFromUser("Which filesystem will this alias point to?",
1061 &args[ALIAS_TRANS]) == SUB_ERROR)
1064 if ((stat = do_mr_query("add_alias", 3, args, NULL, NULL)))
1065 com_err(program_name, stat, " in CreateFSAlias.");
1071 /* Function Name: RealDeleteFSAlias
1072 * Description: Does the real deletion work.
1073 * Arguments: info - array of char *'s containing all useful info.
1074 * one_item - a Boolean that is true if only one item
1075 * in queue that dumped us here.
1079 void RealDeleteFSAlias(char **info, Bool one_item)
1082 char temp_buf[BUFSIZ];
1085 * Deletions are performed if the user hits 'y' on a list of multiple
1086 * filesystem, or if the user confirms on a unique alias.
1089 "Are you sure that you want to delete the filesystem alias %s",
1091 if (!one_item || Confirm(temp_buf))
1093 if ((stat = do_mr_query("delete_alias", CountArgs(info),
1095 com_err(program_name, stat, " filesystem alias not deleted.");
1097 Put_message("Filesystem alias deleted.");
1100 Put_message("Filesystem alias not deleted.");
1103 /* Function Name: DeleteFSAlias
1104 * Description: Delete an alias name for a filesystem
1105 * Arguments: argc, argv - name of alias in argv[1].
1106 * Returns: DM_NORMAL.
1107 * NOTES: This requires (name, type, transl) I get {name, translation}
1108 * from the user. I provide type, which is well-known.
1111 int DeleteFSAlias(int argc, char **argv)
1113 struct mqelem *elem = GetFSInfo(ALIAS, argv[1]);
1114 QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
1115 "Delete the Filesystem Alias");
1120 /* Function Name: AttachHelp
1121 * Description: Print help info on attachmaint.
1123 * Returns: DM_NORMAL.
1126 int AttachHelp(void)
1128 static char *message[] = {
1129 "These are the options:",
1131 "get - get information about a filesystem.",
1132 "add - add a new filesystem to the data base.",
1133 "update - update the information in the database on a filesystem.",
1134 "delete - delete a filesystem from the database.",
1135 "check - check information about association of a name and a filesys.",
1136 "alias - associate a name with a filesystem.",
1137 "unalias - disassociate a name with a filesystem.",
1138 "verbose - toggle the request for delete confirmation.",
1142 return PrintHelp(message);
1145 /* Function Name: FSGroupHelp
1146 * Description: Print help info on fsgroups.
1148 * Returns: DM_NORMAL.
1151 int FSGroupHelp(int argc, char **argv)
1153 static char *message[] = {
1154 "A filesystem group is a named sorted list of filesystems.",
1156 "To create, modify, or delete a group itself, use the menu above",
1157 " this one, and manipulate a filesystem of type FSGROUP.",
1158 "Options here are:",
1159 " get - get info about a group and show its members",
1160 " add - add a new member to a group.",
1161 " remove - remove a member from a group.",
1162 " order - change the sorting order of a group.",
1166 return PrintHelp(message);