From: John Hodge Date: Tue, 21 Feb 2012 10:43:14 +0000 (+0800) Subject: Modules/LVM - Fiddling X-Git-Tag: rel0.15~758 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=19f38ccc051cc9b9bbcb7048b0c12266cb1d4312;p=tpg%2Facess2.git Modules/LVM - Fiddling Also fixed a slight bug in the USBMouse code --- diff --git a/KernelLand/Modules/Storage/LVM/lvm_int.h b/KernelLand/Modules/Storage/LVM/lvm_int.h index 7f528d90..f4ef3c12 100644 --- a/KernelLand/Modules/Storage/LVM/lvm_int.h +++ b/KernelLand/Modules/Storage/LVM/lvm_int.h @@ -8,18 +8,28 @@ #ifndef _LVM_LVM_INT_H_ #define _LVM_LVM_INT_H_ +#include "include/lvm.h" #include "lvm.h" #include typedef struct sLVM_SubVolume tLVM_SubVolume; +enum eLVM_BackType +{ + LVM_BACKING_VFS, + LVM_BACKING_PTRS +}; + struct sLVM_Vol { tLVM_Vol *Next; tVFS_Node Node; - - int BackingDescriptor; + + void *Ptr; + tLVM_ReadFcn Read; + tLVM_WriteFcn Write; + size_t BlockSize; int nSubVolumes; diff --git a/KernelLand/Modules/Storage/LVM/volumes.c b/KernelLand/Modules/Storage/LVM/volumes.c index aac987e2..f8709bdb 100644 --- a/KernelLand/Modules/Storage/LVM/volumes.c +++ b/KernelLand/Modules/Storage/LVM/volumes.c @@ -8,15 +8,27 @@ #include "lvm_int.h" // === PROTOTYPES === + int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest); + int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source); // === CODE === // -------------------------------------------------------------------- // Managment / Initialisation // -------------------------------------------------------------------- -int LVM_AddVolume(const char *Name, int FD) +int LVM_AddVolumeVFS(const char *Name, int FD) { - // Make dummy volume descriptor (for the read code) + return LVM_AddVolume(Name, (void*)FD, LVM_int_VFSReadEmul, LVM_int_VFSWriteEmul); +} + +int LVM_AddVolume(const char *Name, void *Ptr, tLVM_ReadFcn Read, tLVM_WriteFcn Write) +{ + tLVM_Vol dummy_vol; +// tLVM_Vol *real_vol; + dummy_vol.Ptr = Ptr; + dummy_vol.Read = Read; + dummy_vol.Write = Write; + // Determine Type // Type->CountSubvolumes @@ -70,25 +82,35 @@ void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, U // -------------------------------------------------------------------- size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest) { - size_t rv; - rv = VFS_ReadAt( - Volume->BackingDescriptor, - BlockNum * Volume->BlockSize, - BlockCount * Volume->BlockSize, - Dest - ); - return rv / Volume->BlockSize; + return Volume->Read(Volume->Ptr, BlockNum, BlockCount, Dest); } size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src) { + return Volume->Write(Volume->Ptr, BlockNum, BlockCount, Src); +} + +int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest) +{ + size_t blocksize; size_t rv; - rv = VFS_WriteAt( - Volume->BackingDescriptor, - BlockNum * Volume->BlockSize, - BlockCount * Volume->BlockSize, - Src - ); - return rv / Volume->BlockSize; + + blocksize = 512; // TODO: Don't assume + + rv = VFS_ReadAt( (int)Arg, BlockStart * blocksize, BlockCount * blocksize, Dest ); + rv /= blocksize; + return rv; +} + +int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source) +{ + size_t blocksize; + size_t rv; + + blocksize = 512; // TODO: Don't assume + + rv = VFS_WriteAt( (int)Arg, BlockStart * blocksize, BlockCount * blocksize, Source ); + rv /= blocksize; + return rv; } diff --git a/KernelLand/Modules/USB/HID/mouse.c b/KernelLand/Modules/USB/HID/mouse.c index d34ee277..07f41c49 100644 --- a/KernelLand/Modules/USB/HID/mouse.c +++ b/KernelLand/Modules/USB/HID/mouse.c @@ -136,15 +136,37 @@ size_t HID_Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Bu memcpy( Buffer, info->FileData + Offset, Length ); + VFS_MarkAvaliable( &info->Node, 0 ); + return Length; } static const char *csaDevIOCtls[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL}; int HID_Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data) { + tJoystick_NumValue *numval = Data; + tHID_Mouse *info = Node->ImplPtr; switch(ID) { BASE_IOCTLS(DRV_TYPE_JOYSTICK, "USBMouse", 0x050, csaDevIOCtls); + + case JOY_IOCTL_GETSETAXISLIMIT: + if( !numval || !CheckMem(numval, sizeof(*numval)) ) + return -1; + if(numval->Num < 0 || numval->Num >= MAX_AXIES) + return 0; + if(numval->Value != -1) + info->AxisLimits[numval->Num] = numval->Value; + return info->AxisLimits[numval->Num]; + + case JOY_IOCTL_GETSETAXISPOSITION: + if( !numval || !CheckMem(numval, sizeof(*numval)) ) + return -1; + if(numval->Num < 0 || numval->Num >= MAX_AXIES) + return 0; + if(numval->Value != -1) + info->Axies[numval->Num].CursorPos = numval->Value; + return info->Axies[numval->Num].CursorPos; } return -1; } @@ -170,6 +192,7 @@ void HID_Mouse_Dev_Close(tVFS_Node *Node) Sint32 _ReadBits(void *Data, int Offset, int Length) { int dest_ofs = 0; + int rem = Length; Uint32 rv = 0; Uint8 *bytes = (Uint8*)Data + Offset / 8; @@ -188,23 +211,22 @@ Sint32 _ReadBits(void *Data, int Offset, int Length) rv = (*bytes >> Offset); dest_ofs = Offset & 7; - Length -= Offset & 7; + rem = Length - (Offset & 7); bytes ++; } // Body bytes - while( Length >= 8 ) + while( rem >= 8 ) { rv |= *bytes << dest_ofs; dest_ofs += 8; - Length -= 8; + rem -= 8; bytes ++; } - if( Length ) + if( rem ) { - rv |= (*bytes & ((1 << Length)-1)) << dest_ofs; - + rv |= (*bytes & ((1 << rem)-1)) << dest_ofs; } // Do sign extension @@ -225,8 +247,6 @@ void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data) info = USB_GetDeviceDataPtr(Dev); if( !info ) return ; - Log_Debug("USBMouse", "info = %p", info); - ofs = 0; for( int i = 0; i < info->nMappings; i ++ ) { @@ -237,6 +257,7 @@ void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data) return ; value = _ReadBits(Data, ofs, info->Mappings[i].BitSize); + LOG("%i+%i: value = %i", ofs, info->Mappings[i].BitSize, value); ofs += info->Mappings[i].BitSize; if( dest == 0xFF ) continue ; @@ -266,9 +287,10 @@ void HID_Mouse_DataAvail(tUSBInterface *Dev, int EndPt, int Length, void *Data) info->Axies[i].CursorPos = newpos; } - Log_Debug("USBMouse", "New Pos (%i,%i,%i)", - info->Axies[0].CursorPos, info->Axies[1].CursorPos, info->Axies[2].CursorPos - ); +// Log_Debug("USBMouse", "New Pos (%i,%i,%i)", +// info->Axies[0].CursorPos, info->Axies[1].CursorPos, info->Axies[2].CursorPos +// ); + VFS_MarkAvaliable( &info->Node, 1 ); } // ---------------------------------------------------------------------------- @@ -297,6 +319,14 @@ tHID_ReportCallbacks *HID_Mouse_Report_Collection( info->FileHeader = (void*)info->FileData; info->Axies = (void*)(info->FileHeader + 1); info->Buttons = (void*)(info->Axies + MAX_AXIES); + info->FileHeader->NAxies = MAX_AXIES; + info->FileHeader->NButtons = MAX_BUTTONS; + + for( int i = 0; i < MAX_AXIES; i ++ ) { + info->Axies[i].MinValue = -10; + info->Axies[i].MaxValue = 10; + } + LOG("Initialised new mouse at %p", info);