Skip to content

Commit bb81691

Browse files
Merge pull request #16 from unknownbrackets/dax
Allow compression to a DAX file
2 parents 7fbf11b + db91052 commit bb81691

File tree

14 files changed

+303
-71
lines changed

14 files changed

+303
-71
lines changed

7zip/7zip.vcxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
<ClInclude Include="CPP\7zip\Archive\DeflateProps.h" />
2424
<ClInclude Include="CPP\7zip\Common\CWrappers.h" />
2525
<ClInclude Include="CPP\7zip\Common\FileStreams.h" />
26+
<ClInclude Include="CPP\7zip\Common\InBuffer.h" />
2627
<ClInclude Include="CPP\7zip\Common\OutBuffer.h" />
2728
<ClInclude Include="CPP\7zip\Common\StreamUtils.h" />
29+
<ClInclude Include="CPP\7zip\Compress\DeflateDecoder.h" />
2830
<ClInclude Include="CPP\7zip\Compress\DeflateEncoder.h" />
31+
<ClInclude Include="CPP\7zip\Compress\LzOutWindow.h" />
32+
<ClInclude Include="CPP\7zip\Compress\ZlibDecoder.h" />
33+
<ClInclude Include="CPP\7zip\Compress\ZlibEncoder.h" />
2934
<ClInclude Include="CPP\Common\MyString.h" />
3035
<ClInclude Include="CPP\Common\StringConvert.h" />
3136
<ClInclude Include="CPP\Common\StringToInt.h" />
@@ -42,9 +47,15 @@
4247
<ClCompile Include="CPP\7zip\Archive\DeflateProps.cpp" />
4348
<ClCompile Include="CPP\7zip\Common\CWrappers.cpp" />
4449
<ClCompile Include="CPP\7zip\Common\FileStreams.cpp" />
50+
<ClCompile Include="CPP\7zip\Common\InBuffer.cpp" />
4551
<ClCompile Include="CPP\7zip\Common\OutBuffer.cpp" />
4652
<ClCompile Include="CPP\7zip\Common\StreamUtils.cpp" />
53+
<ClCompile Include="CPP\7zip\Compress\BitlDecoder.cpp" />
54+
<ClCompile Include="CPP\7zip\Compress\DeflateDecoder.cpp" />
4755
<ClCompile Include="CPP\7zip\Compress\DeflateEncoder.cpp" />
56+
<ClCompile Include="CPP\7zip\Compress\LzOutWindow.cpp" />
57+
<ClCompile Include="CPP\7zip\Compress\ZlibDecoder.cpp" />
58+
<ClCompile Include="CPP\7zip\Compress\ZlibEncoder.cpp" />
4859
<ClCompile Include="CPP\Common\MyString.cpp" />
4960
<ClCompile Include="CPP\Common\StringConvert.cpp" />
5061
<ClCompile Include="CPP\Common\StringToInt.cpp" />
@@ -56,6 +67,9 @@
5667
<ClCompile Include="C\Sort.c" />
5768
<ClCompile Include="deflate7z.cpp" />
5869
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="Makefile" />
72+
</ItemGroup>
5973
<PropertyGroup Label="Globals">
6074
<ProjectGuid>{6343B36E-030F-4A66-A588-758B2E2B5BEE}</ProjectGuid>
6175
<RootNamespace>7zip</RootNamespace>

7zip/7zip.vcxproj.filters

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@
5555
<ClInclude Include="CPP\7zip\Common\StreamUtils.h">
5656
<Filter>7zip</Filter>
5757
</ClInclude>
58+
<ClInclude Include="CPP\7zip\Compress\ZlibEncoder.h">
59+
<Filter>7zip</Filter>
60+
</ClInclude>
61+
<ClInclude Include="CPP\7zip\Compress\ZlibDecoder.h">
62+
<Filter>7zip</Filter>
63+
</ClInclude>
64+
<ClInclude Include="CPP\7zip\Compress\DeflateDecoder.h">
65+
<Filter>7zip</Filter>
66+
</ClInclude>
67+
<ClInclude Include="CPP\7zip\Compress\LzOutWindow.h">
68+
<Filter>7zip</Filter>
69+
</ClInclude>
70+
<ClInclude Include="CPP\7zip\Common\InBuffer.h">
71+
<Filter>7zip</Filter>
72+
</ClInclude>
5873
</ItemGroup>
5974
<ItemGroup>
6075
<ClCompile Include="CPP\7zip\Archive\DeflateProps.cpp">
@@ -106,5 +121,26 @@
106121
<ClCompile Include="CPP\7zip\Common\StreamUtils.cpp">
107122
<Filter>7zip</Filter>
108123
</ClCompile>
124+
<ClCompile Include="CPP\7zip\Compress\ZlibEncoder.cpp">
125+
<Filter>7zip</Filter>
126+
</ClCompile>
127+
<ClCompile Include="CPP\7zip\Compress\ZlibDecoder.cpp">
128+
<Filter>7zip</Filter>
129+
</ClCompile>
130+
<ClCompile Include="CPP\7zip\Compress\DeflateDecoder.cpp">
131+
<Filter>7zip</Filter>
132+
</ClCompile>
133+
<ClCompile Include="CPP\7zip\Compress\LzOutWindow.cpp">
134+
<Filter>7zip</Filter>
135+
</ClCompile>
136+
<ClCompile Include="CPP\7zip\Common\InBuffer.cpp">
137+
<Filter>7zip</Filter>
138+
</ClCompile>
139+
<ClCompile Include="CPP\7zip\Compress\BitlDecoder.cpp">
140+
<Filter>7zip</Filter>
141+
</ClCompile>
142+
</ItemGroup>
143+
<ItemGroup>
144+
<None Include="Makefile" />
109145
</ItemGroup>
110146
</Project>

