From: Mike Fleetwood <mike.fleetwood@googlemail.com>
To: linux-ext4@vger.kernel.org
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Subject: How to query ext2/3/4 total fs size while mounted?
Date: Fri, 7 Sep 2012 21:12:49 +0100 [thread overview]
Message-ID: <CAMU1PDg-WrH9TS-U9SfeMfV2FTBz7Md+7PR1k55aMTFVq=7NiA@mail.gmail.com> (raw)
Hi,
Is there a way I can/should code GParted (GNOME Partition Editor) to
query a mounted ext2/3/4 file system to get the total file system size?
Unfortunately the f_blocks value from the statvfs() system call has
space occupied by inode tables, allocation bitmaps, etc. subtracted as
overhead and I need the total file system size. This is so that GParted
can inform users when the file system doesn't fill the partition and
recommend resizing the FS to fix it.
I really want some way to get the the total file system size from
statvfs(). The mount option minixdf isn't really appropriate as GParted
shouldn't be remounting file systems adding mount options to query the
file system size.
Is it safe to read the super block off disk using ext2fs_open() or by
running dumpe2fs for a mounted file system? What if the file system has
just been resized? Are there any other methods for querying the total
file system size?
Thanks,
Mike
In this example I want to get the 194560 blocks figure while mounted,
not f_blocks=188403.
# sfdisk -s /dev/sda10
194560
# mkfs.ext4 /dev/sda10
mke2fs 1.41.12 (17-May-2010)
...
48768 inodes, 194560 blocks
...
# dumpe2fs -h /dev/sda10 | grep 'Block count:'
dumpe2fs 1.41.12 (17-May-2010)
Block count: 194560
# mount /dev/sda10 /mnt/0
# strace -e statfs64 stat -f /mnt/0
...
statfs64("/mnt/0", 84, {f_type="EXT2_SUPER_MAGIC", f_bsize=1024,
f_blocks=188403, f_bfree=182757, f_bavail=173029, f_files=48768,
f_ffree=48757, f_fsid={-1366779076, -459235834}, f_namelen=255,
f_frsize=1024}) = 0
File: "/mnt/0"
ID: ae889b3ce4a09e06 Namelen: 255 Type: ext2/ext3
Block size: 1024 Fundamental block size: 1024
Blocks: Total: 188403 Free: 182757 Available: 173029
Inodes: Total: 48768 Free: 48757
next reply other threads:[~2012-09-07 20:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-07 20:12 Mike Fleetwood [this message]
2012-09-08 0:39 ` How to query ext2/3/4 total fs size while mounted? Theodore Ts'o
2012-09-10 10:39 ` Mike Fleetwood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMU1PDg-WrH9TS-U9SfeMfV2FTBz7Md+7PR1k55aMTFVq=7NiA@mail.gmail.com' \
--to=mike.fleetwood@googlemail.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).