]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
5 | /* This is the file nfs.c for allmaint, the SMS client that allows | |
6 | * a user to maintaint most important parts of the SMS database. | |
7 | * It Contains: The nfs maintanance code. | |
8 | * | |
9 | * Created: 5/6/88 | |
10 | * By: Chris D. Peterson | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
16 | * Copyright 1987, 1988 by the Massachusetts Institute of Technology. | |
17 | * | |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
08345b74 | 22 | #include <stdio.h> |
23 | #include <strings.h> | |
24 | #include <sms.h> | |
25 | #include <menu.h> | |
26 | ||
461c03b6 | 27 | #include "mit-copyright.h" |
28 | #include "allmaint.h" | |
29 | #include "allmaint_funcs.h" | |
30 | #include "globals.h" | |
31 | #include "infodefs.h" | |
32 | ||
08345b74 | 33 | /* #include <sys/types.h> */ |
34 | ||
35 | #define TYPE_NFS "NFS" | |
36 | ||
37 | #define DEFAULT_DIR "/mit" | |
38 | #define DEFAULT_STATUS "1" | |
39 | #define DEFAULT_ALLOC "0" | |
40 | #define DEFAULT_SIZE "400000" | |
41 | ||
42 | /* Function Name: PrintNFSInfo | |
43 | * Description: Prints NFS Physical service information. | |
44 | * Arguments: info - the information. | |
45 | * Returns: none. | |
46 | */ | |
47 | ||
48 | void | |
49 | PrintNFSInfo(info) | |
50 | char ** info; | |
51 | { | |
52 | char temp_buf[BUFSIZ]; | |
53 | int status = atoi(info[NFS_STATUS]); | |
54 | ||
55 | sprintf(temp_buf,"Machine: %s,\tDirectory: %s,\tDevice: %s", | |
56 | info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]); | |
57 | Put_message(temp_buf); | |
58 | sprintf(temp_buf, "Status: %s,\tQuota Allocated: %s.\tSize: %s", | |
59 | status ? "Active" : "Inactive", info[NFS_ALLOC], info[NFS_SIZE]); | |
60 | Put_message(temp_buf); | |
61 | sprintf(temp_buf, "Last Modification by %s at %s with %s.", | |
461c03b6 | 62 | info[U_MODBY], info[U_MODTIME], info[U_MODWITH]); |
08345b74 | 63 | Put_message(temp_buf); |
64 | } | |
65 | /* Function Name: AskNFSInfo. | |
66 | * Description: This function askes the user for information about a | |
67 | * machine and saves it into a structure. | |
68 | * Arguments: info - a pointer the the structure to put the | |
69 | * info into. | |
70 | * Returns: the arglist to make the update call with. | |
71 | */ | |
72 | ||
73 | char ** | |
461c03b6 | 74 | AskNFSInfo(info) |
08345b74 | 75 | char ** info; |
76 | { | |
77 | /* Also need name of the machine in this structure. */ | |
78 | ||
79 | GetValueFromUser("Directory for filesystem:", &info[NFS_DIR]); | |
80 | GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]); | |
81 | ||
82 | Put_message("\nTypes: Student, Faculty, Project, Staff, and Other.\n"); | |
83 | GetValueFromUser("Please enter one or more of the above types:" | |
84 | ,&info[NFS_STATUS]); | |
85 | ||
86 | GetValueFromUser("Allocated Space for this filsystem:",&info[NFS_ALLOC]); | |
87 | GetValueFromUser("Size of this Filsystem:",&info[NFS_SIZE]); | |
88 | ||
89 | FreeAndClear(&info[NFS_MODTIME], TRUE); | |
90 | FreeAndClear(&info[NFS_MODBY], TRUE); | |
91 | FreeAndClear(&info[NFS_MODWITH], TRUE); | |
92 | ||
461c03b6 | 93 | return(info); |
08345b74 | 94 | } |
95 | ||
96 | /* Function Name: ShowNFSService | |
97 | * Description: This function prints all exported partitions. | |
461c03b6 | 98 | * Arguments: argc, argv - argv[1] - name of machine. |
99 | * argv[2] - name of directroy. | |
08345b74 | 100 | * Returns: DM_NORMAL. |
101 | */ | |
102 | ||
85ca828a | 103 | /* ARGSUSED */ |
08345b74 | 104 | int |
105 | ShowNFSService(argc, argv) | |
106 | int argc; | |
107 | char **argv; | |
108 | { | |
109 | register int stat; | |
110 | struct qelem * top, *elem = NULL; | |
111 | ||
112 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
113 | StoreInfo, (char *) &elem)) != 0) | |
461c03b6 | 114 | com_err(program_name, stat, " in ShowNFSServices."); |
08345b74 | 115 | |
116 | top = elem; | |
117 | while (elem != NULL) { | |
461c03b6 | 118 | char ** info = (char **) elem->q_data; |
08345b74 | 119 | PrintNFSInfo(info); |
120 | elem = elem->q_forw; | |
121 | } | |
122 | FreeQueue(top); | |
123 | return (DM_NORMAL); | |
124 | } | |
125 | ||
126 | /* Function Name: AddNFSService | |
127 | * Description: Adds a new partition to the nfsphys relation | |
128 | * Arguments: arc, argv - | |
129 | * argv[1] - machine name. | |
461c03b6 | 130 | * argv[2] - directory. |
08345b74 | 131 | * Returns: DM_NORMAL. |
132 | */ | |
133 | ||
85ca828a | 134 | /* ARGSUSED */ |
08345b74 | 135 | int |
136 | AddNFSService(argc, argv) | |
137 | char **argv; | |
138 | int argc; | |
139 | { | |
140 | char **args; | |
141 | static char *info[MAX_ARGS_SIZE]; | |
142 | int stat; | |
143 | ||
144 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
145 | NullFunc, (char *) NULL)) == 0) { | |
146 | Put_message("This service already exists."); | |
147 | if (stat != SMS_NO_MATCH) | |
461c03b6 | 148 | com_err(program_name, stat, " in get_nfsphys."); |
08345b74 | 149 | } |
150 | ||
151 | if ( (info[NFS_NAME] = CanonicalizeHostname(argv[1])) == NULL) { | |
152 | Put_message("Unknown host, try again..."); | |
153 | return(DM_NORMAL); | |
154 | } | |
155 | ||
156 | info[NFS_NAME] = Strsave(info[NFS_NAME]); | |
157 | info[NFS_DEVICE] = Strsave(argv[2]); | |
158 | info[NFS_DIR] = Strsave(DEFAULT_DIR); | |
159 | info[NFS_STATUS] = Strsave(DEFAULT_STATUS); | |
160 | info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); | |
161 | info[NFS_SIZE] = Strsave(DEFAULT_SIZE); | |
162 | info[NFS_SIZE + 1] = NULL; /* NULL terminate. */ | |
163 | ||
164 | args = AskNFSInfo(info); | |
165 | ||
166 | if ((stat = sms_query("add_nfsphys", CountArgs(args), args, | |
167 | Scream, (char *) NULL)) != 0) | |
461c03b6 | 168 | com_err(program_name, stat, " in AdsNFSService"); |
08345b74 | 169 | |
170 | FreeInfo(info); | |
171 | return (DM_NORMAL); | |
172 | } | |
173 | ||
174 | /* Function Name: UpdateNFSService | |
175 | * Description: Update the values for an nfsphys entry. | |
176 | * Arguments: argc, argv - | |
177 | * argv[1] - machine name. | |
461c03b6 | 178 | * argv[2] - directory. |
08345b74 | 179 | * Returns: DM_NORMAL. |
180 | */ | |
181 | ||
182 | /* ARGSUSED. */ | |
183 | int | |
184 | UpdateNFSService(argc, argv) | |
185 | char **argv; | |
186 | int argc; | |
187 | { | |
188 | register int stat; | |
189 | Bool update, one_service; | |
190 | char **args, **info, buf[BUFSIZ]; | |
191 | struct qelem *elem, *top; | |
192 | elem = NULL; | |
193 | ||
194 | if ( (argv[1] = CanonicalizeHostname(argv[1])) == NULL) { | |
195 | Put_message("Unknown host, try again..."); | |
196 | return(DM_NORMAL); | |
197 | } | |
198 | ||
199 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
200 | StoreInfo, (char *) &elem)) != 0) { | |
461c03b6 | 201 | com_err(program_name, stat, " in UpdateNFSService."); |
08345b74 | 202 | return (DM_NORMAL); |
203 | } | |
204 | ||
85ca828a | 205 | top = elem = QueueTop(elem); |
08345b74 | 206 | one_service = ( QueueCount(top) == 1 ); |
207 | while (elem != NULL) { | |
208 | info = (char **) elem->q_data; | |
209 | if (!one_service) { /* If more than one then query through them. */ | |
210 | sprintf(buf,"Update - %s\tDirectory: %s? (y/n/q)", info[NFS_NAME], | |
211 | info[NFS_DIR]); | |
212 | switch( YesNoQuitQuestion(buf, FALSE)) { | |
213 | case TRUE: | |
214 | update = TRUE; | |
215 | break; | |
216 | case FALSE: | |
217 | update = FALSE; | |
218 | break; | |
461c03b6 | 219 | default: |
08345b74 | 220 | FreeQueue(top); |
221 | Put_message("Aborting update."); | |
461c03b6 | 222 | return(DM_NORMAL); |
08345b74 | 223 | } |
224 | } | |
225 | else | |
226 | update = TRUE; | |
227 | ||
228 | if (update) { /* actually perform update */ | |
229 | args = AskNFSInfo(info); | |
461c03b6 | 230 | if ((stat = sms_query("update_nfsphys", CountArgs(args), args, |
231 | Scream, (char *)NULL)) != 0) | |
232 | com_err(program_name, stat, (char *) NULL); | |
08345b74 | 233 | } |
461c03b6 | 234 | elem = elem->q_forw; |
08345b74 | 235 | } |
236 | ||
237 | FreeQueue(top); | |
238 | return (DM_NORMAL); | |
239 | } | |
240 | ||
08345b74 | 241 | /* Function Name: DeleteNFSService |
242 | * Description: Delete an nfsphys entry. | |
243 | * Arguments: argc, argv - name of file system in argv[1]. | |
244 | * directory of file system in argv[2]. | |
245 | * Returns: DM_NORMAL. | |
246 | */ | |
247 | ||
248 | /* ARGSUSED */ | |
249 | int | |
250 | DeleteNFSService(argc, argv) | |
251 | int argc; | |
252 | char **argv; | |
253 | { | |
254 | register int stat; | |
461c03b6 | 255 | struct qelem *top, *elem = NULL; |
08345b74 | 256 | char * dir = argv[2]; |
257 | int length; | |
258 | Bool delete_ok = TRUE; | |
259 | ||
08345b74 | 260 | argv[1] = CanonicalizeHostname(argv[1]); |
261 | ||
262 | stat = sms_query("get_nfsphys", 2, argv + 1, NullFunc, (char *) NULL); | |
263 | if (stat == SMS_NO_MATCH) { | |
264 | Put_message("This filsystem does not exist!"); | |
265 | return(DM_NORMAL); | |
266 | } | |
267 | if (stat) { | |
461c03b6 | 268 | com_err(program_name, stat, " in DeleteNFSService"); |
08345b74 | 269 | return(DM_NORMAL); |
270 | } | |
271 | ||
272 | stat = sms_query("get_filesys_by_machine", 1, argv + 1, StoreInfo, | |
273 | &elem); | |
274 | if (stat && stat != SMS_NO_MATCH) | |
461c03b6 | 275 | com_err(program_name, stat, " while checking usage of partition"); |
08345b74 | 276 | |
277 | length = strlen( dir ); | |
85ca828a | 278 | top = elem = QueueTop(elem); |
08345b74 | 279 | while (elem != NULL) { |
461c03b6 | 280 | char buf[BUFSIZ]; |
281 | char ** info = (char ** ) elem->q_data; | |
08345b74 | 282 | if ( (strcmp(info[FS_TYPE], TYPE_NFS) == 0) && |
283 | (strcmp(info[FS_PACK], dir, length) == 0) ) { | |
284 | sprintf(buf, "Filesystem %s uses that partition", info[FS_NAME]); | |
285 | Put_message(buf); | |
286 | delete_ok = FALSE; | |
287 | } | |
288 | elem = elem->q_forw; | |
289 | } | |
290 | ||
291 | if ( delete_ok && | |
292 | Confirm("Do you really want to delete this Filesystem? (y/n) ")) { | |
293 | if ( (stat = sms_query("delete_nfsphys", 2, argv + 1, | |
294 | Scream, (char *) NULL )) !=0 ) | |
461c03b6 | 295 | com_err(program_name, stat, " in DeleteNFSService"); |
08345b74 | 296 | } |
297 | else | |
298 | Put_message("Operation Aborted.\n"); | |
299 | ||
300 | FreeQueue(top); | |
301 | return(DM_NORMAL); | |
302 | } | |
303 | ||
304 | ||
305 | /* | |
306 | * Local Variables: | |
307 | * mode: c | |
308 | * c-indent-level: 4 | |
309 | * c-continued-statement-offset: 4 | |
310 | * c-brace-offset: -4 | |
311 | * c-argdecl-indent: 4 | |
312 | * c-label-offset: -4 | |
313 | * End: | |
314 | */ |