如何使用 SetFilePointerEx 转到物理磁盘的末尾?

发布于 2024-10-10 13:58:57 字数 581 浏览 6 评论 0原文

仅在设置位置时,我已经能够很好地使用 SetFilePointerEx

SetFilePointerEx(PD, 512, @PositionVar, FILE_BEGIN);
SetFilePointerEx(PD, 0, @PositionVar, FILE_CURRENT);

两者都有效;我可以设置位置,甚至可以检查我当前的位置。但是,当我根据文档设置 FILE_END 时,无论第二个参数是什么以及是否为第三个参数提供指针,它都会失败,即使在许多其他操作都可以的有效句柄上也是如此使用无误。

例如:

SetFailed := SetFilePointerEx(PD, 0, @PositionVar, FILE_END);
SetFailed := SetFilePointerEx(PD, 0, nil, FILE_END);

无论我输入什么,它都会失败。我正在使用物理磁盘的句柄,它肯定已经结束了。 SetFilePointer 工作得很好,但它只是比我想要的要麻烦一些。

这不是世界末日,而是正在发生的事情。

I have been able to use SetFilePointerEx just fine, when setting the position only.

SetFilePointerEx(PD, 512, @PositionVar, FILE_BEGIN);
SetFilePointerEx(PD, 0, @PositionVar, FILE_CURRENT);

Both work; I can set positions and even check my current one. But when I set FILE_END as per the documentation no matter what the second parameter is and whether or not I provide a pointer for the third parameter, it fails, even on a valid handle that many other operations are able to use without fail.

For example:

SetFailed := SetFilePointerEx(PD, 0, @PositionVar, FILE_END);
SetFailed := SetFilePointerEx(PD, 0, nil, FILE_END);

Whatever I put, it fails. I am working with a handle to a physical disk and it most definitely has an end. SetFilePointer works just fine, but it's just a little more trouble than I would like.

It's not the end of the world, but whats happening.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

任性一次 2024-10-17 13:58:57

正如您所发现的,您不能这样做。你必须从头开始或从当前开始寻找。使用 DeviceIoControl 找出设备的大小。

You can't do this as you have found out. You have to seek from the beginning or current. Use DeviceIoControl to find out the size of the device.

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