]> andersk Git - moira.git/blame - lib/nfsparttype.c
POSIX, ANSI, sanity fixes
[moira.git] / lib / nfsparttype.c
CommitLineData
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
13static 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
23extern char *strsave();
24extern char *strtrim();
25
26struct pair {
27 int type;
28 char *name;
29};
30
31/*
32 * Table of fs type names.
33 */
34
35static struct pair fs_names[] = {
8defc06b 36 { MR_FS_STUDENT, "Student" },
8defc06b 37 { MR_FS_FACULTY, "Faculty" },
8defc06b 38 { MR_FS_STAFF, "Staff" },
39 { MR_FS_MISC, "Other" },
20c0ae1b 40 { MR_FS_GROUPQUOTA, "GroupQuota" },
56a69e4e 41 /* Insert new entries before the 0,0 pair */
42 { 0, 0 },
43};
44
45/*
46 * Given a numeric string containing a filesystem status value, return
47 * a string indicating what allocation type it is.
48 */
49char *
50format_filesys_type(fs_status)
51 char *fs_status;
52{
53 char buf[BUFSIZ];
54 register struct pair *pp;
55
56 int n_names = 0;
57 int stat = atoi(fs_status);
58
59 buf[0] = '\0';
60
61 for (pp = fs_names; pp->type; pp++) {
62 if (stat & pp->type) {
63 if (n_names) (void) strcat(buf, ", ");
64 (void) strcat(buf, pp->name);
65 n_names++;
66 stat &= ~pp->type;
67 }
68 }
69 if (stat) {
70 char buf1[100];
71
72 if (n_names) (void) strcat (buf, ", ");
73 (void) sprintf(buf1, "Unknown bits 0x%x", stat);
74 (void) strcat (buf, buf1);
75 }
76 if (!n_names) (void) strcpy(buf, "none");
77 return strsave(buf);
78}
79
80/*
81 * Given a string describing a filesystem allocation type, return the
82 * numeric value.
83 */
84char *
85parse_filesys_type(fs_type_name)
86 char *fs_type_name;
87{
88 register struct pair *pp;
89 register char *cp = fs_type_name;
90 char temp[BUFSIZ];
91 int flags = 0;
92
93 do {
94 /* Copy next component of type to temp */
8fd777cf 95 char *t = strchr (cp, ',');
56a69e4e 96 if (t) {
8fd777cf 97 memcpy(temp, cp, t-cp);
56a69e4e 98 temp[t-cp]='\0';
99 cp = t + 1; /* one after the comma */
100 } else {
101 (void) strcpy(temp, cp);
102 cp = NULL;
103 }
104
105 t = strtrim(temp); /* nuke leading and trailing whitespace */
106
107 for (pp = fs_names; pp->type; pp++) {
20c0ae1b 108 if (strcasecmp(pp->name, t) == 0) {
56a69e4e 109 flags |= pp->type;
110 break;
111 }
112 }
113 } while (cp);
114 (void) sprintf(temp, "%d", flags);
115 return strsave(temp);
116}
This page took 0.137129 seconds and 5 git commands to generate.