From de5167a304b5e3b2db7462329334ac01d492d72c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 1 Apr 2004 04:35:55 +0000 Subject: - Fixes all round - Uncontiguous FAT - Move to C (instead of C++) - Preparing for porting --- src/win32.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/win32.c (limited to 'src/win32.c') diff --git a/src/win32.c b/src/win32.c new file mode 100644 index 0000000..0726fad --- /dev/null +++ b/src/win32.c @@ -0,0 +1,78 @@ +/* + * AUTHOR + * N. Nielsen + * + * LICENSE + * This software is in the public domain. + * + * The software is provided "as is", without warranty of any kind, + * express or implied, including but not limited to the warranties + * of merchantability, fitness for a particular purpose, and + * noninfringement. In no event shall the author(s) be liable for any + * claim, damages, or other liability, whether in an action of + * contract, tort, or otherwise, arising from, out of, or in connection + * with the software or the use or other dealings in the software. + * + * SUPPORT + * Send bug reports to: + */ + +#define WIN32_LEAN_AND_MEAN 1 +#include + +#include "usuals.h" +#include "ntfs.h" + +const char kDriveName[] = "\\\\.\\PhysicalDrive%d"; + +#define ntfs_makefiletime(i64, ft) \ + ((ft).dwLowDateTime = LOWDWORD(i64), (ft).dwHighDateTime = HIGHDWORD(i64)) + +void makeDriveName(char* driveName, int i) +{ + wsprintf(driveName, kDriveName, i); +} + +void setFileTime(wchar_t* filename, uint64* created, + uint64* accessed, uint64* modified) +{ + FILETIME ftcr; + FILETIME ftac; + FILETIME ftmd; + HANDLE file; + + ntfs_makefiletime(*created, ftcr); + ntfs_makefiletime(*accessed, ftac); + ntfs_makefiletime(*modified, ftmd); + + /* Write to the File */ + file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + if(file == INVALID_HANDLE_VALUE) + { + warnx("couldn't set file time: %S", filename); + return; + } + + if(!SetFileTime(file, &ftcr, &ftac, &ftmd)) + warnx("couldn't set file time: %S", filename); + + CloseHandle(file); +} + +void setFileAttributes(wchar_t* filename, uint32 flags) +{ + DWORD attributes; + + /* Attributes */ + if(flags & kNTFS_FileReadOnly) + attributes |= FILE_ATTRIBUTE_READONLY; + if(flags & kNTFS_FileHidden) + attributes |= FILE_ATTRIBUTE_HIDDEN; + if(flags & kNTFS_FileArchive) + attributes |= FILE_ATTRIBUTE_ARCHIVE; + if(flags & kNTFS_FileSystem) + attributes |= FILE_ATTRIBUTE_SYSTEM; + + if(!SetFileAttributesW(filename, attributes)) + warnx("couldn't set file attributes: %S", filename); +} -- cgit v1.2.3