OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [internal_statvfs.c] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
  /* Now fill in the fields we have information for.  */
21
  buf->f_bsize = fsbuf.f_bsize;
22
  /* Linux does not support f_frsize, so set it to the full block size.  */
23
  buf->f_frsize = fsbuf.f_bsize;
24
  buf->f_blocks = fsbuf.f_blocks;
25
  buf->f_bfree = fsbuf.f_bfree;
26
  buf->f_bavail = fsbuf.f_bavail;
27
  buf->f_files = fsbuf.f_files;
28
  buf->f_ffree = fsbuf.f_ffree;
29
  if (sizeof (buf->f_fsid) == sizeof (fsbuf.f_fsid))
30
    buf->f_fsid = (fsbuf.f_fsid.__val[0]
31
                   | ((unsigned long int) fsbuf.f_fsid.__val[1]
32
                      << (8 * (sizeof (buf->f_fsid)
33
                               - sizeof (fsbuf.f_fsid.__val[0])))));
34
  else
35
    /* We cannot help here.  The statvfs element is not large enough to
36
       contain both words of the statfs f_fsid field.  */
37
    buf->f_fsid = fsbuf.f_fsid.__val[0];
38
#ifdef _STATVFSBUF_F_UNUSED
39
  buf->__f_unused = 0;
40
#endif
41
  buf->f_namemax = fsbuf.f_namelen;
42
  memset (buf->__f_spare, '\0', 6 * sizeof (int));
43
 
44
  /* What remains to do is to fill the fields f_favail and f_flag.  */
45
 
46
  /* XXX I have no idea how to compute f_favail.  Any idea???  */
47
  buf->f_favail = buf->f_ffree;
48
 
49
  /* Determining the flags is tricky.  We have to read /proc/mounts or
50
     the /etc/mtab file and search for the entry which matches the given
51
     file.  The way we can test for matching filesystem is using the
52
     device number.  */
53
  buf->f_flag = 0;
54
  if (STAT (&st) >= 0)
55
    {
56
      int save_errno = errno;
57
      struct mntent mntbuf;
58
      FILE *mtab;
59
 
60
      mtab = __setmntent ("/proc/mounts", "r");
61
      if (mtab == NULL)
62
        mtab = __setmntent (_PATH_MOUNTED, "r");
63
 
64
      if (mtab != NULL)
65
        {
66
          char tmpbuf[1024];
67
 
68
          while (__getmntent_r (mtab, &mntbuf, tmpbuf, sizeof (tmpbuf)))
69
            {
70
              struct stat64 fsst;
71
 
72
              /* Find out about the device the current entry is for.  */
73
              if (stat64 (mntbuf.mnt_dir, &fsst) >= 0
74
                  && st.st_dev == fsst.st_dev)
75
                {
76
                  /* Bingo, we found the entry for the device FD is on.
77
                     Now interpret the option string.  */
78
                  char *cp = mntbuf.mnt_opts;
79
                  char *opt;
80
 
81
                  while ((opt = strsep (&cp, ",")) != NULL)
82
                    if (strcmp (opt, "ro") == 0)
83
                      buf->f_flag |= ST_RDONLY;
84
                    else if (strcmp (opt, "nosuid") == 0)
85
                      buf->f_flag |= ST_NOSUID;
86
                    else if (strcmp (opt, "noexec") == 0)
87
                      buf->f_flag |= ST_NOEXEC;
88
                    else if (strcmp (opt, "nodev") == 0)
89
                      buf->f_flag |= ST_NODEV;
90
                    else if (strcmp (opt, "sync") == 0)
91
                      buf->f_flag |= ST_SYNCHRONOUS;
92
                    else if (strcmp (opt, "mand") == 0)
93
                      buf->f_flag |= ST_MANDLOCK;
94
                    else if (strcmp (opt, "noatime") == 0)
95
                      buf->f_flag |= ST_NOATIME;
96
                    else if (strcmp (opt, "nodiratime") == 0)
97
                      buf->f_flag |= ST_NODIRATIME;
98
 
99
                  /* We can stop looking for more entries.  */
100
                  break;
101
                }
102
            }
103
 
104
          /* Close the file.  */
105
          __endmntent (mtab);
106
        }
107
 
108
      errno = (save_errno);
109
    }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.