Skip to content

Commit df5db6e

Browse files
Add DAX support to cli.
1 parent c1b9fbf commit df5db6e

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

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

0 commit comments

Comments
 (0)