我需要读取硬盘扇区。具体来说,我正在尝试编写如下函数:
findFreeBlocks - analyze disk structures and find two uninterrupted free blocks of a given length.
int findFreeBlocks(char * drivePath, DWORD sectorsNeeded, u_int64_t *freeSector1, u_int64_t *freeSector2)
Parameters: [IN] drivePath – path to a logical drive [IN] sectorsNeeded – length of needed free block in sectors (sector = 512 bytes) [OUT] freeSector1 – the first sector of the first found free block [OUT] freeSector2 – the first sector of the second found free block
Return: 0 – if success, error code – if error
有人可以指出可以帮助我做到这一点的 API 吗?我有使用 Objective-c 的经验,但 C/C++ 也可以工作(我猜它会是这样,因为这是非常低的级别)。谢谢
最佳答案
正如@PlasmaHH 指出的那样,像 MacOS 这样的操作系统不会为您提供 Objective C 或 C++ API 来处理物理磁盘上的扇区和磁道。 (它也不会让您改变驱动器内部电机的速度,或将驱动头移动到板的中心或外部。)
如果您想编写“低级”代码,如碎片整理程序或类似程序,您必须知道您正在处理哪个文件系统。 Mac 的默认 HFS+ 没有很多开源工具来使用它。结构上有一些注意事项:
http://developer.apple.com/library/mac/#technotes/tn/tn1150.html
...一个名为 hfsdebug
的工具已经被弃用,取而代之的是 fileXray
:
(不过,没有这些的源代码。自称是教育 worker 的人却用闭源工具发布了他的“Mac OS/X Internals”一书,这充分说明了 [双关语意] 的文化Apple 开发。令人沮丧的是我实际上可以通过写一本名为“Mac OS/X Internals Internals”的书来赚钱。)
长话短说:如果您想弄乱文件系统,您将不得不在 /dev/rdisk*
的 block 设备上使用原始 IO。没有图书馆。这几乎肯定不值得你花时间,而是去用 Linux 做一些很酷的事情。 :)
关于objective-c - Mac 分析磁盘的空闲扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7737588/