Skip to content

Latest commit

 

History

History
159 lines (130 loc) · 5.83 KB

fileio.h

File metadata and controls

159 lines (130 loc) · 5.83 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Mar 23, 2006
Mar 23, 2006
9
10
11
12
13
#ifndef _INCL_FILEIO_H_
#define _INCL_FILEIO_H_
#include "universal.h"
Mar 24, 2006
Mar 24, 2006
14
15
16
17
#ifdef __cplusplus
extern "C" {
#endif
Mar 23, 2006
Mar 23, 2006
18
19
20
21
22
23
24
/*
* File i/o may go through multiple layers: the archive attached to the binary,
* then an archive in there that's being read entirely out of memory that's
* being uncompressed to on the fly, or it might be a straight read from a
* regular uncompressed file on physical media. It might be a single file
* compressed with bzip2. As such, we have to have an abstraction over the
* usual channels...basically what we need here is archives-within-archives,
Dec 2, 2006
Dec 2, 2006
25
* done transparently and with arbitrary depth, although usually not more
Mar 23, 2006
Mar 23, 2006
26
27
28
29
* than one deep. This also works as a general transport layer, so the
* abstraction could be extended to network connections and such, too.
*/
Mar 25, 2006
Mar 25, 2006
30
// Abstract input interface. Files, memory, archive entries, etc.
Mar 23, 2006
Mar 23, 2006
31
32
33
typedef struct MojoInput MojoInput;
struct MojoInput
{
Mar 25, 2006
Mar 25, 2006
34
// public
May 7, 2007
May 7, 2007
35
boolean (*ready)(MojoInput *io);
Mar 26, 2006
Mar 26, 2006
36
int64 (*read)(MojoInput *io, void *buf, uint32 bufsize);
Mar 23, 2006
Mar 23, 2006
37
boolean (*seek)(MojoInput *io, uint64 pos);
Mar 26, 2006
Mar 26, 2006
38
39
40
int64 (*tell)(MojoInput *io);
int64 (*length)(MojoInput *io);
MojoInput* (*duplicate)(MojoInput *io);
Mar 23, 2006
Mar 23, 2006
41
42
void (*close)(MojoInput *io);
Mar 25, 2006
Mar 25, 2006
43
// private
Mar 23, 2006
Mar 23, 2006
44
45
46
void *opaque;
};
Jan 24, 2011
Jan 24, 2011
47
48
// If constant == 0, then this copies the memory, so you may free (ptr) after
// this function returns in that case.
Jan 13, 2008
Jan 13, 2008
49
MojoInput *MojoInput_newFromMemory(const uint8 *ptr, uint32 len, int constant);
Jan 24, 2011
Jan 24, 2011
50
51
// Get a MojoInput for a real file in the physical filesystem.
Mar 23, 2006
Mar 23, 2006
52
53
MojoInput *MojoInput_newFromFile(const char *fname);
Jan 24, 2011
Jan 24, 2011
54
55
56
57
58
// Make a subset range of (io) look like the entire file. This will take over
// control of (io), closing it when done, so never reference (io) directly
// again, if this call succeeds.
MojoInput *MojoInput_newFromSubset(MojoInput *io, const uint64 start,
const uint64 end);
Jan 13, 2008
Jan 13, 2008
59
Mar 25, 2006
Mar 25, 2006
60
61
typedef enum
{
Mar 25, 2006
Mar 25, 2006
62
63
MOJOARCHIVE_ENTRY_UNKNOWN = 0,
MOJOARCHIVE_ENTRY_FILE,
Mar 25, 2006
Mar 25, 2006
64
65
66
MOJOARCHIVE_ENTRY_DIR,
MOJOARCHIVE_ENTRY_SYMLINK,
} MojoArchiveEntryType;
Mar 23, 2006
Mar 23, 2006
67
Mar 25, 2006
Mar 25, 2006
68
// Abstract archive interface. Archives, directories, etc.
Apr 29, 2007
Apr 29, 2007
69
typedef struct MojoArchiveEntry
Mar 23, 2006
Mar 23, 2006
70
{
Mar 25, 2006
Mar 25, 2006
71
char *filename;
May 1, 2007
May 1, 2007
72
char *linkdest;
Mar 23, 2006
Mar 23, 2006
73
MojoArchiveEntryType type;
Mar 25, 2006
Mar 25, 2006
74
int64 filesize;
May 3, 2007
May 3, 2007
75
uint16 perms;
Apr 29, 2007
Apr 29, 2007
76
} MojoArchiveEntry;
Mar 23, 2006
Mar 23, 2006
77
May 4, 2007
May 4, 2007
78
void MojoArchive_resetEntry(MojoArchiveEntry *info);
Mar 26, 2006
Mar 26, 2006
79
80
Mar 23, 2006
Mar 23, 2006
81
82
83
typedef struct MojoArchive MojoArchive;
struct MojoArchive
{
Mar 25, 2006
Mar 25, 2006
84
// public
May 4, 2007
May 4, 2007
85
boolean (*enumerate)(MojoArchive *ar);
Apr 29, 2007
Apr 29, 2007
86
const MojoArchiveEntry* (*enumNext)(MojoArchive *ar);
Mar 23, 2006
Mar 23, 2006
87
88
89
MojoInput* (*openCurrentEntry)(MojoArchive *ar);
void (*close)(MojoArchive *ar);
Mar 25, 2006
Mar 25, 2006
90
// private
Mar 23, 2006
Mar 23, 2006
91
MojoInput *io;
Apr 29, 2007
Apr 29, 2007
92
MojoArchiveEntry prevEnum;
Jan 16, 2008
Jan 16, 2008
93
int64 offsetOfStart; // byte offset in MojoInput where archive starts.
Mar 23, 2006
Mar 23, 2006
94
95
96
void *opaque;
};
Mar 24, 2006
Mar 24, 2006
97
MojoArchive *MojoArchive_newFromDirectory(const char *dirname);
May 5, 2007
May 5, 2007
98
MojoArchive *MojoArchive_newFromInput(MojoInput *io, const char *origfname);
Mar 23, 2006
Mar 23, 2006
99
Dec 3, 2006
Dec 3, 2006
100
101
102
103
104
105
106
// This will reset enumeration in the archive, don't use it while iterating!
// Also, this can be very slow depending on the archive in question, so
// try to limit your random access filename lookups to known-fast quantities
// (like directories on the physical filesystem or a zipfile...tarballs and
// zipfiles-in-zipfiles will bog down here, for example).
MojoInput *MojoInput_newFromArchivePath(MojoArchive *ar, const char *fname);
Feb 28, 2010
Feb 28, 2010
107
108
109
110
111
112
113
114
115
// Wrap (origio) in a new MojoInput that decompresses a compressed stream
// on the fly. Returns NULL on error or if (origio) isn't a supported
// compressed format. The returned MojoInput wraps the original input;
// closing the returned MojoInput will close (origio), too, and you should
// consider origio lost. If this function returns non-NULL, you should not,
// under any circumstances, interact directly with origio again, as the
// new MojoInput now owns it.
MojoInput *MojoInput_newCompressedStream(MojoInput *origio);
Apr 24, 2010
Apr 24, 2010
116
// !!! FIXME: fill in missing documentation here.
Mar 25, 2006
Mar 25, 2006
117
extern MojoArchive *GBaseArchive;
May 20, 2007
May 20, 2007
118
extern const char *GBaseArchivePath;
Mar 25, 2006
Mar 25, 2006
119
120
121
MojoArchive *MojoArchive_initBaseArchive(void);
void MojoArchive_deinitBaseArchive(void);
May 8, 2007
May 8, 2007
122
123
typedef boolean (*MojoInput_FileCopyCallback)(uint32 ticks, int64 justwrote,
int64 bw, int64 total, void *data);
May 3, 2007
May 3, 2007
124
boolean MojoInput_toPhysicalFile(MojoInput *in, const char *fname, uint16 perms,
Jan 16, 2008
Jan 16, 2008
125
MojoChecksums *checksums, int64 maxbytes,
May 1, 2007
May 1, 2007
126
MojoInput_FileCopyCallback cb, void *data);
Mar 25, 2006
Mar 25, 2006
127
Jan 17, 2008
Jan 17, 2008
128
MojoInput *MojoInput_newFromURL(const char *url);
May 5, 2007
May 5, 2007
129
Apr 24, 2010
Apr 24, 2010
130
131
132
133
// Read a littleendian, unsigned 16-bit integer from (io), swapping it to
// the correct byteorder for the platform, and moving the file pointer
// ahead 2 bytes. Returns true on successful read and fills the swapped
// value into (*ui16), false on i/o error or EOF.
Apr 24, 2010
Apr 24, 2010
134
boolean MojoInput_readui16(MojoInput *io, uint16 *ui16);
Apr 24, 2010
Apr 24, 2010
135
136
137
138
139
// Read a littleendian, unsigned 32-bit integer from (io), swapping it to
// the correct byteorder for the platform, and moving the file pointer
// ahead 4 bytes. Returns true on successful read and fills the swapped
// value into (*ui32), false on i/o error or EOF.
Apr 24, 2010
Apr 24, 2010
140
boolean MojoInput_readui32(MojoInput *io, uint32 *ui32);
Apr 24, 2010
Apr 24, 2010
141
Jan 24, 2011
Jan 24, 2011
142
143
144
145
146
147
// Read a littleendian, unsigned 64-bit integer from (io), swapping it to
// the correct byteorder for the platform, and moving the file pointer
// ahead 8 bytes. Returns true on successful read and fills the swapped
// value into (*ui64), false on i/o error or EOF.
boolean MojoInput_readui64(MojoInput *io, uint64 *ui64);
Apr 24, 2010
Apr 24, 2010
148
149
150
151
// (Please note that there are not bigendian versions of MojoInput_readuiXX()
// at the moment, as we don't need them for our current feature set. However,
// they could be added easily enough.)
Mar 24, 2006
Mar 24, 2006
152
153
154
155
#ifdef __cplusplus
}
#endif
Mar 23, 2006
Mar 23, 2006
156
157
#endif
Mar 25, 2006
Mar 25, 2006
158
// end of fileio.h ...