Fix a bug (in revision 426) which made "Mode 3 - Unhook Syscalls" un-effectivei ...
[open-ps2-loader.git] / modules / ps2fs / pfs.h
blobcd1b07bd1ac00affbff39f1fd0cf1b2f0282a4fc
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
10 # $Id: pfs.h 1421 2007-07-07 01:56:53Z radad $
13 #ifndef _PFS_H
14 #define _PFS_H
16 #include <types.h>
17 #include <defs.h>
18 #include <irx.h>
19 #include <loadcore.h>
20 #include <poweroff.h>
21 #include <sysmem.h>
22 #include <stdio.h>
23 #include <sysclib.h>
24 #include <errno.h>
25 #include <sys/fcntl.h>
26 #include <sys/stat.h>
27 #include <iomanX.h>
28 #include <thsemap.h>
29 #include <intrman.h>
30 #include <cdvdman.h>
32 #include "pfs_types.h"
34 #ifndef min
35 #define min(a, b) ((a) < (b) ? (a) : (b))
36 #endif
38 #define PFS_MAJOR 1
39 #define PFS_MINOR 0
41 ///////////////////////////////////////////////////////////////////////////////
42 // Global types
44 typedef int (*deviceTransfer_p)(int fd, void *buffer, /*u16*/u32 sub, u32 sector, u32 size, u32 mode);
45 typedef u32 (*deviceGetSubNumber_p)(int fd);
46 typedef u32 (*deviceGetSize_p)(int fd, /*u16*/u32 sub/*0=main 1+=subs*/);
47 typedef void (*deviceSetPartError_p)(int fd);
48 typedef int/*0 only :P*/ (*deviceFlushCache_p)(int fd);
50 typedef struct {
51 char *devName; //
52 deviceTransfer_p transfer; //
53 deviceGetSubNumber_p getSubNumber; //
54 deviceGetSize_p getSize; //
55 deviceSetPartError_p setPartitionError; // set open partition as haveing a error
56 deviceFlushCache_p flushCache; //
58 } block_device;
61 typedef struct {
62 block_device *blockDev; // call table for hdd(hddCallTable)
63 int fd; //
64 u32 flags; // rename to attr ones checked
65 u32 total_sector; // number of sectors in the filesystem
66 u32 zfree; // zone free
67 u32 sector_scale; //
68 u32 inode_scale; //
69 u32 zsize; // zone size
70 u32 num_subs; // number of sub partitions in the filesystem
71 pfs_blockinfo root_dir; // block info for root directory
72 pfs_blockinfo log; // block info for the log
73 pfs_blockinfo current_dir; // block info for current directory
74 u32 lastError; // 0 if no error :)
75 u16 uid; //
76 u16 gid; //
77 u32 free_zone[65]; // free zones in each partition (1 main + 64 possible subs)
78 } pfs_mount_t;
80 typedef struct pfs_cache_s {
81 struct pfs_cache_s *next; //
82 struct pfs_cache_s *prev; //
83 u16 flags; //
84 u16 nused; //
85 pfs_mount_t *pfsMount; //
86 u32 sub; // main(0)/sub(+1) partition
87 u32 sector; // block/sector for partition
88 union{ //
89 void *data;
90 pfs_inode *inode;
91 pfs_aentry_t *aentry;
92 pfs_dentry *dentry;
93 pfs_super_block *superblock;
94 u32 *bitmap;
95 } u;
96 } pfs_cache_t;
98 typedef struct
100 u16 dirty; //
101 u16 sub; // Sub/main partition
102 u32 sector; // Sector
103 } pfs_restsInfo_t;
105 typedef struct
107 char key[256];
108 char value[256];
109 } pfs_ioctl2attr_t;
111 typedef struct
113 pfs_cache_t *inode;
114 u32 block_segment; // index into data array in inode structure for current zone segment
115 u32 block_offset; // block offset from start of current zone segment
116 u32 byte_offset; // byte offset into current zone
117 } pfs_blockpos_t;
119 typedef struct {
120 iop_file_t *fd; //
121 pfs_cache_t *clink; //
122 u32 aentryOffset; // used for read offset
123 u64 position; //
124 pfs_blockpos_t block_pos; // current position into file
125 pfs_restsInfo_t restsInfo; //
126 u8 restsBuffer[512]; // used for reading mis-aligned/remainder data
127 } pfs_file_slot_t;
129 typedef struct {
130 u32 maxMount;
131 u32 maxOpen;
132 } pfs_config_t;
134 ///////////////////////////////////////////////////////////////////////////////
135 // Global defines
137 // attribute flags
138 #define FIO_ATTR_READABLE 0x0001
139 #define FIO_ATTR_WRITEABLE 0x0002
140 #define FIO_ATTR_EXECUTABLE 0x0004
141 #define FIO_ATTR_COPYPROTECT 0x0008
142 #define FIO_ATTR_UNK0010 0x0010
143 #define FIO_ATTR_SUBDIR 0x0020
144 #define FIO_ATTR_UNK0040 0x0040
145 #define FIO_ATTR_CLOSED 0x0080
146 #define FIO_ATTR_UNK0100 0x0100
147 #define FIO_ATTR_UNK0200 0x0200
148 #define FIO_ATTR_UNK0400 0x0400
149 #define FIO_ATTR_PDA 0x0800
150 #define FIO_ATTR_PSX 0x1000
151 #define FIO_ATTR_UNK2000 0x2000
152 #define FIO_ATTR_HIDDEN 0x4000
154 // cache flags(status)
155 #define CACHE_FLAG_DIRTY 0x01
156 #define CACHE_FLAG_NOLOAD 0x02
157 #define CACHE_FLAG_MASKSTATUS 0x0F
159 // cache flags(types)
160 #define CACHE_FLAG_NOTHING 0x00
161 #define CACHE_FLAG_SEGD 0x10
162 #define CACHE_FLAG_SEGI 0x20
163 #define CACHE_FLAG_BITMAP 0x40
164 #define CACHE_FLAG_MASKTYPE 0xF0
166 // fsck stats
167 #define FSCK_STAT_OK 0x00
168 #define FSCK_STAT_WRITE_ERROR 0x01
169 #define FSCK_STAT_ERROR_0x02 0x02
171 // odd and end
172 #define MODE_SET_FLAG 0x00
173 #define MODE_REMOVE_FLAG 0x01
174 #define MODE_CHECK_FLAG 0x02
176 // mount flags
177 #define MOUNT_BUSY 0x8000
179 ///////////////////////////////////////////////////////////////////////////////
180 // Externs
182 extern pfs_file_slot_t *fileSlots;
183 extern pfs_config_t pfsConfig;
184 extern pfs_cache_t *cacheBuf;
185 extern u32 numBuffers;
186 extern u32 metaSize;
187 extern int blockSize;
188 extern pfs_mount_t *pfsMountBuf;
189 extern int symbolicLinks;
190 extern int pfsFioSema;
192 ///////////////////////////////////////////////////////////////////////////////
193 // Function declerations
195 pfs_mount_t * getMountedUnit(u32 unit);
196 void clearMount(pfs_mount_t *pfsMount);
198 extern int pfsDebug;
200 ///////////////////////////////////////////////////////////////////////////////
201 // Debug stuff
203 #define DEBUG_CALL_LOG
204 #define DEBUG_VERBOSE_LOG
206 #ifdef DEBUG_VERBOSE_LOG
207 #define dprintf if(pfsDebug) printf
208 #else
209 #define dprintf(format, args...)
210 #endif
212 #ifdef DEBUG_CALL_LOG
213 #define dprintf2 if(pfsDebug) printf
214 #else
215 #define dprintf2(format, args...)
216 #endif
218 #include "misc.h"
219 #include "bitmap.h"
220 #include "dir.h"
221 #include "inode.h"
222 #include "journal.h"
223 #include "super.h"
224 #include "cache.h"
225 #include "block.h"
226 #include "pfs_fio.h"
227 #include "pfs_fioctl.h"
229 #endif /* _PFS_H */