implement user mode catchable exceptions, refactor system status codes to use NTLSTATUS_ prefix, update build scripts to use shared literal macros for linker arguments, update named queue lifetime cleanup to include KeNamedQueueUnpublishHandle.
This commit is contained in:
1 parent
1f5477cf66
commit
b7fcfce6f7
140 files changed
+7649
-3943
No files matched your search
+144
-144
@@ -208,7 +208,7 @@ static KSTATUS FatCacheRead(FAT32_VOL *v, uint64_t lba, uint8_t **out) {
|
||||
|
||||
if (e->valid && e->vol == v && e->lba == lba) {
|
||||
*out = e->data;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Evict current occupant: single-copy writeback on collision.
|
||||
@@ -226,7 +226,7 @@ static KSTATUS FatCacheRead(FAT32_VOL *v, uint64_t lba, uint8_t **out) {
|
||||
e->valid = true;
|
||||
e->dirty = false;
|
||||
*out = e->data;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Implements the fat Cache Mark Dirty operation.
|
||||
@@ -285,13 +285,13 @@ typedef struct {
|
||||
// Raw sector I/O (bypasses FAT cache; used for file data and cache eviction).
|
||||
static KSTATUS ReadSectorsRaw(FAT32_VOL *v, uint64_t lba,
|
||||
uint32_t count, void *buf) {
|
||||
if (!v) return STATUS_INVALID_PARAMETER;
|
||||
if (!v) return NTLSTATUS_INVALID_PARAMETER;
|
||||
return IoReadDiskSectors(v->DriveIndex, lba, count, buf);
|
||||
}
|
||||
|
||||
static KSTATUS WriteSectorsRaw(FAT32_VOL *v, uint64_t lba,
|
||||
uint32_t count, const void *buf) {
|
||||
if (!v) return STATUS_INVALID_PARAMETER;
|
||||
if (!v) return NTLSTATUS_INVALID_PARAMETER;
|
||||
return IoWriteDiskSectors(v->DriveIndex, lba, count, buf);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ static KSTATUS WriteFatEntry(FAT32_VOL *v, uint32_t cluster, uint32_t value) {
|
||||
| (value & 0x0FFFFFFFu);
|
||||
FatCacheMarkDirty(v, sector);
|
||||
FatCacheRelease(held);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Cluster allocation (fix #3: next-free hint + two-phase wrap-around scan).
|
||||
@@ -535,7 +535,7 @@ static uint8_t FatEncodeCreateTimeTenth(const SYS_SYSTEM_TIME* t) {
|
||||
static void FatQueryEncodedTime(FAT32_ENCODED_TIME* out) {
|
||||
SYS_SYSTEM_TIME now;
|
||||
memset(&now, 0, sizeof(now));
|
||||
if (KeQuerySystemTime(&now) != STATUS_SUCCESS) {
|
||||
if (KeQuerySystemTime(&now) != NTLSTATUS_SUCCESS) {
|
||||
now.Year = 1980;
|
||||
now.Month = 1;
|
||||
now.Day = 1;
|
||||
@@ -584,9 +584,9 @@ static void FatDecodeAccessDate(uint16_t date, SYS_SYSTEM_TIME* out) {
|
||||
static KSTATUS DirentUpdateMetadata(FAT32_VOL *v, uint64_t lba,
|
||||
uint32_t offset,
|
||||
const FAT32_DIRENT_UPDATE* update) {
|
||||
if (!v || !update || !update->Flags) return STATUS_INVALID_PARAMETER;
|
||||
if (!v || !update || !update->Flags) return NTLSTATUS_INVALID_PARAMETER;
|
||||
uint8_t *sec = (uint8_t *)MmAllocatePool(v->BytesPerSector);
|
||||
if (!sec) return STATUS_NO_MEMORY;
|
||||
if (!sec) return NTLSTATUS_NO_MEMORY;
|
||||
KSTATUS s = ReadSectors(v, lba, 1, sec);
|
||||
if (KSUCCESS(s)) {
|
||||
DIRENT *d = (DIRENT *)(sec + offset);
|
||||
@@ -967,13 +967,13 @@ static void MakeLegacyBrokenDot83V(SYS_STRING_VIEW src, char name8[8], char ext3
|
||||
|
||||
static KSTATUS DeleteLegacyBrokenDotAliasV(FAT32_VOL *v, uint32_t dirCluster,
|
||||
SYS_STRING_VIEW longName) {
|
||||
if (!SysSvIsValid(longName) || longName.Length < 2 || longName.Data[0] != '.') return STATUS_SUCCESS;
|
||||
if (!SysSvIsValid(longName) || longName.Length < 2 || longName.Data[0] != '.') return NTLSTATUS_SUCCESS;
|
||||
|
||||
char badName[8], badExt[3];
|
||||
MakeLegacyBrokenDot83V(longName, badName, badExt);
|
||||
|
||||
uint8_t *clusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!clusterBuf) return STATUS_NO_MEMORY;
|
||||
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
uint32_t cluster = dirCluster;
|
||||
while (cluster >= 2 && cluster < FAT32_EOC) {
|
||||
@@ -984,7 +984,7 @@ static KSTATUS DeleteLegacyBrokenDotAliasV(FAT32_VOL *v, uint32_t dirCluster,
|
||||
uint32_t entries = v->BytesPerCluster / sizeof(DIRENT);
|
||||
DIRENT *dir = (DIRENT *)clusterBuf;
|
||||
for (uint32_t i = 0; i < entries; i++) {
|
||||
if (dir[i].Name[0] == 0x00) { MmFreePool(clusterBuf); return STATUS_SUCCESS; }
|
||||
if (dir[i].Name[0] == 0x00) { MmFreePool(clusterBuf); return NTLSTATUS_SUCCESS; }
|
||||
if ((uint8_t)dir[i].Name[0] == 0xE5 || dir[i].Attr == ATTR_LFN) continue;
|
||||
if (MatchRaw83(dir[i].Name, dir[i].Ext, badName, badExt)) {
|
||||
int emptyBase = 1;
|
||||
@@ -1005,7 +1005,7 @@ static KSTATUS DeleteLegacyBrokenDotAliasV(FAT32_VOL *v, uint32_t dirCluster,
|
||||
}
|
||||
|
||||
MmFreePool(clusterBuf);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Implements the lfn Append operation.
|
||||
@@ -1419,9 +1419,9 @@ static KSTATUS Fat32LookupPathV(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
uint8_t *outAttr,
|
||||
uint64_t *outDirentLba, uint32_t *outDirentOffset) {
|
||||
if (!v || !outCluster || !outSize || !SysSvIsValid(path))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
if (SysSvContainsByte(path, '\0'))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint32_t cluster = v->RootCluster, size = 0;
|
||||
uint8_t attr = ATTR_DIRECTORY;
|
||||
@@ -1433,21 +1433,21 @@ static KSTATUS Fat32LookupPathV(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
if (Fat32PathCacheLookup(v, path, outCluster, outSize, &attr,
|
||||
outDirentLba, outDirentOffset)) {
|
||||
if (outAttr) *outAttr = attr;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
size_t cursor = 0;
|
||||
SYS_STRING_VIEW component;
|
||||
while (Fat32PathNextComponent(path, &cursor, &component)) {
|
||||
if (component.Length >= MAX_LFN) return STATUS_BUFFER_TOO_SMALL;
|
||||
if (!Fat32NameViewIsValid(component)) return STATUS_INVALID_PARAMETER;
|
||||
if (!(attr & ATTR_DIRECTORY)) return STATUS_NOT_FOUND;
|
||||
if (component.Length >= MAX_LFN) return NTLSTATUS_BUFFER_TOO_SMALL;
|
||||
if (!Fat32NameViewIsValid(component)) return NTLSTATUS_INVALID_PARAMETER;
|
||||
if (!(attr & ATTR_DIRECTORY)) return NTLSTATUS_NOT_FOUND;
|
||||
|
||||
uint32_t childCluster, childSize; uint8_t childAttr;
|
||||
uint64_t childLba = 0; uint32_t childOffset = 0;
|
||||
if (!SearchDirV(v, cluster, component, &childCluster, &childSize,
|
||||
&childAttr, &childLba, &childOffset))
|
||||
return STATUS_NOT_FOUND;
|
||||
return NTLSTATUS_NOT_FOUND;
|
||||
|
||||
cluster = childCluster; size = childSize; attr = childAttr;
|
||||
finalDirentLba = childLba;
|
||||
@@ -1461,7 +1461,7 @@ static KSTATUS Fat32LookupPathV(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
if (outAttr) *outAttr = attr;
|
||||
Fat32PathCacheStore(v, path, cluster, size, attr,
|
||||
finalDirentLba, finalDirentOffset);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static KSTATUS TraverseV(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
@@ -1471,15 +1471,15 @@ static KSTATUS TraverseV(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
|
||||
static KSTATUS SplitPathV(SYS_STRING_VIEW path, SYS_STRING_VIEW* parent,
|
||||
SYS_STRING_VIEW* name) {
|
||||
if (!parent || !name || !SysSvIsValid(path)) return STATUS_INVALID_PARAMETER;
|
||||
if (!parent || !name || !SysSvIsValid(path)) return NTLSTATUS_INVALID_PARAMETER;
|
||||
*parent = SYS_SV_NULL;
|
||||
*name = SYS_SV_NULL;
|
||||
|
||||
while (path.Length && Fat32IsPathSep(path.Data[path.Length - 1]))
|
||||
path.Length--;
|
||||
if (path.Length == 0) return STATUS_INVALID_PARAMETER;
|
||||
if (path.Length == 0) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
if (SysSvContainsByte(path, '\0')) return STATUS_INVALID_PARAMETER;
|
||||
if (SysSvContainsByte(path, '\0')) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
size_t lastSep = (size_t)-1;
|
||||
for (size_t i = 0; i < path.Length; i++) {
|
||||
@@ -1494,8 +1494,8 @@ static KSTATUS SplitPathV(SYS_STRING_VIEW path, SYS_STRING_VIEW* parent,
|
||||
*name = SysSvFromParts(path.Data + lastSep + 1, path.Length - lastSep - 1);
|
||||
}
|
||||
|
||||
if (!Fat32NameViewIsValid(*name)) return STATUS_INVALID_PARAMETER;
|
||||
return STATUS_SUCCESS;
|
||||
if (!Fat32NameViewIsValid(*name)) return NTLSTATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Find a free DIRENT slot.
|
||||
@@ -1593,7 +1593,7 @@ static KSTATUS Fat32ResolveParentForMutation(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
uint32_t *parentClusterOut,
|
||||
SYS_STRING_VIEW *filenameOut) {
|
||||
if (!v || !parentClusterOut || !filenameOut)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
SYS_STRING_VIEW parentPath;
|
||||
SYS_STRING_VIEW filenameView;
|
||||
@@ -1606,11 +1606,11 @@ static KSTATUS Fat32ResolveParentForMutation(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
s = Fat32LookupPathV(v, parentPath, &parentCluster, &parentSize,
|
||||
&parentAttr, NULL, NULL);
|
||||
if (!KSUCCESS(s)) return s;
|
||||
if (!(parentAttr & ATTR_DIRECTORY)) return STATUS_NOT_FOUND;
|
||||
if (!(parentAttr & ATTR_DIRECTORY)) return NTLSTATUS_NOT_FOUND;
|
||||
|
||||
*parentClusterOut = parentCluster;
|
||||
*filenameOut = filenameView;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Creates a FAT directory entry run for a new file or directory.
|
||||
@@ -1620,7 +1620,7 @@ static KSTATUS Fat32CreateDirent(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
uint64_t *direntLbaOut,
|
||||
uint32_t *direntOffsetOut) {
|
||||
if (!v || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint32_t parentCluster = 0;
|
||||
SYS_STRING_VIEW filenameView;
|
||||
@@ -1634,7 +1634,7 @@ static KSTATUS Fat32CreateDirent(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
uint32_t existingOffset = 0;
|
||||
if (SearchDirV(v, parentCluster, filenameView, &ec, &es, &ea,
|
||||
&existingLba, &existingOffset)) {
|
||||
return STATUS_OBJECT_NAME_COLLISION;
|
||||
return NTLSTATUS_OBJECT_NAME_COLLISION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1644,22 +1644,22 @@ static KSTATUS Fat32CreateDirent(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
s = DeleteLegacyBrokenDotAliasV(v, parentCluster, filenameView);
|
||||
if (!KSUCCESS(s)) return s;
|
||||
if (!MakeUniqueShortAliasV(v, parentCluster, filenameView, shortName, shortExt))
|
||||
return STATUS_OBJECT_NAME_COLLISION;
|
||||
return NTLSTATUS_OBJECT_NAME_COLLISION;
|
||||
} else {
|
||||
Make83NameV(filenameView, shortName, shortExt);
|
||||
}
|
||||
|
||||
size_t nameLen = filenameView.Length;
|
||||
if (nameLen == 0 || nameLen >= MAX_LFN) return STATUS_INVALID_PARAMETER;
|
||||
if (nameLen == 0 || nameLen >= MAX_LFN) return NTLSTATUS_INVALID_PARAMETER;
|
||||
uint32_t lfnCount = useLfn ? (uint32_t)((nameLen + 12u) / 13u) : 0;
|
||||
uint32_t neededEntries = lfnCount + 1u;
|
||||
|
||||
uint32_t entryCluster, firstIndex;
|
||||
if (!FindFreeDirentRun(v, parentCluster, neededEntries, &entryCluster, &firstIndex))
|
||||
return STATUS_NO_MEMORY;
|
||||
return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
uint8_t *clusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!clusterBuf) return STATUS_NO_MEMORY;
|
||||
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
uint64_t clusterLba = ClusterToLba(v, entryCluster);
|
||||
s = ReadSectors(v, clusterLba, v->SectorsPerCluster, clusterBuf);
|
||||
@@ -1708,7 +1708,7 @@ static KSTATUS Fat32CreateDirent(FAT32_VOL *v, SYS_STRING_VIEW path,
|
||||
if (direntOffsetOut) *direntOffsetOut = direntOffset;
|
||||
|
||||
Fat32PathCacheInvalidate(v);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Initializes one dot entry in a new directory cluster.
|
||||
@@ -1735,10 +1735,10 @@ static void Fat32InitDotEntry(DIRENT *d, const char *name,
|
||||
static KSTATUS Fat32InitializeDirectoryCluster(FAT32_VOL *v, uint32_t dirCluster,
|
||||
uint32_t parentCluster) {
|
||||
if (!v || dirCluster < 2)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint8_t *clusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!clusterBuf) return STATUS_NO_MEMORY;
|
||||
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
|
||||
memset(clusterBuf, 0, v->BytesPerCluster);
|
||||
|
||||
FAT32_ENCODED_TIME now;
|
||||
@@ -1766,10 +1766,10 @@ static int Fat32IsDotEntry(const DIRENT *d) {
|
||||
static KSTATUS Fat32DirectoryIsEmpty(FAT32_VOL *v, uint32_t dirCluster,
|
||||
int *emptyOut) {
|
||||
if (!v || !emptyOut || dirCluster < 2)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint8_t *clusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!clusterBuf) return STATUS_NO_MEMORY;
|
||||
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
uint32_t cluster = dirCluster;
|
||||
while (cluster >= 2 && cluster < FAT32_EOC) {
|
||||
@@ -1781,14 +1781,14 @@ static KSTATUS Fat32DirectoryIsEmpty(FAT32_VOL *v, uint32_t dirCluster,
|
||||
DIRENT *dir = (DIRENT *)clusterBuf;
|
||||
for (uint32_t i = 0; i < entries; i++) {
|
||||
uint8_t first = (uint8_t)dir[i].Name[0];
|
||||
if (first == 0x00) { MmFreePool(clusterBuf); *emptyOut = 1; return STATUS_SUCCESS; }
|
||||
if (first == 0x00) { MmFreePool(clusterBuf); *emptyOut = 1; return NTLSTATUS_SUCCESS; }
|
||||
if (first == 0xE5 || dir[i].Attr == ATTR_LFN) continue;
|
||||
if ((dir[i].Attr & ATTR_VOLUME_ID) && !(dir[i].Attr & ATTR_DIRECTORY)) continue;
|
||||
if (Fat32IsDotEntry(&dir[i])) continue;
|
||||
|
||||
MmFreePool(clusterBuf);
|
||||
*emptyOut = 0;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
cluster = FatEntry(v, cluster);
|
||||
@@ -1796,17 +1796,17 @@ static KSTATUS Fat32DirectoryIsEmpty(FAT32_VOL *v, uint32_t dirCluster,
|
||||
|
||||
MmFreePool(clusterBuf);
|
||||
*emptyOut = 1;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Deletes the directory-entry run for one child name from a parent directory.
|
||||
static KSTATUS Fat32DeleteDirentRunV(FAT32_VOL *v, uint32_t parentCluster,
|
||||
SYS_STRING_VIEW name) {
|
||||
if (!v || !Fat32NameViewIsValid(name))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint8_t *clusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!clusterBuf) return STATUS_NO_MEMORY;
|
||||
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
char lfn[MAX_LFN];
|
||||
int hasLfn = 0;
|
||||
@@ -1829,7 +1829,7 @@ static KSTATUS Fat32DeleteDirentRunV(FAT32_VOL *v, uint32_t parentCluster,
|
||||
memset(lfn, 0, sizeof(lfn));
|
||||
for (uint32_t i = 0; i < entries; i++) {
|
||||
uint8_t first = (uint8_t)dir[i].Name[0];
|
||||
if (first == 0x00) { MmFreePool(clusterBuf); return STATUS_NOT_FOUND; }
|
||||
if (first == 0x00) { MmFreePool(clusterBuf); return NTLSTATUS_NOT_FOUND; }
|
||||
if (first == 0xE5) { hasLfn = 0; memset(lfn, 0, sizeof(lfn)); continue; }
|
||||
if (dir[i].Attr == ATTR_LFN) {
|
||||
if (!hasLfn) lfnStart = i;
|
||||
@@ -1863,13 +1863,13 @@ static KSTATUS Fat32DeleteDirentRunV(FAT32_VOL *v, uint32_t parentCluster,
|
||||
}
|
||||
|
||||
MmFreePool(clusterBuf);
|
||||
return STATUS_NOT_FOUND;
|
||||
return NTLSTATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Open / Close.
|
||||
KSTATUS Fat32Open(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, void **fileCtx) {
|
||||
if (!fs || !fileCtx || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint32_t cluster, size; uint64_t direntLba; uint32_t direntOffset;
|
||||
@@ -1877,12 +1877,12 @@ KSTATUS Fat32Open(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, void **fileCtx) {
|
||||
if (!KSUCCESS(s)) return s;
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)MmAllocatePool(sizeof(FAT32_FILE));
|
||||
if (!f) return STATUS_NO_MEMORY;
|
||||
if (!f) return NTLSTATUS_NO_MEMORY;
|
||||
f->StartCluster = cluster; f->FileSize = size; f->Vol = v;
|
||||
f->DirentLba = direntLba; f->DirentOffset = direntOffset;
|
||||
Fat32FileInitChainCache(f);
|
||||
*fileCtx = f;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Releases the requested object.
|
||||
@@ -1902,13 +1902,13 @@ KSTATUS Fat32Read(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
uint64_t offset, void *buf,
|
||||
size_t size, size_t *bytesRead) {
|
||||
(void)fs;
|
||||
if (!bytesRead) return STATUS_INVALID_PARAMETER;
|
||||
if (!bytesRead) return NTLSTATUS_INVALID_PARAMETER;
|
||||
*bytesRead = 0;
|
||||
if (!fileCtx || !buf) return STATUS_INVALID_PARAMETER;
|
||||
if (!fileCtx || !buf) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)fileCtx;
|
||||
FAT32_VOL *v = f->Vol;
|
||||
if (offset >= f->FileSize || size == 0) return STATUS_SUCCESS;
|
||||
if (offset >= f->FileSize || size == 0) return NTLSTATUS_SUCCESS;
|
||||
if (size > (size_t)(f->FileSize - offset)) size = (size_t)(f->FileSize - offset);
|
||||
size_t wanted = size;
|
||||
|
||||
@@ -1920,11 +1920,11 @@ KSTATUS Fat32Read(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
maxUsefulSectors = FAT32_READ_RUN_MAX_SECTORS;
|
||||
|
||||
uint8_t *runBuf = (uint8_t *)MmAllocatePool((size_t)maxUsefulSectors * 512u);
|
||||
if (!runBuf) return STATUS_NO_MEMORY;
|
||||
if (!runBuf) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
size_t totalRead = 0;
|
||||
uint8_t *out = (uint8_t *)buf;
|
||||
KSTATUS readStatus = STATUS_SUCCESS;
|
||||
KSTATUS readStatus = NTLSTATUS_SUCCESS;
|
||||
uint32_t logicalCluster = (uint32_t)(offset / v->BytesPerCluster);
|
||||
uint32_t offsetInCluster = (uint32_t)(offset % v->BytesPerCluster);
|
||||
uint32_t cluster = Fat32ResolveFileCluster(f, logicalCluster);
|
||||
@@ -1941,7 +1941,7 @@ KSTATUS Fat32Read(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
uint32_t next = 0;
|
||||
if (!Fat32BuildReadRun(f, logicalCluster, cluster, usefulSectors,
|
||||
&runSectors, &next)) {
|
||||
readStatus = STATUS_DEVICE_ERROR;
|
||||
readStatus = NTLSTATUS_DEVICE_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1977,8 +1977,8 @@ KSTATUS Fat32Read(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
MmFreePool(runBuf);
|
||||
*bytesRead = totalRead;
|
||||
if (totalRead != wanted)
|
||||
return KSUCCESS(readStatus) ? STATUS_DEVICE_ERROR : readStatus;
|
||||
return STATUS_SUCCESS;
|
||||
return KSUCCESS(readStatus) ? NTLSTATUS_DEVICE_ERROR : readStatus;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Write (fix #4: contiguous-run coalescing)
|
||||
@@ -1989,7 +1989,7 @@ KSTATUS Fat32Write(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
uint64_t offset, const void *buf,
|
||||
size_t size, size_t *bytesWritten) {
|
||||
(void)fs;
|
||||
if (!size) { *bytesWritten = 0; return STATUS_SUCCESS; }
|
||||
if (!size) { *bytesWritten = 0; return NTLSTATUS_SUCCESS; }
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)fileCtx;
|
||||
FAT32_VOL *v = f->Vol;
|
||||
@@ -1999,7 +1999,7 @@ KSTATUS Fat32Write(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
// Ensure at least one cluster exists.
|
||||
if (f->StartCluster < 2) {
|
||||
uint32_t first = AllocCluster(v);
|
||||
if (!first) { *bytesWritten = 0; return STATUS_NO_MEMORY; }
|
||||
if (!first) { *bytesWritten = 0; return NTLSTATUS_NO_MEMORY; }
|
||||
f->StartCluster = first;
|
||||
DirentUpdateFirstCluster(v, f->DirentLba, f->DirentOffset, first);
|
||||
}
|
||||
@@ -2013,13 +2013,13 @@ KSTATUS Fat32Write(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
uint32_t next = FatEntry(v, cluster);
|
||||
if (next < 2 || next >= FAT32_EOC) {
|
||||
next = AppendCluster(v, cluster);
|
||||
if (!next) { *bytesWritten = 0; return STATUS_NO_MEMORY; }
|
||||
if (!next) { *bytesWritten = 0; return NTLSTATUS_NO_MEMORY; }
|
||||
}
|
||||
cluster = next;
|
||||
}
|
||||
|
||||
uint8_t *runBuf = (uint8_t *)MmAllocatePool(FAT32_WRITE_RUN_MAX_SECTORS * 512u);
|
||||
if (!runBuf) { *bytesWritten = 0; return STATUS_NO_MEMORY; }
|
||||
if (!runBuf) { *bytesWritten = 0; return NTLSTATUS_NO_MEMORY; }
|
||||
|
||||
size_t written = 0, remaining = size;
|
||||
|
||||
@@ -2095,14 +2095,14 @@ KSTATUS Fat32Write(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
}
|
||||
|
||||
*bytesWritten = written;
|
||||
return (written == size) ? STATUS_SUCCESS : STATUS_DEVICE_ERROR;
|
||||
return (written == size) ? NTLSTATUS_SUCCESS : NTLSTATUS_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
// Create.
|
||||
// Creates the requested file and fails if the name already exists.
|
||||
KSTATUS Fat32Create(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, void **fileCtx) {
|
||||
if (!fs || !fileCtx || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint64_t direntLba = 0;
|
||||
@@ -2112,7 +2112,7 @@ KSTATUS Fat32Create(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, void **fileCtx) {
|
||||
if (!KSUCCESS(s)) return s;
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)MmAllocatePool(sizeof(FAT32_FILE));
|
||||
if (!f) return STATUS_NO_MEMORY;
|
||||
if (!f) return NTLSTATUS_NO_MEMORY;
|
||||
f->StartCluster = 0;
|
||||
f->FileSize = 0;
|
||||
f->Vol = v;
|
||||
@@ -2120,13 +2120,13 @@ KSTATUS Fat32Create(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, void **fileCtx) {
|
||||
f->DirentOffset = direntOffset;
|
||||
Fat32FileInitChainCache(f);
|
||||
*fileCtx = f;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Creates a directory and initializes its dot entries.
|
||||
KSTATUS Fat32CreateDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
if (!fs || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint32_t parentCluster = 0;
|
||||
@@ -2136,7 +2136,7 @@ KSTATUS Fat32CreateDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
(void)filenameView;
|
||||
|
||||
uint32_t dirCluster = AllocCluster(v);
|
||||
if (!dirCluster) return STATUS_NO_MEMORY;
|
||||
if (!dirCluster) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
s = Fat32InitializeDirectoryCluster(v, dirCluster, parentCluster);
|
||||
if (!KSUCCESS(s)) {
|
||||
@@ -2153,13 +2153,13 @@ KSTATUS Fat32CreateDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
}
|
||||
|
||||
FlushFatCache(v);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Removes an empty directory.
|
||||
KSTATUS Fat32RemoveDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
if (!fs || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint32_t cluster = 0;
|
||||
@@ -2170,13 +2170,13 @@ KSTATUS Fat32RemoveDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
KSTATUS s = Fat32LookupPathV(v, path, &cluster, &size, &attr,
|
||||
&direntLba, &direntOffset);
|
||||
if (!KSUCCESS(s)) return s;
|
||||
if (!direntLba) return STATUS_ACCESS_DENIED;
|
||||
if (!(attr & ATTR_DIRECTORY)) return STATUS_ACCESS_DENIED;
|
||||
if (!direntLba) return NTLSTATUS_ACCESS_DENIED;
|
||||
if (!(attr & ATTR_DIRECTORY)) return NTLSTATUS_ACCESS_DENIED;
|
||||
|
||||
int empty = 0;
|
||||
s = Fat32DirectoryIsEmpty(v, cluster, &empty);
|
||||
if (!KSUCCESS(s)) return s;
|
||||
if (!empty) return STATUS_ACCESS_DENIED;
|
||||
if (!empty) return NTLSTATUS_ACCESS_DENIED;
|
||||
|
||||
uint32_t parentCluster = 0;
|
||||
SYS_STRING_VIEW filenameView;
|
||||
@@ -2189,7 +2189,7 @@ KSTATUS Fat32RemoveDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
if (cluster >= 2) FreeClusterChain(v, cluster);
|
||||
FlushFatCache(v);
|
||||
Fat32PathCacheInvalidate(v);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Truncate.
|
||||
@@ -2240,7 +2240,7 @@ KSTATUS Fat32Truncate(IO_FILESYSTEM *fs, void *fileCtx, uint64_t newSize, uint32
|
||||
uint32_t lastCluster = 0;
|
||||
if (f->StartCluster < 2) {
|
||||
uint32_t first = AllocClusterEx(v, zeroNewClusters);
|
||||
if (!first) return STATUS_NO_MEMORY;
|
||||
if (!first) return NTLSTATUS_NO_MEMORY;
|
||||
f->StartCluster = first;
|
||||
DirentUpdateFirstCluster(v, f->DirentLba, f->DirentOffset, first);
|
||||
lastCluster = first; curClusters = 1;
|
||||
@@ -2249,7 +2249,7 @@ KSTATUS Fat32Truncate(IO_FILESYSTEM *fs, void *fileCtx, uint64_t newSize, uint32
|
||||
}
|
||||
for (uint32_t i = curClusters; i < newClusters; i++) {
|
||||
uint32_t next = AppendClusterEx(v, lastCluster, zeroNewClusters);
|
||||
if (!next) return STATUS_NO_MEMORY;
|
||||
if (!next) return NTLSTATUS_NO_MEMORY;
|
||||
lastCluster = next;
|
||||
}
|
||||
}
|
||||
@@ -2265,16 +2265,16 @@ update_size:
|
||||
// Delete.
|
||||
KSTATUS Fat32Delete(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
if (!fs || !SysSvIsValid(path) || path.Length == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint32_t cluster, size; uint64_t direntLba; uint32_t direntOffset;
|
||||
KSTATUS s = Fat32LookupPathV(v, path, &cluster, &size, NULL, &direntLba, &direntOffset);
|
||||
if (!KSUCCESS(s)) return s;
|
||||
if (!direntLba) return STATUS_ACCESS_DENIED;
|
||||
if (!direntLba) return NTLSTATUS_ACCESS_DENIED;
|
||||
|
||||
uint8_t *sec = (uint8_t *)MmAllocatePool(v->BytesPerSector);
|
||||
if (!sec) return STATUS_NO_MEMORY;
|
||||
if (!sec) return NTLSTATUS_NO_MEMORY;
|
||||
s = ReadSectors(v, direntLba, 1, sec);
|
||||
if (KSUCCESS(s)) { sec[direntOffset] = 0xE5; s = WriteSectors(v, direntLba, 1, sec); }
|
||||
MmFreePool(sec);
|
||||
@@ -2283,7 +2283,7 @@ KSTATUS Fat32Delete(IO_FILESYSTEM *fs, SYS_STRING_VIEW path) {
|
||||
if (cluster >= 2) FreeClusterChain(v, cluster);
|
||||
FlushFatCache(v);
|
||||
Fat32PathCacheInvalidate(v);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Returns size.
|
||||
@@ -2343,11 +2343,11 @@ static void Fat32FillRootStat(FAT32_VOL *v, SYS_FILE_STAT *out) {
|
||||
// Queries metadata for an open FAT32 file.
|
||||
KSTATUS Fat32QueryInfo(IO_FILESYSTEM *fs, void *fileCtx, SYS_FILE_STAT *out) {
|
||||
(void)fs;
|
||||
if (!fileCtx || !out) return STATUS_INVALID_PARAMETER;
|
||||
if (!fileCtx || !out) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)fileCtx;
|
||||
FAT32_VOL *v = f->Vol;
|
||||
if (!v) return STATUS_INVALID_PARAMETER;
|
||||
if (!v) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
if (f->DirentLba == 0) {
|
||||
if (f->StartCluster == v->RootCluster && f->FileSize == 0) {
|
||||
@@ -2362,11 +2362,11 @@ KSTATUS Fat32QueryInfo(IO_FILESYSTEM *fs, void *fileCtx, SYS_FILE_STAT *out) {
|
||||
out->VolumeId = Fat32VolumeIdentity(v);
|
||||
out->FileId = ((uint64_t)f->StartCluster << 1);
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t *sec = (uint8_t *)MmAllocatePool(v->BytesPerSector);
|
||||
if (!sec) return STATUS_NO_MEMORY;
|
||||
if (!sec) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
KSTATUS s = ReadSectors(v, f->DirentLba, 1, sec);
|
||||
if (!KSUCCESS(s)) { MmFreePool(sec); return s; }
|
||||
@@ -2374,22 +2374,22 @@ KSTATUS Fat32QueryInfo(IO_FILESYSTEM *fs, void *fileCtx, SYS_FILE_STAT *out) {
|
||||
DIRENT *d = (DIRENT *)(sec + f->DirentOffset);
|
||||
if ((uint8_t)d->Name[0] == 0x00 || (uint8_t)d->Name[0] == 0xE5) {
|
||||
MmFreePool(sec);
|
||||
return STATUS_NOT_FOUND;
|
||||
return NTLSTATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
Fat32FillStatFromDirent(v, d, f->DirentLba, f->DirentOffset, out);
|
||||
f->StartCluster = ((uint32_t)d->FirstClusterHi << 16) | d->FirstClusterLo;
|
||||
f->FileSize = d->FileSize;
|
||||
MmFreePool(sec);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Queries metadata for a FAT32 path.
|
||||
KSTATUS Fat32Stat(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, SYS_FILE_STAT *out) {
|
||||
if (!fs || !out || !SysSvIsValid(path)) return STATUS_INVALID_PARAMETER;
|
||||
if (!fs || !out || !SysSvIsValid(path)) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
if (!v) return STATUS_INVALID_PARAMETER;
|
||||
if (!v) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint32_t cluster = 0;
|
||||
uint32_t size = 0;
|
||||
@@ -2402,11 +2402,11 @@ KSTATUS Fat32Stat(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, SYS_FILE_STAT *out) {
|
||||
|
||||
if (direntLba == 0) {
|
||||
Fat32FillRootStat(v, out);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t *sec = (uint8_t *)MmAllocatePool(v->BytesPerSector);
|
||||
if (!sec) return STATUS_NO_MEMORY;
|
||||
if (!sec) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
s = ReadSectors(v, direntLba, 1, sec);
|
||||
if (!KSUCCESS(s)) { MmFreePool(sec); return s; }
|
||||
@@ -2414,14 +2414,14 @@ KSTATUS Fat32Stat(IO_FILESYSTEM *fs, SYS_STRING_VIEW path, SYS_FILE_STAT *out) {
|
||||
DIRENT *d = (DIRENT *)(sec + direntOffset);
|
||||
if ((uint8_t)d->Name[0] == 0x00 || (uint8_t)d->Name[0] == 0xE5) {
|
||||
MmFreePool(sec);
|
||||
return STATUS_NOT_FOUND;
|
||||
return NTLSTATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
Fat32FillStatFromDirent(v, d, direntLba, direntOffset, out);
|
||||
out->Type = Fat32FileTypeFromAttr(attr);
|
||||
out->FileSize = size;
|
||||
MmFreePool(sec);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Mixes FAT directory metadata into a per-file content generation.
|
||||
@@ -2446,12 +2446,12 @@ static uint64_t Fat32DirentGeneration(const DIRENT *d) {
|
||||
KSTATUS Fat32QueryIdentity(IO_FILESYSTEM *fs, void *fileCtx, IO_FILE_IDENTITY *out) {
|
||||
(void)fs;
|
||||
if (!fileCtx || !out)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_FILE *f = (FAT32_FILE *)fileCtx;
|
||||
FAT32_VOL *v = f->Vol;
|
||||
if (!v)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
uint32_t startCluster = f->StartCluster;
|
||||
uint32_t fileSize = f->FileSize;
|
||||
@@ -2461,7 +2461,7 @@ KSTATUS Fat32QueryIdentity(IO_FILESYSTEM *fs, void *fileCtx, IO_FILE_IDENTITY *o
|
||||
if (f->DirentLba != 0) {
|
||||
uint8_t *sec = (uint8_t *)MmAllocatePool(v->BytesPerSector);
|
||||
if (!sec)
|
||||
return STATUS_NO_MEMORY;
|
||||
return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
KSTATUS s = ReadSectors(v, f->DirentLba, 1, sec);
|
||||
if (!KSUCCESS(s)) {
|
||||
@@ -2472,7 +2472,7 @@ KSTATUS Fat32QueryIdentity(IO_FILESYSTEM *fs, void *fileCtx, IO_FILE_IDENTITY *o
|
||||
DIRENT *d = (DIRENT *)(sec + f->DirentOffset);
|
||||
if ((uint8_t)d->Name[0] == 0x00 || (uint8_t)d->Name[0] == 0xE5) {
|
||||
MmFreePool(sec);
|
||||
return STATUS_NOT_FOUND;
|
||||
return NTLSTATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
startCluster = ((uint32_t)d->FirstClusterHi << 16) | d->FirstClusterLo;
|
||||
@@ -2487,7 +2487,7 @@ KSTATUS Fat32QueryIdentity(IO_FILESYSTEM *fs, void *fileCtx, IO_FILE_IDENTITY *o
|
||||
((uint64_t)startCluster << 1);
|
||||
out->Generation = generation ? generation : 1;
|
||||
out->Size = fileSize;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Directory enumeration (fix #2: cluster buffer cached in context)
|
||||
@@ -2509,7 +2509,7 @@ typedef struct {
|
||||
// Opens dir.
|
||||
KSTATUS Fat32OpenDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW dirPath, void **dirCtx) {
|
||||
if (!fs || !dirCtx || !SysSvIsValid(dirPath))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FAT32_VOL *v = (FAT32_VOL *)fs->DriverCtx;
|
||||
uint32_t cluster;
|
||||
@@ -2522,10 +2522,10 @@ KSTATUS Fat32OpenDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW dirPath, void **dirCtx)
|
||||
}
|
||||
|
||||
FAT32_DIR_CTX *ctx = (FAT32_DIR_CTX *)MmAllocatePool(sizeof(FAT32_DIR_CTX));
|
||||
if (!ctx) return STATUS_NO_MEMORY;
|
||||
if (!ctx) return NTLSTATUS_NO_MEMORY;
|
||||
|
||||
ctx->ClusterBuf = (uint8_t *)MmAllocatePool(v->BytesPerCluster);
|
||||
if (!ctx->ClusterBuf) { MmFreePool(ctx); return STATUS_NO_MEMORY; }
|
||||
if (!ctx->ClusterBuf) { MmFreePool(ctx); return NTLSTATUS_NO_MEMORY; }
|
||||
|
||||
ctx->Vol = v;
|
||||
ctx->DirCluster = cluster;
|
||||
@@ -2535,7 +2535,7 @@ KSTATUS Fat32OpenDir(IO_FILESYSTEM *fs, SYS_STRING_VIEW dirPath, void **dirCtx)
|
||||
ctx->HasLfn = 0;
|
||||
memset(ctx->LfnBuf, 0, sizeof(ctx->LfnBuf));
|
||||
*dirCtx = ctx;
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Returns dir.
|
||||
@@ -2558,7 +2558,7 @@ KSTATUS Fat32ReadDir(IO_FILESYSTEM *fs, void *dirCtx, KDIR_ENTRY *out) {
|
||||
while (ctx->EntryIndex < epc) {
|
||||
DIRENT *e = &dir[ctx->EntryIndex++];
|
||||
|
||||
if (e->Name[0] == 0x00) { ctx->CurCluster = FAT32_EOC; return STATUS_NO_MORE_FILES; }
|
||||
if (e->Name[0] == 0x00) { ctx->CurCluster = FAT32_EOC; return NTLSTATUS_NO_MORE_FILES; }
|
||||
if ((uint8_t)e->Name[0] == 0xE5) { ctx->HasLfn = 0; memset(ctx->LfnBuf, 0, sizeof(ctx->LfnBuf)); continue; }
|
||||
if (e->Attr == ATTR_LFN) { LfnAppend(ctx->LfnBuf, (LFN_ENTRY *)e); ctx->HasLfn = 1; continue; }
|
||||
if (e->Attr & 0x08 && !(e->Attr & ATTR_DIRECTORY)) { ctx->HasLfn = 0; memset(ctx->LfnBuf, 0, sizeof(ctx->LfnBuf)); continue; }
|
||||
@@ -2589,14 +2589,14 @@ KSTATUS Fat32ReadDir(IO_FILESYSTEM *fs, void *dirCtx, KDIR_ENTRY *out) {
|
||||
FatDecodeAccessDate(e->LastAccDate, &out->LastAccessTime);
|
||||
FatDecodeDateTime(e->WrtDate, e->WrtTime, 0, &out->LastWriteTime);
|
||||
ctx->HasLfn = 0; memset(ctx->LfnBuf, 0, sizeof(ctx->LfnBuf));
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ctx->CurCluster = FatEntry(v, ctx->CurCluster);
|
||||
ctx->EntryIndex = 0;
|
||||
}
|
||||
|
||||
return STATUS_NO_MORE_FILES;
|
||||
return NTLSTATUS_NO_MORE_FILES;
|
||||
}
|
||||
|
||||
// Releases dir.
|
||||
@@ -2855,13 +2855,13 @@ static KSTATUS Fat32EnsureAsyncWorkerStarted(void) {
|
||||
uintptr_t flags = KeAcquireSpinlock(&gFat32AsyncLock);
|
||||
if (gFat32AsyncInitState == 2) {
|
||||
KeReleaseSpinlock(&gFat32AsyncLock, flags);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
if (gFat32AsyncInitState == 1) {
|
||||
KeReleaseSpinlock(&gFat32AsyncLock, flags);
|
||||
while (gFat32AsyncInitState == 1)
|
||||
KeYield();
|
||||
return gFat32AsyncInitState == 2 ? STATUS_SUCCESS : STATUS_FAILURE;
|
||||
return gFat32AsyncInitState == 2 ? NTLSTATUS_SUCCESS : NTLSTATUS_FAILURE;
|
||||
}
|
||||
|
||||
gFat32AsyncInitState = 1;
|
||||
@@ -2939,14 +2939,14 @@ static void Fat32AsyncReadIrpComplete(IRP* irp, void* completeCtx) {
|
||||
// Implements the async Read Submit Next operation.
|
||||
static void Fat32AsyncReadSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
if (ctx->Remaining == 0) {
|
||||
Fat32AsyncFinish(ctx, STATUS_SUCCESS, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_SUCCESS, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->Cluster < 2 || ctx->Cluster >= FAT32_EOC) {
|
||||
if (ctx->Done < ctx->Requested)
|
||||
memset(ctx->Dst, 0, ctx->Requested - ctx->Done);
|
||||
Fat32AsyncFinish(ctx, STATUS_DEVICE_ERROR, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_DEVICE_ERROR, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2956,7 +2956,7 @@ static void Fat32AsyncReadSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
uint32_t next = 0;
|
||||
if (!Fat32BuildReadRun(ctx->File, ctx->LogicalCluster, ctx->Cluster,
|
||||
FAT32_READ_RUN_MAX_SECTORS, &runSectors, &next)) {
|
||||
Fat32AsyncFinish(ctx, STATUS_DEVICE_ERROR, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_DEVICE_ERROR, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2972,7 +2972,7 @@ static void Fat32AsyncReadSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
|
||||
ctx->CurrentDevice = IoReferenceDiskDevice(v->DriveIndex);
|
||||
if (!ctx->CurrentDevice) {
|
||||
Fat32AsyncFinish(ctx, STATUS_NOT_FOUND, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_NOT_FOUND, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2984,7 +2984,7 @@ static void Fat32AsyncReadSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
ctx->Irp.CompletionCtx = ctx;
|
||||
|
||||
KSTATUS s = IoSubmitIrp(ctx->CurrentDevice, &ctx->Irp);
|
||||
if (s != STATUS_PENDING) {
|
||||
if (s != NTLSTATUS_PENDING) {
|
||||
IoDereferenceDeviceObject(ctx->CurrentDevice);
|
||||
ctx->CurrentDevice = (DEVICE_OBJECT*)0;
|
||||
Fat32AsyncFinish(ctx, s, ctx->Done);
|
||||
@@ -2996,17 +2996,17 @@ KSTATUS Fat32ReadAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
IO_FS_ASYNC_COMPLETE complete,
|
||||
void *completeContext) {
|
||||
(void)fs;
|
||||
if (!complete) return STATUS_INVALID_PARAMETER;
|
||||
if (!complete) return NTLSTATUS_INVALID_PARAMETER;
|
||||
if (!fileCtx || (!buf && size)) {
|
||||
complete(completeContext, STATUS_INVALID_PARAMETER, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_INVALID_PARAMETER, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
FAT32_FILE* f = (FAT32_FILE*)fileCtx;
|
||||
FAT32_VOL* v = f->Vol;
|
||||
if (offset >= f->FileSize || size == 0) {
|
||||
complete(completeContext, STATUS_SUCCESS, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_SUCCESS, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
if (offset + size > f->FileSize)
|
||||
size = (size_t)(f->FileSize - offset);
|
||||
@@ -3014,13 +3014,13 @@ KSTATUS Fat32ReadAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
KSTATUS ws = Fat32EnsureAsyncWorkerStarted();
|
||||
if (!KSUCCESS(ws)) {
|
||||
complete(completeContext, ws, 0);
|
||||
return STATUS_PENDING;
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
FAT32_ASYNC_RW* ctx = (FAT32_ASYNC_RW*)MmAllocatePool(sizeof(FAT32_ASYNC_RW));
|
||||
if (!ctx) {
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
LIST_INIT(&ctx->Link);
|
||||
@@ -3028,8 +3028,8 @@ KSTATUS Fat32ReadAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
ctx->RunBuf = (uint8_t*)MmAllocatePool(FAT32_READ_RUN_MAX_SECTORS * 512u);
|
||||
if (!ctx->RunBuf) {
|
||||
MmFreePool(ctx);
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
ctx->Vol = v;
|
||||
@@ -3046,7 +3046,7 @@ KSTATUS Fat32ReadAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
ctx->CompleteContext = completeContext;
|
||||
|
||||
Fat32AsyncQueueContinuation(ctx);
|
||||
return STATUS_PENDING;
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
// Implements the async Write Irp Complete operation.
|
||||
@@ -3089,7 +3089,7 @@ static void Fat32AsyncWriteSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
DirentUpdateMetadata(ctx->Vol, ctx->File->DirentLba,
|
||||
ctx->File->DirentOffset, &u);
|
||||
}
|
||||
Fat32AsyncFinish(ctx, STATUS_SUCCESS, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_SUCCESS, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3098,11 +3098,11 @@ static void Fat32AsyncWriteSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
if (ctx->CurrentLast >= 2 && ctx->CurrentLast < FAT32_EOC) {
|
||||
ctx->Cluster = AppendCluster(v, ctx->CurrentLast);
|
||||
if (!ctx->Cluster) {
|
||||
Fat32AsyncFinish(ctx, STATUS_NO_MEMORY, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_NO_MEMORY, ctx->Done);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Fat32AsyncFinish(ctx, STATUS_DEVICE_ERROR, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_DEVICE_ERROR, ctx->Done);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -3143,7 +3143,7 @@ static void Fat32AsyncWriteSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
|
||||
ctx->CurrentDevice = IoReferenceDiskDevice(v->DriveIndex);
|
||||
if (!ctx->CurrentDevice) {
|
||||
Fat32AsyncFinish(ctx, STATUS_NOT_FOUND, ctx->Done);
|
||||
Fat32AsyncFinish(ctx, NTLSTATUS_NOT_FOUND, ctx->Done);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3155,7 +3155,7 @@ static void Fat32AsyncWriteSubmitNext(FAT32_ASYNC_RW* ctx) {
|
||||
ctx->Irp.CompletionCtx = ctx;
|
||||
|
||||
KSTATUS s = IoSubmitIrp(ctx->CurrentDevice, &ctx->Irp);
|
||||
if (s != STATUS_PENDING) {
|
||||
if (s != NTLSTATUS_PENDING) {
|
||||
IoDereferenceDeviceObject(ctx->CurrentDevice);
|
||||
ctx->CurrentDevice = (DEVICE_OBJECT*)0;
|
||||
Fat32AsyncFinish(ctx, s, ctx->Done);
|
||||
@@ -3167,20 +3167,20 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
IO_FS_ASYNC_COMPLETE complete,
|
||||
void *completeContext) {
|
||||
(void)fs;
|
||||
if (!complete) return STATUS_INVALID_PARAMETER;
|
||||
if (!complete) return NTLSTATUS_INVALID_PARAMETER;
|
||||
if (!fileCtx || (!buf && size)) {
|
||||
complete(completeContext, STATUS_INVALID_PARAMETER, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_INVALID_PARAMETER, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
if (size == 0) {
|
||||
complete(completeContext, STATUS_SUCCESS, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_SUCCESS, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
KSTATUS ws = Fat32EnsureAsyncWorkerStarted();
|
||||
if (!KSUCCESS(ws)) {
|
||||
complete(completeContext, ws, 0);
|
||||
return STATUS_PENDING;
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
FAT32_FILE* f = (FAT32_FILE*)fileCtx;
|
||||
@@ -3190,8 +3190,8 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
if (f->StartCluster < 2) {
|
||||
uint32_t first = AllocCluster(v);
|
||||
if (!first) {
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
f->StartCluster = first;
|
||||
DirentUpdateFirstCluster(v, f->DirentLba, f->DirentOffset, first);
|
||||
@@ -3204,8 +3204,8 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
if (next < 2 || next >= FAT32_EOC) {
|
||||
next = AppendCluster(v, cluster);
|
||||
if (!next) {
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
}
|
||||
cluster = next;
|
||||
@@ -3213,8 +3213,8 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
|
||||
FAT32_ASYNC_RW* ctx = (FAT32_ASYNC_RW*)MmAllocatePool(sizeof(FAT32_ASYNC_RW));
|
||||
if (!ctx) {
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
LIST_INIT(&ctx->Link);
|
||||
@@ -3222,8 +3222,8 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
ctx->RunBuf = (uint8_t*)MmAllocatePool(FAT32_WRITE_RUN_MAX_SECTORS * 512u);
|
||||
if (!ctx->RunBuf) {
|
||||
MmFreePool(ctx);
|
||||
complete(completeContext, STATUS_NO_MEMORY, 0);
|
||||
return STATUS_PENDING;
|
||||
complete(completeContext, NTLSTATUS_NO_MEMORY, 0);
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
ctx->Vol = v;
|
||||
@@ -3239,7 +3239,7 @@ KSTATUS Fat32WriteAsync(IO_FILESYSTEM *fs, void *fileCtx,
|
||||
ctx->CompleteContext = completeContext;
|
||||
|
||||
Fat32AsyncQueueContinuation(ctx);
|
||||
return STATUS_PENDING;
|
||||
return NTLSTATUS_PENDING;
|
||||
}
|
||||
|
||||
// DriverEntry.
|
||||
@@ -3431,7 +3431,7 @@ static void Fat32DiskChange(uint8_t driveIndex,
|
||||
// Implements the driver Entry operation.
|
||||
KSTATUS DriverEntry(const HAL_API *hal) {
|
||||
DbgPrint("FAT32: Init\n");
|
||||
if (!hal) return STATUS_INVALID_PARAMETER;
|
||||
if (!hal) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
FatCacheInvalidate();
|
||||
(void)hal;
|
||||
@@ -3450,9 +3450,9 @@ KSTATUS DriverEntry(const HAL_API *hal) {
|
||||
|
||||
if (!gMountedCount) {
|
||||
DbgPrint("FAT32: no mountable FAT32 volumes found.\n");
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
return NTLSTATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
DbgPrint("FAT32: Init complete; mounted %u volume(s).\n", gMountedCount);
|
||||
return STATUS_SUCCESS;
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user