]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/internal_statvfs.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / internal_statvfs.c
1 /* Copyright (C) 1998, 1999, 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 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 buf->f_fsid = fsbuf.f_fsid;
30 buf->f_namemax = fsbuf.f_namelen;
31 memset (buf->f_spare, '\0', 6 * sizeof (int));
32
33 /* What remains to do is to fill the fields f_favail and f_flag. */
34
35 /* XXX I have no idea how to compute f_favail. Any idea??? */
36 buf->f_favail = buf->f_ffree;
37
38 /* Determining the flags is tricky. We have to read /proc/mounts or
39 the /etc/mtab file and search for the entry which matches the given
40 file. The way we can test for matching filesystem is using the
41 device number. */
42 buf->f_flag = 0;
43 if (STAT (&st) >= 0)
44 {
45 int save_errno = errno;
46 struct mntent mntbuf;
47 FILE *mtab;
48
49 mtab = __setmntent ("/proc/mounts", "r");
50 if (mtab == NULL)
51 mtab = __setmntent (_PATH_MOUNTED, "r");
52
53 if (mtab != NULL)
54 {
55 char tmpbuf[1024];
56
57 while (__getmntent_r (mtab, &mntbuf, tmpbuf, sizeof (tmpbuf)))
58 {
59 struct stat fsst;
60
61 /* Find out about the device the current entry is for. */
62 if (stat (mntbuf.mnt_dir, &fsst) >= 0
63 && st.st_dev == fsst.st_dev)
64 {
65 /* Bingo, we found the entry for the device FD is on.
66 Now interpret the option string. */
67 char *cp = mntbuf.mnt_opts;
68 char *opt;
69
70 while ((opt = strsep (&cp, ",")) != NULL)
71 if (strcmp (opt, "ro") == 0)
72 buf->f_flag |= ST_RDONLY;
73 else if (strcmp (opt, "nosuid") == 0)
74 buf->f_flag |= ST_NOSUID;
75 else if (strcmp (opt, "noexec") == 0)
76 buf->f_flag |= ST_NOEXEC;
77 else if (strcmp (opt, "nodev") == 0)
78 buf->f_flag |= ST_NODEV;
79 else if (strcmp (opt, "sync") == 0)
80 buf->f_flag |= ST_SYNCHRONOUS;
81 else if (strcmp (opt, "mand") == 0)
82 buf->f_flag |= ST_MANDLOCK;
83 else if (strcmp (opt, "noatime") == 0)
84 buf->f_flag |= ST_NOATIME;
85 else if (strcmp (opt, "nodiratime") == 0)
86 buf->f_flag |= ST_NODIRATIME;
87
88 /* We can stop looking for more entries. */
89 break;
90 }
91 }
92
93 /* Close the file. */
94 __endmntent (mtab);
95 }
96
97 __set_errno (save_errno);
98 }