reactos/rosapps/drivers/ramdrv/minix/block.c
Aleksey Bragin f7f8963f3a - Gather drivers in a special "drivers" subdirectory.
- Remove legacy _USE_W32API from those drivers.

svn path=/trunk/; revision=32964
2008-04-14 20:49:45 +00:00

109 lines
2.1 KiB
C

/*
* 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 <ntddk.h>
//#define NDEBUG
#include <debug.h>
#include "minix.h"
/* FUNCTIONS ****************************************************************/
static unsigned int MinixGetBlock(PDEVICE_OBJECT DeviceObject,
PMINIX_DEVICE_EXTENSION DeviceExt,
struct minix_inode* inode,
ULONG FileOffset)
{
int block;
PVOID BaseAddress;
ULONG blk;
blk = FileOffset / BLOCKSIZE;
DPRINT("MinixGetBlock(inode %x, blk %d)\n",inode,blk);
/*
* The first few blocks are available in the inode
*/
if (blk < 7)
{
block = inode->i_zone[blk];
return(block);
}
blk = blk - 7;
/*
* Retrieve a single-indirect block
*/
if (blk < 512)
{
block = inode->i_zone[7];
BaseAddress = ExAllocatePool(NonPagedPool, 512);
MinixReadSector(DeviceObject,
block,
BaseAddress);
block = ((PUSHORT)(BaseAddress))[blk];
ExFreePool(BaseAddress);
return(block);
}
/*
* Get a double indirect block
*/
blk = blk - 512;
block = inode->i_zone[8];
BaseAddress = ExAllocatePool(NonPagedPool, 512);
MinixReadSector(DeviceObject,
block,
BaseAddress);
block = ((PUSHORT)BaseAddress)[(blk>>9)&511];
ExFreePool(BaseAddress);
BaseAddress = ExAllocatePool(NonPagedPool, 512);
MinixReadSector(DeviceObject,
block,
BaseAddress);
block = ((PUSHORT)BaseAddress)[blk&512];
ExFreePool(BaseAddress);
return(block);
}
NTSTATUS MinixReadBlock(PDEVICE_OBJECT DeviceObject,
PMINIX_DEVICE_EXTENSION DeviceExt,
struct minix_inode* inode,
ULONG FileOffset,
PULONG DiskOffset)
{
unsigned int block;
DPRINT("MinixReadBlock()\n");
block = MinixGetBlock(DeviceObject, DeviceExt,inode, FileOffset);
(*DiskOffset) = block * BLOCKSIZE;
return(STATUS_SUCCESS);
}