- /*
- * Compile with:
- * $ gcc -std=gnu17 -Wall disposefileex1.c -lntdll -o disposefileex1.exe #
- */
- #include <stdio.h>
- #include <windows.h>
- #include <winternl.h>
- #define EXIT_USAGE 2
- #if 0
- typedef struct _FILE_DISPOSITION_INFO_EX {
- DWORD Flags;
- } FILE_DISPOSITION_INFO_EX, *PFILE_DISPOSITION_INFO_EX;
- #endif
- #define FILE_DISPOSITION_DELETE 0x00000001
- #define FILE_DISPOSITION_DO_NOT_DELETE 0x00000002
- #define FILE_DISPOSITION_POSIX_DISPOSITION 0x00000003
- #define FILE_DISPOSITION_FORCE_IMAGE_DEINSTALL 0x00000004
- #define FILE_DISPOSITION_ON_CLOSE 0x00000008
- #define FILE_DISPOSITION_SPARSE 0x00000010
- int main(int argc, char *argv[]) {
- int retval;
- if (argc != 2) {
- return EXIT_USAGE;
- }
- const char *filename = argv[1];
- HANDLE hFile = INVALID_HANDLE_VALUE;
- hFile = CreateFileA(
- filename,
- DELETE,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- NULL,
- OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_POSIX_SEMANTICS,
- NULL
- );
- if (hFile == INVALID_HANDLE_VALUE) {
- "Error: Could not open file '%s'. GetLastError: %ld\n",
- filename, (long)GetLastError());
- return 1;
- }
- FILE_DISPOSITION_INFO_EX fileDispositionInfoEx = {
- .Flags = FILE_DISPOSITION_DELETE | FILE_DISPOSITION_ON_CLOSE
- };
- if (SetFileInformationByHandle(hFile,
- FileDispositionInfoEx,
- &fileDispositionInfoEx,
- sizeof(FILE_DISPOSITION_INFO_EX))) {
- retval = EXIT_SUCCESS;
- }
- else {
- (long)GetLastError());
- retval = EXIT_FAILURE;
- }
- (void)CloseHandle(hFile);
- return retval;
- }
disposefileex1.c - FileDispositionInfoEx test
Posted by Anonymous on Tue 22nd Jul 2025 18:54
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.