40#define FSCTL_IS_VOLUME_DIRTY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
66#define close WIN32close
116#define write WIN32write
156#define lseek WIN32lseek
193 DPRINT1(
"NtOpenFile() failed with status 0x%.08x\n",
Status);
223 NULL, 0, &DirtyMask,
sizeof(DirtyMask));
227 DPRINT1(
"NtFsControlFile() failed with Status 0x%08x\n",
Status);
232 return (DirtyMask & 1);
249 DPRINT1(
"NtFsControlFile() failed with Status 0x%08x\n",
Status);
255void fs_dismount(
void)
268 DPRINT1(
"NtFsControlFile() failed with Status 0x%08x\n",
Status);
288 const size_t readsize_aligned = (
size % 512) ? (
size + (512 - (
size % 512))) :
size;
290 const size_t seek_delta = (
size_t)(
pos - seekpos_aligned);
292 const size_t readsize = (
size_t)(
pos - seekpos_aligned) + readsize_aligned;
294 char* tmpBuf =
alloc(readsize_aligned);
295 if (
lseek(
fd, seekpos_aligned, 0) != seekpos_aligned)
pdie(
"Seek to %lld",
pos);
296 if ((got =
read(
fd, tmpBuf, readsize_aligned)) < 0)
pdie(
"Read %d bytes at %lld",
size,
pos);
304 pdie(
"Seek to %lld", (
long long)
pos);
306 pdie(
"Read %d bytes at %lld",
size, (
long long)
pos);
309 die(
"Got %d bytes instead of %d at %lld", got,
size, (
long long)
pos);
328 const size_t readsize_aligned = (
size % 512) ? (
size + (512 - (
size % 512))) :
size;
330 scratch =
alloc(readsize_aligned);
331 if (
lseek(
fd, seekpos_aligned, 0) != seekpos_aligned)
pdie(
"Seek to %lld",
pos);
332 okay =
read(
fd, scratch, readsize_aligned) == (
int)readsize_aligned;
336 pdie(
"Seek to %lld", (
long long)
pos);
354 const size_t readsize_aligned = (
size % 512) ? (
size + (512 - (
size % 512))) :
size;
356 const size_t seek_delta = (
size_t)(
pos - seekpos_aligned);
357 BOOLEAN use_read = (seek_delta != 0) || ((readsize_aligned-
size) != 0);
361 scratch =
alloc(readsize_aligned);
366 if (
lseek(
fd, seekpos_aligned, 0) != seekpos_aligned)
pdie(
"Seek to %lld",seekpos_aligned);
371 if (
read(
fd, scratch, readsize_aligned) < 0)
pdie(
"Read %d bytes at %lld",
size,
pos);
378 if ((did =
write(
fd, scratch, readsize_aligned)) == (
int)readsize_aligned)
380 if (use_read)
free(scratch);
383 if (did < 0)
pdie(
"Write %d bytes at %lld",
size,
pos);
384 die(
"Wrote %d bytes instead of %d at %lld", did,
size,
pos);
390 pdie(
"Seek to %lld", (
long long)
pos);
394 pdie(
"Write %d bytes at %lld",
size, (
long long)
pos);
395 die(
"Wrote %d bytes instead of %d at %lld", did,
size, (
long long)
pos);
441 "Seek to %lld failed: %s\n Did not write %d bytes.\n",
444 fprintf(
stderr,
"Writing %d bytes at %lld failed: %s\n", this->size,
446 else if (
size != this->size)
447 fprintf(
stderr,
"Wrote %d bytes instead of %d bytes at %lld."
448 "\n",
size, this->size, (
long long)this->pos);
471 pdie(
"closing filesystem");
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
#define FILE_SYNCHRONOUS_IO_ALERT
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define memcpy(s1, s2, n)
static const struct @1644 read_write[]
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define InitializeObjectAttributes(p, n, a, r, s)
const char * strerror(int err)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
#define FSCTL_LOCK_VOLUME
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
#define FSCTL_UNLOCK_VOLUME
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define FSCTL_DISMOUNT_VOLUME
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_GENERIC_READ
#define FILE_GENERIC_WRITE
_In_ ULONG _In_ ULONG Offset
static unsigned __int64 next
#define FSCHECK_IMMEDIATE_WRITE
void pdie(const char *msg,...)
#define FSCTL_IS_VOLUME_DIRTY
int fs_test(off_t pos, int size)
void fs_read(off_t pos, int size, void *data)
void fs_write(off_t pos, int size, void *data)
static void fs_flush(void)
void fs_open(char *path, int rw)
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
#define new(TYPE, numElems)