11 HANDLE createFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile,
abort_callback & abort);
14 template<
bool p_seekable,
bool p_writeable>
21 static file::ptr
g_CreateFile(
const char * p_path,DWORD p_access,DWORD p_sharemode,LPSECURITY_ATTRIBUTES p_security_attributes,DWORD p_createmode,DWORD p_flags,
HANDLE p_template) {
22 SetLastError(NO_ERROR);
23 HANDLE handle =
uCreateFile(p_path,p_access,p_sharemode,p_security_attributes,p_createmode,p_flags,p_template);
24 if (handle == INVALID_HANDLE_VALUE) {
25 const DWORD code = GetLastError();
30 return g_create_from_handle(handle);
31 }
catch(...) {CloseHandle(handle);
throw;}
42 if (!p_writeable)
throw exception_io_denied();
44 PFC_STATIC_ASSERT(
sizeof(
t_size) >=
sizeof(DWORD));
46 t_size bytes_written_total = 0;
48 if (
sizeof(
t_size) ==
sizeof(DWORD)) {
50 DWORD bytes_written = 0;
51 SetLastError(ERROR_SUCCESS);
53 if (bytes_written != p_bytes)
throw exception_io(
"Write failure");
54 bytes_written_total = bytes_written;
55 m_position += bytes_written;
57 while(bytes_written_total < p_bytes) {
59 DWORD bytes_written = 0;
60 DWORD delta = (DWORD) pfc::min_t<t_size>(p_bytes - bytes_written_total, 0x80000000);
61 SetLastError(ERROR_SUCCESS);
63 if (bytes_written != delta)
throw exception_io(
"Write failure");
64 bytes_written_total += bytes_written;
65 m_position += bytes_written;
71 PFC_STATIC_ASSERT(
sizeof(
t_size) >=
sizeof(DWORD));
73 t_size bytes_read_total = 0;
74 if (
sizeof(
t_size) ==
sizeof(DWORD)) {
77 SetLastError(ERROR_SUCCESS);
78 if (!ReadFile(m_handle,p_buffer,pfc::downcast_guarded<DWORD>(p_bytes),&bytes_read,0))
exception_io_from_win32(GetLastError());
79 bytes_read_total = bytes_read;
80 m_position += bytes_read;
82 while(bytes_read_total < p_bytes) {
85 DWORD delta = (DWORD) pfc::min_t<t_size>(p_bytes - bytes_read_total, 0x80000000);
86 SetLastError(ERROR_SUCCESS);
88 bytes_read_total += bytes_read;
89 m_position += bytes_read;
90 if (bytes_read != delta)
break;
93 return bytes_read_total;
108 if (!p_writeable)
throw exception_io_denied();
110 if (m_position != p_size) {
113 SetLastError(ERROR_SUCCESS);
114 if (!SetEndOfFile(m_handle)) {
115 DWORD code = GetLastError();
116 if (m_position != p_size)
try {
file_win32_helpers::seek(m_handle,m_position,file::seek_from_beginning);}
catch(...) {}
119 if (m_position > p_size) m_position = p_size;
125 if (!p_seekable)
throw exception_io_object_not_seekable();
129 m_position = p_position;
139 FlushFileBuffers(m_handle);
140 SetLastError(ERROR_SUCCESS);
153 template<
bool p_writeable>
157 WIN32_OP( (m_event =
CreateEvent(NULL, TRUE, FALSE, NULL)) != NULL );
161 if (!p_writeable)
throw exception_io_denied();
182 if (!p_writeable)
throw exception_io_denied();
185 SetLastError(ERROR_SUCCESS);
186 if (!SetEndOfFile(m_handle)) {
187 DWORD code = GetLastError();
190 if (m_position > p_size) m_position = p_size;
198 m_position = p_position;
208 FlushFileBuffers(m_handle);
209 SetLastError(ERROR_SUCCESS);
218 static file::ptr
g_CreateFile(
const char * p_path,DWORD p_access,DWORD p_sharemode,LPSECURITY_ATTRIBUTES p_security_attributes,DWORD p_createmode,DWORD p_flags,
HANDLE p_template) {
219 p_flags |= FILE_FLAG_OVERLAPPED;
220 SetLastError(NO_ERROR);
221 HANDLE handle =
uCreateFile(p_path,p_access,p_sharemode,p_security_attributes,p_createmode,p_flags,p_template);
222 if (handle == INVALID_HANDLE_VALUE) {
223 const DWORD code = GetLastError();
228 return g_create_from_handle(handle);
229 }
catch(...) {CloseHandle(handle);
throw;}
static file::ptr g_CreateFile(const char *p_path, DWORD p_access, DWORD p_sharemode, LPSECURITY_ATTRIBUTES p_security_attributes, DWORD p_createmode, DWORD p_flags, HANDLE p_template)
t_filesize get_size(HANDLE p_handle)
file_win32_wrapper_overlapped_t(HANDLE file)
void resize(t_filesize p_size, abort_callback &p_abort)
t_int64 t_sfilesize
Type used for file size related variables when a signed value is needed.
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
t_filesize get_size(abort_callback &p_abort)
PFC_NORETURN void win32_file_write_failure(DWORD p_code, const char *path)
void seek(HANDLE p_handle, t_sfilesize p_position, file::t_seek_mode p_mode)
t_filesize get_position(abort_callback &p_abort)
void seek(t_filesize p_position, abort_callback &p_abort)
PFC_NORETURN void exception_io_from_win32(DWORD p_code)
void fillOverlapped(OVERLAPPED &ol, HANDLE myEvent, t_filesize s)
HANDLE SHARED_EXPORT uCreateFile(const char *p_path, DWORD p_access, DWORD p_sharemode, LPSECURITY_ATTRIBUTES p_security_attributes, DWORD p_createmode, DWORD p_flags, HANDLE p_template)
~file_win32_wrapper_overlapped_t()
t_filetimestamp get_timestamp(abort_callback &p_abort)
void reopen(abort_callback &p_abort)
void writeOverlapped(HANDLE handle, HANDLE myEvent, t_filesize &position, const void *in, size_t inBytes, abort_callback &abort)
void seek(t_filesize p_position, abort_callback &p_abort)
t_filetimestamp get_timestamp(abort_callback &p_abort)
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
t_size read(void *p_buffer, t_size p_bytes, abort_callback &p_abort)
void write(const void *p_buffer, t_size p_bytes, abort_callback &p_abort)
void resize(t_filesize p_size, abort_callback &p_abort)
t_size read(void *p_buffer, t_size p_bytes, abort_callback &p_abort)
static file::ptr g_create_from_handle(HANDLE p_handle)
t_filesize get_position(abort_callback &p_abort)
t_filesize get_size(abort_callback &p_abort)
bool get_content_type(pfc::string_base &out)
DWORD readOverlappedPass(HANDLE handle, HANDLE myEvent, t_filesize position, void *out, DWORD outBytes, abort_callback &abort)
void on_idle(abort_callback &p_abort)
file_win32_wrapper_t(HANDLE p_handle)
HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName)
static file::ptr g_CreateFile(const char *p_path, DWORD p_access, DWORD p_sharemode, LPSECURITY_ATTRIBUTES p_security_attributes, DWORD p_createmode, DWORD p_flags, HANDLE p_template)
void write(const void *p_buffer, t_size p_bytes, abort_callback &p_abort)
t_uint64 t_filetimestamp
Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecon...
bool get_content_type(pfc::string_base &out)
void on_idle(abort_callback &p_abort)
t_uint64 t_filesize
Type used for file size related variables.
size_t readStreamOverlapped(HANDLE handle, HANDLE myEvent, void *out, size_t outBytes, abort_callback &abort)
size_t readOverlapped(HANDLE handle, HANDLE myEvent, t_filesize &position, void *out, size_t outBytes, abort_callback &abort)
HANDLE createFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile, abort_callback &abort)
void writeOverlappedPass(HANDLE handle, HANDLE myEvent, t_filesize position, const void *in, DWORD inBytes, abort_callback &abort)
static service_ptr_t< file > g_create_from_handle(HANDLE p_handle)
void reopen(abort_callback &p_abort)
void writeStreamOverlapped(HANDLE handle, HANDLE myEvent, const void *in, size_t inBytes, abort_callback &abort)