Skip to content

Commit

Permalink
fix some mo bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tash-had committed Apr 6, 2019
1 parent b7078b5 commit 16ac0c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion a4/ext2_restore.c
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char **argv) {
struct ext2_dir_entry *deleted_dir_entry = (void *) curr_dir + get_rec_len(curr_dir->name);

if (deleted_dir_entry->inode > 0) {
if (!is_valid(get_inode_map(), deleted_dir_entry->inode)) {
if (!is_valid(get_inode_map(), deleted_dir_entry->inode - 1)) {
if (strlen(pd->file_name) == deleted_dir_entry->name_len && strncmp(pd->file_name, deleted_dir_entry->name, deleted_dir_entry->name_len) == 0) {
allocate_inode_with_num(deleted_dir_entry->inode);
(&inode_table[deleted_dir_entry->inode -1])->i_dtime = 0;
Expand Down
4 changes: 2 additions & 2 deletions a4/utils.c
Expand Up @@ -47,9 +47,9 @@ unsigned char *get_block_bitmap() {
return (unsigned char *)(disk + EXT2_BLOCK_SIZE * get_group_desc()->bg_block_bitmap);
}

int is_valid(unsigned char *inode_bitmap, int bit_idx) {
int is_valid(unsigned char *bitmap, int bit_idx) {
int mask = 1 << (bit_idx % 8);
return inode_bitmap[bit_idx / 8] & mask;
return bitmap[bit_idx / 8] & mask;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion a4/utils.h
Expand Up @@ -15,7 +15,7 @@ unsigned char *get_block_bitmap();
unsigned char *get_inode_map();

void init_disk(char *img_name);
int is_valid(unsigned char *inode_bitmap, int bit_idx);
int is_valid(unsigned char *bitmap, int bit_idx);
int get_rec_len(char *dir_ent_name);
void init_dir_entry(int dir_block_num, int offset, int type, int inode_idx, char name[], int size);
int add_file_to_parent(int parent_inode_num, int inode_num, char name[], int type);
Expand Down

0 comments on commit 16ac0c6

Please sign in to comment.