JNA ByteBuffer statvfs

发布于 2024-08-11 17:27:59 字数 545 浏览 3 评论 0原文

我正在尝试使用来自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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-08-18 17:27:59

不是解决方案,而是一些想法。

  1. 您应该检查 fsblkcnt_t 类型的大小。我非常肯定它是 4 个字节,但这只是基于整个结构的 44 个字节的假设。
  2. 我认为,f_blocks字段的第一个字节的索引是8,而不是12。f_bsizef_frsize各为4个字节,总共是 8 个字节,下一个值从第九个位置(索引 8)开始。
  3. 我对你的“顺序”设置有点困惑。它不应该是“44”,而应该是 Byteorder.BIG_ENDIANByteOrder.LITTLE_ENDIAN。但也许这只是您问题中的一个拼写错误

您是否尝试过转储缓冲区内容或使用调试器来查看缓冲区?它是否符合预期值?只是为了弄清楚问题是否与填充或读取缓冲区有关。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文