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