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 "/mit"
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 GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]);
136 GetFSTypes(&info[NFS_STATUS]);
137 GetValueFromUser("Allocated Space for this filsystem:",&info[NFS_ALLOC]);
138 GetValueFromUser("Size of this Filsystem:",&info[NFS_SIZE]);
140 FreeAndClear(&info[NFS_MODTIME], TRUE);
141 FreeAndClear(&info[NFS_MODBY], TRUE);
142 FreeAndClear(&info[NFS_MODWITH], TRUE);
147 /* Function Name: GetDirName
148 * Description: get the directory name.
150 * Returns: the directory name.
157 if (Prompt_input("Directory: ", buf, BUFSIZ) == -1)
159 return(Strsave(buf));
162 /* Function Name: ShowNFSService
163 * Description: This function prints all exported partitions.
164 * Arguments: argc, argv - argv[1] - name of machine.
165 * Returns: DM_NORMAL.
170 ShowNFSService(argc, argv)
175 struct qelem *elem = NULL;
178 if (!ValidName(argv[1]))
181 args[0] = canonicalize_hostname(strsave(argv[1]));
182 if ( (args[1] = GetDirName()) == NULL)
185 if ( (stat = do_mr_query("get_nfsphys", 2, args,
186 StoreInfo, (char *) &elem)) != MR_SUCCESS)
187 com_err(program_name, stat, " in ShowNFSServices.");
189 free(args[1]); /* prevents memory leaks. */
191 elem = QueueTop(elem);
192 Loop(elem, (void *) PrintNFSInfo);
198 /* Function Name: AddNFSService
199 * Description: Adds a new partition to the nfsphys relation
200 * Arguments: arc, argv - argv[1] - machine name.
201 * Returns: DM_NORMAL.
206 AddNFSService(argc, argv)
210 char **add_args, *args[10];
211 char *info[MAX_ARGS_SIZE];
214 args[0] = canonicalize_hostname(strsave(argv[1]));
215 if ( (args[1] = GetDirName()) == NULL)
218 if (!ValidName(args[0]) || !ValidName(args[1]))
221 if ( (stat = do_mr_query("get_nfsphys", 2, args,
222 NullFunc, (char *) NULL)) == MR_SUCCESS)
223 Put_message("This service already exists.");
224 if (stat != MR_NO_MATCH)
225 com_err(program_name, stat, " in get_nfsphys.");
227 info[NFS_NAME] = Strsave(args[0]);
228 info[NFS_DIR] = args[1]; /* already saved. */
229 info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
230 info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
231 info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
232 info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
233 info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
234 info[NFS_END] = NULL;
236 add_args = AskNFSInfo(info);
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 args = AskNFSInfo(info);
264 if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args,
265 Scream, (char *)NULL)) != MR_SUCCESS)
266 com_err(program_name, stat, (char *) NULL);
269 /* Function Name: UpdateNFSService
270 * Description: Update the values for an nfsphys entry.
271 * Arguments: argc, argv - argv[1] - machine name.
272 * Returns: DM_NORMAL.
277 UpdateNFSService(argc, argv)
282 struct qelem *elem = NULL;
285 if (!ValidName(argv[1]))
288 args[0] = canonicalize_hostname(strsave(argv[1]));
289 if ( (args[1] = GetDirName()) == NULL)
292 if ( (stat = do_mr_query("get_nfsphys", 2, args,
293 StoreInfo, (char *) &elem)) != MR_SUCCESS) {
294 com_err(program_name, stat, " in UpdateNFSService.");
298 free(args[1]); /* stop memory leaks. */
300 elem = QueueTop(elem);
301 QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
302 "Update NFS Service for");
308 /* Function Name: FSPartPrint
309 * Description: print filesystem partition usage.
310 * Arguments: info - the filesystem information.
319 sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
323 /* Function Name: RealDeleteNFSService
324 * Description: Actually Deletes the filesystem (some checks are made).
325 * Arguments: info - info about NFS service stored in array of strings.
326 * one_item - if TRUE then only one item on the queue, and
332 RealDeleteNFSService(info, one_item)
336 char temp_buf[BUFSIZ], *args[10];
337 struct qelem *elem= NULL;
341 "Are you sure that you want to delete the %s directory on %s",
342 info[NFS_DIR],info[NFS_NAME]);
345 * Check to be sure that it is not used by any of the nfs packs.
348 if (!one_item || Confirm(temp_buf)) {
349 args[0] = info[NFS_NAME];
350 args[1] = info[NFS_DIR];
352 switch(stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args),
353 args, StoreInfo, (char *)&elem)) {
354 case MR_NO_MATCH: /* it is unused, delete it. */
355 if ( (stat = do_mr_query("delete_nfsphys", 2, info, Scream,
356 (char *) NULL )) != MR_SUCCESS)
357 com_err(program_name, stat, " in DeleteNFSService");
359 Put_message("Physical Filesystem Deleted.");
361 case MR_SUCCESS: /* it is used, print filesys's that use it. */
362 elem = QueueTop(elem);
363 Put_message("The following fileystems are using this partition,");
364 Put_message("and must be removed before it can be deleted.");
366 Loop(elem, FSPartPrint);
372 com_err(program_name, stat, " while checking usage of partition");
376 Put_message("Physical filesystem not deleted.");
379 /* Function Name: DeleteNFSService
380 * Description: Delete an nfsphys entry.
381 * Arguments: argc, argv - name of the machine in argv[1].
382 * Returns: DM_NORMAL.
387 DeleteNFSService(argc, argv)
392 struct qelem *elem = NULL;
395 if (!ValidName(argv[1]))
398 args[0] = canonicalize_hostname(strsave(argv[1]));
399 if ( (args[1] = GetDirName()) == NULL)
402 switch(stat = do_mr_query("get_nfsphys", 2, args,
403 StoreInfo, (char *) &elem)) {
405 Put_message("This filsystem does not exist!");
410 com_err(program_name, stat, " in DeleteNFSService");
414 free(args[1]); /* stop memory leaks, in your neighborhood. */
416 QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
417 "Delete the Physical Filesystem on Directory");