Lots of changes to the kernel
[reactos.git] / reactos / drivers / fs / ext2 / file.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/ext2/super.c
5 * PURPOSE: ext2 filesystem
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 #include "ext2fs.h"
18
19 /* FUNCTIONS ****************************************************************/
20
21 #define addr_per_block (BLOCKSIZE / sizeof(ULONG))
22
23 ULONG Ext2BlockMap(PDEVICE_EXTENSION DeviceExt,
24 struct ext2_inode* inode,
25 ULONG offset)
26 {
27 ULONG block;
28 PULONG TempBuffer;
29 BOOL b;
30
31 DPRINT("Ext2BlockMap(DeviceExt %x, inode %x, offset %d)\n",
32 DeviceExt,inode,offset);
33 if (offset < EXT2_NDIR_BLOCKS)
34 {
35 block = inode->i_block[offset];
36 DPRINT("block %d\n",block);
37 return(block);
38 }
39 offset = offset - EXT2_NDIR_BLOCKS;
40 if (offset < addr_per_block)
41 {
42 block = inode->i_block[EXT2_IND_BLOCK];
43 TempBuffer = ExAllocatePool(NonPagedPool, BLOCKSIZE);
44 b = Ext2ReadSectors(DeviceExt->StorageDevice,
45 block,
46 1,
47 TempBuffer);
48 if (!b)
49 {
50 DbgPrint("ext2fs:%s:%d: Disk io failed\n", __FILE__, __LINE__);
51 return(0);
52 }
53 block = TempBuffer[offset];
54 ExFreePool(TempBuffer);
55 return(block);
56 }
57 offset = offset - addr_per_block;
58 DbgPrint("Failed at %s:%d\n",__FILE__,__LINE__);
59 for(;;);
60 }
61