[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: df: auto fs's don't show in normal df
From: |
Jim Meyering |
Subject: |
Re: df: auto fs's don't show in normal df |
Date: |
Sun, 09 Dec 2001 22:53:33 +0100 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1.50 (i686-pc-linux-gnu) |
Jim Meyering <address@hidden> wrote:
> Burton Windle <address@hidden> wrote:
>> Hello. I recently started using Ext3, and based on advice on the LKML,
>> changed my /etc/fstab to mount / as auto (incase I didn't have ext2
>> support). This was tested on 2.4.16, as well as 2.5.1-pre4.
>>
>> Now, my / partition doesn't show up in 'df' unless I do 'df -a' or
>> explictly as for /
>>
>> If I change my /etc/fstab to mount / as ext3 instead of auto, it works
>> again.
>
> Thanks for the report.
> However, this doesn't seem to be a problem with df.
>
> I suspect that you're not using new enough tools like mount
> or a new enough libc. I've just created an ext3 partition,
> marked it as `auto' in /etc/fstab, and rebooted. Now, df lists
> it and df -T shows its type as `ext3'.
>
> I'm using libc-2.2.4, mount-2.11m, e2fsck-1.25, and linux-2.4.16.
I now know that this problem arises only when / is of type ext3.
There's an ongoing discussion about how to fix this on the ext3-users
mailing list. IMHO it's not a problem with df. df ignores entries
of type `auto' because historically those have been duplicate entries
associated with certain types of automount systems. If you're really set
on using df with the current set-up, you might want to try the following
truly kludgey patch that works only if you have procfs. It's relative
to the latest test release:
ftp://alpha.gnu.org/gnu/fetish/fileutils-4.1.3.tar.gz
I've barely tested that patch, so treat it with caution.
Since I expect mount (or something) to be fixed, I don't plan to
check in this change -- it'd just bloat the code unnecessarily.
You can always change fstab to specify ext3 instead of auto if you
really care (and be careful to change it if you change to a kernel
that's not ext3-aware).
Index: mountlist.c
===================================================================
RCS file: /fetish/fileutils/lib/mountlist.c,v
retrieving revision 1.37
diff -u -p -u -p -r1.37 mountlist.c
--- mountlist.c 2001/11/17 13:50:40 1.37
+++ mountlist.c 2001/12/09 21:46:22
@@ -33,6 +33,7 @@ void free ();
#else
# include <strings.h>
#endif
+#include "getstr.h"
#include "xalloc.h"
#ifndef strstr
@@ -145,6 +146,8 @@ extern int errno;
#include "mountlist.h"
#include "unlocked-io.h"
+#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
+
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
/* Return the value of the hexadecimal number represented by CP.
No prefix (like '0x') or suffix (like 'h') is expected to be
@@ -171,6 +174,82 @@ xatoi (char *cp)
}
return val;
}
+
+#define CLOSE_AND_RETURN(Fp, String) \
+ do { fclose (Fp); return String; } while (0)
+
+/* This is a kludge to determine the real type of the root file system
+ when it is recorded as `auto' in /etc/fstab and /etc/mtab (by mount).
+ As far as I know, this happens only for the root partition on Linux
+ systems when that partition is of type ext3 and when its type is
+ listed as `auto' in /etc/fstab. Until mount is fixed, this should help.
+
+ Return in malloc'd storage the type of the root file system as recorded
+ in /proc/mounts. Each line in that file is expected to look like this:
+
+ /dev/scsi/host0/bus0/target0/lun0/part4 / ext3 rw 0 0
+
+ where there is no leading white space, and there is a single space
+ between tokens. This function reads /proc/mounts and returns the
+ type, `ext3' in the above example. If no matching line is found,
+ or if the file can't be opened, or if getstr can't allocate space,
+ return NULL. */
+static char *
+resolve_root_mount_type (char const *proc_mount_file)
+{
+ FILE *fp = fopen (proc_mount_file, "r");
+ if (!fp)
+ return NULL;
+
+ while (1)
+ {
+ /* skip first sequence of non-spaces */
+ while (1)
+ {
+ int c = fgetc (fp);
+ if (c == ' ')
+ break;
+ if (c == EOF)
+ CLOSE_AND_RETURN (fp, NULL);
+ }
+
+ /* The next sequence of non-spaces is the mount point.
+ Skip this line if it's not `/'. */
+ int ch = fgetc (fp);
+ if (ch == '/' && fgetc (fp) == ' ')
+ {
+ /* This sequence of non-spaces is the file system type. */
+ char *fs_name = NULL;
+ size_t fs_name_alloc;
+ int fs_name_len = getstr (&fs_name, &fs_name_alloc, fp, ' ', 0, 0);
+ fclose (fp);
+ if (fs_name_len <= 1)
+ return NULL;
+ if (fs_name[fs_name_len - 1] != ' ')
+ {
+ free (fs_name);
+ return NULL;
+ }
+ fs_name[--fs_name_len] = '\0';
+
+ return fs_name;
+ }
+
+ if (ch == EOF)
+ CLOSE_AND_RETURN (fp, NULL);
+
+ /* read up to and including the next newline */
+ while (1)
+ {
+ int c = fgetc (fp);
+ if (c == '\n')
+ break;
+ if (c == EOF)
+ CLOSE_AND_RETURN (fp, NULL);
+ }
+ }
+}
+
#endif /* MOUNTED_GETMNTENT1. */
#if MOUNTED_GETMNTINFO
@@ -352,10 +431,14 @@ read_filesystem_list (int need_fs_type)
while ((mnt = getmntent (fp)))
{
+ char *t;
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
me->me_devname = xstrdup (mnt->mnt_fsname);
me->me_mountdir = xstrdup (mnt->mnt_dir);
- me->me_type = xstrdup (mnt->mnt_type);
+ me->me_type = ((STREQ (mnt->mnt_type, "auto")
+ && STREQ (mnt->mnt_dir, "/")
+ && (t = resolve_root_mount_type ("/proc/mounts")))
+ ? t : xstrdup (mnt->mnt_type));
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
devopt = strstr (mnt->mnt_opts, "dev=");