static int hello_mkdir(const char *path, mode_t mode) { int index = find_empty_inode(); time_t cr_time = time(NULL); puts("mkdir"); if(index == -1){ puts("mk_dir end abnormally"); return -1; } else { strcpy(inodes[index].name, path); inodes[index].STAT.st_mode = mode | S_IFDIR; inodes[index].STAT.st_nlink = 2; inodes[index].STAT.st_ino = index; inode_flag[inode_index] = 1; inodes[index].STAT.st_atime = cr_time; inodes[index].STAT.st_mtime = cr_time; inodes[index].STAT.st_ctime = cr_time; inodes[index].STAT.st_size = 0; printf("inode_index = %d, mode is %d\n", inode_index, mode); inode_index ++; puts("mk_dir end"); } return 0; }
int main(int argc, char *argv[]) { printf("--- test inode table leaf methods ---\n"); struct sb *sb = &(struct sb){ .blocksize = 4096 }; struct btree *btree = &(struct btree){ .sb = sb, .ops = &itable_ops, .entries_per_leaf = 64, // !!! should depend on blocksize }; struct ileaf *leaf = ileaf_create(btree); struct ileaf *dest = ileaf_create(btree); leaf->ibase = to_be_u64(0x10); ileaf_dump(btree, leaf); test_append(btree, leaf, 0x13, 2, 'a'); test_append(btree, leaf, 0x14, 4, 'b'); test_append(btree, leaf, 0x16, 6, 'c'); ileaf_dump(btree, leaf); ileaf_split(btree, 0x10, leaf, dest); ileaf_dump(btree, leaf); ileaf_dump(btree, dest); ileaf_merge(btree, leaf, dest); ileaf_dump(btree, leaf); test_append(btree, leaf, 0x13, 3, 'x'); ileaf_dump(btree, leaf); test_append(btree, leaf, 0x18, 3, 'y'); ileaf_dump(btree, leaf); test_remove(btree, leaf, 0x16, 5); ileaf_dump(btree, leaf); unsigned size = 0; char *inode = ileaf_lookup(btree, 0x13, leaf, &size); hexdump(inode, size); for (int i = 0x11; i <= 0x20; i++) printf("goal 0x%x => 0x%Lx\n", i, (L)find_empty_inode(btree, leaf, i)); ileaf_purge(btree, 0x14, leaf); ileaf_purge(btree, 0x18, leaf); ileaf_check(btree, leaf); ileaf_dump(btree, leaf); ileaf_destroy(btree, leaf); ileaf_destroy(btree, dest); exit(0); }