-
Notifications
You must be signed in to change notification settings - Fork 0
/
break.cpp
58 lines (43 loc) · 1.71 KB
/
break.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
#include <linux/fs.h>
#include <iostream>
#include <fstream>
#include "Filesystem.h"
#include "biofs.h"
int main() {
Filesystem fs{"../file"};
std::cout << fs.fileTreeString() << std::endl;
INode& example = fs.inodes[std::get<1>(fs.inodes[2].children[4])];
INode& user = fs.inodes[std::get<1>(fs.inodes[2].children[3])];
// for (size_t i = 0; i < fs.image.block_usage.size(); ++i)
// std::cout << fs.image.block_usage[i];
// std::cout << std::endl;
// std::cout << fs.getAllErrors() << std::endl;
// uint32_t inode_i = example.inode_i;
// ext2_inode inode = example.inode;
uint32_t inode_i = user.inode_i;
ext2_inode inode = user.inode;
uint32_t block_size = fs.image.block_size;
uint32_t group_i = (inode_i - 1) / fs.image.inodes_per_group;
uint32_t offset = fs.block_groups[group_i].inode_table_i * block_size + (inode_i - 1) % fs.image.inodes_per_group * sizeof(ext2_inode);
inode.i_size = 0; // 2048
// inode.i_block[0] = 0;
// inode.i_block[1] = 1;
biofs ostream{"../file2", biofs::WRITE};
// char* buffer = new char[offset];
// fs.image.istream.seek(0);
// fs.image.istream.read(buffer, offset);
// ostream.write(buffer, offset);
// delete[] buffer;
ostream.seek(offset);
ostream.write((char*) &inode, sizeof(inode));
// fs.image.istream.seek(0, std::ios::end);
// uint32_t size = fs.image.istream.tellg();
// offset += sizeof(ext2_inode);
// buffer = new char[size - offset];
// fs.image.istream.seek(offset);
// fs.image.istream.read(buffer, size - offset);
// ostream.write(buffer, size - offset);
// delete[] buffer;
std::cout << "Successfully broke your filesystem!)" << std::endl;
return 0;
}