1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file nfs.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
7 * It Contains: All functions for manipulating NFS Physical directories.
10 * By: Chris D. Peterson
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
25 #include <moira_site.h>
28 #include "mit-copyright.h"
34 #define TYPE_NFS "NFS"
36 #define DEFAULT_DIR "/u1/lockers"
37 #define DEFAULT_DEVICE "/dev/ra1c"
38 #define DEFAULT_STATUS DEFAULT_YES /* active. */
39 #define DEFAULT_ALLOC "0"
40 #define DEFAULT_SIZE "0"
42 /* Function Name: UpdatePrint
43 * Description: store a useful string for updates to print.
44 * Arguments: info - info about NFS service stored in array of strings.
45 * Returns: useful string.
52 char temp_buf[BUFSIZ];
53 sprintf(temp_buf, "Machine %s Directory %s",
54 info[NFS_NAME], info[NFS_DIR]);
55 return(Strsave(temp_buf)); /* Small memory leak here, but no good way
56 to avoid it that I see. */
59 /* Function Name: PrintNFSInfo
60 * Description: Prints NFS Physical service information.
61 * Arguments: info - the information.
62 * Returns: directory of this nfs server, for DeleteNFSService().
69 char buf[BUFSIZ], status_buf[BUFSIZ];
70 int status = atoi(info[NFS_STATUS]);
73 status_buf[0] = '\0'; /* clear string. */
75 if (status & MR_FS_STUDENT) {
76 strcat(status_buf, "Student");
79 if (status & MR_FS_FACULTY) {
81 strcat(status_buf, " and ");
82 strcat(status_buf, "Faculty");
85 if (status & MR_FS_STAFF) {
87 strcat(status_buf, " and ");
88 strcat(status_buf, "Staff");
91 if (status & MR_FS_MISC) {
93 strcat(status_buf, " and ");
94 strcat(status_buf, "Miscellaneous");
96 /* Add another type here. */
97 if (status & MR_FS_GROUPQUOTA) {
99 strcat(status_buf, " / ");
100 strcat(status_buf, "Group Quotas Enabled");
103 if (status_buf[0] == '\0')
104 strcat(status_buf, "-- None --");
107 sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s",
108 info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]);
110 sprintf(buf, "Status: %s", status_buf);
112 sprintf(buf, "Quota Allocated: %-17s Size: %s",
113 info[NFS_ALLOC], info[NFS_SIZE]);
115 sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME],
118 return(info[NFS_DIR]);
121 /* Function Name: AskNFSInfo.
122 * Description: This function askes the user for information about a
123 * machine and saves it into a structure.
124 * Arguments: info - a pointer the the structure to put the
126 * Returns: the arglist to make the update call with.
133 /* Also need name of the machine in this structure. */
135 if (GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]) ==
138 if (GetFSTypes(&info[NFS_STATUS], TRUE) == SUB_ERROR)
140 if (GetValueFromUser("Allocated Space for this filsystem:",
141 &info[NFS_ALLOC]) == SUB_ERROR)
143 if (GetValueFromUser("Size of this Filsystem:", &info[NFS_SIZE]) ==
147 FreeAndClear(&info[NFS_MODTIME], TRUE);
148 FreeAndClear(&info[NFS_MODBY], TRUE);
149 FreeAndClear(&info[NFS_MODWITH], TRUE);
155 /* Function Name: ShowNFSService
156 * Description: This function prints all exported partitions.
157 * Arguments: argc, argv - argv[1] - name of machine.
158 * Returns: DM_NORMAL.
163 ShowNFSService(argc, argv)
168 struct qelem *elem = NULL;
171 if (!ValidName(argv[1]))
174 args[0] = canonicalize_hostname(strsave(argv[1]));
175 args[1] = strsave(DEFAULT_DIR);
176 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
179 if ( (stat = do_mr_query("get_nfsphys", 2, args,
180 StoreInfo, (char *) &elem)) != MR_SUCCESS)
181 com_err(program_name, stat, " in ShowNFSServices.");
183 free(args[1]); /* prevents memory leaks. */
185 elem = QueueTop(elem);
186 Loop(elem, (void *) PrintNFSInfo);
192 /* Function Name: AddNFSService
193 * Description: Adds a new partition to the nfsphys relation
194 * Arguments: arc, argv - argv[1] - machine name.
195 * Returns: DM_NORMAL.
200 AddNFSService(argc, argv)
204 char **add_args, *args[10];
205 char *info[MAX_ARGS_SIZE];
208 args[0] = canonicalize_hostname(strsave(argv[1]));
209 args[1] = strsave(DEFAULT_DIR);
210 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
213 if (!ValidName(args[0]) || !ValidName(args[1]))
216 if ( (stat = do_mr_query("get_nfsphys", 2, args,
217 NullFunc, (char *) NULL)) == MR_SUCCESS)
219 if (stat != MR_NO_MATCH) {
220 com_err(program_name, stat, " in get_nfsphys.");
224 info[NFS_NAME] = Strsave(args[0]);
225 info[NFS_DIR] = args[1]; /* already saved. */
226 info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
227 info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
228 info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
229 info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
230 info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
231 info[NFS_END] = NULL;
233 if ((add_args = AskNFSInfo(info)) == NULL) {
234 Put_message("Aborted.");
238 if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args,
239 Scream, (char *) NULL)) != 0)
240 com_err(program_name, stat, " in AdsNFSService");
247 /* Function Name: RealUpdateNFSService
248 * Description: performs the actual update of the nfs service.
249 * Arguments: info - info about NFS service stored in array of strings.
250 * junk - an unused boolean.
256 RealUpdateNFSService(info, junk)
263 if ((args = AskNFSInfo(info)) == NULL) {
264 Put_message("Aborted.");
268 if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args,
269 Scream, (char *)NULL)) != MR_SUCCESS)
270 com_err(program_name, stat, " in RealUpdateNFSService");
273 /* Function Name: UpdateNFSService
274 * Description: Update the values for an nfsphys entry.
275 * Arguments: argc, argv - argv[1] - machine name.
276 * Returns: DM_NORMAL.
281 UpdateNFSService(argc, argv)
286 struct qelem *elem = NULL;
289 if (!ValidName(argv[1]))
292 args[0] = canonicalize_hostname(strsave(argv[1]));
293 args[1] = strsave(DEFAULT_DIR);
294 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
297 if ( (stat = do_mr_query("get_nfsphys", 2, args,
298 StoreInfo, (char *) &elem)) != MR_SUCCESS) {
299 com_err(program_name, stat, " in UpdateNFSService.");
303 free(args[1]); /* stop memory leaks. */
305 elem = QueueTop(elem);
306 QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
307 "Update NFS Service for");
313 /* Function Name: FSPartPrint
314 * Description: print filesystem partition usage.
315 * Arguments: info - the filesystem information.
324 sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
328 /* Function Name: RealDeleteNFSService
329 * Description: Actually Deletes the filesystem (some checks are made).
330 * Arguments: info - info about NFS service stored in array of strings.
331 * one_item - if TRUE then only one item on the queue, and
337 RealDeleteNFSService(info, one_item)
341 char temp_buf[BUFSIZ], *args[10];
342 struct qelem *elem= NULL;
346 "Are you sure that you want to delete the %s directory on %s",
347 info[NFS_DIR],info[NFS_NAME]);
350 * Check to be sure that it is not used by any of the nfs packs.
353 if (!one_item || Confirm(temp_buf)) {
354 args[0] = info[NFS_NAME];
355 args[1] = info[NFS_DIR];
357 switch(stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args),
358 args, StoreInfo, (char *)&elem)) {
359 case MR_NO_MATCH: /* it is unused, delete it. */
360 if ( (stat = do_mr_query("delete_nfsphys", 2, info, Scream,
361 (char *) NULL )) != MR_SUCCESS)
362 com_err(program_name, stat, " in DeleteNFSService");
364 Put_message("Physical Filesystem Deleted.");
366 case MR_SUCCESS: /* it is used, print filesys's that use it. */
367 elem = QueueTop(elem);
368 Put_message("The following fileystems are using this partition,");
369 Put_message("and must be removed before it can be deleted.");
371 Loop(elem, FSPartPrint);
377 com_err(program_name, stat, " while checking usage of partition");
381 Put_message("Physical filesystem not deleted.");
384 /* Function Name: DeleteNFSService
385 * Description: Delete an nfsphys entry.
386 * Arguments: argc, argv - name of the machine in argv[1].
387 * Returns: DM_NORMAL.
392 DeleteNFSService(argc, argv)
397 struct qelem *elem = NULL;
400 if (!ValidName(argv[1]))
403 args[0] = canonicalize_hostname(strsave(argv[1]));
404 args[1] = strsave(DEFAULT_DIR);
405 if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
408 switch(stat = do_mr_query("get_nfsphys", 2, args,
409 StoreInfo, (char *) &elem)) {
411 Put_message("This filsystem does not exist!");
416 com_err(program_name, stat, " in DeleteNFSService");
420 free(args[1]); /* stop memory leaks, in your neighborhood. */
422 QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
423 "Delete the Physical Filesystem on Directory");