Polyfill statfs() and fstatfs() on Windows

This commit is contained in:
Justine Tunney 2022-08-17 18:57:03 -07:00
parent f7ee9d7d99
commit c2211c9e63
16 changed files with 370 additions and 50 deletions

29
libc/nt/enum/statfs.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define kNtFileCasePreservedNames 0x00000002
#define kNtFileCaseSensitiveSearch 0x00000001
#define kNtFileFileCompression 0x00000010
#define kNtFileNamedStreams 0x00040000
#define kNtFilePersistentAcls 0x00000008
#define kNtFileReadOnlyVolume 0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce 0x00100000
#define kNtFileSupportsEncryption 0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks 0x00400000
#define kNtFileSupportsObjectIds 0x00010000
#define kNtFileSupportsOpenByFileId 0x01000000
#define kNtFileSupportsReparsePoints 0x00000080
#define kNtFileSupportsSparseFiles 0x00000040
#define kNtFileSupportsTransactions 0x00200000
#define kNtFileSupportsUsnJournal 0x02000000
#define kNtFileUnicodeOnDisk 0x00000004
#define kNtFileVolumeIsCompressed 0x00008000
#define kNtFileVolumeQuotas 0x00000020
#define kNtFileSupportsBlockRefcounting 0x08000000
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_ */

View file

@ -219,6 +219,15 @@ bool32 GetVolumePathName(const char16_t *lpszFileName,
char16_t *lpszVolumePathName,
uint32_t cchBufferLength);
bool32 GetVolumeInformationByHandle(int64_t hFile,
char16_t *opt_out_lpVolumeNameBuffer,
uint32_t nVolumeNameSize,
uint32_t *opt_out_lpVolumeSerialNumber,
uint32_t *opt_out_lpMaximumComponentLength,
uint32_t *opt_out_lpFileSystemFlags,
char16_t *opt_out_lpFileSystemNameBuffer,
uint32_t nFileSystemNameSize);
#if ShouldUseMsabiAttribute()
#include "libc/nt/thunk/files.inc"
#endif /* ShouldUseMsabiAttribute() */

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp kernel32,__imp_GetVolumeInformationByHandleW,GetVolumeInformationByHandleW,0
.text.windows
GetVolumeInformationByHandle:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_GetVolumeInformationByHandleW(%rip),%rax
jmp __sysv2nt8
.endfn GetVolumeInformationByHandle,globl
.previous

View file

@ -580,7 +580,7 @@ imp 'GetVDMCurrentDirectories' GetVDMCurrentDirectories kernel32 798
imp 'GetVersion' GetVersion kernel32 0
imp 'GetVersionEx' GetVersionExW kernel32 0 1
imp 'GetVolumeInformation' GetVolumeInformationW kernel32 0
imp 'GetVolumeInformationByHandle' GetVolumeInformationByHandleW kernel32 0
imp 'GetVolumeInformationByHandle' GetVolumeInformationByHandleW kernel32 0 8
imp 'GetVolumeNameForVolumeMountPoint' GetVolumeNameForVolumeMountPointW kernel32 0
imp 'GetVolumePathName' GetVolumePathNameW kernel32 0 3
imp 'GetVolumePathNamesForVolumeName' GetVolumePathNamesForVolumeNameW kernel32 0

View file

@ -0,0 +1,16 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct NtFileFsFullSizeInformation {
int64_t TotalAllocationUnits;
int64_t CallerAvailableAllocationUnits;
int64_t ActualAvailableAllocationUnits;
uint32_t SectorsPerAllocationUnit;
uint32_t BytesPerSector;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_ */