-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminixfs.c
85 lines (75 loc) · 2.37 KB
/
minixfs.c
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
85
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
/**
* finding_filesystems
* CS 241 - Fall 2021
*/
#include "minixfs.h"
#include "minixfs_utils.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
/**
* Virtual paths:
* Add your new virtual endpoint to minixfs_virtual_path_names
*/
char *minixfs_virtual_path_names[] = {"info", /* add your paths here*/};
/**
* Forward declaring block_info_string so that we can attach unused on it
* This prevents a compiler warning if you haven't used it yet.
*
* This function generates the info string that the virtual endpoint info should
* emit when read
*/
static char *block_info_string(ssize_t num_used_blocks) __attribute__((unused));
static char *block_info_string(ssize_t num_used_blocks) {
char *block_string = NULL;
ssize_t curr_free_blocks = DATA_NUMBER - num_used_blocks;
asprintf(&block_string,
"Free blocks: %zd\n"
"Used blocks: %zd\n",
curr_free_blocks, num_used_blocks);
return block_string;
}
// Don't modify this line unless you know what you're doing
int minixfs_virtual_path_count =
sizeof(minixfs_virtual_path_names) / sizeof(minixfs_virtual_path_names[0]);
int minixfs_chmod(file_system *fs, char *path, int new_permissions) {
// Thar she blows!
return 0;
}
int minixfs_chown(file_system *fs, char *path, uid_t owner, gid_t group) {
// Land ahoy!
return -1;
}
inode *minixfs_create_inode_for_path(file_system *fs, const char *path) {
// Land ahoy!
return NULL;
}
ssize_t minixfs_virtual_read(file_system *fs, const char *path, void *buf,
size_t count, off_t *off) {
if (!strcmp(path, "info")) {
// TODO implement the "info" virtual file here
}
errno = ENOENT;
return -1;
}
ssize_t minixfs_write(file_system *fs, const char *path, const void *buf,
size_t count, off_t *off) {
// X marks the spot
return -1;
}
ssize_t minixfs_read(file_system *fs, const char *path, void *buf, size_t count,
off_t *off) {
const char *virtual_path = is_virtual_path(path);
if (virtual_path)
return minixfs_virtual_read(fs, virtual_path, buf, count, off);
// 'ere be treasure!
return -1;
}