Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mksfs.c add_entry问题 #1

Open
hhxx1994 opened this issue Jul 29, 2018 · 0 comments
Open

mksfs.c add_entry问题 #1

hhxx1994 opened this issue Jul 29, 2018 · 0 comments

Comments

@hhxx1994
Copy link

static void
add_entry(struct sfs_fs *sfs, struct cache_inode *current, struct cache_inode *file, const char *name) {
    //sfs_disk_entry
    static struct sfs_entry __entry, *entry = &__entry;
    //current必须是目录类型的inode
    assert(current->inode.type == SFS_TYPE_DIR && strlen(name) <= SFS_MAX_FNAME_LEN);
    //设置block number id和文件名称
    entry->ino = file->ino, strcpy(entry->name, name);
    // 下一个 block ino
    uint32_t entry_ino = sfs_alloc_ino(sfs);
    // 都是从 entry_no * blocksize开始写,这个意思是 一个entry占有一个disk block 了
    //               data ,  len=256          , block number id 
    write_block(sfs, entry, sizeof(entry->name), entry_ino);
    
    // printf("entry->name: %s entry_ino: %d  len:%d \n", entry->name, entry_ino ,sizeof(entry->name));
    
    // 在sfs->blocks中添加一个cache_block和相应的ino
    // 就是将entry_ino 记录到current->inode->direct 或则 current->inode->indirect 或者 current->inode->db_indirect
    //current->inode->direct[current->nblks] = entry_ino
    // 给目录 current 添加一个表示 文件或者目录的sfs_entry数据
    append_block_slot(sfs, current, entry_ino, name);
    //append_block(sfs, current, sizeof(entry->name), entry_ino, name);
    file->inode.nlinks ++;
}

write_block(sfs, entry, sizeof(entry->name), entry_ino);
这里为什么是sizeof(entry->name),而不是sizeof(sfs_entry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant