ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c# – 如何在硬盘上获取文件物理位置

2019-06-13 18:52:59  阅读:270  来源: 互联网

标签:c file delete-file drive erase


我想通过将零写入其物理区域来制作文件脱粒器以完全删除文件.

文件可以存储在硬盘驱动器中,而不是总是存储在整个块中.

当我说物理区域.我指的是文件存储的物理部分,或者我可以执行“写零”的那些部分的任何引用.

更好的C#.

解决方法:

不幸的是,即使您正在编写内核模式驱动程序,这在C#中也不是完全可能的,在C/C++中也是如此.

引自Bleachbit documentation:

Shredding an individual file properly assumes its location can be completely known, but basically it can only be known in one ideal case.The ideal case has three characteristics:

  1. The file size has never shrunk because of editing. Imagine starting with a 3MB spreadsheet, editing it down to 1MB (using the spreadsheet application), and asking the cleaner application to delete the 1MB version: the cleaner has no way of knowing where the missing 2MB was allocated on the physical hard drive. (Remember: file systems often don’t store files continuously, so you can’t assume the missing part was directly after the known part.)
  2. The file never moved. Imagine the spreadsheet software saves the document by writing a new copy to a temporary file, deleting the old copy, and renaming the temporary file to the original name. In this case, the cleaner application has no way of knowing where any of the old spreadsheet was located.
  3. The file system overwrites files to the same place. This is a good assumption. On Windows NTFS and on Linux the most common ext3 configuration (which is the default on Ubuntu 9.10 and other Linux distributions) overwrite files in the same place, but transparent disk compression, encryption, and sparse files may not overwrite files in place.

此外:当现代硬盘驱动器的某个区域损坏时,它会自动将坏扇区重新映射到备用区域.这些操作由驱动器的固件决定,操作系统和应用程序都不知道移动,因此擦除驱动器会忽略损坏的区域.

话虽如此,有可能(尽管不容易)找出文件当前占用的驱动器的哪些扇区.但是,这要求您的应用程序(至少部分地)了解所使用的文件系统以及该文件系统如何在底层介质上存储文件.

最后,问题仍然是通过识别文件所占用的所有扇区并将其填充为0而不是仅仅执行来获得额外的安全性

using(var fs = new System.IO.FileStream(@"m:\delme.zip", 
                                        FileMode.Open,
                                        FileAccess.Write,
                                        FileShare.None))
{
    var zeros = new byte[fs.Length];

    fs.Write(zeros, 0, zeros.Length);       
}

标签:c,file,delete-file,drive,erase
来源: https://codeday.me/bug/20190613/1234633.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有