7zip/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CC ?= gcc
22
CXX ?= g++
3+
AR ?= ar
34

45
CFLAGS += -W -Wall -Wextra -O2
56
CXXFLAGS += -W -Wall -Wextra -std=c++11 -O2 -ICPP
@@ -8,9 +9,15 @@ CXXFLAGS += -W -Wall -Wextra -std=c++11 -O2 -ICPP
89
CPP/7zip/Archive/DeflateProps.cpp \
910
CPP/7zip/Common/CWrappers.cpp \
1011
CPP/7zip/Common/FileStreams.cpp \
12+
CPP/7zip/Common/InBuffer.cpp \
1113
CPP/7zip/Common/OutBuffer.cpp \
1214
CPP/7zip/Common/StreamUtils.cpp \
15+
CPP/7zip/Compress/BitlDecoder.cpp \
16+
CPP/7zip/Compress/DeflateDecoder.cpp \
1317
CPP/7zip/Compress/DeflateEncoder.cpp \
18+
CPP/7zip/Compress/LzOutWindow.cpp \
19+
CPP/7zip/Compress/ZlibDecoder.cpp \
20+
CPP/7zip/Compress/ZlibEncoder.cpp \
1421
CPP/Common/MyString.cpp \
1522
CPP/Common/StringConvert.cpp \
1623
CPP/Common/StringToInt.cpp \
@@ -32,7 +39,7 @@ CXXFLAGS += -W -Wall -Wextra -std=c++11 -O2 -ICPP
3239
$(CC) -c $(CFLAGS) -o $@ $<
3340

3441
7zip.a: $(7ZIP_CXX_OBJ) $(7ZIP_C_OBJ)
35-
ar rcs $@ $^
42+
$(AR) rcs $@ $^
3643

3744
clean:
3845
rm -f $(7ZIP_CXX_OBJ) $(7ZIP_C_OBJ) 7zip.a

7zip/deflate7z.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CPP/7zip/IStream.h"
1515
#include "CPP/7zip/Archive/DeflateProps.h"
1616
#include "CPP/7zip/Compress/DeflateEncoder.h"
17+
#include "CPP/7zip/Compress/ZlibEncoder.h"
1718

