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

Christian Schmid cschmid at rapidshare.com
Thu Jan 31 11:45:30 UTC 2013


Hi Jon

Unfortunately, it did not work. Although /dev/sda2 is a 500 gb device, statfvs("dev/sda2", out stat) and fstatvfs(fd, out stat) returned the following:

bavail=2560
bfree=2560
blocks=2560
bsize=4096
files=8262645
frsize=4096




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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20130131/b225559b/attachment.pgp>


More information about the Mono-list mailing list