Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check file size limit of a file system?

31 views
Skip to first unread message

Rui Maciel

unread,
Nov 26, 2009, 5:44:03 AM11/26/09
to
Is it possible to check the file size limit of a file system that is being used in
a partition? If it's possible then how is it done?


Thanks in advance,
Rui Maciel

Geoff Clare

unread,
Nov 26, 2009, 9:36:51 AM11/26/09
to
Rui Maciel wrote:

> Is it possible to check the file size limit of a file system that is
> being used in a partition? If it's possible then how is it done?

You can get an upper and lower bound for the limit by using
pathconf() with _PC_FILESIZEBITS. This returns the "minimum number of
bits needed to represent, as a signed integer value, the maximum size
of a regular file allowed in the specified directory".

For example, if pathconf() returns 32 then you know the maximum file
size is between 2^30 and 2^31-1 (inclusive).

If you need a more accurate answer, and:

* you can write to a file on the file system,
* sizeof(off_t)*8 in your process is not less than the value returned
by pathconf(),
* your process's file size limit is large enough (or you can set it
large enough with setrlimit(), and
* the file system supports sparse files,

then you can do a binary search between the upper and lower bounds
using either truncate() or a combination of lseek() and write().

--
Geoff Clare <net...@gclare.org.uk>


Ben Finney

unread,
Nov 26, 2009, 5:14:57 PM11/26/09
to
Geoff Clare <ge...@clare.See-My-Signature.invalid> writes:

> Rui Maciel wrote:
>
> > Is it possible to check the file size limit of a file system that is
> > being used in a partition? If it's possible then how is it done?
>
> You can get an upper and lower bound for the limit by using pathconf()
> with _PC_FILESIZEBITS. This returns the "minimum number of bits needed
> to represent, as a signed integer value, the maximum size of a regular
> file allowed in the specified directory".

On a system with the GNU libc binaries, the ‘getconf(1)’ program can
help if you want to test this out from the command line:

$ getconf FILESIZEBITS /tmp
64

--
\ “Creativity can be a social contribution, but only in so far as |
`\ society is free to use the results.” —Richard Stallman |
_o__) |
Ben Finney

0 new messages