ReactOS 0.4.16-dev-112-g52265ae
volume.c File Reference
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "volume.h"
Include dependency graph for volume.c:

Go to the source code of this file.

Functions

BOOL OpenVolume (LPCTSTR lpszVolumeName)
 
void CloseVolume (void)
 
BOOL ReadVolumeSector (ULONG SectorNumber, PVOID SectorBuffer)
 
BOOL WriteVolumeSector (ULONG SectorNumber, PVOID SectorBuffer)
 

Variables

static HANDLE hDiskVolume = NULL
 

Function Documentation

◆ CloseVolume()

void CloseVolume ( void  )

Definition at line 68 of file volume.c.

69{
71}
static HANDLE hDiskVolume
Definition: volume.c:26
#define CloseHandle
Definition: compat.h:739

Referenced by main().

◆ OpenVolume()

BOOL OpenVolume ( LPCTSTR  lpszVolumeName)

Definition at line 28 of file volume.c.

29{
30 TCHAR RealVolumeName[MAX_PATH];
31
32 //
33 // If they passed in a drive letter (e.g. "A:")
34 // then try to open the physical device volume,
35 // otherwise we will assume it is a disk image
36 // file they are writing to. (not fully supported yet)
37 //
38 if ((_tcslen(lpszVolumeName) == 2) && (lpszVolumeName[1] == _T(':')))
39 {
40 _tcscpy(RealVolumeName, _T("\\\\.\\"));
41 _tcscat(RealVolumeName, lpszVolumeName);
42 }
43 else
44 {
45 _tcscpy(RealVolumeName, lpszVolumeName);
46 }
47
48 _tprintf(_T("Opening volume \'%s\'\n"), lpszVolumeName);
49
50 hDiskVolume = CreateFile(RealVolumeName,
53 NULL,
55 0,
56 NULL);
57
59 {
60 _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
61 _tprintf(_T("Failed. Error code %ld.\n"), GetLastError());
62 return FALSE;
63 }
64
65 return TRUE;
66}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define _tprintf
Definition: tchar.h:506
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateFile
Definition: winbase.h:3749
char TCHAR
Definition: xmlstorage.h:189
#define _tcslen
Definition: xmlstorage.h:198

◆ ReadVolumeSector()

BOOL ReadVolumeSector ( ULONG  SectorNumber,
PVOID  SectorBuffer 
)

Definition at line 73 of file volume.c.

74{
75 DWORD dwNumberOfBytesRead;
76 DWORD dwFilePosition;
77 BOOL bRetVal;
78
79 //
80 // FIXME: this doesn't seem to handle the situation
81 // properly when SectorNumber is bigger than the
82 // amount of sectors on the disk. Seems to me that
83 // the call to SetFilePointer() should just give an
84 // out of bounds error or something but it doesn't.
85 //
86 dwFilePosition = SetFilePointer(hDiskVolume, (SectorNumber * 512), NULL, FILE_BEGIN);
87 if (dwFilePosition != (SectorNumber * 512))
88 {
89 _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
90 _tprintf(_T("SetFilePointer() failed. Error code %ld.\n"), GetLastError());
91 return FALSE;
92 }
93
94 bRetVal = ReadFile(hDiskVolume, SectorBuffer, 512, &dwNumberOfBytesRead, NULL);
95 if (!bRetVal || (dwNumberOfBytesRead != 512))
96 {
97 _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
98 _tprintf(_T("ReadFile() failed. Error code %ld.\n"), GetLastError());
99 return FALSE;
100 }
101
102 return TRUE;
103}
#define FILE_BEGIN
Definition: compat.h:761
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by BackupBootSector(), and InstallBootSector().

◆ WriteVolumeSector()

BOOL WriteVolumeSector ( ULONG  SectorNumber,
PVOID  SectorBuffer 
)

Definition at line 105 of file volume.c.

106{
107 DWORD dwNumberOfBytesWritten;
108 DWORD dwFilePosition;
109 BOOL bRetVal;
110
111 //
112 // FIXME: this doesn't seem to handle the situation
113 // properly when SectorNumber is bigger than the
114 // amount of sectors on the disk. Seems to me that
115 // the call to SetFilePointer() should just give an
116 // out of bounds error or something but it doesn't.
117 //
118 dwFilePosition = SetFilePointer(hDiskVolume, (SectorNumber * 512), NULL, FILE_BEGIN);
119 if (dwFilePosition != (SectorNumber * 512))
120 {
121 _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
122 _tprintf(_T("SetFilePointer() failed. Error code %ld.\n"), GetLastError());
123 return FALSE;
124 }
125
126 bRetVal = WriteFile(hDiskVolume, SectorBuffer, 512, &dwNumberOfBytesWritten, NULL);
127 if (!bRetVal || (dwNumberOfBytesWritten != 512))
128 {
129 _tprintf(_T("%s:%d: "), __FILE__, __LINE__);
130 _tprintf(_T("WriteFile() failed. Error code %ld.\n"), GetLastError());
131 return FALSE;
132 }
133
134 return TRUE;
135}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24

Referenced by InstallBootSector().

Variable Documentation

◆ hDiskVolume

HANDLE hDiskVolume = NULL
static

Definition at line 26 of file volume.c.

Referenced by CloseVolume(), OpenVolume(), ReadVolumeSector(), and WriteVolumeSector().