QQ:122567712 msn:myprotein0007@hotmail.com 敝人专著《大话存储》终于出版了!2008年10月中旬全面上市!

剖析ntfs的一些细节。

上一篇 / 下一篇  2006-12-29 13:14:46 / 个人分类:我的原创文章

今中午吃完饭没事,请会写代码的同事帮了一个忙:在磁盘上creatfile(),之后setlenth()到600M。执行后,磁盘几乎没很少读写操作,这个根据fs的机制可以解释。关于fs具体机制请参考《存储秘史》中有关章节。

执行完毕,磁盘上出现了一个600M大小的文件。此时其实并不是真正占用磁盘空间600M,而只是mft中一条记录而已。我想做的是?我用winhex打开这个文件,fs会怎么操作?因为这600M空间,有可能会占据一些原来已经删除的文件的空间。如果此时我打开,我思维定势的认为,会出现一些非00的16进制数,如果确实出现了,那么证明fs并不是将所有空间都写00的。我打开之后,却发现全是00,那么有2种可能,第一就是新申请的磁盘空间,以前确实没有数据,第二,就是以前确实有数据,但是fs会在打开的时候擦除这些数据。

以上实在不好做判断,其实我可以更加细致的实验,比如在一个几乎写满的分区中,先删除600M的文件,然后cfile()600M的文件,此时,空间一定是被已经删除的文件所占据,如果此时打开确都是00,那么无疑fs是在打开的时候擦除以前的数据。

决定有空再细致的实验一下。

终于弄明白了,每个文件的描述中,还有一个bitmap,用来映射vcn,这样就完全茅塞顿开了,哈哈

另外看到在cfile()注释中有一些很有价值的东西,贴出来:那些不求甚解的朋友,看不看都无所谓了。

The system is to open the file with no system caching. This flag has

no effect on hard disk caching. When combined with

FILE_FLAG_OVERLAPPED, the flag gives maximum asynchronous

performance, because the I/O does not rely on the synchronous

operations of the memory manager. However, some I/O operations will

take longer, because data is not being held in the cache. Also, the

file metadata may still be cached. To flush the metadata to disk,

use the FlushFileBuffers function.
An application must meet certain requirements when working with

files opened with FILE_FLAG_NO_BUFFERING:


File access must begin at byte offsets within the file that are

integer multiples of the volume's sector size.
File access must be for numbers of bytes that are integer multiples

of the volume's sector size. For example, if the sector size is 512

bytes, an application can request reads and writes of 512, 1024, or

2048 bytes, but not of 335, 981, or 7171 bytes.
Buffer addresses for read and write operations should be sector

aligned (aligned on addresses in memory that are integer multiples

of the volume's sector size). Depending on the disk, this

requirement may not be enforced.
One way to align buffers on integer multiples of the volume sector

size is to use VirtualAlloc to allocate the buffers. It allocates

memory that is aligned on addresses that are integer multiples of

the operating system's memory page size. Because both memory page

and volume sector sizes are powers of 2, this memory is also aligned

on addresses that are integer multiples of a volume's sector size.

An application can determine a volume's sector size by calling the

GetDiskFreeSpace function.


TAG: 我的原创文章

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar