tags:

views:

149

answers:

1

I am trying to get the free space on the / folder using statvfs call from java,

I have check the size of statvfs struct from c it shows 44 bytes, I have allocated a byte buffer using java.nio.ByteBuffer.allocateDirect 44 bytes, and it's order is set to 44 bytes. when i call statvfs i get a return value of 0, so i am assuming call is successful, but i can't seem to get information out of ByteBuffer using buffer.getInt returns 512 f_bsize which is correct but after that i can't read.

buffer.getInt(12) should give me f_blocks but i get 0.

unsigned long f_bsize; /* File system block size */
unsigned long f_frsize; /* Fundamental file system block size */
fsblkcnt_t f_blocks; /* Blocks on FS in units of f_frsize */

or do i have a fault in my logic?

A: 

Not a solution but a few thoughts.

  1. you should check the size of fsblkcnt_t type. I'm quite positive, that it is 4 bytes, but that's just an assumption based on your 44 bytes for the whole struct.
  2. I think, the index of the first byte of the f_blocks field is 8, not 12. f_bsize and f_frsize are 4 bytes each, the total is 8 bytes, the next value starts at the nineth position which is index 8.
  3. I'm a bit confused about your 'order' setting. It should not be '44' but either Byteorder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN. But maybe that's just a typo in your question

Have your tried dumping the buffer content or used a debugger to peek into the buffer? Does it hold the expected values? Just to sort out, if the problem is related to filling or to reading the buffer.

Andreas_D