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