forked from vAmigaWeb/vAmigaWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOtherFile.cpp
84 lines (68 loc) · 2.22 KB
/
OtherFile.cpp
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
// -----------------------------------------------------------------------------
// This file is part of vAmiga
//
// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
// Licensed under the GNU General Public License v3
//
// See https://www.gnu.org for license information
// -----------------------------------------------------------------------------
#include "config.h"
#include "OtherFile.h"
#include "AmigaFile.h"
#include "MutableFileSystem.h"
#include "IOUtils.h"
#include "OSDescriptors.h"
namespace vamiga {
bool
OtherFile::isCompatible(const string &path)
{
//return true;
auto suffix = util::uppercased(util::extractSuffix(path));
return suffix == "DISK";
}
bool
OtherFile::isCompatible(std::istream &stream)
{
// u8 signature[] = { 0x00, 0x00, 0x03, 0xF3 };
// Only accept the file if it fits onto a HD disk
//return util::matchingStreamHeader(stream, signature, sizeof(signature));
return true;
}
void
OtherFile::finalizeRead()
{
// Check if this file requires a high-density disk
bool hd = data.size > 853000;
// Create a new file system
MutableFileSystem volume(INCH_35, hd ? DENSITY_HD : DENSITY_DD, FS_OFS);
volume.setName(FSName(filename));
// Make the volume bootable
volume.makeBootable(BB_AMIGADOS_13);
// Add the file
FSBlock *file = volume.createFile(filename, data.ptr, data.size);
if (!file) throw VAError(ERROR_FS_OUT_OF_SPACE);
// Add a script directory
// volume.createDir("s");
// volume.changeDir("s");
// Add a startup sequence
// file = volume.createFile("startup-sequence", "file");
// if (!file) throw VAError(ERROR_FS_OUT_OF_SPACE);
// Finalize
volume.updateChecksums();
// Move to the to root directory
volume.changeDir("/");
// Print some debug information about the volume
if (FS_DEBUG) {
volume.dump(Category::State);
volume.printDirectory(true);
}
// Check file system integrity
FSErrorReport report = volume.check(true);
if (report.corruptedBlocks > 0) {
warn("Found %ld corrupted blocks\n", report.corruptedBlocks);
if (FS_DEBUG) volume.dump(Category::Blocks);
}
// Convert the volume into an ADF
adf.init(volume);
}
}