source: trunk/third/moira/lib/nfsparttype.c @ 24319

Revision 24319, 2.2 KB checked in by broder, 15 years ago (diff)
New Moira snapshot from SVN.
RevLine 
[24319]1/* $Id: nfsparttype.c 3956 2010-01-05 20:56:56Z zacheiss $
[23095]2 *
3 * Deal with NFS partition types
4 *
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>.
8 *
9 */
10
11#include <mit-copyright.h>
12#include <moira.h>
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
[24319]18RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/lib/nfsparttype.c $ $Id: nfsparttype.c 3956 2010-01-05 20:56:56Z zacheiss $");
[23095]19
20struct pair {
21  int type;
22  char *name;
23};
24
25/*
26 * Table of fs type names.
27 */
28
29static struct pair fs_names[] = {
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 },
37};
38
39/*
40 * Given a numeric string containing a filesystem status value, return
41 * a string indicating what allocation type it is.
42 */
43char *format_filesys_type(char *fs_status)
44{
45  char buf[BUFSIZ];
46  struct pair *pp;
47
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;
62        }
63    }
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);
72    }
73  if (!n_names)
74    strcpy(buf, "none");
75  return strdup(buf);
76}
77
78/*
79 * Given a string describing a filesystem allocation type, return the
80 * numeric value.
81 */
82char *parse_filesys_type(char *fs_type_name)
83{
84  struct pair *pp;
85  char *cp = fs_type_name;
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;
103        }
104
105      t = strtrim(temp);        /* nuke leading and trailing whitespace */
106
107      for (pp = fs_names; pp->type; pp++)
108        {
109          if (!strcasecmp(pp->name, t))
110            {
111              flags |= pp->type;
112              break;
113            }
114        }
115    }
116  while (cp);
117  sprintf(temp, "%d", flags);
118  return strdup(temp);
119}
Note: See TracBrowser for help on using the repository browser.