資源簡介
不用windows接口實現FAT文件系統的文件信息
代碼片段和文件信息
#ifndef??_WIN32_WINNT?
#define?_WIN32_WINNT?0x501
#endif
#include?“.\diskdevice.h“
#include?
#include?
CDiskDevice::CDiskDevice(int?iDiskIndex):
m_iDiskIndex(iDiskIndex)
m_hDevice(NULL)
m_s64TotalSector(0)
{
Open();
}
CDiskDevice::~CDiskDevice(void)
{
if(m_hDevice?!=?NULL?||
m_hDevice?!=?INVALID_HANDLE_VALUE)
{
Close();
}
}
BOOL?CDiskDevice::IsOpen()
{
return?m_hDevice?!=?NULL?&&
m_hDevice?!=?INVALID_HANDLE_VALUE;
}
BOOL?CDiskDevice::Open()
{
TCHAR szDriveName[MAX_PATH];
if(m_iDiskIndex?0?||
m_iDiskIndex?>=?MAX_SUPPORT_DISK_CONUT)
{
return?FALSE;
}
if(m_hDevice?!=?INVALID_HANDLE_VALUE?&&?
m_hDevice?!=?NULL)
{
Close();
}
sprintf(szDriveName?TEXT(“\\\\.\\PHYSICALDRIVE%d“)?m_iDiskIndex);
m_hDevice?=?CreateFile(?szDriveName????????????????????????//?設備路徑
GENERIC_READ|GENERIC_WRITE //?讀寫方式
FILE_SHARE_READ?|?FILE_SHARE_WRITE //?共享方式
NULL //?默認的安全描述符
OPEN_EXISTING //?創建方式
FILE_ATTRIBUTE_NORMAL //?文件屬性
NULL); //?不需參照模板文件
if(?m_hDevice?==?INVALID_HANDLE_VALUE?||
m_hDevice==NULL)
{
return?FALSE;
}
return?TRUE;
}
BOOL?CDiskDevice::Close()
{
if(m_hDevice!=INVALID_HANDLE_VALUE&&m_hDevice)
{
CloseHandle(m_hDevice);
}
m_hDevice=NULL;
return?TRUE;
}
BOOL?CDiskDevice::ReadSector(void?*pBuffer?__int64?i64StartSector?__int64?i64CountofSectors)
{
DWORD?dwRead;
//?convert?to?the?address?of?absolute?sector??on?W2k?environment.
S64?s64RealSectorsToRead?=?i64CountofSectors;
if?(i64StartSector?>=?m_s64TotalSector?)
{
return?FALSE;
}
if?(i64StartSector?+?i64CountofSectors?>?m_s64TotalSector)
{
s64RealSectorsToRead?=?m_s64TotalSector?-?i64StartSector;
}
LARGE_INTEGER?n64DistanceToMove;
n64DistanceToMove.QuadPart?=?512?*?(__int64)i64StartSector;
DWORD dwLDToMove?=?n64DistanceToMove.LowPart;
long lHDToMove?=?n64DistanceToMove.HighPart;
if(m_hDevice==INVALID_HANDLE_VALUE||m_hDevice==NULL)
{
return?FALSE;
}
//jump?to?the?address
SetFilePointer(?m_hDevice?dwLDToMove?&lHDToMoveFILE_BEGIN);
BOOL?bOk?=?ReadFile(?m_hDevice?pBuffer?512?*?(DWORD)s64RealSectorsToRead?&dwRead?NULL?);
if(dwRead/512!=(DWORD)s64RealSectorsToRead||!bOk)
{
return?FALSE;
}
return?TRUE;
}
DWORD?CDiskDevice::GetDiskHead()
{
DISK_GEOMETRY?DiskGeometry;
DWORD dwBytesReturned=0;
BOOL?bReturn?=?DeviceIoControl(m_hDeviceIOCTL_DISK_GET_DRIVE_GEOMETRY
0
NULL
&DiskGeometry
sizeof(DiskGeometry)
&dwBytesReturnedNULL);
if(!bReturn)
{
return?255;
}
else
{
return?DiskGeometry.TracksPerCylinder;
}
}
BOOL?CDiskDevice::GetDiskGeometry(DISK_GEOMETRY?&DiskGeometry)
{
DWORD dwBytesReturned=0;
BOOL?bReturn?=?DeviceIoControl(m_hDeviceIOCTL_DISK_GET_DRIVE_GEOMETRY
0
NULL
&DiskGeometry
sizeof(DiskGeometry)
&dwBytesReturnedNULL);
return?bReturn;
}
__int64?CDiskDevice:
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????12523??2008-01-28?10:41??Send\Common\DiskDevice.cpp
?????文件???????1042??2009-09-03?15:11??Send\Common\DiskDevice.h
?????文件???????2094??2007-08-18?12:01??Send\Common\DiskDeviceDesc
?????文件???????4245??2009-09-24?17:39??Send\Common\fat12accessor.cpp
?????文件???????2132??2009-09-27?10:27??Send\Common\fat12accessor.h
?????文件???????3865??2009-09-24?15:46??Send\Common\fat16accessor.cpp
?????文件???????2162??2009-09-27?10:27??Send\Common\fat16accessor.h
?????文件???????5750??2009-09-24?15:46??Send\Common\fat32accessor.cpp
?????文件???????2401??2009-09-27?10:27??Send\Common\fat32accessor.h
?????文件???????1966??2009-09-27?10:27??Send\Common\FATDirEntryStruct.h
?????文件???????3275??2009-09-27?10:27??Send\Common\FATPartitionDBRStruct.h
?????文件???????1610??2009-09-27?10:27??Send\Common\FileAttributeDefine.h
?????文件????????678??2009-09-27?10:27??Send\Common\IStorageDevice.h
?????文件???????1249??2009-09-27?10:27??Send\Common\ObCommon.h
?????文件???????1644??2009-09-27?10:27??Send\Common\obfataccessor.h
?????文件????????803??2009-09-27?10:27??Send\Common\ObType.h
?????文件???????1953??2009-09-27?10:27??Send\Common\typedef.h
?????文件???????6317??2009-09-27?10:27??Send\Common\VolumeDevice.cpp
?????文件????????564??2009-09-27?10:27??Send\Common\VolumeDevice.h
?????文件????????898??2009-09-27?17:03??Send\Observer.sln
????..A..H.??????8704??2009-09-27?17:03??Send\Observer.suo
?????文件??????17401??2009-09-25?17:11??Send\ObserverDisk\function.cpp
?????文件???????2115??2009-09-27?10:27??Send\ObserverDisk\function.h
?????文件???????6793??2009-09-18?13:58??Send\ObserverDisk\getfileinfo.cpp
?????文件????????755??2009-09-27?10:27??Send\ObserverDisk\getfileinfo.h
?????文件????????308??2009-09-22?15:11??Send\ObserverDisk\Observer.cpp
?????文件????????295??2009-09-04?10:01??Send\ObserverDisk\stdafx.cpp
?????文件????????376??2009-09-04?10:01??Send\ObserverDisk\stdafx.h
?????文件???????7188??2009-09-24?11:15??Send\ObserverDisk\test.cpp
?????文件????????397??2009-09-10?14:45??Send\ObserverDisk\test.h
............此處省略35個文件信息
- 上一篇:C語言實現拉格朗日插值
- 下一篇:分治策略算法設計尋找最鄰近點對c++源代碼
評論
共有 條評論