尝试使用HANDLE为磁盘刷新锁定扇区块。可能与std :: atomic< HANDLE>或者std :: mutex< HANDLE>? [英] trying to lock block of sectors using HANDLE for RW for disk refresh. possible with std::atomic<HANDLE> or std::mutex<HANDLE>?

查看:69
本文介绍了尝试使用HANDLE为磁盘刷新锁定扇区块。可能与std :: atomic< HANDLE>或者std :: mutex< HANDLE>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我正在尝试锁定磁盘的磁盘部分以进行磁盘刷新+坏块测试,意图制作坏块列表。可能与std :: atomic< HANDLE>或者std :: mutex< HANDLE>?
  • 我不想锁定整个磁盘,事实上,如果可以,我想让磁盘为FILE_SHARE_READ | FILE_SHARE_WRITE打开。或者我有错误,应该将这两个都留为0(我认为0)?

  • 但我不想要我的写入由其他进程读取或写入它们的混乱,因为坏块的测试数据进入它们。

    but I don't want my writes messed with by other processes reading from them or writing to them, because test data for bad blocks is going into them.

    我还想添加到NT中的坏块列表中我知道它是一个稀疏文件(我有点不确定该怎么做)。我阅读了这篇文章,并以1/2的理解离开了什么,并且有点害怕弄乱它。我可以轻松制作一个坏块
    列表。太糟糕了,没有WIN32 API函数。

    I would also like to add to the bad blocks list in NT and I understand it's a sparse file (that I am somewhat unsure how to do). I read the article and came away with 1/2 an understanding of what to do and a bit afraid to mess with it. I can make a bad blocks list easy enough. too bad there is not an WIN32 API function for this.

    它将进入商业代码。


    • Win32或DeviceIOCTL中有哪些条款用于锁定对正在读取或写入的扇区块的访问?
    • 如何写入坏块稀疏文件 - 例如它是否由簇组成,扇区,字节,?我想写在我想要的位置吗?这是旧帽子,不再使用了吗?磁盘坏块列表怎么样? EDD6(怎么样?devioctl?)?

    • 我有另一个程序,嘟嘟声,它可以作为单轨音乐音序器使用。嘟嘟声总是通过分成两半而带有令人讨厌的"beedeep"。声音而不是哔哔声,我无法制作音乐。 芯片组中的定时器芯片不应该在
      声音中有这种中断,它应该在持续时间内打开。

    推荐答案

    std :: atomic< HANDLE>和std :: mutex在这里没用,因为文件系统驱动程序和其他进程不会知道你的互斥锁,也不会试图锁定它。

    std::atomic<HANDLE> and std::mutex are not useful here, because the file system driver and the other processes won't know about your mutex and won't try to lock it.

    在Windows中, LockFile和LockFileEx函数是如何锁定文件的一个区域,以便它不能通过其他文件句柄读取或写入。但是,我怀疑这些函数是否适用于卷句柄。特别是,如果给定一个卷句柄(TypeOfOpen == UserVolumeOpen),fastfat驱动程序中的FatCommonLockControl函数
    将直接返回STATUS_INVALID_PARAMETER。

    In Windows, the LockFile and LockFileEx functions are how to lock a region of a file so that it cannot be read or written via other file handles. However, I doubt those functions work with volume handles. In particular, the FatCommonLockControl function in the fastfat driver returns STATUS_INVALID_PARAMETER outright if given a volume handle (TypeOfOpen == UserVolumeOpen).

    相反,我会尝试创建一个文件所需的大小,使用FSCTL_MOVE_FILE将文件移动到卷的所需区域,使用FSCTL_MARK_HANDLE MARK_HANDLE_PROTECT_CLUSTERS来防止文件被移动到其他地方,并通过该文件读取和写入
    卷。如果卷的所需部分已用于其他文件,那么我认为您必须先将其他文件移开,可能使用FSCTL_LOOKUP_STREAM_FROM_CLUSTER来识别它们。总体而言,这个计划感觉相当不可靠。在卷上要求独占访问肯定会更容易。

    Instead, I'd attempt creating a file of the desired size, using FSCTL_MOVE_FILE to move the file to the desired region of the volume, using FSCTL_MARK_HANDLE MARK_HANDLE_PROTECT_CLUSTERS to prevent the file from being moved elsewhere, and reading and writing the volume via that file. If the desired part of the volume is already being used for other files, then I suppose you'd have to move the other files out of the way first, perhaps using FSCTL_LOOKUP_STREAM_FROM_CLUSTER to identify them. This scheme feels rather unreliable, overall. It would surely be easier to require exclusive access on the volume.

    我建议将哔声问题作为一个单独的问题发布。

    I suggest posting the beep problem as a separate question.


    这篇关于尝试使用HANDLE为磁盘刷新锁定扇区块。可能与std :: atomic&lt; HANDLE&gt;或者std :: mutex&lt; HANDLE&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