Initial revision

svn path=/trunk/; revision=37
This commit is contained in:
Rex Jolliff 1998-09-13 15:55:36 +00:00
parent e8652909ce
commit ffc37c2cfd
10 changed files with 1173 additions and 0 deletions

View file

@ -0,0 +1,84 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: services/fs/minix/minix.c
* PURPOSE: Minix FSD
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/string.h>
#define NDEBUG
#include <internal/debug.h>
#include "minix_fs.h"
/* FUNCTIONS ***************************************************************/
BOOLEAN MinixReadSector(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN UCHAR* Buffer)
{
LARGE_INTEGER sectorNumber;
PIRP irp;
IO_STATUS_BLOCK ioStatus;
KEVENT event;
NTSTATUS status;
ULONG sectorSize;
PULONG mbr;
DPRINT("MinixReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject,DiskSector,Buffer);
sectorNumber.LowPart = DiskSector * BLOCKSIZE;
KeInitializeEvent(&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE;
mbr = ExAllocatePool(NonPagedPool, sectorSize);
if (!mbr) {
return FALSE;
}
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
pDeviceObject,
mbr,
sectorSize,
&sectorNumber,
&event,
&ioStatus );
if (!irp) {
ExFreePool(mbr);
return FALSE;
}
status = IoCallDriver(pDeviceObject,
irp);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(&event,
Suspended,
KernelMode,
FALSE,
NULL);
status = ioStatus.Status;
}
if (!NT_SUCCESS(status)) {
ExFreePool(mbr);
return FALSE;
}
RtlCopyMemory(Buffer,mbr,sectorSize);
ExFreePool(mbr);
return TRUE;
}

View file

@ -0,0 +1,2 @@
all: minix.o blockdev.o
$(LD) -r minix.o blockdev.o -o minixfsd.o

View file

