Skip to content

Commit 3b4b4c1

Browse files
committed
cursed shall be thy read parameters
1 parent db35148 commit 3b4b4c1

5 files changed

Lines changed: 6257 additions & 139 deletions

File tree

.vscode/launch.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,31 @@
1313
"args": [
1414
// change accordingly
1515
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/1202",
16-
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/407d287-main"
16+
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/af9cbb8-main"
17+
]
18+
},
19+
{
20+
"name": "Compare dumps (main mod)",
21+
"type": "python",
22+
"request": "launch",
23+
"program": "${workspaceFolder}/tests/code/filesystem_dirents/dumps/comparator.py",
24+
"console": "integratedTerminal",
25+
"args": [
26+
// change accordingly
27+
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/1202",
28+
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/af9cbb8-main-mod"
29+
]
30+
},
31+
{
32+
"name": "Compare dumps (current)",
33+
"type": "python",
34+
"request": "launch",
35+
"program": "${workspaceFolder}/tests/code/filesystem_dirents/dumps/comparator.py",
36+
"console": "integratedTerminal",
37+
"args": [
38+
// change accordingly
39+
"${workspaceFolder}/tests/code/filesystem_dirents/dumps/1202",
40+
"${userHome}/.local/share/shadps4/data/enderman/dumps"
1741
]
1842
},
1943
{

tests/code/filesystem_dirents/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ link_libraries(SceSystemService)
44

55
create_pkg(TEST12345 5 50 "code/log.cpp;code/fs_test_tools.cpp;code/fs_test.cpp;code/main.cpp")
66
set_target_properties(TEST12345 PROPERTIES OO_PKG_TITLE "Enderman")
7-
set_target_properties(TEST12345 PROPERTIES OO_PKG_APPVER "1.06")
7+
set_target_properties(TEST12345 PROPERTIES OO_PKG_APPVER "1.07")
88
finalize_pkg(TEST12345)

tests/code/filesystem_dirents/code/fs_test.cpp

Lines changed: 45 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,39 @@
77
#include <filesystem>
88
#include <sstream>
99
#include <string>
10+
#include <vector>
1011

1112
namespace FS_Test {
1213

14+
std::vector<u32> read_sizes {// 8
15+
7, 8, 9,
16+
// 16
17+
15, 16, 17,
18+
// 32
19+
31, 32, 33,
20+
// 64
21+
63, 64, 65,
22+
// 128
23+
127, 128, 129,
24+
// 256
25+
255, 256, 257,
26+
// 512
27+
511, 512, 513,
28+
// 1024
29+
1023, 1024, 1025,
30+
// 2048
31+
2047, 2048, 2049,
32+
// 4096
33+
4095, 4096, 4097,
34+
// 65536
35+
65535, 65536, 65537,
36+
// cursed
37+
2137, 21, 37, 69, 420, 42, 123, 222, 666, 911, 112, 997,
38+
// something for zoomers
39+
67};
40+
std::vector<u32> read_sizes_pfs {65535, 65536, 65537};
41+
std::vector<u16> read_offsets {0, 1, 5, 10, 21, 37, 127, 128, 129, 400, 500, 512, 768, 1024, 111, 666, 420, 1234, 96, 42};
42+
1343
namespace fs = std::filesystem;
1444
namespace oi = OrbisInternals;
1545

@@ -49,76 +79,11 @@ void RunTests() {
4979
Log("LSeek END-100=", sceKernelLseek(fd, -100, 2));
5080
Log("LSeek END-100000=", sceKernelLseek(fd, -100000, 2));
5181

52-
DumpDirectory(fd, 16, 0);
53-
DumpDirectory(fd, 16, 7);
54-
DumpDirectory(fd, 16, 47);
55-
DumpDirectory(fd, 16, 123);
56-
DumpDirectory(fd, 16, 128);
57-
DumpDirectory(fd, 23, 0);
58-
DumpDirectory(fd, 23, 7);
59-
DumpDirectory(fd, 23, 47);
60-
DumpDirectory(fd, 23, 123);
61-
DumpDirectory(fd, 23, 128);
62-
DumpDirectory(fd, 64, 0);
63-
DumpDirectory(fd, 64, 7);
64-
DumpDirectory(fd, 64, 47);
65-
DumpDirectory(fd, 64, 123);
66-
DumpDirectory(fd, 64, 128);
67-
DumpDirectory(fd, 123, 0);
68-
DumpDirectory(fd, 123, 7);
69-
DumpDirectory(fd, 123, 47);
70-
DumpDirectory(fd, 123, 123);
71-
DumpDirectory(fd, 123, 128);
72-
DumpDirectory(fd, 128, 0);
73-
DumpDirectory(fd, 128, 7);
74-
DumpDirectory(fd, 128, 47);
75-
DumpDirectory(fd, 128, 123);
76-
DumpDirectory(fd, 128, 128);
77-
DumpDirectory(fd, 199, 0);
78-
DumpDirectory(fd, 199, 7);
79-
DumpDirectory(fd, 199, 47);
80-
DumpDirectory(fd, 199, 123);
81-
DumpDirectory(fd, 199, 128);
82-
DumpDirectory(fd, 256, 0);
83-
DumpDirectory(fd, 256, 7);
84-
DumpDirectory(fd, 256, 47);
85-
DumpDirectory(fd, 256, 123);
86-
DumpDirectory(fd, 256, 128);
87-
DumpDirectory(fd, 512, 0);
88-
DumpDirectory(fd, 512, 7);
89-
DumpDirectory(fd, 512, 47);
90-
DumpDirectory(fd, 512, 123);
91-
DumpDirectory(fd, 512, 128);
92-
DumpDirectory(fd, 567, 0);
93-
DumpDirectory(fd, 567, 7);
94-
DumpDirectory(fd, 567, 47);
95-
DumpDirectory(fd, 567, 123);
96-
DumpDirectory(fd, 567, 128);
97-
DumpDirectory(fd, 999, 0);
98-
DumpDirectory(fd, 999, 7);
99-
DumpDirectory(fd, 999, 47);
100-
DumpDirectory(fd, 999, 123);
101-
DumpDirectory(fd, 999, 128);
102-
DumpDirectory(fd, 1024, 0);
103-
DumpDirectory(fd, 1024, 7);
104-
DumpDirectory(fd, 1024, 47);
105-
DumpDirectory(fd, 1024, 123);
106-
DumpDirectory(fd, 1024, 128);
107-
DumpDirectory(fd, 1555, 0);
108-
DumpDirectory(fd, 1555, 7);
109-
DumpDirectory(fd, 1555, 47);
110-
DumpDirectory(fd, 1555, 123);
111-
DumpDirectory(fd, 1555, 128);
112-
DumpDirectory(fd, 2048, 0);
113-
DumpDirectory(fd, 2048, 7);
114-
DumpDirectory(fd, 2048, 47);
115-
DumpDirectory(fd, 2048, 123);
116-
DumpDirectory(fd, 2048, 128);
117-
DumpDirectory(fd, 2123, 0);
118-
DumpDirectory(fd, 2123, 7);
119-
DumpDirectory(fd, 2123, 47);
120-
DumpDirectory(fd, 2123, 123);
121-
DumpDirectory(fd, 2123, 128);
82+
for (auto read_size: read_sizes) {
83+
for (auto read_offset: read_offsets) {
84+
DumpDirectory(fd, read_size, read_offset);
85+
}
86+
}
12287

12388
sceKernelClose(fd);
12489

@@ -144,66 +109,11 @@ void RunTests() {
144109
Log("LSeek END-100=", sceKernelLseek(fd, -100, 2));
145110
Log("LSeek END-100000=", sceKernelLseek(fd, -100000, 2));
146111

147-
DumpDirectory(fd, 16, 0, true);
148-
DumpDirectory(fd, 16, 7, true);
149-
DumpDirectory(fd, 16, 47, true);
150-
DumpDirectory(fd, 16, 123, true);
151-
DumpDirectory(fd, 16, 128, true);
152-
DumpDirectory(fd, 23, 0, true);
153-
DumpDirectory(fd, 23, 7, true);
154-
DumpDirectory(fd, 23, 47, true);
155-
DumpDirectory(fd, 23, 123, true);
156-
DumpDirectory(fd, 23, 128, true);
157-
DumpDirectory(fd, 64, 0, true);
158-
DumpDirectory(fd, 64, 7, true);
159-
DumpDirectory(fd, 64, 47, true);
160-
DumpDirectory(fd, 64, 123, true);
161-
DumpDirectory(fd, 64, 128, true);
162-
DumpDirectory(fd, 123, 0, true);
163-
DumpDirectory(fd, 123, 7, true);
164-
DumpDirectory(fd, 123, 47, true);
165-
DumpDirectory(fd, 123, 123, true);
166-
DumpDirectory(fd, 123, 128, true);
167-
DumpDirectory(fd, 128, 0, true);
168-
DumpDirectory(fd, 128, 7, true);
169-
DumpDirectory(fd, 128, 47, true);
170-
DumpDirectory(fd, 128, 123, true);
171-
DumpDirectory(fd, 128, 128, true);
172-
DumpDirectory(fd, 199, 0, true);
173-
DumpDirectory(fd, 199, 7, true);
174-
DumpDirectory(fd, 199, 47, true);
175-
DumpDirectory(fd, 199, 123, true);
176-
DumpDirectory(fd, 199, 128, true);
177-
DumpDirectory(fd, 256, 0, true);
178-
DumpDirectory(fd, 256, 7, true);
179-
DumpDirectory(fd, 256, 47, true);
180-
DumpDirectory(fd, 256, 123, true);
181-
DumpDirectory(fd, 256, 128, true);
182-
DumpDirectory(fd, 512, 0, true);
183-
DumpDirectory(fd, 512, 7, true);
184-
DumpDirectory(fd, 512, 47, true);
185-
DumpDirectory(fd, 512, 123, true);
186-
DumpDirectory(fd, 512, 128, true);
187-
DumpDirectory(fd, 567, 0, true);
188-
DumpDirectory(fd, 567, 7, true);
189-
DumpDirectory(fd, 567, 47, true);
190-
DumpDirectory(fd, 567, 123, true);
191-
DumpDirectory(fd, 567, 128, true);
192-
DumpDirectory(fd, 999, 0, true);
193-
DumpDirectory(fd, 999, 7, true);
194-
DumpDirectory(fd, 999, 47, true);
195-
DumpDirectory(fd, 999, 123, true);
196-
DumpDirectory(fd, 999, 128, true);
197-
DumpDirectory(fd, 1024, 0, true);
198-
DumpDirectory(fd, 1024, 7, true);
199-
DumpDirectory(fd, 1024, 47, true);
200-
DumpDirectory(fd, 1024, 123, true);
201-
DumpDirectory(fd, 1024, 128, true);
202-
DumpDirectory(fd, 65536, 0, true);
203-
DumpDirectory(fd, 65536, 7, true);
204-
DumpDirectory(fd, 65536, 47, true);
205-
DumpDirectory(fd, 65536, 123, true);
206-
DumpDirectory(fd, 65536, 128, true);
112+
for (auto read_size: read_sizes) {
113+
for (auto read_offset: read_offsets) {
114+
DumpDirectory(fd, read_size, read_offset, true);
115+
}
116+
}
207117

208118
sceKernelClose(fd);
209119
}
@@ -212,7 +122,7 @@ bool DumpByRead(int dir_fd, int dump_fd, char* buffer, size_t size) {
212122
memset(buffer, 0xAA, size);
213123

214124
s64 tbr = sceKernelRead(dir_fd, buffer, size);
215-
Log("Read got", tbr, "/", size, "bytes, ptr =", sceKernelLseek(dir_fd, 0, 1));
125+
// Log("Read got", tbr, "/", size, "bytes, ptr =", sceKernelLseek(dir_fd, 0, 1));
216126

217127
if (tbr < 0) {
218128
LogError("Read finished with error:", tbr);
@@ -223,8 +133,7 @@ bool DumpByRead(int dir_fd, int dump_fd, char* buffer, size_t size) {
223133
return false;
224134
}
225135

226-
s64 tbw = sceKernelWrite(dump_fd, buffer, size);
227-
if (tbw != tbr) LogError("Written", tbw, "bytes out of", size, "bytes read");
136+
if (s64 tbw = sceKernelWrite(dump_fd, buffer, size); tbw != size) LogError("Written", tbw, "bytes out of", size, "bytes");
228137
return true;
229138
}
230139

@@ -233,7 +142,7 @@ bool DumpByDirent(int dir_fd, int dump_fd, char* buffer, size_t size, s64* idx)
233142
memset(buffer, 0xAA, size);
234143

235144
s64 tbr = sceKernelGetdirentries(dir_fd, buffer, size, idx);
236-
Log("Dirent got", tbr, "/", size, "bytes, ptr =", sceKernelLseek(dir_fd, 0, 1), "idx =", *idx);
145+
// Log("Dirent got", tbr, "/", size, "bytes, ptr =", sceKernelLseek(dir_fd, 0, 1), "idx =", *idx);
237146

238147
if (tbr < 0) {
239148
LogError("Dirent finished with error:", tbr);
@@ -244,8 +153,7 @@ bool DumpByDirent(int dir_fd, int dump_fd, char* buffer, size_t size, s64* idx)
244153
return false;
245154
}
246155

247-
s64 tbw = sceKernelWrite(dump_fd, buffer, size);
248-
if (tbw != tbr) LogError("Written", tbw, "bytes out of", size, "bytes read");
156+
if (s64 tbw = sceKernelWrite(dump_fd, buffer, size); tbw != size) LogError("Written", tbw, "bytes out of", size, "bytes");
249157
return true;
250158
}
251159

@@ -257,7 +165,7 @@ void DumpDirectory(int fd, int buffer_size, s64 offset, bool is_pfs) {
257165
fs::path dirent_path =
258166
"/data/enderman/dumps/dirent_" + (is_pfs ? std::string("PFS_") : std::string("")) + std::to_string(buffer_size) + '+' + std::to_string(offset) + ".bin";
259167

260-
LogTest("Read", is_pfs ? "PFS" : "normal", "directory, fd =", fd, "size =", buffer_size, "offset =", offset);
168+
LogTest("Read", is_pfs ? "PFS" : "normal", "directory, fd =", fd, "buffer size =", buffer_size, "starting offset =", offset);
261169

262170
u16 max_loops = 0; // 65536 iterations lmao
263171
int read_fd = sceKernelOpen(read_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0777);

tests/code/filesystem_dirents/log_01.06.log

Whitespace-only changes.

0 commit comments

Comments
 (0)