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