@ -0,0 +1,454 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: services/fs/minix/minix.c
* PURPOSE: Minix FSD
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/string.h>
#include <wstring.h>
#define NDEBUG
#include <internal/debug.h>
#include "minix_fs.h"
/* GLOBALS ******************************************************************/
static PDRIVER_OBJECT DriverObject;
typedef struct
{
PDEVICE_OBJECT AttachedDevice;
struct minix_inode root_inode;
char superblock_buf[BLOCKSIZE];
struct minix_super_block* sb;
} MINIX_DEVICE_EXTENSION;
/* FUNCTIONS ****************************************************************/
static unsigned int MinixGetIndirectBlock(struct minix_inode* inode,
unsigned char* buffer, int blk)
{
unsigned short int* buf = (unsigned short int *)buffer;
return(buf[blk]);
}
static unsigned int MinixGetBlock(PDEVICE_OBJECT DeviceObject,
struct minix_inode* inode,
int blk)
{
int block;
char* buffer;
DPRINT("MinixGetBlock(inode %x, blk %d)\n",inode,blk);
if (blk < 7)
{
block = inode->i_zone[blk];
return(block);
}
blk = blk - 7;
buffer = ExAllocatePool(NonPagedPool,1024);
if (blk < 512)
{
block = inode->i_zone[7];
MinixReadSector(DeviceObject,block,buffer);
block = MinixGetIndirectBlock(inode,buffer,blk);
ExFreePool(buffer);
return(block);
}
blk = blk - 512;
block = inode->i_zone[8];
MinixReadSector(DeviceObject,block,buffer);
block = MinixGetIndirectBlock(inode,buffer,(blk>>9)&511);
MinixReadSector(DeviceObject,block,buffer);
block = MinixGetIndirectBlock(inode,buffer,blk&511);
ExFreePool(buffer);
return(block);
}
NTSTATUS MinixReadBlock(PDEVICE_OBJECT DeviceObject,
struct minix_inode* inode,
int blk,
PVOID buffer)
{
unsigned int block;
DPRINT("MinixReadBlock(inode %x, blk %d, buffer %x)\n",inode,blk,buffer);
block = MinixGetBlock(DeviceObject,inode,blk);
DPRINT("block %d\n",block);
return(MinixReadSector(DeviceObject,block,buffer));
}
VOID MinixMount(PDEVICE_OBJECT DeviceToMount)
{
PDEVICE_OBJECT DeviceObject;
MINIX_DEVICE_EXTENSION* DeviceExt;
IoCreateDevice(DriverObject,
sizeof(MINIX_DEVICE_EXTENSION),
NULL,
FILE_DEVICE_FILE_SYSTEM,
0,
FALSE,
&DeviceObject);
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
DeviceExt = DeviceObject->DeviceExtension;
MinixReadSector(DeviceToMount,1,DeviceExt->superblock_buf);
DeviceExt->sb = (struct minix_super_block *)(DeviceExt->superblock_buf);
DeviceExt->AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,
DeviceToMount);
}
NTSTATUS MinixFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PVPB vpb = Stack->Parameters.Mount.Vpb;
PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
NTSTATUS Status;
char* superblock_buf;
struct minix_super_block* sb;
DbgPrint("MinixFileSystemControl(DeviceObject %x, Irp %x)\n",DeviceObject,
Irp);
DPRINT("DeviceToMount %x\n",DeviceToMount);
superblock_buf = ExAllocatePool(NonPagedPool,BLOCKSIZE);
DPRINT("MinixReadSector %x\n",MinixReadSector);
MinixReadSector(DeviceToMount,1,superblock_buf);
sb = (struct minix_super_block *)superblock_buf;
DPRINT("Magic %x\n",sb->s_magic);
DPRINT("Imap blocks %x\n",sb->s_imap_blocks);
DPRINT("Zmap blocks %x\n",sb->s_zmap_blocks);
if (sb->s_magic==MINIX_SUPER_MAGIC2)
{
DPRINT("%s() = STATUS_SUCCESS\n",__FUNCTION__);
MinixMount(DeviceToMount);
Status = STATUS_SUCCESS;
}
else
{
DPRINT("%s() = STATUS_UNRECOGNIZED_VOLUME\n",__FUNCTION__);
Status = STATUS_UNRECOGNIZED_VOLUME;
}
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Status);
}
NTSTATUS MinixReadInode(PDEVICE_OBJECT DeviceObject,
MINIX_DEVICE_EXTENSION* DeviceExt,
ULONG ino,
struct minix_inode* result)
{
int block;
char* buffer;
struct minix_inode* inodes;
DPRINT("MinixReadInode(ino %x, result %x)\n",ino,result);
buffer = ExAllocatePool(NonPagedPool,1024);
inodes = (struct minix_inode *)buffer;
block = 2 + DeviceExt->sb->s_imap_blocks + DeviceExt->sb->s_zmap_blocks
+ ((ino-1) / MINIX_INODES_PER_BLOCK);
DPRINT("Reading block %x offset %x\n",block,block*BLOCKSIZE);
DPRINT("Index %x\n",(ino-1)%MINIX_INODES_PER_BLOCK);
MinixReadSector(DeviceObject,block,buffer);
memcpy(result,&inodes[(ino-1)%MINIX_INODES_PER_BLOCK],
sizeof(struct minix_inode));
DPRINT("result->i_uid %x\n",result->i_uid);
DPRINT("result->i_size %x\n",result->i_size);
return(STATUS_SUCCESS);
}
BOOLEAN MinixCompareUnicodeStringToAnsi(PCH AnsiStr, PWCHAR UnicodeStr,
ULONG MaxLen)
{
unsigned int i = 0;
while (i<MaxLen)
{
if ((*AnsiStr)!=(*UnicodeStr))
{
return(FALSE);
}
if ((*AnsiStr)==0 && (*UnicodeStr)==0)
{
return(TRUE);
}
AnsiStr++;
UnicodeStr++;
i++;
}
return(TRUE);
}
ULONG MinixDirLookup(PDEVICE_OBJECT DeviceObject,
struct minix_inode* dir,
PWCHAR Name)
{
char* buffer;
struct minix_dir_entry* entry;
unsigned int offset;
unsigned int i;
unsigned int inode;
buffer=ExAllocatePool(NonPagedPool,BLOCKSIZE);
for (i=0;i<(dir->i_size/MINIX_DIR_ENTRY_SIZE);i++)
{
offset = i*MINIX_DIR_ENTRY_SIZE;
if ((offset%BLOCKSIZE)==0)
{
MinixReadBlock(DeviceObject,
dir,
offset/BLOCKSIZE,
buffer);
}
entry = (struct minix_dir_entry *)&buffer[offset%BLOCKSIZE];
DPRINT("Inode %x Name %.30s\n",entry->inode,entry->name);
if (MinixCompareUnicodeStringToAnsi(entry->name,Name,30))
{
inode = entry->inode;
ExFreePool(buffer);
DPRINT("MinixDirLookup() = %d\n",inode);
return(inode);
}
}
ExFreePool(buffer);
DPRINT("MinixDirLookup() = %d\n",0);
return(0);
}
NTSTATUS MinixOpen(PDEVICE_OBJECT DeviceObject,
MINIX_DEVICE_EXTENSION* DeviceExt,
PWSTR DeviceName,
struct minix_inode* result)
{
PWSTR current;
PWSTR next;
PWSTR string = DeviceName;
struct minix_inode current_dir;
unsigned int current_ino;
DbgPrint("MinixOpen(DeviceObject %x, DeviceName %w, result %x)\n",
DeviceObject,DeviceName,result);
DPRINT("DeviceName %x\n",DeviceName);
next = &string[0];
current = next+1;
current_ino = MINIX_ROOT_INO;
while (next!=NULL && current_ino!=0)
{
MinixReadInode(DeviceObject,DeviceExt,current_ino,&current_dir);
DPRINT("current %w next %x\n",current,next);
*next = '\\';
current = next+1;
next = wcschr(next+1,'\\');
if (next!=NULL)
{
*next=0;
}
current_ino = MinixDirLookup(DeviceObject,&current_dir,current);
}
if (next==NULL && current_ino!=0)
{
MinixReadInode(DeviceObject,DeviceExt,current_ino,&current_dir);
}
memcpy(result,&current_dir,sizeof(struct minix_inode));
DPRINT("MinxOpen() = STATUS_SUCCESS\n",0);
return(STATUS_SUCCESS);
}
NTSTATUS MinixWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
DPRINT("MinixWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
Irp->IoStatus.Information = 0;
return(STATUS_UNSUCCESSFUL);
}
NTSTATUS MinixRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
ULONG Length;
PVOID Buffer;
ULONG Offset;
ULONG CurrentOffset;
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = Stack->FileObject;
MINIX_DEVICE_EXTENSION* DeviceExt = DeviceObject->DeviceExtension;
struct minix_inode* inode = (struct minix_inode *)FileObject->FsContext;
PVOID TempBuffer;
unsigned int i;
DPRINT("MinixRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
Length = Stack->Parameters.Read.Length;
Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
Offset = Stack->Parameters.Read.ByteOffset.LowPart;
TempBuffer = ExAllocatePool(NonPagedPool,BLOCKSIZE);
DPRINT("Length %x Buffer %x Offset %x\n",Length,Buffer,Offset);
CurrentOffset=Offset;
if ((Offset%BLOCKSIZE)!=0)
{
CHECKPOINT;
CurrentOffset = Offset - (Offset%BLOCKSIZE);
MinixReadBlock(DeviceExt->AttachedDevice,inode,
CurrentOffset/BLOCKSIZE,
TempBuffer);
memcpy(Buffer,TempBuffer+(Offset%BLOCKSIZE),
min(BLOCKSIZE - (Offset%BLOCKSIZE),Length));
DPRINT("(BLOCKSIZE - (Offset%BLOCKSIZE)) %d\n",
(BLOCKSIZE - (Offset%BLOCKSIZE)));
DPRINT("Length %d\n",Length);
CurrentOffset = CurrentOffset + BLOCKSIZE;
Buffer = Buffer + BLOCKSIZE - (Offset%BLOCKSIZE);
Length = Length - min(BLOCKSIZE - (Offset%BLOCKSIZE),Length);
DPRINT("CurrentOffset %d Buffer %x Length %d\n",CurrentOffset,Buffer,
Length);
}
for (i=0;i<(Length/BLOCKSIZE);i++)
{
CHECKPOINT;
MinixReadBlock(DeviceExt->AttachedDevice,inode,
CurrentOffset/BLOCKSIZE,Buffer);
CurrentOffset = CurrentOffset + BLOCKSIZE;
Buffer = Buffer + BLOCKSIZE;
Length = Length - BLOCKSIZE;
}
if (Length > 0)
{
CHECKPOINT;
MinixReadBlock(DeviceExt->AttachedDevice,inode,
CurrentOffset/BLOCKSIZE,
TempBuffer);
memcpy(Buffer,TempBuffer,Length);
}
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = Length;
return(STATUS_SUCCESS);
}
NTSTATUS MinixClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = Stack->FileObject;
DPRINT("MinixClose(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
ExFreePool(FileObject->FsContext);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(STATUS_SUCCESS);
}
NTSTATUS MinixCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = Stack->FileObject;
NTSTATUS Status;
struct minix_inode* result;
MINIX_DEVICE_EXTENSION* DeviceExt;
DPRINT("MinixCreate(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
DPRINT("Opening file %x %w\n",FileObject->FileName.Buffer,
FileObject->FileName.Buffer);
DPRINT("FileObject->FileName.Buffer %x\n",
FileObject->FileName.Buffer);
DeviceExt = (MINIX_DEVICE_EXTENSION *)DeviceObject->DeviceExtension;
result = ExAllocatePool(NonPagedPool,sizeof(struct minix_inode));
DPRINT("result %x\n",result);
Status = MinixOpen(DeviceExt->AttachedDevice,DeviceExt,
FileObject->FileName.Buffer,result);
if (Status==STATUS_SUCCESS)
{
FileObject->FsContext=result;
}
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Status);
}
NTSTATUS DriverEntry(PDRIVER_OBJECT _DriverObject,
PUNICODE_STRING RegistryPath)
/*
* FUNCTION: Called by the system to initalize the driver
* ARGUMENTS:
* DriverObject = object describing this driver
* RegistryPath = path to our configuration entries
* RETURNS: Success or failure
*/
{
PDEVICE_OBJECT DeviceObject;
NTSTATUS ret;
UNICODE_STRING ustr;
ANSI_STRING astr;
DbgPrint("Minix FSD 0.0.1\n");
DriverObject = _DriverObject;
RtlInitAnsiString(&astr,"\\Device\\Minix");
RtlAnsiStringToUnicodeString(&ustr,&astr,TRUE);
ret = IoCreateDevice(DriverObject,0,&ustr,
FILE_DEVICE_PARALLEL_PORT,0,FALSE,&DeviceObject);
if (ret!=STATUS_SUCCESS)
{
return(ret);
}
DeviceObject->Flags=0;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = MinixClose;
DriverObject->MajorFunction[IRP_MJ_CREATE] = MinixCreate;
DriverObject->MajorFunction[IRP_MJ_READ] = MinixRead;
DriverObject->MajorFunction[IRP_MJ_WRITE] = MinixWrite;
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
MinixFileSystemControl;
DriverObject->DriverUnload = NULL;
IoRegisterFileSystem(DeviceObject);
return(STATUS_SUCCESS);
}

