JNA ByteBuffer statvfs
我正在尝试使用来自java的statvfs调用来获取/文件夹上的可用空间,
我已经从c检查了statvfs结构的大小,它显示44字节,我已经使用java.nio.ByteBuffer.allocateDirect 44字节分配了一个字节缓冲区,并且它的顺序设置为44字节。 当我调用 statvfs 时,我得到的返回值为 0,所以我假设调用成功,但我似乎无法使用 buffer.getInt 返回 512 f_bsize 从 ByteBuffer 中获取信息,这是正确的,但之后我无法读取。
buffer.getInt(12) 应该给我 f_blocks 但我得到 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 */
或者我的逻辑有问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是解决方案,而是一些想法。
fsblkcnt_t
类型的大小。我非常肯定它是 4 个字节,但这只是基于整个结构的 44 个字节的假设。f_blocks
字段的第一个字节的索引是8,而不是12。f_bsize
和f_frsize
各为4个字节,总共是 8 个字节,下一个值从第九个位置(索引 8)开始。Byteorder.BIG_ENDIAN
或ByteOrder.LITTLE_ENDIAN
。但也许这只是您问题中的一个拼写错误您是否尝试过转储缓冲区内容或使用调试器来查看缓冲区?它是否符合预期值?只是为了弄清楚问题是否与填充或读取缓冲区有关。
Not a solution but a few thoughts.
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.f_blocks
field is 8, not 12.f_bsize
andf_frsize
are 4 bytes each, the total is 8 bytes, the next value starts at the nineth position which is index 8.Byteorder.BIG_ENDIAN
orByteOrder.LITTLE_ENDIAN
. But maybe that's just a typo in your questionHave 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.