aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2022-01-31 23:31:14 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2022-01-31 23:31:14 +0100
commit63041afa33732ce2f98b58cffa99618f30f1e29b (patch)
tree8827471873122a791b244b61f50ee1da58ea5ae3
parentf4dbc6cb10e78e91aa2b4b0775fba6931fb29093 (diff)
Ostatnia poprawka
-rw-r--r--ext2fs.c48
-rw-r--r--files.sha2562
2 files changed, 18 insertions, 32 deletions
diff --git a/ext2fs.c b/ext2fs.c
index 21e87ed..10174ef 100644
--- a/ext2fs.c
+++ b/ext2fs.c
@@ -1,3 +1,11 @@
+/*
+ * Oświadczam, że zapoznałem(-am) się z regulaminem prowadzenia zajęć
+ * i jestem świadomy(-a) konsekwencji niestosowania się do podanych tam zasad.
+ */
+#ifdef STUDENT
+/* Imię i nazwisko, numer indeksu: Franciszek Malinka, 316093 */
+#endif
+
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -208,26 +216,20 @@ int ext2_block_used(uint32_t blkaddr) {
return EINVAL;
int used = 0;
#ifdef STUDENT
- /* TODO */
- /* MY-TODO: What should be returned if the blkaddr points to meta-data? */
- // debug("ext2_block_used(%d)?\n", blkaddr);
uint32_t grp_no = (blkaddr - first_data_block) / blocks_per_group;
uint32_t b_bitmap_addr = group_desc[grp_no].gd_b_bitmap;
blk_t *bitmap_blk = blk_get(0, b_bitmap_addr);
uint8_t *bitmap = bitmap_blk->b_data;
- /* index of the data block pointed by blkaddr in the group is blkaddr
- * minus (the offset of b_bitmap_addr + 2 (for data bitmap and inode
- * bitmap) + blocks used for inode table.)*/
uint32_t local_idx = (blkaddr - first_data_block) % blocks_per_group;
- // debug("Group: %u, bitmap at %u\n", grp_no, b_bitmap_addr);
- // debug("local idx: %u\n", local_idx);
#ifdef DEBUG
+ debug("Group: %u, bitmap at %u\n", grp_no, b_bitmap_addr);
+ debug("local idx: %u\n", local_idx);
assert(bitmap_blk->b_inode == 0);
assert(bitmap_blk->b_blkaddr == b_bitmap_addr);
assert(local_idx < BLKSIZE * 8);
#endif
-
+ /* Shouldn't it be 128 >> (local_idx % 8)? :P */
used = (bitmap[local_idx / 8] & (1 << (local_idx % 8))) > 0;
blk_put(bitmap_blk);
@@ -242,12 +244,10 @@ int ext2_inode_used(uint32_t ino) {
return EINVAL;
int used = 0;
#ifdef STUDENT
- /* TODO */
- /* MY-TODO: Similar to ext2_block_used. */
uint32_t grp_no = (ino - 1) / inodes_per_group;
uint32_t i_bitmap_addr = group_desc[grp_no].gd_i_bitmap;
- blk_t *i_bitmap = blk_get(0, i_bitmap_addr);
-
+ blk_t *bitmap_blk = blk_get(0, i_bitmap_addr);
+ uint8_t *bitmap = bitmap_blk->b_data;
uint32_t local_idx = (ino - 1) % inodes_per_group;
#ifdef DEBUG
@@ -256,10 +256,9 @@ int ext2_inode_used(uint32_t ino) {
assert(local_idx < BLKSIZE * 8);
#endif
- used =
- (((char *)i_bitmap->b_data)[local_idx / 8] & (1 << (local_idx % 8))) > 0;
+ used = (bitmap[local_idx / 8] & (1 << (local_idx % 8))) > 0;
- blk_put(i_bitmap);
+ blk_put(bitmap_blk);
#endif /* !STUDENT */
return used;
}
@@ -268,8 +267,6 @@ int ext2_inode_used(uint32_t ino) {
* Returns 0 on success. If i-node is not allocated returns ENOENT. */
static int ext2_inode_read(off_t ino, ext2_inode_t *inode) {
#ifdef STUDENT
- /* TODO */
-
if (!ext2_inode_used(ino))
return ENOENT;
@@ -289,8 +286,6 @@ static int ext2_inode_read(off_t ino, ext2_inode_t *inode) {
/* Returns block pointer `blkidx` from block of `blkaddr` address. */
static uint32_t ext2_blkptr_read(uint32_t blkaddr, uint32_t blkidx) {
#ifdef STUDENT
- /* TODO */
- /* MY-TODO -- I don't get the hint from the task statement */
blk_t *blk = blk_get(0, blkaddr);
#ifdef DEGUG
assert(blkidx <= (BLKSIZE / sizeof(uint32_t)));
@@ -315,8 +310,6 @@ long ext2_blkaddr_read(uint32_t ino, uint32_t blkidx) {
/* Read direct pointers or pointers from indirect blocks. */
#ifdef STUDENT
- /* TODO */
- // debug("Pytanko: %d %d, %d\n", ino, blkidx, inode.i_size);
const uint32_t direct_blocks = EXT2_NDADDR;
const uint32_t ind1_blks = BLKSIZE / sizeof(uint32_t);
const uint32_t ind2_blks = ind1_blks * BLKSIZE / sizeof(uint32_t);
@@ -358,7 +351,6 @@ long ext2_blkaddr_read(uint32_t ino, uint32_t blkidx) {
* WARNING: This function assumes that `ino` i-node pointer is valid! */
int ext2_read(uint32_t ino, void *data, size_t pos, size_t len) {
#ifdef STUDENT
- /* TODO */
size_t end_pos = pos + len;
if (ino != 0) {
ext2_inode_t inode;
@@ -372,7 +364,6 @@ int ext2_read(uint32_t ino, void *data, size_t pos, size_t len) {
uint32_t bytes_copied = 0;
for (blkidx = pos / BLKSIZE; blkidx < (end_pos + BLKSIZE - 1) / BLKSIZE;
blkidx++) {
- // debug("Trying to get %d %d\n", ino, blkidx);
blk = blk_get(ino, blkidx);
uint32_t len_to_cpy;
if (bytes_copied == 0) {
@@ -409,7 +400,6 @@ int ext2_read(uint32_t ino, void *data, size_t pos, size_t len) {
int ext2_readdir(uint32_t ino, uint32_t *off_p, ext2_dirent_t *de) {
#ifdef STUDENT
- /* TODO */
ext2_inode_t inode;
ext2_inode_read(ino, &inode);
if (*off_p >= inode.i_size)
@@ -443,7 +433,6 @@ int ext2_readlink(uint32_t ino, char *buf, size_t buflen) {
/* Check if it's a symlink and read it. */
#ifdef STUDENT
- /* TODO */
if (!(inode.i_mode & EXT2_IFLNK))
return EINVAL;
if (inode.i_size > buflen)
@@ -470,7 +459,6 @@ int ext2_stat(uint32_t ino, struct stat *st) {
/* Convert the metadata! */
#ifdef STUDENT
- /* TODO */
st->st_ino = ino;
st->st_mode = inode.i_mode;
st->st_nlink = inode.i_nlink;
@@ -507,9 +495,6 @@ int ext2_lookup(uint32_t ino, const char *name, uint32_t *ino_p,
return error;
#ifdef STUDENT
- /* TODO */
- // (void)ino_p;
- // (void)type_p;
if (!(inode.i_mode & EXT2_IFDIR))
return ENOTDIR;
ext2_dirent_t de;
@@ -566,7 +551,6 @@ int ext2_mount(const char *fspath) {
/* Load interesting data from superblock into global variables.
* Read group descriptor table into memory. */
#ifdef STUDENT
- /* TODO */
inodes_per_group = sb.sb_ipg;
blocks_per_group = sb.sb_bpg;
group_desc_count = (sb.sb_bcount + sb.sb_bpg - 1) / sb.sb_bpg; // ceil
@@ -575,6 +559,7 @@ int ext2_mount(const char *fspath) {
first_data_block = sb.sb_first_dblock;
size_t group_desc_table_sz = group_desc_count * sizeof(*group_desc);
+
debug("group_desc_table_sz: %ld\n", group_desc_table_sz);
debug("group_desc_count: %ld\n", group_desc_count);
debug("first_data_block: %ld\n", first_data_block);
@@ -582,6 +567,7 @@ int ext2_mount(const char *fspath) {
for (int i = 0; i < NBLOCKS; i++) {
debug("blkdata[%d]: %p\n", i, blkdata[i]);
}
+
group_desc = malloc(group_desc_table_sz);
ext2_read(0, group_desc, EXT2_GDOFF, group_desc_table_sz);
diff --git a/files.sha256 b/files.sha256
index 0c03bea..cb3747f 100644
--- a/files.sha256
+++ b/files.sha256
@@ -2,7 +2,7 @@ dd16d5a60d6923565628b05c6bbaa78f86cb47366fc83ffa6168931b28034d96 .clang-format
eb8f0887af4317e9df0dd302f34c2dd30efc4fdcab3ded1a0646c85f01b42c32 .github/classroom/autograding.json
2e015f1dc9a4cc2d044cd6629d66f6aaea3bd83c2fb242f0b5e5b7b5eeabf458 .github/workflows/classroom.yml
99656309552b6bf4d8ff20c2b06cf93ba7c3dda99fff86c03c6893c578e8aa45 check-files.py
-ca271adde44b5fe121f4e3e71cee702885444cd2b1876480f1a60fc8311cfd4e ext2fs.c
+80a7baf32b0b964345e8b02518f79f6b7f7835ef4110dba6d4ecb6963474bb7d ext2fs.c
3bba687490ccf9568763f28e36aefd4837af7853c1b87bd1a308305ab09d4512 ext2fs_defs.h
424b7c445861a803332b8c2ded10f21b7d6d01871cd98e3e154c21d88be20332 ext2fs.h
82cdb09e04b98264a9b17226149aedd0a4649c3fc7ec87967a7710c04668f81c ext2fuse.c