View file

@ -0,0 +1,80 @@
#define MINIX_ROOT_INO 1
/* Not the same as the bogus LINK_MAX in <linux/limits.h>. Oh well. */
#define MINIX_LINK_MAX 250
#define MINIX_I_MAP_SLOTS 8
#define MINIX_Z_MAP_SLOTS 64
#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */
#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
#define MINIX_VALID_FS 0x0001 /* Clean fs. */
#define MINIX_ERROR_FS 0x0002 /* fs has errors. */
#define MINIX_INODES_PER_BLOCK ((BLOCKSIZE)/(sizeof (struct minix_inode)))
#define MINIX2_INODES_PER_BLOCK ((BLOCKSIZE)/(sizeof (struct minix2_inode)))
#define MINIX_V1 0x0001 /* original minix fs */
#define MINIX_V2 0x0002 /* minix V2 fs */
/*
* This is the original minix inode layout on disk.
* Note the 8-bit gid and atime and ctime.
*/
struct minix_inode {
unsigned short int i_mode;
unsigned short int i_uid;
unsigned long i_size;
unsigned long i_time;
unsigned char i_gid;
unsigned char i_nlinks;
unsigned short int i_zone[9];
};
/*
* The new minix inode has all the time entries, as well as
* long block numbers and a third indirect block (7+1+1+1
* instead of 7+1+1). Also, some previously 8-bit values are
* now 16-bit. The inode is now 64 bytes instead of 32.
*/
struct minix2_inode {
unsigned short int i_mode;
unsigned short int i_nlinks;
unsigned short int i_uid;
unsigned short int i_gid;
unsigned long i_size;
unsigned long i_atime;
unsigned long i_mtime;
unsigned long i_ctime;
unsigned long i_zone[10];
};
/*
* minix super-block data on disk
*/
struct minix_super_block {
unsigned short int s_ninodes;
unsigned short int s_nzones;
unsigned short int s_imap_blocks;
unsigned short int s_zmap_blocks;
unsigned short int s_firstdatazone;
unsigned short int s_log_zone_size;
unsigned long s_max_size;
unsigned short int s_magic;
unsigned short int s_state;
unsigned long s_zones;
};
struct minix_dir_entry {
unsigned short int inode;
char name[0];
};
#define MINIX_DIR_ENTRY_SIZE (sizeof(struct minix_dir_entry)+30)
BOOLEAN MinixReadSector(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN UCHAR* Buffer);
#define BLOCKSIZE (1024)

