initial commit
[iso2ps2.git] / ps2classic / iso.h
1 #ifndef __LIBISO_H__
2 #define __LIBISO_H__
3
4 #define ISOTYPE_ILLEGAL 0
5 #define ISOTYPE_CD 1
6 #define ISOTYPE_DVD 2
7 #define ISOTYPE_AUDIO 3
8 #define ISOTYPE_DVDDL 4
9
10 #define ISOFLAGS_Z 0x0001
11 #define ISOFLAGS_Z2 0x0002
12 #define ISOFLAGS_BLOCKDUMP 0x0004
13 #define ISOFLAGS_MULTI 0x0008
14 #define ISOFLAGS_BZ2 0x0010
15
16 #define CD_FRAMESIZE_RAW 2352
17 #define DATA_SIZE (CD_FRAMESIZE_RAW-12)
18
19 #define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */
20 #define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */
21
22 #include "types.h"
23
24 typedef struct
25 {
26 u32 slsn;
27 u32 elsn;
28 void *handle;
29 } _multih;
30
31 struct isoFile
32 {
33 char filename[256];
34 u32 type;
35 u32 flags;
36 u32 offset;
37 u32 blockofs;
38 u32 blocksize;
39 u32 blocks;
40 void *handle;
41 void *htable;
42 char *Ztable;
43 u32 *dtable;
44 int dtablesize;
45 _multih multih[8];
46 int buflsn;
47 u8 *buffer;
48 };
49
50
51 struct rootDirTocHeader
52 {
53 u16 length; //+00
54 u32 tocLBA; //+02
55 u32 tocLBA_bigend; //+06
56 u32 tocSize; //+0A
57 u32 tocSize_bigend; //+0E
58 u8 dateStamp[8]; //+12
59 u8 reserved[6]; //+1A
60 u8 reserved2; //+20
61 u8 reserved3; //+21
62 } __attribute__((packed));
63
64
65 struct asciiDate
66 {
67 char year[4];
68 char month[2];
69 char day[2];
70 char hours[2];
71 char minutes[2];
72 char seconds[2];
73 char hundreths[2];
74 char terminator[1];
75 } __attribute__((packed));
76
77
78 struct cdVolDesc
79 {
80 u8 filesystemType; // 0x01 = ISO9660, 0x02 = Joliet, 0xFF = NULL
81 u8 volID[5]; // "CD001"
82 u8 reserved2;
83 u8 reserved3;
84 u8 sysIdName[32];
85 u8 volName[32]; // The ISO9660 Volume Name
86 u8 reserved5[8];
87 u32 volSize; // Volume Size
88 u32 volSizeBig; // Volume Size Big-Endian
89 u8 reserved6[32];
90 u32 unknown1;
91 u32 unknown1_bigend;
92 u16 volDescSize; //+80
93 u16 volDescSize_bigend; //+82
94 u32 unknown3; //+84
95 u32 unknown3_bigend; //+88
96 u32 priDirTableLBA; // LBA of Primary Dir Table //+8C
97 u32 reserved7; //+90
98 u32 secDirTableLBA; // LBA of Secondary Dir Table //+94
99 u32 reserved8; //+98
100 struct rootDirTocHeader rootToc;
101 s8 volSetName[128];
102 s8 publisherName[128];
103 s8 preparerName[128];
104 s8 applicationName[128];
105 s8 copyrightFileName[37];
106 s8 abstractFileName[37];
107 s8 bibliographyFileName[37];
108 struct asciiDate creationDate;
109 struct asciiDate modificationDate;
110 struct asciiDate effectiveDate;
111 struct asciiDate expirationDate;
112 u8 reserved10;
113 u8 reserved11[1166];
114 } __attribute__((packed));
115
116
117
118 struct isoFile *isoOpen(const char *filename);
119 struct isoFile *isoCreate(const char *filename, int mode);
120 int isoSetFormat(struct isoFile *iso, int blockofs, int blocksize, int blocks);
121 int isoDetect(struct isoFile *iso);
122 int isoReadBlock(struct isoFile *iso, u8 *dst, u32 lsn);
123 int isoWriteBlock(struct isoFile *iso, u8 *src, u32 lsn);
124 void isoClose(struct isoFile *iso);
125 void print_ps2image_info(const char *image_name);
126 void prepare_iso(char image_name[]);
127
128 void *_openfile(const char *filename, int flags);
129 u64 _tellfile(void *handle);
130 int _seekfile(void *handle, u64 offset, int whence);
131 int _readfile(void *handle, void *dst, int size);
132 int _writefile(void *handle, void *src, int size);
133 void _closefile(void *handle);
134
135 #endif /* __LIBISO_H__ */