Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
nt4_dev.c
Package: adfview_src.zip [view]
Upload User: hy_wanghao
Upload Date: 2007-01-08
Package Size: 279k
Code Size: 3k
Category:
Shell api
Development Platform:
Visual C++
- /* nt4_dev.c - routines for direct drive access in Windows NT 4.0
- *
- * Copyright 1999 by Dan Sutherland <dan@chromerhino.demon.co.uk>
- *
- * These routines only currently work with drives <2GB and 512 bytes per sector
- */
- #include <windows.h>
- #include <winioctl.h>
- #include <stdio.h>
- #include "nt4_dev.h"
- HANDLE NT4OpenDrive(char *lpstrDrive)
- {
- char strDriveFile[40];
- HANDLE hDrv;
- DWORD dwRet;
- switch (lpstrDrive[0]) {
- case 'H':
- sprintf(strDriveFile, "\\.\PhysicalDrive%c", lpstrDrive[1]);
- break;
- /* add support for other device types here */
- default:
- return NULL;
- }
- hDrv = CreateFile(strDriveFile, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
- 0, NULL);
- if (hDrv == INVALID_HANDLE_VALUE)
- return NULL;
- if (! DeviceIoControl(hDrv, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0,
- &dwRet, NULL))
- return NULL;
- return hDrv;
- }
- BOOL NT4CloseDrive(HANDLE hDrv)
- {
- DWORD dwRet;
- if (! DeviceIoControl(hDrv, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0,
- &dwRet, NULL))
- return FALSE;
- if (! CloseHandle(hDrv))
- return FALSE;
- return TRUE;
- }
- BOOL NT4ReadSector(HANDLE hDrv, long iSect, int iSize, void *lpvoidBuf)
- {
- void *lpvoidTempBuf;
- DWORD dwActual;
- lpvoidTempBuf = VirtualAlloc(NULL, 512, MEM_COMMIT, PAGE_READWRITE);
- if (SetFilePointer(hDrv, iSect * 512, NULL, FILE_BEGIN) == 0xFFFFFFFF) {
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return FALSE;
- }
- if (! ReadFile(hDrv, lpvoidTempBuf, 512, &dwActual, NULL)) {
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return FALSE;
- }
- memcpy(lpvoidBuf, lpvoidTempBuf, iSize);
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return TRUE;
- }
- BOOL NT4WriteSector(HANDLE hDrv, long iSect, int iSize, void *lpvoidBuf)
- {
- void *lpvoidTempBuf;
- DWORD dwActual;
- if (iSize != 512)
- return FALSE;
- lpvoidTempBuf = VirtualAlloc(NULL, 512, MEM_COMMIT, PAGE_READWRITE);
- if (SetFilePointer(hDrv, iSect * 512, NULL, FILE_BEGIN) == 0xFFFFFFFF) {
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return FALSE;
- }
- memcpy(lpvoidTempBuf, lpvoidBuf, iSize);
- if (! WriteFile(hDrv, lpvoidTempBuf, 512, &dwActual, NULL)) {
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return FALSE;
- }
- VirtualFree(lpvoidTempBuf, 0, MEM_RELEASE);
- return TRUE;
- }
- ULONG NT4GetDriveSize(HANDLE hDrv)
- {
- DWORD dwActual;
- DISK_GEOMETRY dgGeom;
- long size;
- DeviceIoControl(hDrv, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
- &dgGeom, sizeof(DISK_GEOMETRY), &dwActual, NULL);
- size = dgGeom.Cylinders.LowPart * dgGeom.TracksPerCylinder *
- dgGeom.SectorsPerTrack * dgGeom.BytesPerSector;
- printf("Total sectors: %in", dgGeom.Cylinders.LowPart * dgGeom.TracksPerCylinder * dgGeom.SectorsPerTrack);
- printf("Byte size: %in", size);
- return size;
- }