View file

@ -0,0 +1,40 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: include/internal/iomgr.h
* PURPOSE: Internal io manager declarations
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/97: Created
*/
#ifndef __INCLUDE_INTERNAL_IOMGR_H
#define __INCLUDE_INTERNAL_IOMGR_H
#include <ddk/ntddk.h>
#include <internal/ob.h>
/*
* FUNCTION: Called to initalize a loaded driver
* ARGUMENTS:
* entry = pointer to the driver initialization routine
* RETURNS: Success or failure
*/
NTSTATUS InitalizeLoadedDriver(PDRIVER_INITIALIZE entry);
VOID IoInitCancelHandling(VOID);
VOID IoInitSymbolicLinkImplementation(VOID);
NTSTATUS IoTryToMountStorageDevice(PDEVICE_OBJECT DeviceObject);
POBJECT IoOpenSymlink(POBJECT SymbolicLink);
POBJECT IoOpenFileOnDevice(POBJECT SymbolicLink, PWCHAR Name);
PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction,
PDEVICE_OBJECT DeviceObject,
PKEVENT UserEvent,
PIO_STATUS_BLOCK IoStatusBlock,
PDEVICE_OBJECT DeviceToMount);
#endif

View file

@ -0,0 +1,97 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: include/internal/objmgr.h
* PURPOSE: Object manager definitions
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
#ifndef __INCLUDE_INTERNAL_OBJMGR_H
#define __INCLUDE_INTERNAL_OBJMGR_H
#include <ddk/types.h>
typedef struct
{
CSHORT Type;
CSHORT Size;
} COMMON_BODY_HEADER, *PCOMMON_BODY_HEADER;
typedef PVOID POBJECT;
typedef struct _DIRECTORY_OBJECT
{
CSHORT Type;
CSHORT Size;
/*
* PURPOSE: Head of the list of our subdirectories
*/
LIST_ENTRY head;
KSPIN_LOCK Lock;
} DIRECTORY_OBJECT, *PDIRECTORY_OBJECT;
/*
* Enumeration of object types
*/
enum
{
OBJTYP_INVALID,
OBJTYP_TYPE,
OBJTYP_DIRECTORY,
OBJTYP_SYMLNK,
OBJTYP_DEVICE,
OBJTYP_THREAD,
OBJTYP_FILE,
OBJTYP_MAX,
};
BOOL ObAddObjectToNameSpace(PUNICODE_STRING path, POBJECT_HEADER Object);
VOID ObRegisterType(CSHORT id, OBJECT_TYPE* type);
VOID ObInitializeObjectHeader(CSHORT id, PWSTR name,
POBJECT_HEADER obj);
/*
* FUNCTION: Get the size of an object
* ARGUMENTS:
* Type = Object type
* RETURNS: The size in bytes
*/
ULONG ObSizeOf(CSHORT Type);
HANDLE ObAddHandle(PVOID obj);
VOID ObDeleteHandle(HANDLE Handle);
NTSTATUS ObLookupObject(HANDLE rootdir, PWSTR string, PVOID* Object,
PWSTR* UnparsedSection);
PVOID ObGetObjectByHandle(HANDLE h);
PVOID ObGenericCreateObject(PHANDLE Handle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
CSHORT Type);
NTSTATUS ObOpenObjectByName(POBJECT_ATTRIBUTES ObjectAttributes,
PVOID* Object, PWSTR* UnparsedSection);
/*
* FUNCTION: Creates an entry within a directory
* ARGUMENTS:
* parent = Parent directory
* object = Header of the object to add
*/
VOID ObCreateEntry(PDIRECTORY_OBJECT parent, POBJECT_HEADER object);
extern inline POBJECT_HEADER BODY_TO_HEADER(PVOID body)
{
PCOMMON_BODY_HEADER chdr = (PCOMMON_BODY_HEADER)body;
return(CONTAINING_RECORD((&(chdr->Type)),OBJECT_HEADER,Type));
}
extern inline PVOID HEADER_TO_BODY(POBJECT_HEADER obj)
{
return(((void *)obj)+sizeof(OBJECT_HEADER)-sizeof(COMMON_BODY_HEADER));
}
#define OBJECT_ALLOC_SIZE(type) (ObSizeOf(type)+sizeof(OBJECT_HEADER)-sizeof(COMMON_BODY_HEADER))
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */

