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] = CanonicalizeHostname(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.");
184 free(args[1]); /* prevents memory leaks. */
186 elem = QueueTop(elem);
187 Loop(elem, (void *) PrintNFSInfo);
193 /* Function Name: AddNFSService
194 * Description: Adds a new partition to the nfsphys relation
195 * Arguments: arc, argv - argv[1] - machine name.
196 * Returns: DM_NORMAL.
201 AddNFSService(argc, argv)
205 char **add_args, *args[10];
206 char *info[MAX_ARGS_SIZE];
209 args[0] = CanonicalizeHostname(argv[1]);
210 if ( (args[1] = GetDirName()) == NULL)
213 if (!ValidName(args[0]) || !ValidName(args[1]))
216 if ( (stat = do_sms_query("get_nfsphys", 2, args,
217 NullFunc, (char *) NULL)) == SMS_SUCCESS)
218 Put_message("This service already exists.");
219 if (stat != SMS_NO_MATCH)
220 com_err(program_name, stat, " in get_nfsphys.");
222 info[NFS_NAME] = Strsave(args[0]);
223 info[NFS_DIR] = args[1]; /* already saved. */
224 info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
225 info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
226 info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
227 info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
228 info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
229 info[NFS_END] = NULL;
231 add_args = AskNFSInfo(info);
233 if ((stat = do_sms_query("add_nfsphys", CountArgs(add_args), add_args,
234 Scream, (char *) NULL)) != 0)
235 com_err(program_name, stat, " in AdsNFSService");
241 /* Function Name: RealUpdateNFSService
242 * Description: performs the actual update of the nfs service.
243 * Arguments: info - info about NFS service stored in array of strings.
244 * junk - an unused boolean.
250 RealUpdateNFSService(info, junk)
257 args = AskNFSInfo(info);
258 if ((stat = do_sms_query("update_nfsphys", CountArgs(args), args,
259 Scream, (char *)NULL)) != SMS_SUCCESS)
260 com_err(program_name, stat, (char *) NULL);
263 /* Function Name: UpdateNFSService
264 * Description: Update the values for an nfsphys entry.
265 * Arguments: argc, argv - argv[1] - machine name.
266 * Returns: DM_NORMAL.
271 UpdateNFSService(argc, argv)
276 struct qelem *elem = NULL;
279 if (!ValidName(argv[1]))
282 args[0] = CanonicalizeHostname(argv[1]);
283 if ( (args[1] = GetDirName()) == NULL)
286 if ( (stat = do_sms_query("get_nfsphys", 2, args,
287 StoreInfo, (char *) &elem)) != SMS_SUCCESS) {
288 com_err(program_name, stat, " in UpdateNFSService.");
291 free(args[1]); /* stop memory leaks. */
293 elem = QueueTop(elem);
294 QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
295 "Update NFS Service for");
301 /* Function Name: FSPartPrint
302 * Description: print filesystem partition usage.
303 * Arguments: info - the filesystem information.
312 sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
316 /* Function Name: RealDeleteNFSService
317 * Description: Actually Deletes the filesystem (some checks are made).
318 * Arguments: info - info about NFS service stored in array of strings.
319 * one_item - if TRUE then only one item on the queue, and
325 RealDeleteNFSService(info, one_item)
329 char temp_buf[BUFSIZ], *args[10];
330 struct qelem *elem= NULL;
334 "Are you sure that you want to delete the %s directory on %s",
335 info[NFS_DIR],info[NFS_NAME]);
338 * Check to be sure that it is not used by any of the nfs packs.
341 if (!one_item || Confirm(temp_buf)) {
342 args[0] = info[NFS_NAME];
343 args[1] = info[NFS_DIR];
345 switch(stat = do_sms_query("get_filesys_by_nfsphys", CountArgs(args),
346 args, StoreInfo, (char *)&elem)) {
347 case SMS_NO_MATCH: /* it is unused, delete it. */
348 if ( (stat = do_sms_query("delete_nfsphys", 2, info, Scream,
349 (char *) NULL )) != SMS_SUCCESS)
350 com_err(program_name, stat, " in DeleteNFSService");
352 Put_message("Physical Filesystem Deleted.");
354 case SMS_SUCCESS: /* it is used, print filesys's that use it. */
355 elem = QueueTop(elem);
356 Put_message("The following fileystems are using this partition,");
357 Put_message("and must be removed before it can be deleted.");
359 Loop(elem, FSPartPrint);
365 com_err(program_name, stat, " while checking usage of partition");
369 Put_message("Physical filesystem not deleted.");
372 /* Function Name: DeleteNFSService
373 * Description: Delete an nfsphys entry.
374 * Arguments: argc, argv - name of the machine in argv[1].
375 * Returns: DM_NORMAL.
380 DeleteNFSService(argc, argv)
385 struct qelem *elem = NULL;
388 if (!ValidName(argv[1]))
391 args[0] = CanonicalizeHostname(argv[1]);
392 if ( (args[1] = GetDirName()) == NULL)
395 switch(stat = do_sms_query("get_nfsphys", 2, args,
396 StoreInfo, (char *) &elem)) {
398 Put_message("This filsystem does not exist!");
403 com_err(program_name, stat, " in DeleteNFSService");
406 free(args[1]); /* stop memory leaks, in your neighborhood. */
408 QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
409 "Delete the Physical Filesystem on Directory");