[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:

http://linux.die.net/man/2/stat
> 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:

	http://docs.go-mono.com/index.aspx?link=M%3aMono.Unix.Native.Syscall.fstatvfs(System.Int32%2cMono.Unix.Native.Statvfs%40)
	http://docs.go-mono.com/index.aspx?link=T%3aMono.Unix.Native.Statvfs%2f*

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