1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* PSX-Tools Bundle Pack
* Copyright (C) 2002-2003 Nicolas "Pixel" Noble
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: cdutils.h,v 1.21 2006-11-13 22:00:12 pixel Exp $ */
#ifndef __CDUTILS_H__
#define __CDUTILS_H__
#include "yazedc.h"
#include "generic.h"
#include "Handle.h"
#define MODE0 0
#define MODE1 1
#define MODE2 2
#define MODE2_FORM1 3
#define MODE2_FORM2 4
#define MODE_RAW 5
#define GUESS 6
extern const long sec_sizes[];
extern const long sec_offsts[];
extern const String sec_modes[];
#ifdef _MSC_VER
#pragma pack(1)
#endif
class cdutils : public Base {
public:
cdutils(Handle * f_iso_r, Handle * f_iso_w = 0);
virtual ~cdutils();
#ifdef _MSC_VER
#pragma pack(push)
#pragma pack(1)
#endif
struct DirEntry {
unsigned char R;
unsigned char NExt;
unsigned long Sector;
unsigned long BESector;
unsigned long Size;
unsigned long BESize;
unsigned char Year;
unsigned char Month;
unsigned char Day;
unsigned char Hour;
unsigned char Minute;
unsigned char Second;
unsigned char Offset;
unsigned char Flags;
unsigned char HandleUnit;
unsigned char HandleGap;
unsigned short VolSeq;
unsigned short BEVolSeq;
unsigned char N;
char id[1];
} PACKED;
#ifdef _MSC_VER
#pragma pack(pop)
#endif
struct DirEntry * rootDir;
Handle * open_ppf(const String & ppf, const String & comment) throw(GeneralException);
void close_ppf() throw(GeneralException);
void set_iso_w(Handle *);
static Uint16 swap_word(Uint16 i);
static Uint32 swap_dword(Uint32 i);
static Uint16 from_LE16(Uint16 i);
static Uint32 from_LE32(Uint32 i);
static Uint16 from_BE16(Uint16 i);
static Uint32 from_BE32(Uint32 i);
static Uint16 to_LE16(Uint16 i) { return from_LE16(i); }
static Uint32 to_LE32(Uint32 i) { return from_LE32(i); }
static Uint16 to_BE16(Uint16 i) { return from_BE16(i); }
static Uint32 to_BE32(Uint32 i) { return from_BE32(i); }
int guess_type(int number = -1);
void sector_seek(long sector);
long read_sector(Byte * buffer, int type = GUESS, int number = -1);
void read_data(Byte * buffer, long size, int type = GUESS, int number = -1);
void read_file(Handle * Handle, long size, int type = GUESS, int number = -1);
void write_sector(Byte * buffer, int type = GUESS, int number = -1) throw (GeneralException);
void write_data(Byte * buffer, long size, int type = GUESS, int number = -1);
void write_file(Handle * Handle, long size = -1, int type = GUESS, int number = -1);
void create_sector(int type, int number, bool eof = false) throw (GeneralException);
int get_iso_infos();
int show_iso_infos();
int get_pt_infos();
int show_pt_infos();
struct DirEntry find_path(const String & path);
struct DirEntry find_parent(const String & path);
struct DirEntry * find_path(Byte ** buffer, const String & path);
struct DirEntry * find_parent(Byte ** buffer, const String & path);
void show_head_entry(void);
int show_entry(struct DirEntry * dir);
int show_dir(struct DirEntry * dir);
struct DirEntry find_dir_entry(struct DirEntry * dir, const String & name);
struct DirEntry * find_dir_entry(Byte ** buffer, struct DirEntry * dir, const String & name);
static Uint8 from_BCD(Uint8 x);
static Uint8 to_BCD(Uint8 x);
static bool is_valid_BCD(Uint8 x);
static Uint32 from_MSF(Uint32 msf, Uint32 start = 150);
static Uint32 from_MSF(Uint8 m, Uint8 s, Uint8 f, Uint32 start = 150);
static Uint32 to_MSF(int sect, Uint32 start = 150);
static void to_MSF(int sect, Uint8 & m, Uint8 & s, Uint8 & f, Uint32 start = 150);
private:
void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num);
String format_date(const String & input);
yazedc yazedc_o;
Handle * f_iso_r, * f_iso_w, * ppf_file;
int pt1, pt2, snum, ptl, root;
};
class cdfile : public Handle {
public:
cdfile(cdutils *, const cdutils::DirEntry *, int = GUESS);
cdfile(cdutils *, int sector, ssize_t = -1, int = GUESS);
virtual ~cdfile();
virtual ssize_t read(void *buf, size_t count) throw (GeneralException);
virtual bool CanRead() const;
virtual String GetName() const;
virtual bool CanWatch() const;
virtual ssize_t GetSize() const;
virtual bool CanSeek() const;
virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
private:
cdutils * cd;
int sector, mode;
size_t size;
String name;
cdutils::DirEntry * dir;
};
#endif
|