1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file nfs.c for the SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS 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
28 #include "mit-copyright.h"
33 /* #include <sys/types.h> */
35 #define TYPE_NFS "NFS"
37 #define DEFAULT_DIR "/mit"
38 #define DEFAULT_DEVICE "/dev/ra1c"
39 #define DEFAULT_STATUS DEFAULT_YES /* active. */
40 #define DEFAULT_ALLOC "0"
41 #define DEFAULT_SIZE "0"
43 /* Function Name: UpdatePrint
44 * Description: store a useful string for updates to print.
45 * Arguments: info - info about NFS service stored in array of strings.
46 * Returns: useful string.
53 char temp_buf[BUFSIZ];
54 sprintf(temp_buf, "Machine %s Directory %s",
55 info[NFS_NAME], info[NFS_DIR]);
56 return(Strsave(temp_buf)); /* Small memory leak here, but no good way
57 to avoid it that I see. */
60 /* Function Name: PrintNFSInfo
61 * Description: Prints NFS Physical service information.
62 * Arguments: info - the information.
63 * Returns: directory of this nfs server, for DeleteNFSService().
70 char buf[BUFSIZ], status_buf[BUFSIZ];
71 int status = atoi(info[NFS_STATUS]);
74 status_buf[0] = '\0'; /* clear string. */
76 if (status & SMS_FS_STUDENT) {
77 strcat(status_buf, "Student");
80 if (status & SMS_FS_FACULTY) {
82 strcat(status_buf, " and ");
83 strcat(status_buf, "Faculty");
86 if (status & SMS_FS_STAFF) {
88 strcat(status_buf, " and ");
89 strcat(status_buf, "Staff");
92 if (status & SMS_FS_MISC) {
94 strcat(status_buf, " and ");
95 strcat(status_buf, "Miscellaneous");
97 /* Add another type here. */
99 if (status_buf[0] == '\0')
100 strcat(status_buf, "-- None --");
103 sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s",
104 info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]);
106 sprintf(buf, "Status: %s", status_buf);
108 sprintf(buf, "Quota Allocated: %-17s Size: %s",
109 info[NFS_ALLOC], info[NFS_SIZE]);
111 sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME],
114 return(info[NFS_DIR]);
117 /* Function Name: AskNFSInfo.
118 * Description: This function askes the user for information about a
119 * machine and saves it into a structure.
120 * Arguments: info - a pointer the the structure to put the
122 * Returns: the arglist to make the update call with.
129 /* Also need name of the machine in this structure. */
131 GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]);
132 GetFSTypes(&info[NFS_STATUS]);
133 GetValueFromUser("Allocated Space for this filsystem:",&info[NFS_ALLOC]);
134 GetValueFromUser("Size of this Filsystem:",&info[NFS_SIZE]);
136 FreeAndClear(&info[NFS_MODTIME], TRUE);
137 FreeAndClear(&info[NFS_MODBY], TRUE);
138 FreeAndClear(&info[NFS_MODWITH], TRUE);
143 /* Function Name: GetDirName
144 * Description: get the directory name.
146 * Returns: the directory name.
153 if (Prompt_input("Directory: ", buf, BUFSIZ) == -1)
155 return(Strsave(buf));
158 /* Function Name: ShowNFSService
159 * Description: This function prints all exported partitions.
160 * Arguments: argc, argv - argv[1] - name of machine.
161 * Returns: DM_NORMAL.
166 ShowNFSService(argc, argv)
171 struct qelem *elem = NULL;
174 if (!ValidName(argv[1]))
177 args[0] = canonicalize_hostname(strsave(argv[1]));
178 if ( (args[1] = GetDirName()) == NULL)
181 if ( (stat = do_sms_query("get_nfsphys", 2, args,
182 StoreInfo, (char *) &elem)) != SMS_SUCCESS)
183 com_err(program_name, stat, " in ShowNFSServices.");
185 free(args[1]); /* prevents memory leaks. */
187 elem = QueueTop(elem);
188 Loop(elem, (void *) PrintNFSInfo);
194 /* Function Name: AddNFSService
195 * Description: Adds a new partition to the nfsphys relation
196 * Arguments: arc, argv - argv[1] - machine name.
197 * Returns: DM_NORMAL.
202 AddNFSService(argc, argv)
206 char **add_args, *args[10];
207 char *info[MAX_ARGS_SIZE];
210 args[0] = canonicalize_hostname(strsave(argv[1]));
211 if ( (args[1] = GetDirName()) == NULL)
214 if (!ValidName(args[0]) || !ValidName(args[1]))
217 if ( (stat = do_sms_query("get_nfsphys", 2, args,
218 NullFunc, (char *) NULL)) == SMS_SUCCESS)
219 Put_message("This service already exists.");
220 if (stat != SMS_NO_MATCH)
221 com_err(program_name, stat, " in get_nfsphys.");
223 info[NFS_NAME] = Strsave(args[0]);
224 info[NFS_DIR] = args[1]; /* already saved. */
225 info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
226 info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
227 info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
228 info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
229 info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
230 info[NFS_END] = NULL;
232 add_args = AskNFSInfo(info);
234 if ((stat = do_sms_query("add_nfsphys", CountArgs(add_args), add_args,
235 Scream, (char *) NULL)) != 0)
236 com_err(program_name, stat, " in AdsNFSService");
243 /* Function Name: RealUpdateNFSService
244 * Description: performs the actual update of the nfs service.
245 * Arguments: info - info about NFS service stored in array of strings.
246 * junk - an unused boolean.
252 RealUpdateNFSService(info, junk)
259 args = AskNFSInfo(info);
260 if ((stat = do_sms_query("update_nfsphys", CountArgs(args), args,
261 Scream, (char *)NULL)) != SMS_SUCCESS)
262 com_err(program_name, stat, (char *) NULL);
265 /* Function Name: UpdateNFSService
266 * Description: Update the values for an nfsphys entry.
267 * Arguments: argc, argv - argv[1] - machine name.
268 * Returns: DM_NORMAL.
273 UpdateNFSService(argc, argv)
278 struct qelem *elem = NULL;
281 if (!ValidName(argv[1]))
284 args[0] = canonicalize_hostname(strsave(argv[1]));
285 if ( (args[1] = GetDirName()) == NULL)
288 if ( (stat = do_sms_query("get_nfsphys", 2, args,
289 StoreInfo, (char *) &elem)) != SMS_SUCCESS) {
290 com_err(program_name, stat, " in UpdateNFSService.");
294 free(args[1]); /* stop memory leaks. */
296 elem = QueueTop(elem);
297 QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
298 "Update NFS Service for");
304 /* Function Name: FSPartPrint
305 * Description: print filesystem partition usage.
306 * Arguments: info - the filesystem information.
315 sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
319 /* Function Name: RealDeleteNFSService
320 * Description: Actually Deletes the filesystem (some checks are made).
321 * Arguments: info - info about NFS service stored in array of strings.
322 * one_item - if TRUE then only one item on the queue, and
328 RealDeleteNFSService(info, one_item)
332 char temp_buf[BUFSIZ], *args[10];
333 struct qelem *elem= NULL;
337 "Are you sure that you want to delete the %s directory on %s",
338 info[NFS_DIR],info[NFS_NAME]);
341 * Check to be sure that it is not used by any of the nfs packs.
344 if (!one_item || Confirm(temp_buf)) {
345 args[0] = info[NFS_NAME];
346 args[1] = info[NFS_DIR];
348 switch(stat = do_sms_query("get_filesys_by_nfsphys", CountArgs(args),
349 args, StoreInfo, (char *)&elem)) {
350 case SMS_NO_MATCH: /* it is unused, delete it. */
351 if ( (stat = do_sms_query("delete_nfsphys", 2, info, Scream,
352 (char *) NULL )) != SMS_SUCCESS)
353 com_err(program_name, stat, " in DeleteNFSService");
355 Put_message("Physical Filesystem Deleted.");
357 case SMS_SUCCESS: /* it is used, print filesys's that use it. */
358 elem = QueueTop(elem);
359 Put_message("The following fileystems are using this partition,");
360 Put_message("and must be removed before it can be deleted.");
362 Loop(elem, FSPartPrint);
368 com_err(program_name, stat, " while checking usage of partition");
372 Put_message("Physical filesystem not deleted.");
375 /* Function Name: DeleteNFSService
376 * Description: Delete an nfsphys entry.
377 * Arguments: argc, argv - name of the machine in argv[1].
378 * Returns: DM_NORMAL.
383 DeleteNFSService(argc, argv)
388 struct qelem *elem = NULL;
391 if (!ValidName(argv[1]))
394 args[0] = canonicalize_hostname(strsave(argv[1]));
395 if ( (args[1] = GetDirName()) == NULL)
398 switch(stat = do_sms_query("get_nfsphys", 2, args,
399 StoreInfo, (char *) &elem)) {
401 Put_message("This filsystem does not exist!");
406 com_err(program_name, stat, " in DeleteNFSService");
410 free(args[1]); /* stop memory leaks, in your neighborhood. */
412 QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
413 "Delete the Physical Filesystem on Directory");