Support filesystems with invalid inode numbers on individual files
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-07-30 16:20:26 +02:00
parent 5f724b047b
commit 3a5a3b23ee
8 changed files with 89 additions and 57 deletions

View file

@ -38,6 +38,10 @@
#define FILE_INVALID_FILE_ID ((ULONGLONG)-1LL)
#endif
#ifndef FILE_UNSUPPORTED_FILE_ID
#define FILE_UNSUPPORTED_FILE_ID 0
#endif
/**
* Direct access to RtlGenRandom().
* This function is accessible only with LoadLibrary() and it's available from Windows XP.
@ -464,16 +468,44 @@ static int windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, const FILE_
*
* From Microsoft "Application Compatibility with ReFS"
* http://download.microsoft.com/download/C/B/3/CB3561DC-6BF6-443D-B5B9-9676ACDF7F75/Application%20Compatibility%20with%20ReFS.docx
* "64-bit file identifier can be obtained from GetFileInformationByHandle in"
* "the nFileIndexHigh and nFileIndexLow members. This API is an extended version"
* "that includes 128-bit file identifiers. If GetFileInformationByHandle returns"
* "FILE_INVALID_FILE_ID, the identifier may only be described in 128 bit form."
* 64-bit file identifier can be obtained from GetFileInformationByHandle in
* the nFileIndexHigh and nFileIndexLow members. This API is an extended version
* that includes 128-bit file identifiers. If GetFileInformationByHandle returns
* FILE_INVALID_FILE_ID, the identifier may only be described in 128 bit form.
*
* From Microsoft "[MS-FSCC]: File System Control Codes - 11/21/2025 v60.0 - 6 Appendix B: Product Behavior"
* https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/d4bc551b-7aaf-4b4f-ba0e-3a75e7c528f0
*
* 64bitFileID Generate Stable Unique
* FAT Yes No No
* EXFAT Yes No No
* FAT32 Yes No No
* UDFS Yes Yes Yes
* NTFS Yes Yes Yes
* ReFS Yes Yes Yes
*
* NTFS computes the 64-bit file ID as follows: the low 48 bits are the index of the
* file's primary record in the master file table (MFT); the remaining 16 bits are
* a sequence number. Therefore, it is possible, though rare, that a different file
* can have the same 64-bit file ID as a file on that volume had in the past.
*
* ReFS maps a subset of the possible 128-bit file ID values to a 64-bit value using
* a reversible algorithm; for values outside of this subset, ReFS sets the 64-bit
* file ID to -1.
*
* From Microsoft "[MS-FSCC]: File System Control Codes - 11/21/2025 v60.0 - 2.1.9 64-bit file ID"
* https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/2d3333fe-fc98-4a6f-98a2-4bb805aff407?utm_source=chatgpt.com
*
* A 64-bit file ID value uniquely identifies a file within a given volume. This
* identifier is generated and stored by the file system. The identifier SHOULD
* be unique to the volume and stable until the file is deleted.
* For file systems that do not support a 64-bit file ID, this field MUST be
* set to 0, and MUST be ignored.
* For files for which a unique 64-bit file ID cannot be established, this
* field MUST be set to 0xFFFFFFFFFFFFFFFF, and MUST be ignored.
*/
if (st->st_ino == (uint64_t)FILE_INVALID_FILE_ID) {
errno = EINVAL;
os_syslog(OS_LVL_INFO, "invalid inode number! Is this ReFS?");
return -1;
}
if (st->st_ino == (uint64_t)FILE_INVALID_FILE_ID || st->st_ino == (uint64_t)FILE_UNSUPPORTED_FILE_ID)
st->st_ino = INODE_INVALID;
return 0;
}

View file

@ -195,6 +195,11 @@ int os_validate_exec_input(const char* str);
/****************************************************************************/
/* fs */
/**
* Invalid inode number
*/
#define INODE_INVALID 0
/**
* Physical offset not yet read.
*/