1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

Restructure to avoid duplication in 64-bit version.

This commit is contained in:
Ulrich Drepper
2004-04-03 17:32:18 +00:00
parent 68b7392e2c
commit 6016e6f6f5

View File

@ -35,58 +35,19 @@
# define STATFS statfs # define STATFS statfs
# define STATVFS statvfs # define STATVFS statvfs
# define INTERNAL_STATVFS __internal_statvfs # define INTERNAL_STATVFS __internal_statvfs
#endif
void int
INTERNAL_STATVFS (const char *name, struct STATVFS *buf, __statvfs_getflags (const char *name, int fstype, struct stat64 *st)
struct STATFS *fsbuf, struct stat64 *st)
{ {
/* Now fill in the fields we have information for. */ if (st == NULL)
buf->f_bsize = fsbuf->f_bsize; return 0;
/* Linux has the f_frsize size only in later version of the kernel.
If the value is not filled in use f_bsize. */
buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
buf->f_blocks = fsbuf->f_blocks;
buf->f_bfree = fsbuf->f_bfree;
buf->f_bavail = fsbuf->f_bavail;
buf->f_files = fsbuf->f_files;
buf->f_ffree = fsbuf->f_ffree;
if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
buf->f_fsid = (fsbuf->f_fsid.__val[0]
| ((unsigned long int) fsbuf->f_fsid.__val[1]
<< (8 * (sizeof (buf->f_fsid)
- sizeof (fsbuf->f_fsid.__val[0])))));
else
/* We cannot help here. The statvfs element is not large enough to
contain both words of the statfs f_fsid field. */
buf->f_fsid = fsbuf->f_fsid.__val[0];
#ifdef _STATVFSBUF_F_UNUSED
buf->__f_unused = 0;
#endif
buf->f_namemax = fsbuf->f_namelen;
memset (buf->__f_spare, '\0', 6 * sizeof (int));
/* What remains to do is to fill the fields f_favail and f_flag. */
/* XXX I have no idea how to compute f_favail. Any idea??? */
buf->f_favail = buf->f_ffree;
/* Determining the flags is tricky. We have to read /proc/mounts or
the /etc/mtab file and search for the entry which matches the given
file. The way we can test for matching filesystem is using the
device number. */
buf->f_flag = 0;
if (st != NULL)
{
struct mntent mntbuf;
FILE *mtab;
const char *fsname = NULL; const char *fsname = NULL;
const char *fsname2 = NULL; const char *fsname2 = NULL;
bool success = false;
/* Map the filesystem type we got from the statfs call to a string. */ /* Map the filesystem type we got from the statfs call to a string. */
switch (fsbuf->f_type) switch (fstype)
{ {
case EXT2_SUPER_MAGIC: case EXT2_SUPER_MAGIC:
fsname = "ext3"; fsname = "ext3";
@ -112,12 +73,15 @@ INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
break; break;
} }
mtab = __setmntent ("/proc/mounts", "r"); FILE *mtab = __setmntent ("/proc/mounts", "r");
if (mtab == NULL) if (mtab == NULL)
mtab = __setmntent (_PATH_MOUNTED, "r"); mtab = __setmntent (_PATH_MOUNTED, "r");
int result = 0;
if (mtab != NULL) if (mtab != NULL)
{ {
bool success = false;
struct mntent mntbuf;
char tmpbuf[1024]; char tmpbuf[1024];
/* No locking needed. */ /* No locking needed. */
@ -150,21 +114,21 @@ INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
while ((opt = strsep (&cp, ",")) != NULL) while ((opt = strsep (&cp, ",")) != NULL)
if (strcmp (opt, "ro") == 0) if (strcmp (opt, "ro") == 0)
buf->f_flag |= ST_RDONLY; result |= ST_RDONLY;
else if (strcmp (opt, "nosuid") == 0) else if (strcmp (opt, "nosuid") == 0)
buf->f_flag |= ST_NOSUID; result |= ST_NOSUID;
else if (strcmp (opt, "noexec") == 0) else if (strcmp (opt, "noexec") == 0)
buf->f_flag |= ST_NOEXEC; result |= ST_NOEXEC;
else if (strcmp (opt, "nodev") == 0) else if (strcmp (opt, "nodev") == 0)
buf->f_flag |= ST_NODEV; result |= ST_NODEV;
else if (strcmp (opt, "sync") == 0) else if (strcmp (opt, "sync") == 0)
buf->f_flag |= ST_SYNCHRONOUS; result |= ST_SYNCHRONOUS;
else if (strcmp (opt, "mand") == 0) else if (strcmp (opt, "mand") == 0)
buf->f_flag |= ST_MANDLOCK; result |= ST_MANDLOCK;
else if (strcmp (opt, "noatime") == 0) else if (strcmp (opt, "noatime") == 0)
buf->f_flag |= ST_NOATIME; result |= ST_NOATIME;
else if (strcmp (opt, "nodiratime") == 0) else if (strcmp (opt, "nodiratime") == 0)
buf->f_flag |= ST_NODIRATIME; result |= ST_NODIRATIME;
/* We can stop looking for more entries. */ /* We can stop looking for more entries. */
success = true; success = true;
@ -172,9 +136,8 @@ INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
} }
} }
/* Maybe the kernel names for the filesystems changed or the /* Maybe the kernel names for the filesystems changed or the
statvfs call got a name which was not the mount point. statvfs call got a name which was not the mount point. Check
Check again, this time without checking for name matches again, this time without checking for name matches first. */
first. */
if (! success && (name != NULL || fsname != NULL)) if (! success && (name != NULL || fsname != NULL))
{ {
if (name != NULL) if (name != NULL)
@ -197,7 +160,53 @@ INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
/* Close the file. */ /* Close the file. */
__endmntent (mtab); __endmntent (mtab);
}
return result;
} }
} #else
extern int __statvfs_getflags (const char *name, int fstype,
struct stat64 *st);
#endif
void
INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
struct STATFS *fsbuf, struct stat64 *st)
{
/* Now fill in the fields we have information for. */
buf->f_bsize = fsbuf->f_bsize;
/* Linux has the f_frsize size only in later version of the kernel.
If the value is not filled in use f_bsize. */
buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
buf->f_blocks = fsbuf->f_blocks;
buf->f_bfree = fsbuf->f_bfree;
buf->f_bavail = fsbuf->f_bavail;
buf->f_files = fsbuf->f_files;
buf->f_ffree = fsbuf->f_ffree;
if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
buf->f_fsid = (fsbuf->f_fsid.__val[0]
| ((unsigned long int) fsbuf->f_fsid.__val[1]
<< (8 * (sizeof (buf->f_fsid)
- sizeof (fsbuf->f_fsid.__val[0])))));
else
/* We cannot help here. The statvfs element is not large enough to
contain both words of the statfs f_fsid field. */
buf->f_fsid = fsbuf->f_fsid.__val[0];
#ifdef _STATVFSBUF_F_UNUSED
buf->__f_unused = 0;
#endif
buf->f_namemax = fsbuf->f_namelen;
memset (buf->__f_spare, '\0', sizeof (buf->__f_spare));
/* What remains to do is to fill the fields f_favail and f_flag. */
/* XXX I have no idea how to compute f_favail. Any idea??? */
buf->f_favail = buf->f_ffree;
/* Determining the flags is tricky. We have to read /proc/mounts or
the /etc/mtab file and search for the entry which matches the given
file. The way we can test for matching filesystem is using the
device number. */
buf->f_flag = __statvfs_getflags (name, fsbuf->f_type, st);
} }