阅读:3125回复:9
如何在驱动里面创建稀疏文件
请教各位大虾,如何在驱动里面创建稀疏文件?
|
|
沙发#
发布于:2008-08-31 23:06
IRP_MJ_SET_INFORMATION
FILE_BASIC_INFORMATION |
|
|
板凳#
发布于:2008-09-01 12:30
ZwCreateFile 创建文件
ZwFsControlFile 关键在这里,向文件系统发送稀疏控制码,与上层应用是一样的 ZwSetInformationFile 设置大小 如果还不会就加我qq:8060817 |
|
地板#
发布于:2008-09-26 09:01
谢谢楼上的两位
|
|
地下室#
发布于:2008-09-26 09:09
发挥中国特色,直接抄FILEDISK的,嘿嘿。。。。。。
|
|
|
5楼#
发布于:2008-09-26 10:44
wowocock 老大:
不一定要抄filedisk吧,只是一个创建文件而已。 我了解filedisk驱动源码,里面只是创建实文件,不是稀疏文件。创建稀疏文件还有一条件必须在NTFS文件系统下才能创建。 |
|
6楼#
发布于:2008-09-27 09:41
引用第5楼mlkflkf于2008-09-26 10:44发表的 : FileDisk Release 14 (2006-01-05) FileDisk is a virtual disk driver for Windows NT/2000/XP that uses one or more files to emulate physical disks. A console application is included that let you dynamically mount and unmount files. An example of use for this driver is if you have made plans spending the weekend writing an RAID driver for NT but find you are short of disks. FileDisk can also use CD-images. Latest news: Works on Windows XP, FileDisk images can be stored on network drives, support for CD-images, support for UNC paths, support for sparse files. Screenshot of an example of use. filedisk.zip FileDisk can use sparse files as disk images. A sparse file is a file were suficiently large blocks of zeros isn't allocated disk space. You can create sparse files with the tool mksparse.zip. To see how much disk space a file actually uses right click on the file and choose properties. If you for example creates a sparse file of 4GB, mounts it in FileDisk and formats it to NTFS, it will only take up 24MB on disk but looks like a normal disk of 4GB. When you copy files to it the used disk space will automatically increase. /* Program to create a sparse file. Copyright (C) 2002 Bo Brant閚. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <windows.h> #include <winioctl.h> #include <stdio.h> #include <stdlib.h> void PrintLastError(char* Prefix) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL ); fprintf(stderr, "%s: %s", Prefix, (LPTSTR) lpMsgBuf); LocalFree(lpMsgBuf); } int __cdecl main(int argc, char* argv[]) { LARGE_INTEGER FileSize; HANDLE FileHandle; DWORD BytesReturned; if (argc < 2 || argc > 3) { fprintf(stderr, "syntax: mksparse <filename> [size[k|M|G]]\n"); return -1; } if (argc == 3) { if (argv[2][strlen(argv[2]) - 1] == 'G') { FileSize.QuadPart = _atoi64(argv[2]) * 1024 * 1024 * 1024; } else if (argv[2][strlen(argv[2]) - 1] == 'M') { FileSize.QuadPart = _atoi64(argv[2]) * 1024 * 1024; } else if (argv[2][strlen(argv[2]) - 1] == 'k') { FileSize.QuadPart = _atoi64(argv[2]) * 1024; } else { FileSize.QuadPart = _atoi64(argv[2]); } } else { FileSize.QuadPart = 0; } FileHandle = CreateFile( argv[1], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_FLAG_NO_BUFFERING, NULL ); if (FileHandle == INVALID_HANDLE_VALUE) { PrintLastError(argv[1]); return -1; } if (!DeviceIoControl( FileHandle, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &BytesReturned, NULL )) { PrintLastError(argv[1]); return -1; } if (!SetFilePointerEx(FileHandle, FileSize, 0, FILE_BEGIN)) { PrintLastError(argv[1]); return -1; } if (!SetEndOfFile(FileHandle)) { PrintLastError(argv[1]); return -1; } CloseHandle(FileHandle); return 0; } |
|
|
7楼#
发布于:2008-09-27 09:57
wowocock 老大:
这是在应用层里面代码,楼主是要驱动里面代码,看清楚啊。应用层的代码我想楼主肯定知道,在驱动里面我想楼主只是不知道用ZwFsControlFile发送稀疏控制码而已。 |
|
8楼#
发布于:2008-10-08 10:37
mlkflkf 讲得不错,我是需要在驱动里创建稀疏文件。不过也谢谢wowocock的热情帮助。
|
|
9楼#
发布于:2010-06-17 10:25
对着抄就是了
把Createfile换成ZwCreateFile,类似的。 |
|
|