View file

@ -0,0 +1,53 @@
#ifndef __INCLUDE_INTERNAL_PSMGR_H
#define __INCLUDE_INTERNAL_PSMGR_H
#include <internal/hal.h>
extern EPROCESS SystemProcess;
extern HANDLE SystemProcessHandle;
void PsInitThreadManagment(void);
VOID PsInitProcessManagment(VOID);
VOID PsInitIdleThread(VOID);
/*
* PURPOSE: Thread states
*/
enum
{
/*
* PURPOSE: Don't touch
*/
THREAD_STATE_INVALID,
/*
* PURPOSE: Waiting to be dispatched
*/
THREAD_STATE_RUNNABLE,
/*
* PURPOSE: Currently running
*/
THREAD_STATE_RUNNING,
/*
* PURPOSE: Doesn't want to run
*/
THREAD_STATE_SUSPENDED,
/*
* Waiting to be freed
*/
THREAD_STATE_TERMINATED,
};
/*
* Functions the HAL must provide
*/
void HalInitFirstTask(PKTHREAD thread);
BOOLEAN HalInitTask(PKTHREAD thread, PKSTART_ROUTINE fn,
PVOID StartContext);
void HalTaskSwitch(PKTHREAD thread);
#endif

View file

@ -0,0 +1,232 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/buildirp.c
* PURPOSE: Building various types of irp
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction,
PDEVICE_OBJECT DeviceObject,
PKEVENT UserEvent,
PIO_STATUS_BLOCK IoStatusBlock,
PDEVICE_OBJECT DeviceToMount)
/*
* FUNCTION: Allocates and sets up a filesystem control IRP
* ARGUMENTS:
* MinorFunction = Type of filesystem control
* DeviceObject = Device object to send the request to
*/
{
PIRP Irp;
PIO_STACK_LOCATION StackPtr;
Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
if (Irp==NULL)
{
return(NULL);
}
Irp->UserIosb = IoStatusBlock;
Irp->UserEvent = UserEvent;
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = IRP_MJ_FILE_SYSTEM_CONTROL;
StackPtr->MinorFunction = MinorFunction;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Mount.Vpb = DeviceObject->Vpb;
StackPtr->Parameters.Mount.DeviceObject = DeviceToMount;
return(Irp);
}
PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction,
PDEVICE_OBJECT DeviceObject,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER StartingOffset,
PIO_STATUS_BLOCK IoStatusBlock)
/*
* FUNCTION: Allocates and sets up an IRP to be sent to lower level drivers
* ARGUMENTS:
* MajorFunction = One of IRP_MJ_READ, IRP_MJ_WRITE,
* IRP_MJ_FLUSH_BUFFERS or IRP_MJ_SHUTDOWN
* DeviceObject = Device object to send the irp to
* Buffer = Buffer into which data will be read or written
* Length = Length in bytes of the irp to be allocated
* StartingOffset = Starting offset on the device
* IoStatusBlock (OUT) = Storage for the result of the operation
* RETURNS: The IRP allocated on success, or
* NULL on failure
*/
{
PIRP Irp;
PIO_STACK_LOCATION StackPtr;
Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
if (Irp==NULL)
{
return(NULL);
}
Irp->UserBuffer = (LPVOID)Buffer;
if (DeviceObject->Flags&DO_BUFFERED_IO)
{
DPRINT("Doing buffer i/o\n",0);
Irp->AssociatedIrp.SystemBuffer = (PVOID)
ExAllocatePool(NonPagedPool,Length);
if (Irp->AssociatedIrp.SystemBuffer==NULL)
{
return(NULL);
}
Irp->UserBuffer = NULL;
}
if (DeviceObject->Flags&DO_DIRECT_IO)
{
DPRINT("Doing direct i/o\n",0);
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
Irp->UserBuffer = NULL;
Irp->AssociatedIrp.SystemBuffer = NULL;
}
Irp->UserIosb = IoStatusBlock;
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = MajorFunction;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = Length;
if (StartingOffset!=NULL)
{
StackPtr->Parameters.Write.ByteOffset.LowPart =
StartingOffset->LowPart;
StackPtr->Parameters.Write.ByteOffset.HighPart =
StartingOffset->HighPart;
}
else
{
StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
}
return(Irp);
}
PIRP IoBuildDeviceIoControlRequest(ULONG IoControlCode,
PDEVICE_OBJECT DeviceObject,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength,
BOOLEAN InternalDeviceIoControl,
PKEVENT Event,
PIO_STATUS_BLOCK IoStatusBlock)
{
UNIMPLEMENTED;
}
PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
PDEVICE_OBJECT DeviceObject,
PVOID Buffer,
ULONG Length,
PLARGE_INTEGER StartingOffset,
PKEVENT Event,
PIO_STATUS_BLOCK IoStatusBlock)
/*
* FUNCTION: Allocates and builds an IRP to be sent synchronously to lower
* level driver(s)
* ARGUMENTS:
* MajorFunction = Major function code, one of IRP_MJ_READ,
* IRP_MJ_WRITE, IRP_MJ_FLUSH_BUFFERS, IRP_MJ_SHUTDOWN
* DeviceObject = Target device object
* Buffer = Buffer containing data for a read or write
* Length = Length in bytes of the information to be transferred
* StartingOffset = Offset to begin the read/write from
* Event (OUT) = Will be set when the operation is complete
* IoStatusBlock (OUT) = Set to the status of the operation
* RETURNS: The IRP allocated on success, or
* NULL on failure
*/
{
PIRP Irp;
PIO_STACK_LOCATION StackPtr;
DPRINT("IoBuildSynchronousFsdRequest(MajorFunction %x, DeviceObject %x, "
"Buffer %x, Length %x, StartingOffset %x, Event %x, "
"IoStatusBlock %x\n",MajorFunction,DeviceObject,Buffer,Length,
StartingOffset,Event,IoStatusBlock);
Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
if (Irp==NULL)
{
return(NULL);
}
Irp->UserBuffer = (LPVOID)Buffer;
if (DeviceObject->Flags&DO_BUFFERED_IO)
{
DPRINT("Doing buffer i/o\n",0);
Irp->AssociatedIrp.SystemBuffer = (PVOID)
ExAllocatePool(NonPagedPool,Length);
if (Irp->AssociatedIrp.SystemBuffer==NULL)
{
return(NULL);
}
Irp->UserBuffer = NULL;
}
if (DeviceObject->Flags&DO_DIRECT_IO)
{
DPRINT("Doing direct i/o\n",0);
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
Irp->UserBuffer = NULL;
Irp->AssociatedIrp.SystemBuffer = NULL;
}
Irp->UserIosb = IoStatusBlock;
Irp->UserEvent = Event;
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = MajorFunction;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = Length;
if (StartingOffset!=NULL)
{
StackPtr->Parameters.Write.ByteOffset.LowPart =
StartingOffset->LowPart;
StackPtr->Parameters.Write.ByteOffset.HighPart =
StartingOffset->HighPart;
}
else
{
StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
}
return(Irp);
}

