]>
Commit | Line | Data |
---|---|---|
08345b74 | 1 | #ifndef lint |
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 | ||
103 | int | |
104 | ShowNFSService(argc, argv) | |
105 | int argc; | |
106 | char **argv; | |
107 | { | |
108 | register int stat; | |
109 | struct qelem * top, *elem = NULL; | |
110 | ||
111 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
112 | StoreInfo, (char *) &elem)) != 0) | |
461c03b6 | 113 | com_err(program_name, stat, " in ShowNFSServices."); |
08345b74 | 114 | |
115 | top = elem; | |
116 | while (elem != NULL) { | |
461c03b6 | 117 | char ** info = (char **) elem->q_data; |
08345b74 | 118 | PrintNFSInfo(info); |
119 | elem = elem->q_forw; | |
120 | } | |
121 | FreeQueue(top); | |
122 | return (DM_NORMAL); | |
123 | } | |
124 | ||
125 | /* Function Name: AddNFSService | |
126 | * Description: Adds a new partition to the nfsphys relation | |
127 | * Arguments: arc, argv - | |
128 | * argv[1] - machine name. | |
461c03b6 | 129 | * argv[2] - directory. |
08345b74 | 130 | * Returns: DM_NORMAL. |
131 | */ | |
132 | ||
133 | int | |
134 | AddNFSService(argc, argv) | |
135 | char **argv; | |
136 | int argc; | |
137 | { | |
138 | char **args; | |
139 | static char *info[MAX_ARGS_SIZE]; | |
140 | int stat; | |
141 | ||
142 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
143 | NullFunc, (char *) NULL)) == 0) { | |
144 | Put_message("This service already exists."); | |
145 | if (stat != SMS_NO_MATCH) | |
461c03b6 | 146 | com_err(program_name, stat, " in get_nfsphys."); |
08345b74 | 147 | } |
148 | ||
149 | if ( (info[NFS_NAME] = CanonicalizeHostname(argv[1])) == NULL) { | |
150 | Put_message("Unknown host, try again..."); | |
151 | return(DM_NORMAL); | |
152 | } | |
153 | ||
154 | info[NFS_NAME] = Strsave(info[NFS_NAME]); | |
155 | info[NFS_DEVICE] = Strsave(argv[2]); | |
156 | info[NFS_DIR] = Strsave(DEFAULT_DIR); | |
157 | info[NFS_STATUS] = Strsave(DEFAULT_STATUS); | |
158 | info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); | |
159 | info[NFS_SIZE] = Strsave(DEFAULT_SIZE); | |
160 | info[NFS_SIZE + 1] = NULL; /* NULL terminate. */ | |
161 | ||
162 | args = AskNFSInfo(info); | |
163 | ||
164 | if ((stat = sms_query("add_nfsphys", CountArgs(args), args, | |
165 | Scream, (char *) NULL)) != 0) | |
461c03b6 | 166 | com_err(program_name, stat, " in AdsNFSService"); |
08345b74 | 167 | |
168 | FreeInfo(info); | |
169 | return (DM_NORMAL); | |
170 | } | |
171 | ||
172 | /* Function Name: UpdateNFSService | |
173 | * Description: Update the values for an nfsphys entry. | |
174 | * Arguments: argc, argv - | |
175 | * argv[1] - machine name. | |
461c03b6 | 176 | * argv[2] - directory. |
08345b74 | 177 | * Returns: DM_NORMAL. |
178 | */ | |
179 | ||
180 | /* ARGSUSED. */ | |
181 | int | |
182 | UpdateNFSService(argc, argv) | |
183 | char **argv; | |
184 | int argc; | |
185 | { | |
186 | register int stat; | |
187 | Bool update, one_service; | |
188 | char **args, **info, buf[BUFSIZ]; | |
189 | struct qelem *elem, *top; | |
190 | elem = NULL; | |
191 | ||
192 | if ( (argv[1] = CanonicalizeHostname(argv[1])) == NULL) { | |
193 | Put_message("Unknown host, try again..."); | |
194 | return(DM_NORMAL); | |
195 | } | |
196 | ||
197 | if ( (stat = sms_query("get_nfsphys", 2, argv + 1, | |
198 | StoreInfo, (char *) &elem)) != 0) { | |
461c03b6 | 199 | com_err(program_name, stat, " in UpdateNFSService."); |
08345b74 | 200 | return (DM_NORMAL); |
201 | } | |
202 | ||
203 | top = elem; | |
204 | one_service = ( QueueCount(top) == 1 ); | |
205 | while (elem != NULL) { | |
206 | info = (char **) elem->q_data; | |
207 | if (!one_service) { /* If more than one then query through them. */ | |
208 | sprintf(buf,"Update - %s\tDirectory: %s? (y/n/q)", info[NFS_NAME], | |
209 | info[NFS_DIR]); | |
210 | switch( YesNoQuitQuestion(buf, FALSE)) { | |
211 | case TRUE: | |
212 | update = TRUE; | |
213 | break; | |
214 | case FALSE: | |
215 | update = FALSE; | |
216 | break; | |
461c03b6 | 217 | default: |
08345b74 | 218 | FreeQueue(top); |
219 | Put_message("Aborting update."); | |
461c03b6 | 220 | return(DM_NORMAL); |
08345b74 | 221 | } |
222 | } | |
223 | else | |
224 | update = TRUE; | |
225 | ||
226 | if (update) { /* actually perform update */ | |
227 | args = AskNFSInfo(info); | |
461c03b6 | 228 | if ((stat = sms_query("update_nfsphys", CountArgs(args), args, |
229 | Scream, (char *)NULL)) != 0) | |
230 | com_err(program_name, stat, (char *) NULL); | |
08345b74 | 231 | } |
461c03b6 | 232 | elem = elem->q_forw; |
08345b74 | 233 | } |
234 | ||
235 | FreeQueue(top); | |
236 | return (DM_NORMAL); | |
237 | } | |
238 | ||
08345b74 | 239 | /* Function Name: DeleteNFSService |
240 | * Description: Delete an nfsphys entry. | |
241 | * Arguments: argc, argv - name of file system in argv[1]. | |
242 | * directory of file system in argv[2]. | |
243 | * Returns: DM_NORMAL. | |
244 | */ | |
245 | ||
246 | /* ARGSUSED */ | |
247 | int | |
248 | DeleteNFSService(argc, argv) | |
249 | int argc; | |
250 | char **argv; | |
251 | { | |
252 | register int stat; | |
461c03b6 | 253 | struct qelem *top, *elem = NULL; |
08345b74 | 254 | char * dir = argv[2]; |
255 | int length; | |
256 | Bool delete_ok = TRUE; | |
257 | ||
08345b74 | 258 | argv[1] = CanonicalizeHostname(argv[1]); |
259 | ||
260 | stat = sms_query("get_nfsphys", 2, argv + 1, NullFunc, (char *) NULL); | |
261 | if (stat == SMS_NO_MATCH) { | |
262 | Put_message("This filsystem does not exist!"); | |
263 | return(DM_NORMAL); | |
264 | } | |
265 | if (stat) { | |
461c03b6 | 266 | com_err(program_name, stat, " in DeleteNFSService"); |
08345b74 | 267 | return(DM_NORMAL); |
268 | } | |
269 | ||
270 | stat = sms_query("get_filesys_by_machine", 1, argv + 1, StoreInfo, | |
271 | &elem); | |
272 | if (stat && stat != SMS_NO_MATCH) | |
461c03b6 | 273 | com_err(program_name, stat, " while checking usage of partition"); |
08345b74 | 274 | |
275 | length = strlen( dir ); | |
276 | top = elem; | |
277 | while (elem != NULL) { | |
461c03b6 | 278 | char buf[BUFSIZ]; |
279 | char ** info = (char ** ) elem->q_data; | |
08345b74 | 280 | if ( (strcmp(info[FS_TYPE], TYPE_NFS) == 0) && |
281 | (strcmp(info[FS_PACK], dir, length) == 0) ) { | |
282 | sprintf(buf, "Filesystem %s uses that partition", info[FS_NAME]); | |
283 | Put_message(buf); | |
284 | delete_ok = FALSE; | |
285 | } | |
286 | elem = elem->q_forw; | |
287 | } | |
288 | ||
289 | if ( delete_ok && | |
290 | Confirm("Do you really want to delete this Filesystem? (y/n) ")) { | |
291 | if ( (stat = sms_query("delete_nfsphys", 2, argv + 1, | |
292 | Scream, (char *) NULL )) !=0 ) | |
461c03b6 | 293 | com_err(program_name, stat, " in DeleteNFSService"); |
08345b74 | 294 | } |
295 | else | |
296 | Put_message("Operation Aborted.\n"); | |
297 | ||
298 | FreeQueue(top); | |
299 | return(DM_NORMAL); | |
300 | } | |
301 | ||
302 | ||
303 | /* | |
304 | * Local Variables: | |
305 | * mode: c | |
306 | * c-indent-level: 4 | |
307 | * c-continued-statement-offset: 4 | |
308 | * c-brace-offset: -4 | |
309 | * c-argdecl-indent: 4 | |
310 | * c-label-offset: -4 | |
311 | * End: | |
312 | */ |