Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Correction: it actually gets you the size in SECTORS. Edit it and I'll upvote. Commented Jun 22, 2012 at 1:14
  • 12
    @JCCyC: BLKGETSIZE64 returns the size in bytes. See linux/fs.h, which notes "return device size in bytes". Note that BLKGETSIZE (no "64") returns it "/512". Commented Mar 3, 2013 at 23:26
  • I worked out a fuller sample partly based on this at stackoverflow.com/a/48490543/446106. To use the above snippet here, file needs to be a file descriptor (e.g. from open()), and file_size_in_bytes should be a size_t. Commented Jan 28, 2018 at 19:54
  • 1
    (Actually, file_size_in_bytes should be a 64-bit type, so it should be unsigned long long.) Commented Jan 28, 2018 at 20:17