41
reactos/ntoskrnl/io/vpb.c Normal file
View file

@ -0,0 +1,41 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/vpb.c
* PURPOSE: Volume Parameters Block managment
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/string.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS IoAttachVpb(PDEVICE_OBJECT DeviceObject)
{
PVPB Vpb;
Vpb = ExAllocatePool(NonPagedPool,sizeof(VPB));
if (Vpb==NULL)
{
return(STATUS_UNSUCCESSFUL);
}
Vpb->Type = 0;
Vpb->Size = sizeof(VPB) / sizeof(DWORD);
Vpb->Flags = 0;
Vpb->VolumeLabelLength = 0;
Vpb->DeviceObject = NULL;
Vpb->RealDevice = DeviceObject;
Vpb->SerialNumber = 0;
Vpb->ReferenceCount = 0;
memset(Vpb->VolumeLabel,0,sizeof(WCHAR)*MAXIMUM_VOLUME_LABEL_LENGTH);
DeviceObject->Vpb = Vpb;
}

View file

@ -0,0 +1,90 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/tst/readline.c
* PURPOSE: Simple readline library
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* 28/05/98: Created
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/string.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
static HANDLE KeyboardHandle = NULL;
/* FUNCTIONS ****************************************************************/
static unsigned char TstReadLineReadChar(VOID)
{
KEY_EVENT_RECORD key[2];
ZwReadFile(KeyboardHandle,
NULL,
NULL,
NULL,
NULL,
&key[0],
sizeof(KEY_EVENT_RECORD)*2,
0,
0);
// DbgPrint("%c",key[0].AsciiChar);
return(key[0].AsciiChar);
}
VOID TstReadLine(ULONG Length, PCHAR Buffer)
{
char* current = Buffer;
char tmp;
unsigned int i;
for (i=0;i<Length;i++)
{
tmp = TstReadLineReadChar();
DbgPrint("%c",tmp);
// DbgPrint("%x %x ",tmp,'\n');
switch (tmp)
{
case 0xd:
*current = 0;
DbgPrint("\n");
return;
default:
*current = tmp;
current++;
}
}
*current=0;
DbgPrint("\n");
}
VOID TstReadLineInit(VOID)
{
OBJECT_ATTRIBUTES attr;
HANDLE hfile;
ANSI_STRING afilename;
UNICODE_STRING ufilename;
DbgPrint("Opening keyboard\n");
RtlInitAnsiString(&afilename,"\\Device\\Keyboard");
RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE);
InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL);
ZwOpenFile(&KeyboardHandle,0,&attr,NULL,0,0);
if (KeyboardHandle==NULL)
{
DbgPrint("Failed to open keyboard\n");
return;
}
}