-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiskutils.hpp
More file actions
78 lines (61 loc) · 2.79 KB
/
Copy pathdiskutils.hpp
File metadata and controls
78 lines (61 loc) · 2.79 KB
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
#ifndef DISKUTILS_HPP
#define DISKUTILS_HPP
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <vector>
#include <sstream>
// Virtual Disk Specifications
const unsigned int DISK_SIZE = 64 * 1024 * 1024; // 64 MB
const unsigned int BLOCK_SIZE = 1024; // 1 KB blocks
const unsigned int TOTAL_BLOCKS = 65536; // 64MB / 1KB
// Layout / Block locations
const unsigned int SUPERBLOCK = 0;
const unsigned int BITMAP_START = 1;
const unsigned int FAT_START = 9;
const unsigned int ROOT_DIR_BLOCK = 265;
// The metadata structure exactly as specified (32 bytes)
#pragma pack(push, 1)
struct metadata {
char type; // 'f' for file, 'd' for directory
char name[23]; // 23-byte null-terminated string
unsigned int size; // bytes for files, entry count for directories
unsigned int firstblock; // pointer to the first block
};
#pragma pack(pop)
// Global Variables
extern unsigned char* D;
extern unsigned int NBLOCKS;
extern unsigned int NFREEBLOCKS;
extern unsigned int RBN;
// Core disk management
void joindisk();
void leavedisk();
unsigned int getfreeblock();
void freeblock(unsigned int block_num);
// Internal helpers
unsigned int get_next_fat_block(unsigned int current_block);
void set_fat(unsigned int block_num, unsigned int next_block);
std::vector<std::string> split_path(const std::string& path);
// Returns true and fills out_meta if the named entry is found in dir_first_block.
bool find_dir_entry(unsigned int dir_first_block, const std::string& target_name, metadata& out_meta);
// Resolves a path (relative or absolute) starting from cbn / cwd.
// Returns true and sets out_block to the first block of the target dir/file and out_meta to its metadata.
bool resolve_path(const std::string& path, unsigned int cbn, const std::string& cwd, unsigned int& out_block, metadata& out_meta, bool silent = false);
// File system operations called from foosh
// md / mkdir – create a new directory
void fs_mkdir(const std::string& path, unsigned int cbn, const std::string& cwd);
// ls – detailed listing of a directory (or a single file)
void fs_ls(const std::string& path, unsigned int cbn, const std::string& cwd);
// dir – names-only listing of current directory
void fs_dir(unsigned int cbn, const std::string& cwd);
// cp / copy – three-way copy: HD→VD, VD→HD, VD→VD
// Back-tick prefix on a name means it lives on the HD.
void fs_cp(const std::string& src, const std::string& dst, unsigned int cbn, const std::string& cwd);
// prn / type – print a VD text file to stdout
void fs_prn(const std::string& path, unsigned int cbn, const std::string& cwd);
#endif // DISKUTILS_HPP