[Mono-list] Unable to get block device size in UnixStream

Jonathan Pryor jonpryor at vt.edu
Tue Jan 29 19:39:07 UTC 2013

On Jan 29, 2013, at 3:46 AM, Dragony <cschmid at rapidshare.com> wrote:
> I want to get the device size of /dev/sda. I have an open fd and a UnixStream

Don't use UnixStream.Length here; UnixStream.Length uses the stat(2) system call, which states:

> The st_size field gives the size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.

You should instead use Syscall.fstatvfs() and Statvfs:


For example:

	Statvfs stat;
	int r = Syscall.fstatvfs (fd, out stat);
	int filesystem_size = stat.f_blocks*stat.f_frsize;

 - Jon

More information about the Mono-list mailing list