clean up and standardize types across the codebase, unify atomic operations, improve UTF-8 handling throughout the system, remove obsolete input and named queue interfaces, redesign process preparation and creation, tighten IPC and service boundaries, improve error handling and reliability, minor documentation cleanup, fix doom surfaces, fix panic in ini parsing.

This commit is contained in:
maksw committed 2026-10-12 18:17:43 +02:00
1 parent 899225f551
commit c0ad63c27f
226 files changed
+6562 -4147

No files matched your search

+4 -4
View File
@@ -207,8 +207,8 @@ typedef struct HDA_OUTPUT_STREAM {
uint8_t NextCompletionBdl;
bool Prepared;
bool Running;
volatile long PendingPeriodInterrupts;
volatile long PendingDmaErrors;
volatile int32_t PendingPeriodInterrupts;
volatile int32_t PendingDmaErrors;
HDA_OUTPUT_RING Rings[HDA_MAX_LOGICAL_ENDPOINTS];
uint8_t ActiveRingIndex;
IO_DMA_BUFFER* BdlDma;
@@ -249,8 +249,8 @@ struct HDA_CONTROLLER {
bool SurpriseRemoved;
SPINLOCK StateLock;
KDPC Dpc;
volatile long IsrActive;
volatile long DpcActive;
volatile int32_t IsrActive;
volatile int32_t DpcActive;
IO_DMA_ADAPTER* DmaAdapter;
IO_DMA_BUFFER* CorbDma;
IO_DMA_BUFFER* RirbDma;
+5 -4
View File
@@ -1,5 +1,6 @@
// Generic Intel HDA codec discovery and analog render routing.
#include <stdbool.h>
#include "hda.h"
#include <limits.h>
@@ -211,9 +212,9 @@ struct HDA_CODEC_STATE {
EVENT* PollFinished;
THREAD* WorkThread;
THREAD* PollThread;
volatile long WorkRunning;
volatile long PollRunning;
volatile long ShuttingDown;
volatile int32_t WorkRunning;
volatile int32_t PollRunning;
volatile int32_t ShuttingDown;
uint64_t PendingUnsolicitedTags;
bool PollRequested;
bool HavePollingPins;
@@ -1586,7 +1587,7 @@ static void HdaCodecEndpointStop(void* providerContext) {
// Stores or applies one endpoint hardware gain and mute request.
static KSTATUS HdaCodecEndpointSetGain(void* providerContext,
int32_t gainMilliDb,
uint8_t muted) {
bool muted) {
HDA_LOGICAL_ENDPOINT* endpoint = (HDA_LOGICAL_ENDPOINT*)providerContext;
if (!endpoint || !endpoint->State || !endpoint->HasHardwareGain)
return NTLSTATUS_INVALID_PARAMETER;
+6 -4
View File
@@ -1,5 +1,7 @@
// Intel High Definition Audio controller transport, command rings, output DMA, and recovery.
#include <ntlite/atomic.h>
#include <stdbool.h>
#include "hda.h"
#include <intrin.h>
@@ -1079,7 +1081,7 @@ uint64_t HdaQueryOutputPositionFrames(HDA_CONTROLLER* controller) {
void HdaHandleInterrupt(HDA_CONTROLLER* controller) {
if (!controller)
return;
_InterlockedIncrement(&controller->IsrActive);
NtlAtomicIncrement32(&controller->IsrActive);
if (!controller->Started || controller->Removed || controller->SurpriseRemoved)
goto finished;
@@ -1137,7 +1139,7 @@ void HdaHandleInterrupt(HDA_CONTROLLER* controller) {
(void)KeInsertQueueDpc(&controller->Dpc, (void*)0, (void*)0);
finished:
_InterlockedDecrement(&controller->IsrActive);
NtlAtomicDecrement32(&controller->IsrActive);
}
// Promotes an error to stream or controller recovery using the one-second threshold.
@@ -1166,7 +1168,7 @@ void HdaDpcRoutine(KDPC* dpc, void* context, void* systemArgument1, void* system
HDA_CONTROLLER* controller = (HDA_CONTROLLER*)context;
if (!controller)
return;
_InterlockedIncrement(&controller->DpcActive);
NtlAtomicIncrement32(&controller->DpcActive);
if (controller->Removed || controller->SurpriseRemoved)
goto finished;
@@ -1253,7 +1255,7 @@ void HdaDpcRoutine(KDPC* dpc, void* context, void* systemArgument1, void* system
}
finished:
_InterlockedDecrement(&controller->DpcActive);
NtlAtomicDecrement32(&controller->DpcActive);
}
// Recovers one isolated stream error without disturbing the codec topology.
+2 -2
View File
@@ -636,7 +636,7 @@ struct USB_STORAGE_EXTENSION {
uint32_t BlockSize;
uint64_t BlockCount;
USB_STORAGE_FLUSH_CAPABILITY FlushCapability;
volatile long IoBusy;
volatile int32_t IoBusy;
};
struct USB_STORAGE_DISK_EXTENSION {
@@ -723,7 +723,7 @@ typedef struct XHCI_DEVICE {
bool MassRemoveLockReady;
bool MassSurpriseRemoved;
bool MassRemoved;
volatile long MassIoBusy;
volatile int32_t MassIoBusy;
uint64_t InputContextDeviceAddress;
uint64_t DeviceContextDeviceAddress;
+7 -7
View File
@@ -77,9 +77,9 @@ void XhciProcessBootKeyboardReport(XHCI_DEVICE* dev, const uint8_t* report, uint
void XhciProcessBootMouseReport(XHCI_DEVICE* dev, const uint8_t* report, uint16_t len) {
if (len < 3) return;
int dx = (int)(int8_t)report[1];
int dy = (int)(int8_t)report[2];
int wheel = (len >= 4) ? (int)(int8_t)report[3] : 0;
int32_t dx = (int32_t)(int8_t)report[1];
int32_t dy = (int32_t)(int8_t)report[2];
int32_t wheel = (len >= 4) ? (int32_t)(int8_t)report[3] : 0;
uint8_t buttons = report[0] & 0x07u;
if (dx || dy || wheel || buttons != dev->HidLastButtons) {
@@ -397,9 +397,9 @@ static void UsbHidProcessBootKeyboardReport(USB_HID_EXTENSION* ext, const uint8_
static void UsbHidProcessBootMouseReport(USB_HID_EXTENSION* ext, const uint8_t* report, uint16_t len) {
if (!ext || len < 3) return;
int dx = (int)(int8_t)report[1];
int dy = (int)(int8_t)report[2];
int wheel = (len >= 4) ? (int)(int8_t)report[3] : 0;
int32_t dx = (int32_t)(int8_t)report[1];
int32_t dy = (int32_t)(int8_t)report[2];
int32_t wheel = (len >= 4) ? (int32_t)(int8_t)report[3] : 0;
uint8_t buttons = report[0] & 0x07u;
if (dx || dy || wheel || buttons != ext->LastButtons) {
@@ -421,7 +421,7 @@ static void UsbHidProcessQemuTabletReport(USB_HID_EXTENSION* ext, const uint8_t*
uint8_t buttons = report[0] & 0x07u;
uint16_t x = (uint16_t)report[1] | ((uint16_t)report[2] << 8);
uint16_t y = (uint16_t)report[3] | ((uint16_t)report[4] << 8);
int wheel = (len >= 6) ? (int)(int8_t)report[5] : 0;
int32_t wheel = (len >= 6) ? (int32_t)(int8_t)report[5] : 0;
if (x != ext->LastAbsoluteX || y != ext->LastAbsoluteY ||
wheel || buttons != ext->LastButtons) {
+5 -2
View File
@@ -5,6 +5,9 @@
// interface stack and issues BOT transfers through USB URBs. The xHCI HCD
// still backs the bulk URBs with the existing per-device rings; later stages
// will make endpoint rings fully pipe-owned and asynchronous.
#include <ntlite/atomic.h>
#include <stdbool.h>
#include <intrin.h>
#include "usb.h"
DRIVER_OBJECT gUsbStorageDriver;
@@ -464,14 +467,14 @@ static KSTATUS UsbStorageSynchronizeCache(USB_STORAGE_EXTENSION* storage) {
void UsbStorageAcquireIo(USB_STORAGE_EXTENSION* storage) {
if (!storage) return;
XHCI_CONTROLLER* xhci = storage->Device ? (XHCI_CONTROLLER*)storage->Device->Hcd->ControllerContext : (XHCI_CONTROLLER*)0;
while (_InterlockedCompareExchange(&storage->IoBusy, 1, 0) != 0) {
while (NtlAtomicCompareExchange32(&storage->IoBusy, 1, 0) != 0) {
if (xhci) UsbDelayUs(xhci->Ddk, 10);
}
}
// Implements the storage Release Io operation.
void UsbStorageReleaseIo(USB_STORAGE_EXTENSION* storage) {
if (storage) _InterlockedExchange(&storage->IoBusy, 0);
if (storage) NtlAtomicExchange32(&storage->IoBusy, 0);
}
// Implements the storage Dispatch Read Write operation.
+45 -44
View File
@@ -1,5 +1,6 @@
// VMware SVGA-II PCI display provider. This file owns adapter setup, FIFO command submission, framebuffer presentation, and cursor integration.
#include <stdbool.h>
#include "vmwaresvga.h"
const NTL_DDK* gVmwSvgaDdk;
@@ -211,7 +212,7 @@ static void VmwSvgaWakeFifo(VMWSVGA_DEVICE* v) {
VmwSvgaWriteReg(v, SVGA_REG_SYNC, 1u);
}
static KSTATUS VmwSvgaUploadCursorImage(VMWSVGA_DEVICE* v, int width, int height, int hotX, int hotY, const uint32_t* argbPixels);
static KSTATUS VmwSvgaUploadCursorImage(VMWSVGA_DEVICE* v, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels);
// Implements the premultiply Argb For Bgra operation.
static uint32_t VmwSvgaPremultiplyArgbForBgra(uint32_t argb) {
@@ -275,7 +276,7 @@ static void VmwSvgaCursorSetVisible(VMWSVGA_DEVICE* v, bool visible) {
}
// Implements the cursor Set Position operation.
static void VmwSvgaCursorSetPosition(VMWSVGA_DEVICE* v, int x, int y) {
static void VmwSvgaCursorSetPosition(VMWSVGA_DEVICE* v, int32_t x, int32_t y) {
if (!v || !v->HardwareCursor)
return;
v->CursorX = x;
@@ -284,7 +285,7 @@ static void VmwSvgaCursorSetPosition(VMWSVGA_DEVICE* v, int x, int y) {
}
// Implements the define Alpha Cursor operation.
static KSTATUS VmwSvgaDefineAlphaCursor(VMWSVGA_DEVICE* v, int width, int height, int hotX, int hotY, const uint32_t* argbPixels) {
static KSTATUS VmwSvgaDefineAlphaCursor(VMWSVGA_DEVICE* v, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels) {
KSTATUS st = VmwSvgaFifoWrite(v, SVGA_CMD_DEFINE_ALPHA_CURSOR);
if (!KSUCCESS(st)) return st;
st = VmwSvgaFifoWrite(v, 0u); // cursor id, reserved
@@ -298,8 +299,8 @@ static KSTATUS VmwSvgaDefineAlphaCursor(VMWSVGA_DEVICE* v, int width, int height
st = VmwSvgaFifoWrite(v, (uint32_t)height);
if (!KSUCCESS(st)) return st;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int32_t y = 0; y < height; y++) {
for (int32_t x = 0; x < width; x++) {
uint32_t p = argbPixels[(size_t)y * (size_t)width + (size_t)x];
st = VmwSvgaFifoWrite(v, VmwSvgaPremultiplyArgbForBgra(p));
if (!KSUCCESS(st)) return st;
@@ -310,9 +311,9 @@ static KSTATUS VmwSvgaDefineAlphaCursor(VMWSVGA_DEVICE* v, int width, int height
}
static uint32_t VmwSvgaPackMonoCursorDword(const uint8_t* bits,
int width,
int height,
int y,
int32_t width,
int32_t height,
int32_t y,
uint32_t dwordIndex) {
// SVGA classic cursor scanlines are padded to 32 bits. QEMU stores
@@ -343,7 +344,7 @@ static uint32_t VmwSvgaPackMonoCursorDword(const uint8_t* bits,
}
// Implements the classic Cursor Width operation.
static int VmwSvgaClassicCursorWidth(int width) {
static int32_t VmwSvgaClassicCursorWidth(int32_t width) {
// QEMU's VMware SVGA implementation reads classic cursor masks as
// SVGA dword-padded scanlines, then passes the raw byte stream to
@@ -358,9 +359,9 @@ static int VmwSvgaClassicCursorWidth(int width) {
}
static void VmwSvgaBuildMonoCursorBits(const uint32_t* argbPixels,
int sourceWidth,
int encodedWidth,
int height,
int32_t sourceWidth,
int32_t encodedWidth,
int32_t height,
uint8_t* andBits,
uint8_t* xorBits) {
@@ -372,8 +373,8 @@ static void VmwSvgaBuildMonoCursorBits(const uint32_t* argbPixels,
// This intentionally discards antialiasing, but avoids QEMU/GTK's
// fragile 32bpp classic host-cursor path.
for (int y = 0; y < height; y++) {
for (int x = 0; x < encodedWidth; x++) {
for (int32_t y = 0; y < height; y++) {
for (int32_t x = 0; x < encodedWidth; x++) {
size_t out = (size_t)y * (size_t)encodedWidth + (size_t)x;
if (x >= sourceWidth) {
andBits[out] = 1u;
@@ -400,8 +401,8 @@ static void VmwSvgaBuildMonoCursorBits(const uint32_t* argbPixels,
}
// Implements the define Classic Cursor operation.
static KSTATUS VmwSvgaDefineClassicCursor(VMWSVGA_DEVICE* v, int width, int height, int hotX, int hotY, const uint32_t* argbPixels) {
int encodedWidth = VmwSvgaClassicCursorWidth(width);
static KSTATUS VmwSvgaDefineClassicCursor(VMWSVGA_DEVICE* v, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels) {
int32_t encodedWidth = VmwSvgaClassicCursorWidth(width);
uint32_t dwordsPerRow = ((uint32_t)encodedWidth + 31u) / 32u;
size_t pixelCount = (size_t)encodedWidth * (size_t)height;
@@ -438,14 +439,14 @@ static KSTATUS VmwSvgaDefineClassicCursor(VMWSVGA_DEVICE* v, int width, int heig
st = VmwSvgaFifoWrite(v, 1u); // XOR mask depth
if (!KSUCCESS(st)) goto done;
for (int y = 0; y < height; y++) {
for (int32_t y = 0; y < height; y++) {
for (uint32_t d = 0; d < dwordsPerRow; d++) {
st = VmwSvgaFifoWrite(v, VmwSvgaPackMonoCursorDword(andBits, encodedWidth, height, y, d));
if (!KSUCCESS(st)) goto done;
}
}
for (int y = 0; y < height; y++) {
for (int32_t y = 0; y < height; y++) {
for (uint32_t d = 0; d < dwordsPerRow; d++) {
st = VmwSvgaFifoWrite(v, VmwSvgaPackMonoCursorDword(xorBits, encodedWidth, height, y, d));
if (!KSUCCESS(st)) goto done;
@@ -461,7 +462,7 @@ done:
}
// Implements the upload Cursor Image operation.
static KSTATUS VmwSvgaUploadCursorImage(VMWSVGA_DEVICE* v, int width, int height, int hotX, int hotY, const uint32_t* argbPixels) {
static KSTATUS VmwSvgaUploadCursorImage(VMWSVGA_DEVICE* v, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels) {
if (!v || !v->HardwareCursor || !argbPixels || width <= 0 || height <= 0)
return NTLSTATUS_INVALID_PARAMETER;
if (width > 256 || height > 256 || hotX < 0 || hotY < 0 || hotX >= width || hotY >= height)
@@ -479,7 +480,7 @@ static KSTATUS VmwSvgaUploadCursorImage(VMWSVGA_DEVICE* v, int width, int height
}
// Implements the define Cursor Image operation.
static KSTATUS VmwSvgaDefineCursorImage(VMWSVGA_DEVICE* v, int width, int height, int hotX, int hotY, const uint32_t* argbPixels) {
static KSTATUS VmwSvgaDefineCursorImage(VMWSVGA_DEVICE* v, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels) {
if (!v || !v->HardwareCursor || !argbPixels || width <= 0 || height <= 0)
return NTLSTATUS_INVALID_PARAMETER;
if (width > 256 || height > 256 || hotX < 0 || hotY < 0 || hotX >= width || hotY >= height)
@@ -568,7 +569,7 @@ static KSTATUS VmwSvgaDefineGmrfb(VMWSVGA_DEVICE* v) {
}
// Blits gmrfb To Screen.
static KSTATUS VmwSvgaBlitGmrfbToScreen(VMWSVGA_DEVICE* v, int x, int y, int w, int h) {
static KSTATUS VmwSvgaBlitGmrfbToScreen(VMWSVGA_DEVICE* v, int32_t x, int32_t y, int32_t w, int32_t h) {
DISPLAY_RECT r = { x, y, w, h };
if (!VmwSvgaClipRect(v, &r))
return NTLSTATUS_SUCCESS;
@@ -659,7 +660,7 @@ static KSTATUS VmwSvgaInitializeScreenObject(VMWSVGA_DEVICE* v) {
}
// Implements the legacy Update operation.
static KSTATUS VmwSvgaLegacyUpdate(VMWSVGA_DEVICE* v, int x, int y, int w, int h) {
static KSTATUS VmwSvgaLegacyUpdate(VMWSVGA_DEVICE* v, int32_t x, int32_t y, int32_t w, int32_t h) {
DISPLAY_RECT r = { x, y, w, h };
if (!VmwSvgaClipRect(v, &r))
return NTLSTATUS_SUCCESS;
@@ -680,7 +681,7 @@ static KSTATUS VmwSvgaLegacyUpdate(VMWSVGA_DEVICE* v, int x, int y, int w, int h
}
// Updates the requested value.
static KSTATUS VmwSvgaUpdate(VMWSVGA_DEVICE* v, int x, int y, int w, int h) {
static KSTATUS VmwSvgaUpdate(VMWSVGA_DEVICE* v, int32_t x, int32_t y, int32_t w, int32_t h) {
DISPLAY_RECT r = { x, y, w, h };
if (!VmwSvgaClipRect(v, &r))
return NTLSTATUS_SUCCESS;
@@ -841,7 +842,7 @@ static void VmwSvgaCopyToShadowAndFramebuffer(uint32_t* shadow,
}
// Implements the display pitched blit operation.
static KSTATUS VmwSvgaDisplayBlit(DISPLAY_DEVICE* device, int x, int y, int w, int h, const uint32_t* pixels, uint32_t pitchBytes) {
static KSTATUS VmwSvgaDisplayBlit(DISPLAY_DEVICE* device, int32_t x, int32_t y, int32_t w, int32_t h, const uint32_t* pixels, uint32_t pitchBytes) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v || !v->Backbuffer || !pixels || w <= 0 || h <= 0 ||
pitchBytes < (uint32_t)w * sizeof(uint32_t))
@@ -857,7 +858,7 @@ static KSTATUS VmwSvgaDisplayBlit(DISPLAY_DEVICE* device, int x, int y, int w, i
int srcOffsetX = r.X - x;
int srcOffsetY = r.Y - y;
size_t bytesPerRow = (size_t)r.W * sizeof(uint32_t);
for (int row = 0; row < r.H; row++) {
for (int32_t row = 0; row < r.H; row++) {
uint32_t* dst = v->Backbuffer + ((size_t)(r.Y + row) * v->Stride) + r.X;
const uint8_t* sourceRow = (const uint8_t*)pixels + (size_t)(srcOffsetY + row) * pitchBytes;
const uint32_t* src = (const uint32_t*)sourceRow + srcOffsetX;
@@ -868,10 +869,10 @@ static KSTATUS VmwSvgaDisplayBlit(DISPLAY_DEVICE* device, int x, int y, int w, i
// Presents one pitched rectangle without a shadow-to-framebuffer second pass.
static KSTATUS VmwSvgaDisplayPresentPitched(DISPLAY_DEVICE* device,
int x,
int y,
int w,
int h,
int32_t x,
int32_t y,
int32_t w,
int32_t h,
const uint32_t* pixels,
uint32_t pitchBytes) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
@@ -894,7 +895,7 @@ static KSTATUS VmwSvgaDisplayPresentPitched(DISPLAY_DEVICE* device,
v->Stats.ScanoutBytes += bytes;
v->Stats.BytesCopied += bytes * 2u;
for (int row = 0; row < r.H; row++) {
for (int32_t row = 0; row < r.H; row++) {
const uint8_t* sourceRow = (const uint8_t*)pixels +
(size_t)(srcOffsetY + row) * pitchBytes;
const uint32_t* source = (const uint32_t*)sourceRow + srcOffsetX;
@@ -914,7 +915,7 @@ static KSTATUS VmwSvgaDisplayPresentPitched(DISPLAY_DEVICE* device,
}
// Implements the display Fill Rect operation.
static KSTATUS VmwSvgaDisplayFillRect(DISPLAY_DEVICE* device, int x, int y, int w, int h, uint32_t color) {
static KSTATUS VmwSvgaDisplayFillRect(DISPLAY_DEVICE* device, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v || !v->Backbuffer || w <= 0 || h <= 0)
return NTLSTATUS_INVALID_PARAMETER;
@@ -935,7 +936,7 @@ static KSTATUS VmwSvgaDisplayFillRect(DISPLAY_DEVICE* device, int x, int y, int
}
// Implements the display Copy Rect operation.
static KSTATUS VmwSvgaDisplayCopyRect(DISPLAY_DEVICE* device, int dstX, int dstY, int srcX, int srcY, int w, int h) {
static KSTATUS VmwSvgaDisplayCopyRect(DISPLAY_DEVICE* device, int32_t dstX, int32_t dstY, int32_t srcX, int32_t srcY, int32_t w, int32_t h) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v || !v->Backbuffer || w <= 0 || h <= 0)
return NTLSTATUS_INVALID_PARAMETER;
@@ -956,13 +957,13 @@ static KSTATUS VmwSvgaDisplayCopyRect(DISPLAY_DEVICE* device, int dstX, int dstY
size_t rowBytes = (size_t)w * sizeof(uint32_t);
if (dstY > srcY) {
for (int row = h - 1; row >= 0; row--) {
for (int32_t row = h - 1; row >= 0; row--) {
uint32_t* dst = v->Backbuffer + ((size_t)(dstY + row) * v->Stride) + dstX;
uint32_t* src = v->Backbuffer + ((size_t)(srcY + row) * v->Stride) + srcX;
memmove(dst, src, rowBytes);
}
} else {
for (int row = 0; row < h; row++) {
for (int32_t row = 0; row < h; row++) {
uint32_t* dst = v->Backbuffer + ((size_t)(dstY + row) * v->Stride) + dstX;
uint32_t* src = v->Backbuffer + ((size_t)(srcY + row) * v->Stride) + srcX;
memmove(dst, src, rowBytes);
@@ -972,7 +973,7 @@ static KSTATUS VmwSvgaDisplayCopyRect(DISPLAY_DEVICE* device, int dstX, int dstY
}
// Implements the display Read Rect operation.
static KSTATUS VmwSvgaDisplayReadRect(DISPLAY_DEVICE* device, int x, int y, int w, int h, uint32_t* outPixels, uint32_t outStride) {
static KSTATUS VmwSvgaDisplayReadRect(DISPLAY_DEVICE* device, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t* outPixels, uint32_t outStride) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v || !v->Backbuffer || !outPixels || outStride == 0 || w <= 0 || h <= 0)
return NTLSTATUS_INVALID_PARAMETER;
@@ -986,7 +987,7 @@ static KSTATUS VmwSvgaDisplayReadRect(DISPLAY_DEVICE* device, int x, int y, int
int dstOffsetX = r.X - x;
int dstOffsetY = r.Y - y;
for (int row = 0; row < r.H; row++) {
for (int32_t row = 0; row < r.H; row++) {
const uint32_t* src = v->Backbuffer + ((size_t)(r.Y + row) * v->Stride) + r.X;
uint32_t* dst = outPixels + ((size_t)(dstOffsetY + row) * outStride) + dstOffsetX;
memcpy(dst, src, (size_t)r.W * sizeof(uint32_t));
@@ -1015,7 +1016,7 @@ static KSTATUS VmwSvgaDisplayPresent(DISPLAY_DEVICE* device, const DISPLAY_RECT*
v->Stats.BytesCopied += bytes;
v->Stats.ScanoutBytes += bytes;
size_t pixelCount = (size_t)r.W;
for (int row = 0; row < r.H; row++) {
for (int32_t row = 0; row < r.H; row++) {
uint32_t* dst = (uint32_t*)(uintptr_t)(v->Framebuffer +
((size_t)(r.Y + row) * v->BytesPerLine) +
((size_t)r.X * sizeof(uint32_t)));
@@ -1046,7 +1047,7 @@ static KSTATUS VmwSvgaDisplaySync(DISPLAY_DEVICE* device) {
}
// Implements the display Set Cursor Image operation.
static KSTATUS VmwSvgaDisplaySetCursorImage(DISPLAY_DEVICE* device, int width, int height, int hotX, int hotY, const uint32_t* argbPixels) {
static KSTATUS VmwSvgaDisplaySetCursorImage(DISPLAY_DEVICE* device, int32_t width, int32_t height, int32_t hotX, int32_t hotY, const uint32_t* argbPixels) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v || !v->HardwareCursor)
return NTLSTATUS_NOT_SUPPORTED;
@@ -1054,7 +1055,7 @@ static KSTATUS VmwSvgaDisplaySetCursorImage(DISPLAY_DEVICE* device, int width, i
}
// Implements the display Set Cursor Position operation.
static KSTATUS VmwSvgaDisplaySetCursorPosition(DISPLAY_DEVICE* device, int x, int y) {
static KSTATUS VmwSvgaDisplaySetCursorPosition(DISPLAY_DEVICE* device, int32_t x, int32_t y) {
VMWSVGA_DEVICE* v = VmwSvgaFromDisplay(device);
if (!v)
return NTLSTATUS_INVALID_PARAMETER;
@@ -1073,7 +1074,7 @@ static void VmwSvgaRestoreCursor(VMWSVGA_DEVICE* v) {
DISPLAY_RECT r = { v->CursorDrawX, v->CursorDrawY, VMWSVGA_CURSOR_W, VMWSVGA_CURSOR_H };
if (VmwSvgaClipRect(v, &r)) {
for (int row = 0; row < r.H; row++) {
for (int32_t row = 0; row < r.H; row++) {
volatile uint8_t* dstBytes = v->Framebuffer + ((size_t)(r.Y + row) * v->BytesPerLine) + ((size_t)r.X * sizeof(uint32_t));
uint32_t* src = v->Backbuffer + ((size_t)(r.Y + row) * v->Stride) + r.X;
memcpy((void*)dstBytes, src, (size_t)r.W * sizeof(uint32_t));
@@ -1091,17 +1092,17 @@ static void VmwSvgaDrawCursor(VMWSVGA_DEVICE* v) {
if (!v || !v->Backbuffer || !v->Framebuffer)
return;
int x = v->CursorX;
int y = v->CursorY;
int32_t x = v->CursorX;
int32_t y = v->CursorY;
v->CursorDrawX = x;
v->CursorDrawY = y;
DISPLAY_RECT dirty = { x, y, VMWSVGA_CURSOR_W, VMWSVGA_CURSOR_H };
for (int row = 0; row < VMWSVGA_CURSOR_H; row++) {
for (int32_t row = 0; row < VMWSVGA_CURSOR_H; row++) {
int fy = y + row;
if ((unsigned)fy >= v->Height)
continue;
for (int col = 0; col < VMWSVGA_CURSOR_W; col++) {
for (int32_t col = 0; col < VMWSVGA_CURSOR_W; col++) {
int fx = x + col;
if ((unsigned)fx >= v->Width)
continue;
+8 -8
View File
@@ -192,18 +192,18 @@ typedef struct VMWSVGA_DEVICE {
bool CursorVisible;
uint32_t* CursorImageArgb;
size_t CursorImageBytes;
int CursorImageWidth;
int CursorImageHeight;
int CursorHotX;
int CursorHotY;
int32_t CursorImageWidth;
int32_t CursorImageHeight;
int32_t CursorHotX;
int32_t CursorHotY;
bool Started;
bool Removed;
bool SurpriseRemoved;
int CursorX;
int CursorY;
int CursorDrawX;
int CursorDrawY;
int32_t CursorX;
int32_t CursorY;
int32_t CursorDrawX;
int32_t CursorDrawY;
bool CursorDrawn;
DISPLAY_STATS Stats;
+5 -5
View File
@@ -838,11 +838,11 @@ static KSTATUS Ext4ReadDir(IO_VOLUME_PROVIDER* provider, void* dirCtx, KDIR_ENTR
}
memset(out, 0, sizeof(*out));
size_t nameLength = entry->name_length;
if (nameLength >= SYS_DIR_NAME_MAX)
nameLength = SYS_DIR_NAME_MAX - 1;
memcpy(out->Name, entry->name, nameLength);
out->Name[nameLength] = '\0';
// ext4 allows arbitrary non-NUL filename bytes. Project malformed UTF-8
// to U+FFFD only for enumeration; keep raw bytes for ext4 metadata lookups.
// The displayed name is not a reversible path for malformed disk names.
(void)SysSvCopyUtf8WithReplacement(
SysSvFromParts(entry->name, entry->name_length), out->Name, sizeof(out->Name));
out->Attr = entry->inode_type == EXT4_DE_DIR
? SYS_FILE_ATTR_DIRECTORY
: SYS_FILE_ATTR_ARCHIVE;
+18 -17
View File
@@ -1,5 +1,6 @@
// FAT allocation, cache, and metadata core shared by the filesystem operation translation units.
#include <stdbool.h>
#include "fat_internal.h"
// FAT sector cache (fixes #1 and #5)
@@ -169,7 +170,7 @@ uint32_t FatEocMark(FAT_VOL* v) {
return v && v->Variant == FatVariant16 ? FAT16_EOC_MARK : FAT32_EOC_MARK;
}
int FatIsDataCluster(FAT_VOL* v, uint32_t cluster) {
bool FatIsDataCluster(FAT_VOL* v, uint32_t cluster) {
return v && cluster >= 2u && cluster < FatEocThreshold(v);
}
@@ -185,49 +186,49 @@ void FatSetDirentFirstCluster(FAT_VOL* v, DIRENT* d, uint32_t cluster) {
d->FirstClusterHi = (v && v->Variant == FatVariant32) ? (uint16_t)(cluster >> 16) : 0u;
}
int FatIsFixedRoot(FAT_VOL* v, uint32_t dirCluster) {
bool FatIsFixedRoot(FAT_VOL* v, uint32_t dirCluster) {
return v && v->Variant == FatVariant16 && dirCluster == FAT_FIXED_ROOT_CLUSTER;
}
uint64_t FatClusterToLba(FAT_VOL* v, uint32_t cluster);
uint32_t FatEntry(FAT_VOL* v, uint32_t cluster);
int FatDirectoryFirstSegment(FAT_VOL* v, uint32_t dirCluster,
bool FatDirectoryFirstSegment(FAT_VOL* v, uint32_t dirCluster,
uint32_t* cursor, uint64_t* lba,
uint32_t* sectors) {
if (!v || !cursor || !lba || !sectors) return 0;
if (!v || !cursor || !lba || !sectors) return false;
if (FatIsFixedRoot(v, dirCluster)) {
if (!v->RootDirSectors) return 0;
if (!v->RootDirSectors) return false;
*cursor = 0;
*lba = v->RootDirStart;
*sectors = 1;
return 1;
return true;
}
if (!FatIsDataCluster(v, dirCluster)) return 0;
if (!FatIsDataCluster(v, dirCluster)) return false;
*cursor = dirCluster;
*lba = FatClusterToLba(v, dirCluster);
*sectors = v->SectorsPerCluster;
return 1;
return true;
}
int FatDirectoryNextSegment(FAT_VOL* v, uint32_t dirCluster,
bool FatDirectoryNextSegment(FAT_VOL* v, uint32_t dirCluster,
uint32_t* cursor, uint64_t* lba,
uint32_t* sectors) {
if (!v || !cursor || !lba || !sectors) return 0;
if (!v || !cursor || !lba || !sectors) return false;
if (FatIsFixedRoot(v, dirCluster)) {
uint32_t next = *cursor + 1u;
if (next >= v->RootDirSectors) return 0;
if (next >= v->RootDirSectors) return false;
*cursor = next;
*lba = v->RootDirStart + next;
*sectors = 1;
return 1;
return true;
}
uint32_t next = FatEntry(v, *cursor);
if (!FatIsDataCluster(v, next)) return 0;
if (!FatIsDataCluster(v, next)) return false;
*cursor = next;
*lba = FatClusterToLba(v, next);
*sectors = v->SectorsPerCluster;
return 1;
return true;
}
// Implements the cluster To Lba operation.
@@ -314,7 +315,7 @@ KSTATUS FatWriteEntry(FAT_VOL* v, uint32_t cluster, uint32_t value) {
}
// Cluster allocation (fix #3: next-free hint + two-phase wrap-around scan).
uint32_t FatAllocClusterEx(FAT_VOL* v, int zeroCluster) {
uint32_t FatAllocClusterEx(FAT_VOL* v, bool zeroCluster) {
if (v->TotalClusters == 0) return 0;
uint32_t total = v->TotalClusters;
@@ -353,7 +354,7 @@ uint32_t FatAllocCluster(FAT_VOL* v) {
return FatAllocClusterEx(v, 1);
}
uint32_t FatAppendClusterEx(FAT_VOL* v, uint32_t lastCluster, int zeroCluster) {
uint32_t FatAppendClusterEx(FAT_VOL* v, uint32_t lastCluster, bool zeroCluster) {
uint32_t newCluster = FatAllocClusterEx(v, zeroCluster);
if (!newCluster) return 0;
if (!KSUCCESS(FatWriteEntry(v, lastCluster, newCluster))) return 0;
@@ -390,7 +391,7 @@ void FatFreeClusterChain(FAT_VOL* v, uint32_t start) {
// FAT timestamp and DIRENT metadata helpers.
// Implements the fat Is Leap Year operation.
static int FatIsLeapYear(uint32_t year) {
static bool FatIsLeapYear(uint32_t year) {
return ((year % 4u) == 0u && (year % 100u) != 0u) || ((year % 400u) == 0u);
}
+99 -98
View File
@@ -1,18 +1,19 @@
// FAT name handling, path traversal, and directory mutation.
#include <stdbool.h>
#include "fat_internal.h"
// 8.3 name matching / assembly.
static int MatchRaw83(const char dirName[8], const char dirExt[3],
static bool MatchRaw83(const char dirName[8], const char dirExt[3],
const char wantName[8], const char wantExt[3]) {
return memcmp(dirName, wantName, 8) == 0 &&
memcmp(dirExt, wantExt, 3) == 0;
}
static char FatUpperChar(char c);
static int FatIsLowerChar(char c);
static int FatIsValidShortChar(char c);
static bool FatIsLowerChar(char c);
static bool FatIsValidShortChar(char c);
// Implements the make83 Name V operation.
static void Make83NameV(SYS_STRING_VIEW src, char name8[8], char ext3[3]) {
@@ -53,40 +54,40 @@ static char FatUpperChar(char c) {
}
// Implements the fat Is Lower Char operation.
static int FatIsLowerChar(char c) {
static bool FatIsLowerChar(char c) {
return c >= 'a' && c <= 'z';
}
// Implements the fat Is Valid Short Char operation.
static int FatIsValidShortChar(char c) {
static bool FatIsValidShortChar(char c) {
c = FatUpperChar(c);
if (c >= 'A' && c <= 'Z') return 1;
if (c >= '0' && c <= '9') return 1;
if (c >= 'A' && c <= 'Z') return true;
if (c >= '0' && c <= '9') return true;
switch (c) {
case '$': case '%': case '\'': case '-': case '_': case '@':
case '~': case '`': case '!': case '(': case ')': case '{':
case '}': case '^': case '#': case '&':
return 1;
return true;
default:
return 0;
return false;
}
}
// True when the user spelling can refer to a normal FAT 8.3 entry. This is
// intentionally structural and case-insensitive: "doom1.wad" must still open
// an existing short entry named DOOM1.WAD. Leading-dot names are not 8.3.
static int FatNameIsStructurallyShort83V(SYS_STRING_VIEW name) {
if (!SysSvIsValid(name) || name.Length == 0) return 0;
if (name.Data[0] == '.') return 0;
static bool FatNameIsStructurallyShort83V(SYS_STRING_VIEW name) {
if (!SysSvIsValid(name) || name.Length == 0) return false;
if (name.Data[0] == '.') return false;
size_t dot = (size_t)-1;
for (size_t i = 0; i < name.Length; i++) {
char c = name.Data[i];
if (c == '.') {
if (dot != (size_t)-1) return 0;
if (dot != (size_t)-1) return false;
dot = i;
} else if (!FatIsValidShortChar(c)) {
return 0;
return false;
}
}
@@ -96,17 +97,17 @@ static int FatNameIsStructurallyShort83V(SYS_STRING_VIEW name) {
}
// Implements the fat Component Has Lower V operation.
static int FatComponentHasLowerV(SYS_STRING_VIEW name, size_t start, size_t end) {
static bool FatComponentHasLowerV(SYS_STRING_VIEW name, size_t start, size_t end) {
for (size_t i = start; i < end; i++)
if (FatIsLowerChar(name.Data[i])) return 1;
return 0;
if (FatIsLowerChar(name.Data[i])) return true;
return false;
}
// Implements the fat Component Has Upper V operation.
static int FatComponentHasUpperV(SYS_STRING_VIEW name, size_t start, size_t end) {
static bool FatComponentHasUpperV(SYS_STRING_VIEW name, size_t start, size_t end) {
for (size_t i = start; i < end; i++)
if (name.Data[i] >= 'A' && name.Data[i] <= 'Z') return 1;
return 0;
if (name.Data[i] >= 'A' && name.Data[i] <= 'Z') return true;
return false;
}
static void FatSplitShortNameV(SYS_STRING_VIEW name, size_t* baseEnd,
@@ -128,19 +129,19 @@ static void FatSplitShortNameV(SYS_STRING_VIEW name, size_t* baseEnd,
// Creation uses LFN only when the spelling cannot be represented by a short
// entry, or when mixed-case 8.3 spelling would be lost. Plain lowercase
// 8.3 names are represented with FAT's NT case bits, not VFAT LFN entries.
static int FatNameNeedsLfnForCreateV(SYS_STRING_VIEW name) {
if (!FatNameIsStructurallyShort83V(name)) return 1;
static bool FatNameNeedsLfnForCreateV(SYS_STRING_VIEW name) {
if (!FatNameIsStructurallyShort83V(name)) return true;
size_t baseEnd, extStart, extEnd;
FatSplitShortNameV(name, &baseEnd, &extStart, &extEnd);
int baseLower = FatComponentHasLowerV(name, 0, baseEnd);
int baseUpper = FatComponentHasUpperV(name, 0, baseEnd);
int extLower = FatComponentHasLowerV(name, extStart, extEnd);
int extUpper = FatComponentHasUpperV(name, extStart, extEnd);
bool baseLower = FatComponentHasLowerV(name, 0, baseEnd);
bool baseUpper = FatComponentHasUpperV(name, 0, baseEnd);
bool extLower = FatComponentHasLowerV(name, extStart, extEnd);
bool extUpper = FatComponentHasUpperV(name, extStart, extEnd);
if ((baseLower && baseUpper) || (extLower && extUpper)) return 1;
return 0;
if ((baseLower && baseUpper) || (extLower && extUpper)) return true;
return false;
}
// Implements the fat Short Name Case Flags V operation.
@@ -211,15 +212,15 @@ static void MakeLegacyBrokenDot83(const char* src, char name8[8], char ext3[3])
ext3[ei++] = FatUpperChar(*p);
}
static int ShortNameExistsRaw(FAT_VOL* v, uint32_t dirCluster,
static bool ShortNameExistsRaw(FAT_VOL* v, uint32_t dirCluster,
const char name8[8], const char ext3[3]) {
uint8_t* clusterBuf = (uint8_t*)MmAllocatePool(v->BytesPerCluster);
if (!clusterBuf) return 1; // fail closed; caller should pick another alias
if (!clusterBuf) return true; // fail closed; caller should pick another alias
uint32_t cursor; uint64_t lba; uint32_t sectors;
if (!FatDirectoryFirstSegment(v, dirCluster, &cursor, &lba, &sectors)) {
MmFreePool(clusterBuf);
return 0;
return false;
}
do {
@@ -228,17 +229,17 @@ static int ShortNameExistsRaw(FAT_VOL* v, uint32_t dirCluster,
uint32_t entries = (sectors * v->BytesPerSector) / sizeof(DIRENT);
DIRENT* dir = (DIRENT*)clusterBuf;
for (uint32_t i = 0; i < entries; i++) {
if (dir[i].Name[0] == 0x00) { MmFreePool(clusterBuf); return 0; }
if (dir[i].Name[0] == 0x00) { MmFreePool(clusterBuf); return false; }
if ((uint8_t)dir[i].Name[0] == 0xE5 || dir[i].Attr == ATTR_LFN) continue;
if (MatchRaw83(dir[i].Name, dir[i].Ext, name8, ext3)) {
MmFreePool(clusterBuf);
return 1;
return true;
}
}
} while (FatDirectoryNextSegment(v, dirCluster, &cursor, &lba, &sectors));
MmFreePool(clusterBuf);
return 0;
return false;
}
// Implements the fat Alias Append Char operation.
@@ -310,7 +311,7 @@ static void MakeAliasAttempt(const char stem[9], const char extIn[3],
memcpy(name8 + keep, suffix, suffixLen);
}
static int MakeUniqueShortAliasV(FAT_VOL* v, uint32_t dirCluster,
static bool MakeUniqueShortAliasV(FAT_VOL* v, uint32_t dirCluster,
SYS_STRING_VIEW longName,
char name8[8], char ext3[3]) {
char stem[9], extCandidate[3];
@@ -318,9 +319,9 @@ static int MakeUniqueShortAliasV(FAT_VOL* v, uint32_t dirCluster,
for (uint32_t attempt = 1; attempt < 1000000; attempt++) {
MakeAliasAttempt(stem, extCandidate, attempt, name8, ext3);
if (!ShortNameExistsRaw(v, dirCluster, name8, ext3)) return 1;
if (!ShortNameExistsRaw(v, dirCluster, name8, ext3)) return true;
}
return 0;
return false;
}
// Creates legacy Broken Dot83 V.
@@ -400,44 +401,44 @@ void FatLfnAppend(char* lfn, const LFN_ENTRY* e) {
}
// Directory search and view-native path traversal.
static int FatIsPathSep(char c) {
static bool FatIsPathSep(char c) {
return c == '\\' || c == '/';
}
// Tests whether a non-empty FAT path view points at plausible kernel-owned storage.
static int FatStringViewDataIsPlausible(SYS_STRING_VIEW view) {
if (!SysSvIsValid(view)) return 0;
if (view.Length == 0) return 1;
static bool FatStringViewDataIsPlausible(SYS_STRING_VIEW view) {
if (!SysSvIsValid(view)) return false;
if (view.Length == 0) return true;
uintptr_t data = (uintptr_t)view.Data;
return data >= 0x10000u;
}
// Implements the name View Is Valid operation.
static int FatNameViewIsValid(SYS_STRING_VIEW name) {
if (!FatStringViewDataIsPlausible(name)) return 0;
if (name.Length == 0 || name.Length >= FAT_MAX_LFN) return 0;
static bool FatNameViewIsValid(SYS_STRING_VIEW name) {
if (!FatStringViewDataIsPlausible(name)) return false;
if (name.Length == 0 || name.Length >= FAT_MAX_LFN) return false;
for (size_t i = 0; i < name.Length; i++) {
char c = name.Data[i];
if (c == '\0' || FatIsPathSep(c)) return 0;
if (c == '\0' || FatIsPathSep(c)) return false;
}
return 1;
return true;
}
// Implements the lfn Match V operation.
static int LfnMatchV(const char* lfn, SYS_STRING_VIEW want) {
if (!lfn || !SysSvIsValid(want)) return 0;
static bool LfnMatchV(const char* lfn, SYS_STRING_VIEW want) {
if (!lfn || !SysSvIsValid(want)) return false;
size_t i = 0;
while (lfn[i] && i < want.Length) {
char a = lfn[i], b = want.Data[i];
if (a >= 'A' && a <= 'Z') a += 32;
if (b >= 'A' && b <= 'Z') b += 32;
if (a != b) return 0;
if (a != b) return false;
i++;
}
return lfn[i] == '\0' && i == want.Length;
}
static int MatchName83V(const char* dirName, const char* dirExt,
static bool MatchName83V(const char* dirName, const char* dirExt,
SYS_STRING_VIEW want) {
char buf[13];
int n = 0;
@@ -449,14 +450,14 @@ static int MatchName83V(const char* dirName, const char* dirExt,
buf[n++] = (char)(dirExt[i] >= 'A' && dirExt[i] <= 'Z' ? dirExt[i]+32 : dirExt[i]);
}
if ((size_t)n != want.Length) return 0;
if ((size_t)n != want.Length) return false;
for (int i = 0; i < n; i++) {
char a = buf[i], b = want.Data[i];
if (a >= 'A' && a <= 'Z') a += 32;
if (b >= 'A' && b <= 'Z') b += 32;
if (a != b) return 0;
if (a != b) return false;
}
return 1;
return true;
}
// Returns the path cache canonical byte used for hashes and comparisons.
@@ -719,21 +720,21 @@ bool FatBuildReadRun(FAT_FILE* f, uint32_t logicalIndex,
return true;
}
static int SearchDirV(FAT_VOL* v, uint32_t dirCluster, SYS_STRING_VIEW name,
static bool SearchDirV(FAT_VOL* v, uint32_t dirCluster, SYS_STRING_VIEW name,
uint32_t* outCluster, uint32_t* outSize, uint8_t* outAttr,
uint64_t* outDirentLba, uint32_t* outDirentOffset) {
if (!FatNameViewIsValid(name)) return 0;
if (!FatNameViewIsValid(name)) return false;
uint8_t* clusterBuf = (uint8_t*)MmAllocatePool(v->BytesPerCluster);
if (!clusterBuf) return 0;
if (!clusterBuf) return false;
char lfn[FAT_MAX_LFN]; int hasLfn = 0; memset(lfn, 0, sizeof(lfn));
char lfn[FAT_MAX_LFN]; bool hasLfn = false; memset(lfn, 0, sizeof(lfn));
char wantName83[8], wantExt83[3];
int allowShortMatch = FatNameIsStructurallyShort83V(name);
bool allowShortMatch = FatNameIsStructurallyShort83V(name);
Make83NameV(name, wantName83, wantExt83);
uint64_t clustersRead = 0;
uint64_t entriesScanned = 0;
int found = 0;
bool found = false;
uint32_t cursor; uint64_t lba; uint32_t sectors;
if (!FatDirectoryFirstSegment(v, dirCluster, &cursor, &lba, &sectors))
@@ -749,16 +750,16 @@ static int SearchDirV(FAT_VOL* v, uint32_t dirCluster, SYS_STRING_VIEW name,
for (uint32_t i = 0; i < entries; i++) {
entriesScanned++;
if (dir[i].Name[0] == 0x00) goto done;
if ((uint8_t)dir[i].Name[0] == 0xE5) { hasLfn = 0; memset(lfn, 0, sizeof(lfn)); continue; }
if (dir[i].Attr == ATTR_LFN) { FatLfnAppend(lfn, (LFN_ENTRY*)&dir[i]); hasLfn = 1; continue; }
if ((uint8_t)dir[i].Name[0] == 0xE5) { hasLfn = false; memset(lfn, 0, sizeof(lfn)); continue; }
if (dir[i].Attr == ATTR_LFN) { FatLfnAppend(lfn, (LFN_ENTRY*)&dir[i]); hasLfn = true; continue; }
int match = 0;
bool match = false;
if (hasLfn && lfn[0]) match = LfnMatchV(lfn, name);
if (!match && allowShortMatch)
match = MatchName83V(dir[i].Name, dir[i].Ext, name);
if (!match && allowShortMatch)
match = MatchRaw83(dir[i].Name, dir[i].Ext, wantName83, wantExt83);
hasLfn = 0; memset(lfn, 0, sizeof(lfn));
hasLfn = false; memset(lfn, 0, sizeof(lfn));
if (match) {
*outCluster = FatDirentFirstCluster(v, &dir[i]);
@@ -769,7 +770,7 @@ static int SearchDirV(FAT_VOL* v, uint32_t dirCluster, SYS_STRING_VIEW name,
if (outDirentLba) *outDirentLba = lba + eb / v->BytesPerSector;
if (outDirentOffset) *outDirentOffset = (uint32_t)(eb % v->BytesPerSector);
}
found = 1;
found = true;
goto done;
}
}
@@ -781,22 +782,22 @@ done:
return found;
}
static int FatPathNextComponent(SYS_STRING_VIEW path, size_t* cursor,
static bool FatPathNextComponent(SYS_STRING_VIEW path, size_t* cursor,
SYS_STRING_VIEW* component) {
if (!cursor || !component || !SysSvIsValid(path)) return 0;
if (!cursor || !component || !SysSvIsValid(path)) return false;
size_t pos = *cursor;
while (pos < path.Length && FatIsPathSep(path.Data[pos])) pos++;
if (pos >= path.Length) {
*cursor = pos;
*component = SYS_SV_NULL;
return 0;
return false;
}
size_t start = pos;
while (pos < path.Length && !FatIsPathSep(path.Data[pos])) pos++;
*cursor = pos;
*component = SysSvFromParts(path.Data + start, pos - start);
return 1;
return true;
}
KSTATUS FatLookupPathV(FAT_VOL* v, SYS_STRING_VIEW path,
@@ -884,20 +885,20 @@ static KSTATUS SplitPathV(SYS_STRING_VIEW path, SYS_STRING_VIEW* parent,
}
// Find a free DIRENT slot.
static int FindFreeDirent(FAT_VOL* v, uint32_t dirCluster,
static bool FindFreeDirent(FAT_VOL* v, uint32_t dirCluster,
uint64_t* outLba, uint32_t* outOffset) {
uint8_t* clusterBuf = (uint8_t*)MmAllocatePool(v->BytesPerCluster);
if (!clusterBuf) return 0;
if (!clusterBuf) return false;
uint32_t cursor; uint64_t lba; uint32_t sectors;
if (!FatDirectoryFirstSegment(v, dirCluster, &cursor, &lba, &sectors)) {
MmFreePool(clusterBuf);
return 0;
return false;
}
do {
if (!KSUCCESS(FatReadSectors(v, lba, sectors, clusterBuf))) {
MmFreePool(clusterBuf); return 0;
MmFreePool(clusterBuf); return false;
}
uint32_t entries = (sectors * v->BytesPerSector) / sizeof(DIRENT);
DIRENT* dir = (DIRENT*)clusterBuf;
@@ -907,46 +908,46 @@ static int FindFreeDirent(FAT_VOL* v, uint32_t dirCluster,
uint64_t eb = (uint64_t)i * sizeof(DIRENT);
*outLba = lba + eb / v->BytesPerSector;
*outOffset = (uint32_t)(eb % v->BytesPerSector);
MmFreePool(clusterBuf); return 1;
MmFreePool(clusterBuf); return true;
}
}
} while (FatDirectoryNextSegment(v, dirCluster, &cursor, &lba, &sectors));
if (FatIsFixedRoot(v, dirCluster)) {
MmFreePool(clusterBuf);
return 0;
return false;
}
uint32_t newCluster = FatAppendCluster(v, cursor);
if (newCluster) {
*outLba = FatClusterToLba(v, newCluster); *outOffset = 0;
MmFreePool(clusterBuf); return 1;
MmFreePool(clusterBuf); return true;
}
MmFreePool(clusterBuf);
return 0;
return false;
}
// Find a contiguous run of free directory entries.
// VFAT LFN creation requires N long-name entries to immediately precede the
// final short entry, so the run must live inside one readable/writeable segment.
static int FindFreeDirentRun(FAT_VOL* v, uint32_t dirCluster, uint32_t needed,
static bool FindFreeDirentRun(FAT_VOL* v, uint32_t dirCluster, uint32_t needed,
uint64_t* outLba, uint32_t* outFirstIndex,
uint32_t* outSectors) {
if (!needed) return 0;
if (!needed) return false;
uint8_t* clusterBuf = (uint8_t*)MmAllocatePool(v->BytesPerCluster);
if (!clusterBuf) return 0;
if (!clusterBuf) return false;
uint32_t cursor; uint64_t lba; uint32_t sectors;
if (!FatDirectoryFirstSegment(v, dirCluster, &cursor, &lba, &sectors)) {
MmFreePool(clusterBuf);
return 0;
return false;
}
do {
if (!KSUCCESS(FatReadSectors(v, lba, sectors, clusterBuf))) {
MmFreePool(clusterBuf);
return 0;
return false;
}
uint32_t entries = (sectors * v->BytesPerSector) / sizeof(DIRENT);
@@ -963,7 +964,7 @@ static int FindFreeDirentRun(FAT_VOL* v, uint32_t dirCluster, uint32_t needed,
*outFirstIndex = runStart;
*outSectors = sectors;
MmFreePool(clusterBuf);
return 1;
return true;
}
} else {
runLen = 0;
@@ -973,7 +974,7 @@ static int FindFreeDirentRun(FAT_VOL* v, uint32_t dirCluster, uint32_t needed,
if (FatIsFixedRoot(v, dirCluster)) {
MmFreePool(clusterBuf);
return 0;
return false;
}
uint32_t newCluster = FatAppendCluster(v, cursor);
@@ -982,11 +983,11 @@ static int FindFreeDirentRun(FAT_VOL* v, uint32_t dirCluster, uint32_t needed,
*outFirstIndex = 0;
*outSectors = v->SectorsPerCluster;
MmFreePool(clusterBuf);
return 1;
return true;
}
MmFreePool(clusterBuf);
return 0;
return false;
}
// Finds the parent directory and final component for a create or delete path.
@@ -1039,7 +1040,7 @@ KSTATUS FatCreateDirent(FAT_VOL* v, SYS_STRING_VIEW path,
}
}
int useLfn = FatNameNeedsLfnForCreateV(filenameView);
bool useLfn = FatNameNeedsLfnForCreateV(filenameView);
char shortName[8], shortExt[3];
if (useLfn) {
s = DeleteLegacyBrokenDotAliasV(v, parentCluster, filenameView);
@@ -1152,17 +1153,17 @@ KSTATUS FatInitializeDirectoryCluster(FAT_VOL* v, uint32_t dirCluster,
}
// Tests whether a FAT directory entry is one of the synthetic dot entries.
static int FatIsDotEntry(const DIRENT* d) {
if (!d || !(d->Attr & ATTR_DIRECTORY)) return 0;
if (d->Name[0] != '.') return 0;
static bool FatIsDotEntry(const DIRENT* d) {
if (!d || !(d->Attr & ATTR_DIRECTORY)) return false;
if (d->Name[0] != '.') return false;
if (d->Name[1] == ' ')
return 1;
return true;
return d->Name[1] == '.' && d->Name[2] == ' ';
}
// Tests whether a directory contains any real child entries.
KSTATUS FatDirectoryIsEmpty(FAT_VOL* v, uint32_t dirCluster,
int* emptyOut) {
bool* emptyOut) {
if (!v || !emptyOut)
return NTLSTATUS_INVALID_PARAMETER;
@@ -1209,12 +1210,12 @@ KSTATUS FatDeleteDirentRunV(FAT_VOL* v, uint32_t parentCluster,
if (!clusterBuf) return NTLSTATUS_NO_MEMORY;
char lfn[FAT_MAX_LFN];
int hasLfn = 0;
bool hasLfn = false;
uint32_t lfnStart = 0;
memset(lfn, 0, sizeof(lfn));
char wantName83[8], wantExt83[3];
int allowShortMatch = FatNameIsStructurallyShort83V(name);
bool allowShortMatch = FatNameIsStructurallyShort83V(name);
Make83NameV(name, wantName83, wantExt83);
uint32_t cursor; uint64_t lba; uint32_t sectors;
@@ -1229,20 +1230,20 @@ KSTATUS FatDeleteDirentRunV(FAT_VOL* v, uint32_t parentCluster,
uint32_t entries = (sectors * v->BytesPerSector) / sizeof(DIRENT);
DIRENT* dir = (DIRENT*)clusterBuf;
hasLfn = 0;
hasLfn = false;
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 NTLSTATUS_NOT_FOUND; }
if (first == 0xE5) { hasLfn = 0; memset(lfn, 0, sizeof(lfn)); continue; }
if (first == 0xE5) { hasLfn = false; memset(lfn, 0, sizeof(lfn)); continue; }
if (dir[i].Attr == ATTR_LFN) {
if (!hasLfn) lfnStart = i;
FatLfnAppend(lfn, (LFN_ENTRY*)&dir[i]);
hasLfn = 1;
hasLfn = true;
continue;
}
int match = 0;
bool match = false;
if (hasLfn && lfn[0]) match = LfnMatchV(lfn, name);
if (!match && allowShortMatch)
match = MatchName83V(dir[i].Name, dir[i].Ext, name);
@@ -1259,7 +1260,7 @@ KSTATUS FatDeleteDirentRunV(FAT_VOL* v, uint32_t parentCluster,
return s;
}
hasLfn = 0;
hasLfn = false;
memset(lfn, 0, sizeof(lfn));
}
} while (FatDirectoryNextSegment(v, parentCluster, &cursor, &lba, &sectors));
+13 -12
View File
@@ -1,5 +1,6 @@
// FAT mount discovery, BPB validation, and driver lifetime.
#include <stdbool.h>
#include "fat_internal.h"
// FAT BPB validation.
@@ -12,18 +13,18 @@ typedef struct FAT_BPB_LAYOUT {
uint32_t TotalClusters;
} FAT_BPB_LAYOUT;
static int FatComputeBpbLayout(const BPB* bpb, FAT_BPB_LAYOUT* out) {
if (!bpb || !out) return 0;
static bool FatComputeBpbLayout(const BPB* bpb, FAT_BPB_LAYOUT* out) {
if (!bpb || !out) return false;
memset(out, 0, sizeof(*out));
if (bpb->BytesPerSector != 512) return 0;
if (bpb->SectorsPerCluster == 0) return 0;
if (bpb->NumFats == 0) return 0;
if (bpb->ReservedSectors == 0) return 0;
if (bpb->BytesPerSector != 512) return false;
if (bpb->SectorsPerCluster == 0) return false;
if (bpb->NumFats == 0) return false;
if (bpb->ReservedSectors == 0) return false;
uint32_t totalSectors = bpb->TotalSectors16 ? bpb->TotalSectors16 : bpb->TotalSectors32;
uint32_t fatSize = bpb->FatSize16 ? bpb->FatSize16 : bpb->FatSize32;
if (!totalSectors || !fatSize) return 0;
if (!totalSectors || !fatSize) return false;
uint32_t rootDirSectors = ((uint32_t)bpb->RootEntryCount * sizeof(DIRENT) +
(uint32_t)bpb->BytesPerSector - 1u) /
@@ -31,7 +32,7 @@ static int FatComputeBpbLayout(const BPB* bpb, FAT_BPB_LAYOUT* out) {
uint32_t metadataSectors = (uint32_t)bpb->ReservedSectors +
(uint32_t)bpb->NumFats * fatSize +
rootDirSectors;
if (totalSectors <= metadataSectors) return 0;
if (totalSectors <= metadataSectors) return false;
uint32_t dataSectors = totalSectors - metadataSectors;
uint32_t totalClusters = dataSectors / bpb->SectorsPerCluster;
@@ -44,10 +45,10 @@ static int FatComputeBpbLayout(const BPB* bpb, FAT_BPB_LAYOUT* out) {
variant = FatVariant32;
if (variant == FatVariant16) {
if (bpb->FatSize16 == 0 || bpb->RootEntryCount == 0) return 0;
if (bpb->FatSize16 == 0 || bpb->RootEntryCount == 0) return false;
} else if (variant == FatVariant32) {
if (bpb->FatSize16 != 0 || bpb->RootEntryCount != 0) return 0;
if (bpb->FatSize32 == 0 || bpb->RootCluster < 2) return 0;
if (bpb->FatSize16 != 0 || bpb->RootEntryCount != 0) return false;
if (bpb->FatSize32 == 0 || bpb->RootCluster < 2) return false;
}
out->Variant = variant;
@@ -56,7 +57,7 @@ static int FatComputeBpbLayout(const BPB* bpb, FAT_BPB_LAYOUT* out) {
out->RootDirSectors = rootDirSectors;
out->DataSectors = dataSectors;
out->TotalClusters = totalClusters;
return 1;
return true;
}
+2 -1
View File
@@ -1,5 +1,6 @@
// FAT synchronous file and directory operations.
#include <stdbool.h>
#include "fat_internal.h"
// Open / Close.
@@ -323,7 +324,7 @@ KSTATUS FatRemoveDir(IO_VOLUME_PROVIDER* fs, SYS_STRING_VIEW path) {
if (!direntLba) return NTLSTATUS_ACCESS_DENIED;
if (!(attr & ATTR_DIRECTORY)) return NTLSTATUS_ACCESS_DENIED;
int empty = 0;
bool empty = false;
s = FatDirectoryIsEmpty(v, cluster, &empty);
if (!KSUCCESS(s)) return s;
if (!empty) return NTLSTATUS_ACCESS_DENIED;
+8 -7
View File
@@ -2,6 +2,7 @@
#pragma once
#include <stdbool.h>
#include "fat.h"
#include "fat_disk.h"
@@ -99,21 +100,21 @@ KSTATUS FatReadSectors(FAT_VOL* volume, uint64_t lba, uint32_t count, void* buff
KSTATUS FatWriteSectors(FAT_VOL* volume, uint64_t lba, uint32_t count, const void* buffer);
const char* FatVariantName(FAT_VARIANT variant);
uint32_t FatEocMark(FAT_VOL* volume);
int FatIsDataCluster(FAT_VOL* volume, uint32_t cluster);
bool FatIsDataCluster(FAT_VOL* volume, uint32_t cluster);
uint32_t FatDirentFirstCluster(FAT_VOL* volume, const DIRENT* dirent);
void FatSetDirentFirstCluster(FAT_VOL* volume, DIRENT* dirent, uint32_t cluster);
int FatIsFixedRoot(FAT_VOL* volume, uint32_t dirCluster);
int FatDirectoryFirstSegment(FAT_VOL* volume, uint32_t dirCluster,
bool FatIsFixedRoot(FAT_VOL* volume, uint32_t dirCluster);
bool FatDirectoryFirstSegment(FAT_VOL* volume, uint32_t dirCluster,
uint32_t* cursorOut, uint64_t* lbaOut, uint32_t* sectorsOut);
int FatDirectoryNextSegment(FAT_VOL* volume, uint32_t dirCluster,
bool FatDirectoryNextSegment(FAT_VOL* volume, uint32_t dirCluster,
uint32_t* cursorInOut, uint64_t* lbaOut, uint32_t* sectorsOut);
uint64_t FatClusterToLba(FAT_VOL* volume, uint32_t cluster);
uint32_t FatEntry(FAT_VOL* volume, uint32_t cluster);
KSTATUS FatWriteEntry(FAT_VOL* volume, uint32_t cluster, uint32_t value);
void FatFlushCache(FAT_VOL* volume);
uint32_t FatAllocClusterEx(FAT_VOL* volume, int zeroCluster);
uint32_t FatAllocClusterEx(FAT_VOL* volume, bool zeroCluster);
uint32_t FatAllocCluster(FAT_VOL* volume);
uint32_t FatAppendClusterEx(FAT_VOL* volume, uint32_t lastCluster, int zeroCluster);
uint32_t FatAppendClusterEx(FAT_VOL* volume, uint32_t lastCluster, bool zeroCluster);
uint32_t FatAppendCluster(FAT_VOL* volume, uint32_t lastCluster);
uint32_t FatGetChainEnd(FAT_VOL* volume, uint32_t start, uint32_t* countOut);
void FatFreeClusterChain(FAT_VOL* volume, uint32_t start);
@@ -145,7 +146,7 @@ KSTATUS FatCreateDirent(FAT_VOL* volume, SYS_STRING_VIEW path,
uint64_t* direntLbaOut, uint32_t* direntOffsetOut);
KSTATUS FatInitializeDirectoryCluster(FAT_VOL* volume, uint32_t dirCluster,
uint32_t parentCluster);
KSTATUS FatDirectoryIsEmpty(FAT_VOL* volume, uint32_t dirCluster, int* emptyOut);
KSTATUS FatDirectoryIsEmpty(FAT_VOL* volume, uint32_t dirCluster, bool* emptyOut);
KSTATUS FatDeleteDirentRunV(FAT_VOL* volume, uint32_t parentCluster,
SYS_STRING_VIEW name);
void FatCacheInvalidate(void);
+2 -2
View File
@@ -216,8 +216,8 @@ static void Ps2MouseIsr(void) {
if (flags & 0xC0u)
return;
int dx = (int)gMousePacket[1] - ((flags & 0x10u) ? 256 : 0);
int dy = (int)gMousePacket[2] - ((flags & 0x20u) ? 256 : 0);
int32_t dx = (int32_t)gMousePacket[1] - ((flags & 0x10u) ? 256 : 0);
int32_t dy = (int32_t)gMousePacket[2] - ((flags & 0x20u) ? 256 : 0);
dy = -dy;
int next = (gMouseDpcTail + 1) & (int)MOUSE_DPC_QUEUE_MASK;
+2 -2
View File
@@ -33,8 +33,8 @@
#define MOUSE_DPC_QUEUE_MASK (MOUSE_DPC_QUEUE_SIZE - 1u)
typedef struct PS2_MOUSE_PACKET {
int dx;
int dy;
int32_t dx;
int32_t dy;
uint8_t buttons;
} PS2_MOUSE_PACKET;
+29 -28
View File
@@ -1,5 +1,6 @@
// lwIP stack provider glue. This file bridges the kernel network-device model into lwIP.
#include <ntlite/atomic.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
@@ -77,7 +78,7 @@ typedef struct LWIP_ATTACH_CTX {
typedef struct LWIP_RESOLVE_CONTEXT {
SEMAPHORE* Done;
volatile long References;
volatile int32_t References;
err_t Result;
u8_t DnsType;
ip_addr_t Address;
@@ -167,12 +168,12 @@ static KSTATUS LwipErrToStatus(err_t err) {
}
// Implements the ascii Is Digit operation.
static int LwipAsciiIsDigit(char c) {
static bool LwipAsciiIsDigit(char c) {
return c >= '0' && c <= '9';
}
// Parses ipv4 Part.
static int LwipParseIpv4Part(const char** cursor, uint8_t* out) {
static bool LwipParseIpv4Part(const char** cursor, uint8_t* out) {
const char* p = *cursor;
uint32_t value = 0;
uint32_t digits = 0;
@@ -180,37 +181,37 @@ static int LwipParseIpv4Part(const char** cursor, uint8_t* out) {
while (LwipAsciiIsDigit(*p)) {
value = value * 10u + (uint32_t)(*p - '0');
if (value > 255u)
return 0;
return false;
p++;
digits++;
}
if (digits == 0)
return 0;
return false;
*out = (uint8_t)value;
*cursor = p;
return 1;
return true;
}
// Parses ipv4.
static int LwipParseIpv4(const char* text, ip4_addr_t* out) {
static bool LwipParseIpv4(const char* text, ip4_addr_t* out) {
if (!text || !out)
return 0;
return false;
const char* p = text;
uint8_t a = 0, b = 0, c = 0, d = 0;
if (!LwipParseIpv4Part(&p, &a) || *p++ != '.') return 0;
if (!LwipParseIpv4Part(&p, &b) || *p++ != '.') return 0;
if (!LwipParseIpv4Part(&p, &c) || *p++ != '.') return 0;
if (!LwipParseIpv4Part(&p, &d) || *p != '\0') return 0;
if (!LwipParseIpv4Part(&p, &a) || *p++ != '.') return false;
if (!LwipParseIpv4Part(&p, &b) || *p++ != '.') return false;
if (!LwipParseIpv4Part(&p, &c) || *p++ != '.') return false;
if (!LwipParseIpv4Part(&p, &d) || *p != '\0') return false;
IP4_ADDR(out, a, b, c, d);
return 1;
return true;
}
static KSTATUS LwipGetSettingIpv4(const char* section, const char* key,
ip4_addr_t* out, int required) {
ip4_addr_t* out, bool required) {
char value[LWIP_SETTINGS_VALUE_MAX];
KSTATUS st = KeGetSettingString(section, key, value, sizeof(value));
if (st == NTLSTATUS_NOT_FOUND && !required)
@@ -225,7 +226,7 @@ static KSTATUS LwipGetSettingIpv4(const char* section, const char* key,
}
static KSTATUS LwipGetSettingIpv6(const char* section, const char* key,
ip6_addr_t* out, int required) {
ip6_addr_t* out, bool required) {
char value[LWIP_SETTINGS_VALUE_MAX];
KSTATUS st = KeGetSettingString(section, key, value, sizeof(value));
if (st == NTLSTATUS_NOT_FOUND && !required)
@@ -308,13 +309,13 @@ static KSTATUS LwipLoadConfigFromSection(const char* section, LWIP_NETIF_CONFIG*
if (strcmp(mode, "static") == 0) {
cfg->UseDhcp = 0;
st = LwipGetSettingIpv4(section, "address", &cfg->Address, 1);
st = LwipGetSettingIpv4(section, "address", &cfg->Address, true);
if (!KSUCCESS(st)) return st;
st = LwipGetSettingIpv4(section, "netmask", &cfg->Netmask, 1);
st = LwipGetSettingIpv4(section, "netmask", &cfg->Netmask, true);
if (!KSUCCESS(st)) return st;
st = LwipGetSettingIpv4(section, "gateway", &cfg->Gateway, 1);
st = LwipGetSettingIpv4(section, "gateway", &cfg->Gateway, true);
if (!KSUCCESS(st)) return st;
st = LwipGetSettingIpv4(section, "dns", &cfg->Dns4, 1);
st = LwipGetSettingIpv4(section, "dns", &cfg->Dns4, true);
if (!KSUCCESS(st)) return st;
cfg->HasDns4 = 1;
return LwipLoadIpv6Config(section, cfg);
@@ -322,7 +323,7 @@ static KSTATUS LwipLoadConfigFromSection(const char* section, LWIP_NETIF_CONFIG*
if (strcmp(mode, "dhcp") == 0) {
cfg->UseDhcp = 1;
st = LwipGetSettingIpv4(section, "dns", &cfg->Dns4, 0);
st = LwipGetSettingIpv4(section, "dns", &cfg->Dns4, false);
if (KSUCCESS(st))
cfg->HasDns4 = 1;
else if (st != NTLSTATUS_NOT_FOUND)
@@ -449,7 +450,7 @@ static KSTATUS LwipSocketAllocateWithConn(uint32_t domain, uint32_t type, uint32
// Returns whether the IRP cancel token has been set by SysCancelIo.
static int LwipSocketCancelRequested(volatile uint8_t* cancelRequested) {
static bool LwipSocketCancelRequested(volatile uint8_t* cancelRequested) {
return cancelRequested && *cancelRequested;
}
@@ -552,22 +553,22 @@ static KSTATUS LwipSocketWaitAccept(LWIP_PROVIDER_SOCKET* s,
}
}
static int LwipSocketAddressValid(const SYS_SOCKET_ADDRESS_K* address, size_t addressSize) {
static bool LwipSocketAddressValid(const SYS_SOCKET_ADDRESS_K* address, size_t addressSize) {
if (!address || addressSize != sizeof(SYS_SOCKET_ADDRESS_K))
return 0;
return false;
if (address->Size != sizeof(SYS_SOCKET_ADDRESS_K))
return 0;
return false;
return address->Family == SYS_AF_INET || address->Family == SYS_AF_INET6;
}
static int LwipSocketFamilyMatches(const LWIP_PROVIDER_SOCKET* s, const SYS_SOCKET_ADDRESS_K* address) {
static bool LwipSocketFamilyMatches(const LWIP_PROVIDER_SOCKET* s, const SYS_SOCKET_ADDRESS_K* address) {
if (!s || !address)
return 0;
return false;
if (s->Domain == SYS_AF_INET)
return address->Family == SYS_AF_INET;
if (s->Domain == SYS_AF_INET6)
return address->Family == SYS_AF_INET6;
return 0;
return false;
}
// Implements the socket Make Ip operation.
@@ -1613,7 +1614,7 @@ static void LwipResolveRelease(LWIP_RESOLVE_CONTEXT* context) {
if (!context)
return;
if (_InterlockedDecrement(&context->References) != 0)
if (NtlAtomicDecrement32(&context->References) != 0)
return;
if (context->Done)
+8 -8
View File
@@ -266,7 +266,7 @@ static void AhciIsr(void) {
if (!pending)
continue;
for (int i = 0; i < ctl->driveCount; i++) {
for (uint32_t i = 0; i < ctl->driveCount; i++) {
AHCI_DRIVE* drv = &ctl->drives[i];
uint32_t portBit = (1u << drv->portNo);
if (!(pending & portBit)) continue;
@@ -676,7 +676,7 @@ static KSTATUS AhciDispatchControllerPnp(DEVICE_OBJECT* device, IRP* irp) {
case IRP_MN_SURPRISE_REMOVAL:
ctl->surpriseRemoved = true;
device->PnpState = DevicePnpSurpriseRemoved;
for (int i = 0; i < ctl->driveCount; i++) {
for (uint32_t i = 0; i < ctl->driveCount; i++) {
AHCI_DRIVE* drv = &ctl->drives[i];
drv->surpriseRemoved = true;
if (drv->deviceObject)
@@ -689,7 +689,7 @@ static KSTATUS AhciDispatchControllerPnp(DEVICE_OBJECT* device, IRP* irp) {
case IRP_MN_REMOVE_DEVICE:
ctl->removed = true;
device->PnpState = DevicePnpDeleted;
for (int i = 0; i < ctl->driveCount; i++) {
for (uint32_t i = 0; i < ctl->driveCount; i++) {
AHCI_DRIVE* drv = &ctl->drives[i];
if (drv->deviceObject) {
(void)IoUnregisterDiskDevice(drv->deviceObject->u.Disk.DiskIndex);
@@ -974,7 +974,7 @@ static KSTATUS AhciStartController(AHCI_CONTROLLER* ctl) {
DbgPrint("AHCI: port %u: link up, initializing...\n", portno);
int driveIdx = ctl->driveCount;
uint32_t driveIdx = ctl->driveCount;
AHCI_DRIVE* drv = &ctl->drives[driveIdx];
memset(drv, 0, sizeof(*drv));
drv->magic = AHCI_DRIVE_MAGIC;
@@ -1119,11 +1119,11 @@ static KSTATUS AhciStartController(AHCI_CONTROLLER* ctl) {
ctl->pciInfo.Address.Function);
if (!ctl->pollingMode) {
DbgPrint("AHCI: ISR registered on IRQ %u (%s); controller drives=%d\n",
(unsigned)ctl->irq, ctl->usingMsi ? "MSI" : "INTx", ctl->driveCount);
DbgPrint("AHCI: ISR registered on IRQ %u (%s); controller drives=%u\n",
(unsigned)ctl->irq, ctl->usingMsi ? "MSI" : "INTx", (unsigned)ctl->driveCount);
} else {
DbgPrint("AHCI: controller started in polling mode; controller drives=%d\n",
ctl->driveCount);
DbgPrint("AHCI: controller started in polling mode; controller drives=%u\n",
(unsigned)ctl->driveCount);
}
ctl->started = true;
ctl->fdo->PnpState = DevicePnpStarted;
+1 -1
View File
@@ -378,7 +378,7 @@ struct AHCI_CONTROLLER {
bool pollingMode;
AHCI_DRIVE drives[MAX_AHCI_DRIVES];
int driveCount;
uint32_t driveCount;
bool started;
bool surpriseRemoved;