]>
Commit | Line | Data |
---|---|---|
56a69e4e | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.1 1987-09-03 03:13:40 wesommer | |
10 | * Initial revision | |
11 | * | |
12 | */ | |
13 | ||
14 | #ifndef lint | |
15 | static char *rcsid_nfsparttype_c = "$Header$"; | |
16 | #endif lint | |
17 | ||
18 | #include <sms.h> | |
19 | #include <stdio.h> | |
20 | #include <strings.h> | |
21 | #include <ctype.h> | |
22 | ||
23 | extern char *strsave(); | |
24 | extern char *strtrim(); | |
25 | ||
26 | struct pair { | |
27 | int type; | |
28 | char *name; | |
29 | }; | |
30 | ||
31 | /* | |
32 | * Table of fs type names. | |
33 | */ | |
34 | ||
35 | static struct pair fs_names[] = { | |
36 | { SMS_FS_STUDENT, "Student" }, | |
37 | { SMS_FS_FACULTY, "Faculty/Project" }, | |
38 | { SMS_FS_FACULTY, "Faculty" }, | |
39 | { SMS_FS_FACULTY, "Project" }, | |
40 | { SMS_FS_STAFF, "Staff" }, | |
41 | { SMS_FS_MISC, "Other" }, | |
42 | /* Insert new entries before the 0,0 pair */ | |
43 | { 0, 0 }, | |
44 | }; | |
45 | ||
46 | /* | |
47 | * Given a numeric string containing a filesystem status value, return | |
48 | * a string indicating what allocation type it is. | |
49 | */ | |
50 | char * | |
51 | format_filesys_type(fs_status) | |
52 | char *fs_status; | |
53 | { | |
54 | char buf[BUFSIZ]; | |
55 | register struct pair *pp; | |
56 | ||
57 | int n_names = 0; | |
58 | int stat = atoi(fs_status); | |
59 | ||
60 | buf[0] = '\0'; | |
61 | ||
62 | for (pp = fs_names; pp->type; pp++) { | |
63 | if (stat & pp->type) { | |
64 | if (n_names) (void) strcat(buf, ", "); | |
65 | (void) strcat(buf, pp->name); | |
66 | n_names++; | |
67 | stat &= ~pp->type; | |
68 | } | |
69 | } | |
70 | if (stat) { | |
71 | char buf1[100]; | |
72 | ||
73 | if (n_names) (void) strcat (buf, ", "); | |
74 | (void) sprintf(buf1, "Unknown bits 0x%x", stat); | |
75 | (void) strcat (buf, buf1); | |
76 | } | |
77 | if (!n_names) (void) strcpy(buf, "none"); | |
78 | return strsave(buf); | |
79 | } | |
80 | ||
81 | /* | |
82 | * Given a string describing a filesystem allocation type, return the | |
83 | * numeric value. | |
84 | */ | |
85 | char * | |
86 | parse_filesys_type(fs_type_name) | |
87 | char *fs_type_name; | |
88 | { | |
89 | register struct pair *pp; | |
90 | register char *cp = fs_type_name; | |
91 | char temp[BUFSIZ]; | |
92 | int flags = 0; | |
93 | ||
94 | do { | |
95 | /* Copy next component of type to temp */ | |
96 | char *t = index (cp, ','); | |
97 | if (t) { | |
98 | bcopy(cp, temp, t-cp); | |
99 | temp[t-cp]='\0'; | |
100 | cp = t + 1; /* one after the comma */ | |
101 | } else { | |
102 | (void) strcpy(temp, cp); | |
103 | cp = NULL; | |
104 | } | |
105 | ||
106 | t = strtrim(temp); /* nuke leading and trailing whitespace */ | |
107 | ||
108 | for (pp = fs_names; pp->type; pp++) { | |
109 | if (cistrcmp(pp->name, t) == 0) { | |
110 | flags |= pp->type; | |
111 | break; | |
112 | } | |
113 | } | |
114 | } while (cp); | |
115 | (void) sprintf(temp, "%d", flags); | |
116 | return strsave(temp); | |
117 | } |