From: "Theodore Ts'o" <tytso@mit.edu>
To: Al Viro <viro@ftp.linux.org.uk>
Cc: Parag Warudkar <kernel-stuff@comcast.net>,
"linux-os (Dick Johnson)" <linux-os@analogic.com>,
Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: Compatible fstat()
Date: Tue, 8 Nov 2005 13:49:57 -0500 [thread overview]
Message-ID: <20051108184957.GF6129@thunk.org> (raw)
In-Reply-To: <20051108172244.GR7992@ftp.linux.org.uk>
On Tue, Nov 08, 2005 at 05:22:44PM +0000, Al Viro wrote:
> On Tue, Nov 08, 2005 at 12:10:25PM -0500, Parag Warudkar wrote:
> >
> > On Nov 8, 2005, at 10:48 AM, linux-os ((Dick Johnson)) wrote:
> >
> > >The Linux fstat() doesn't return any information number of blocks,
> > >or the byte-length of a physical hard disk.
> >
> > I don't think (f)stat returns size and blocks information about a
> > block device on any UNIX platform.
> >
> > But I don't know for sure how to get it - perhaps ioctl on the
> > device? BLKGETSIZE?
>
> fd = open(bdev, O_RDONLY);
> lseek(fd, SEEK_END, 0);
> size = lseek(fd, SEEK_SET, 0);
> close(fd);
>
> i.e. same as for regular files. Won't be portable, though...
As I recall, this didn't always work; e2fsprogs falls back to using a
binary search using SEEK_SET to find the device size. Folks who need
to do this should look at lib/ext2fs/getsize.c in the e2fsprogs
sources; it has ioctl's and other procedures for determining block
device size for Linux, *BSD, MacOSX, as well a generalized binary
search algorithm.
- Ted
next prev parent reply other threads:[~2005-11-08 18:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-08 15:48 Compatible fstat() linux-os (Dick Johnson)
2005-11-08 17:10 ` Parag Warudkar
2005-11-08 17:22 ` Al Viro
2005-11-08 17:56 ` linux-os (Dick Johnson)
2005-11-08 17:58 ` Parag Warudkar
2005-11-08 18:10 ` linux-os (Dick Johnson)
2005-11-08 18:15 ` Parag Warudkar
2005-11-08 18:20 ` linux-os (Dick Johnson)
2005-11-08 19:39 ` Bob Copeland
2005-11-08 20:03 ` linux-os (Dick Johnson)
2005-11-08 21:06 ` Parag Warudkar
2005-11-08 22:57 ` Bill Davidsen
2005-11-09 0:14 ` Parag Warudkar
2005-11-12 13:41 ` Bill Davidsen
2005-11-08 18:49 ` Theodore Ts'o [this message]
2005-11-08 19:12 ` Parag Warudkar
2005-11-09 3:23 ` Theodore Ts'o
2005-11-08 17:53 ` linux-os (Dick Johnson)
2005-11-08 18:04 ` Parag Warudkar
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=20051108184957.GF6129@thunk.org \
--to=tytso@mit.edu \
--cc=kernel-stuff@comcast.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
--cc=viro@ftp.linux.org.uk \
/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