1819
#ifdef _WIN32
1920
#include <propvarutil.h>
@@ -118,7 +119,7 @@ HRESULT COutBlockStream::Write(const void *data, UInt32 size, UInt32 *processedS
118119
struct Context {
119120
CInBlockStream *in;
120121
COutBlockStream *out;
121-
NCompress::NDeflate::NEncoder::CCOMCoder *coder;
122+
ICompressCoder *coder;
122123
};
123124

124125
void SetDefaults(Options *opts) {
@@ -127,6 +128,7 @@ void SetDefaults(Options *opts) {
127128
opts->fastbytes = 0xFFFFFFFF;
128129
opts->algo = 0xFFFFFFFF;
129130
opts->matchcycles = 0xFFFFFFFF;
131+
opts->useZlib = false;
130132
}
131133

132134
static void SetupProperties(const Options *opts, NCompress::NDeflate::NEncoder::CCOMCoder *coder) {
@@ -149,8 +151,16 @@ void Alloc(Context **ctx, const Options *opts) {
149151
c->in->AddRef();
150152
c->out->AddRef();
151153

152-
c->coder = new NCompress::NDeflate::NEncoder::CCOMCoder();
153-
SetupProperties(opts, c->coder);
154+
if (opts->useZlib) {
155+
NCompress::NZlib::CEncoder *coder = new NCompress::NZlib::CEncoder();
156+
coder->Create();
157+
SetupProperties(opts, coder->DeflateEncoderSpec);
158+
c->coder = coder;
159+
} else {
160+
NCompress::NDeflate::NEncoder::CCOMCoder *coder = new NCompress::NDeflate::NEncoder::CCOMCoder();
161+
SetupProperties(opts, coder);
162+
c->coder = coder;
163+
}
154164
}
155165

156166
void Release(Context **ctx) {

7zip/deflate7z.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Deflate7z {
1010
uint32_t fastbytes;
1111
uint32_t algo;
1212
uint32_t matchcycles;
13+
bool useZlib;
1314
};
1415

1516
struct Context;

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Larger block sizes than the default will help compression, in the range of 2-3%.
4848
files may not be compatible with some software. For example, [PPSSPP][] versions released
4949
after 2014-10-26 will support larger block sizes.
5050

51+
Avoid DAX where CSOs using larger block sizes are supported, since DAX is less efficient.
52+
5153
LZ4 support is mostly for experimentation.
5254

5355

@@ -79,7 +81,7 @@ Multiple files may be specified. Inputs can be iso or cso files.
7981
--decompress Write out to raw ISO, decompressing as needed
8082
--block=N Specify a block size (default depends on iso size)
8183
Many readers only support the 2048 size
82-
--format=VER Specify cso version (options: cso1, cso2, zso)
84+
--format=VER Specify cso version (options: cso1, cso2, zso, dax)
8385
These are experimental, default is cso1
8486
--use-zlib Enable trials with zlib for deflate compression
8587
--use-zopfli Enable trials with Zopfli for deflate compression

cli/cli.cpp

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void show_help(const char *arg0) {
2727
fprintf(stderr, " --decompress Write out to raw ISO, decompressing as needed\n");
2828
fprintf(stderr, " --block=N Specify a block size (default depends on iso size)\n");
2929
fprintf(stderr, " Many readers only support the 2048 size\n");
30-
fprintf(stderr, " --format=VER Specify cso version (options: cso1, cso2, zso)\n");
30+
fprintf(stderr, " --format=VER Specify cso version (options: cso1, cso2, zso, dax)\n");
3131
fprintf(stderr, " These are experimental, default is cso1\n");
3232
// TODO: Bring this back once it's functional.
3333
//fprintf(stderr, " --smallest Force compression of all sectors for smallest result\n");
@@ -173,6 +173,8 @@ int parse_args(Arguments &args, int argc, char *argv[]) {
173173
args.flags_fmt = maxcso::TASKFLAG_FMT_CSO_2;
174174
} else if (strcmp(val, "zso") == 0) {
175175
args.flags_fmt = maxcso::TASKFLAG_FMT_ZSO;
176+
} else if (strcmp(val, "dax") == 0) {
177+
args.flags_fmt = maxcso::TASKFLAG_FMT_DAX;
176178
} else {
177179
show_help(argv[0]);
178180
fprintf(stderr, "\nERROR: Unknown format %s, expecting cso1, cso2, or zso.\n", val);
@@ -231,11 +233,18 @@ int validate_args(const char *arg0, Arguments &args) {
231233

232234
if (args.crc) {
233235
if (args.outputs.size()) {
234-
show_help(arg0);
235-
fprintf(stderr, "\nERROR: Output files not used with --crc.\n");
236-
return 1;
236+
show_help(arg0);
237+
fprintf(stderr, "\nERROR: Output files not used with --crc.\n");
238+
return 1;
237239
}
238240
} else {
241+
std::string outputExt = ".cso";
242+
if (args.flags_fmt & maxcso::TASKFLAG_FMT_DAX) {
243+
outputExt = ".dax";
244+
} else if (args.flags_fmt & maxcso::TASKFLAG_FMT_ZSO) {
245+
outputExt = ".zso";
246+
}
247+
239248
// Automatically write to .cso files if not specified.
240249
for (size_t i = args.outputs.size(); i < args.inputs.size(); ++i) {
241250
if (args.inputs[i].size() <= 4) {
@@ -244,10 +253,13 @@ int validate_args(const char *arg0, Arguments &args) {
244253

245254
std::string ext = args.inputs[i].substr(args.inputs[i].size() - 4);
246255
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
256+
const bool inputRawExt = ext == ".iso";
257+
const bool inputCompressedExt = ext == ".cso" || ext == ".zso" || ext == ".dax";
247258

248-
if (!args.decompress && ext == ".iso") {
249-
args.outputs.push_back(args.inputs[i].substr(0, args.inputs[i].size() - 4) + ".cso");
250-
} else if (args.decompress && (ext == ".cso" || ext == ".zso")) {
259+
// Automatically switch extensions for convenience.
260+
if (!args.decompress && (inputRawExt || inputCompressedExt) && ext != outputExt) {
261+
args.outputs.push_back(args.inputs[i].substr(0, args.inputs[i].size() - 4) + outputExt);
262+
} else if (args.decompress && inputCompressedExt) {
251263
args.outputs.push_back(args.inputs[i].substr(0, args.inputs[i].size() - 4) + ".iso");
252264
}
253265
}
@@ -271,7 +283,7 @@ int validate_args(const char *arg0, Arguments &args) {
271283
} else if (args.flags_fmt & maxcso::TASKFLAG_FMT_ZSO) {
272284
args.flags_final = maxcso::TASKFLAG_NO_ZLIB | maxcso::TASKFLAG_NO_7ZIP | maxcso::TASKFLAG_NO_ZOPFLI | maxcso::TASKFLAG_NO_LZ4_HC_BRUTE;
273285
} else {
274-
// CSO v1, just disable lz4.
286+
// CSO v1 or DAX, just disable lz4.
275287
args.flags_final = maxcso::TASKFLAG_NO_ZOPFLI | maxcso::TASKFLAG_NO_LZ4;
276288
}
277289

@@ -297,6 +309,23 @@ int validate_args(const char *arg0, Arguments &args) {
297309
}
298310
args.flags_final |= args.flags_fmt;
299311

312+
if (args.flags_fmt & maxcso::TASKFLAG_FMT_DAX) {
313+
// DAX has a fixed block size.
314+
if (args.block_size != maxcso::DEFAULT_BLOCK_SIZE) {
315+
show_help(arg0);
316+
fprintf(stderr, "\nERROR: Block size must be default for DAX.\n");
317+
return 1;
318+
}
319+
320+
// Currently, compression will fail if no DEFLATE format is enabled for DAX.
321+
uint32_t deflateFlags = maxcso::TASKFLAG_NO_ZLIB | maxcso::TASKFLAG_NO_ZLIB_DEFAULT | maxcso::TASKFLAG_NO_ZLIB_BRUTE | maxcso::TASKFLAG_NO_ZOPFLI | maxcso::TASKFLAG_NO_7ZIP;
322+
if ((args.flags_final & deflateFlags) == deflateFlags) {
323+
show_help(arg0);
324+
fprintf(stderr, "\nERROR: DAX must use some kind of DEFLATE.\n");
325+
return 1;
326+
}
327+
}
328+
300329
return 0;
301330
}
302331

src/compress.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "compress.h"
44
#include "uv_helper.h"
55
#include "cso.h"
6+
#include "dax.h"
67
#include "input.h"
78
#include "output.h"
89
#include "buffer_pool.h"
@@ -62,9 +63,13 @@ class CompressionTask {
6263

6364
void CompressionTask::Enqueue() {
6465
if (task_.block_size == DEFAULT_BLOCK_SIZE) {
65-
// Start with a small block size.
66-
// We'll re-evaluate later.
67-
blockSize_ = SMALL_BLOCK_SIZE;
66+
if (task_.flags & TASKFLAG_FMT_DAX) {
67+
blockSize_ = DAX_FRAME_SIZE;
68+
} else {
69+
// Start with a small block size.
70+
// We'll re-evaluate later.
71+
blockSize_ = SMALL_BLOCK_SIZE;
72+
}
6873
} else {
6974
if (task_.block_size > MAX_BLOCK_SIZE) {
7075
Notify(TASK_INVALID_OPTION, "Block size too large");
@@ -148,6 +153,8 @@ void CompressionTask::BeginProcessing() {
148153
fmt = CSO_FMT_CSO2;
149154
} else if (task_.flags & TASKFLAG_FMT_ZSO) {
150155
fmt = CSO_FMT_ZSO;
156+
} else if (task_.flags & TASKFLAG_FMT_DAX) {
157+
fmt = CSO_FMT_DAX;
151158
}
152159

153160
// Now that we know the file size, check if we should resize the blockSize_.

src/compress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum TaskFlags {
4747
TASKFLAG_NO_ALL = TASKFLAG_NO_ZLIB | TASKFLAG_NO_ZOPFLI | TASKFLAG_NO_7ZIP | TASKFLAG_NO_LZ4,
4848

4949
TASKFLAG_DECOMPRESS = 0x400,
50+
TASKFLAG_FMT_DAX = 0x800,
5051
};
5152

5253
typedef std::function<void (const Task *, TaskStatus status, int64_t pos, int64_t total, int64_t written)> ProgressCallback;

src/cso.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum CSOFormat {
1717
CSO_FMT_CSO1,
1818
CSO_FMT_CSO2,
1919
CSO_FMT_ZSO,
20+
CSO_FMT_DAX,
2021
};
2122

2223
#ifdef _MSC_VER

0 commit comments

Comments
 (0)