Linux文件系统omfs的目录创建和删除
Omfs文件目录的结构是通过对name做hash来实现的:
定义inode_operations结构体,
相关阅读:
const struct inode_operations omfs_dir_inops = {
.lookup = omfs_lookup,
.mkdir = omfs_mkdir,
.rename = omfs_rename,
.create = omfs_create,
.unlink = omfs_unlink,
.rmdir = omfs_rmdir,
};
系统调用mkdir dir1
Breakpoint 2, omfs_mkdir (dir=0xdee25d88, dentry=0xdedc8660, mode=493)
at fs/omfs/dir.c:298
298 return omfs_add_node(dir, dentry, mode | S_IFDIR);
(gdb) bt
#0 omfs_mkdir (dir=0xdee25d88, dentry=0xdedc8660, mode=493)
at fs/omfs/dir.c:298
#1 0xc029fdb6 in vfs_mkdir (dir=0xdee25d88, dentry=0xdedc8660, mode=493)
at fs/namei.c:2086
#2 0xc029fe8c in sys_mkdirat (dfd=-100, pathname=0xbf8de932 "dir1", mode=493)
at fs/namei.c:2116
#3 0xc029fef3 in sys_mkdir (pathname=0xbf8de932 "dir1", mode=511)
at fs/namei.c:2131
#4 0xc0104657 in ?? () at arch/x86/kernel/entry_32.S:457
可以看到系统调用的过程:
Sys_mkdiràsys_mkdiratàvfs_mkdiràomfs_mkdir
dir=0xdee25d88
dentry=0xdedc8660
p *dentry
$7 = {d_count = {counter = 1}, d_flags = 0, d_lock = {{rlock = {raw_lock = {
slock = 257}}}}, d_mounted = 0, d_inode = 0x0, d_hash = {next = 0x0,
pprev = 0xc144096c}, d_parent = 0xdf4ea198, d_name = {hash = 25987720,
len = 4, name = 0xdedc86bc "dir1"}, d_lru = {next = 0xdedc868c,
prev = 0xdedc868c}, d_u = {d_child = {next = 0xdf4ea1d4,
prev = 0xdf4ea1d4}, d_rcu = {next = 0xdf4ea1d4, func = 0xdf4ea1d4}},
d_subdirs = {next = 0xdedc869c, prev = 0xdedc869c}, d_alias = {
next = 0xdedc86a4, prev = 0xdedc86a4}, d_time = 1701080941, d_op = 0x0,
d_sb = 0xdd91e400, d_fsdata = 0x0,
d_iname = "dir1\000ne\000_larval_drop\000__ticket_spin_unloc"}
p *(struct dentry *)0xdf4ea198
$8 = {d_count = {counter = 6}, d_flags = 16, d_lock = {{rlock = {raw_lock = {
slock = 1028}}}}, d_mounted = 0, d_inode = 0xdee25d88, d_hash = {
next = 0x0, pprev = 0x0}, d_parent = 0xdf4ea198, d_name = {hash = 0,
len = 1, name = 0xdf4ea1f4 "/"}, d_lru = {next = 0xdf4ea1c4,
prev = 0xdf4ea1c4}, d_u = {d_child = {next = 0xdf4ea1cc,
prev = 0xdf4ea1cc}, d_rcu = {next = 0xdf4ea1cc, func = 0xdf4ea1cc}},
d_subdirs = {next = 0xdedc8694, prev = 0xdedc8694}, d_alias = {
next = 0xdee25da0, prev = 0xdee25da0}, d_time = 0, d_op = 0x0,
d_sb = 0xdd91e400, d_fsdata = 0x0,
d_iname = "/\000v\000-linux-gnu\000\337`M|\300\340L|\300\000d\200\337\000\000\000\000\030\242N\337h\241N", <incomplete sequence \337>}
p *dir
$6 = {i_hash = {next = 0x0, pprev = 0xc1463a90}, i_list = {next = 0xdf597480,
prev = 0xd2335648}, i_sb_list = {next = 0xdd91e474, prev = 0xdd91e474},
i_dentry = {next = 0xdf4ea1dc, prev = 0xdf4ea1dc}, i_ino = 3, i_count = {
counter = 1}, i_nlink = 2, i_uid = 0, i_gid = 0, i_rdev = 0,
i_blkbits = 11, i_version = 0, i_size = 2048, i_size_seqcount = {
sequence = 0}, i_atime = {tv_sec = 1328683425, tv_nsec = 0}, i_mtime = {
tv_sec = 1328683648, tv_nsec = 915000}, i_ctime = {tv_sec = 1328683648,
tv_nsec = 915000}, i_blocks = 0, i_bytes = 0, i_mode = 16877, i_lock = {{
rlock = {raw_lock = {slock = 514}}}}, i_mutex = {count = {counter = 0},
wait_lock = {{rlock = {raw_lock = {slock = 0}}}}, wait_list = {
next = 0xdee25e08, prev = 0xdee25e08}, owner = 0xddb0c000},
i_alloc_sem = {count = 0, wait_lock = {{rlock = {raw_lock = {slock = 0}}}},
wait_list = {next = 0xdee25e1c, prev = 0xdee25e1c}}, i_op = 0xe27ccb60,
i_fop = 0xe27ccbc0, i_sb = 0xdd91e400, i_flock = 0x0,
i_mapping = 0xdee25e38, i_data = {host = 0xdee25d88, page_tree = {
height = 0, gfp_mask = 32, rnode = 0x0}, tree_lock = {{rlock = {
raw_lock = {slock = 0}}}}, i_mmap_writable = 0, i_mmap = {
prio_tree_node = 0x0, index_bits = 1, raw = 1}, i_mmap_nonlinear = {
next = 0xdee25e58, prev = 0xdee25e58}, i_mmap_lock = {{rlock = {
raw_lock = {slock = 0}}}}, truncate_count = 0, nrpages = 0,
writeback_index = 0, a_ops = 0xe27ccd20, flags = 131290,
backing_dev_info = 0xd233559c, private_lock = {{rlock = {raw_lock = {
slock = 0}}}}, private_list = {next = 0xdee25e80,
---Type <return> to continue, or q <return> to quit---
prev = 0xdee25e80}, assoc_mapping = 0x0}, i_dquot = {0x0, 0x0},
i_devices = {next = 0xdee25e94, prev = 0xdee25e94}, {i_pipe = 0x0,
i_bdev = 0x0, i_cdev = 0x0}, i_generation = 0, i_fsnotify_mask = 0,
i_fsnotify_mark_entries = {first = 0x0}, inotify_watches = {
next = 0xdee25eac, prev = 0xdee25eac}, inotify_mutex = {count = {
counter = 1}, wait_lock = {{rlock = {raw_lock = {slock = 0}}}},
wait_list = {next = 0xdee25ebc, prev = 0xdee25ebc}, owner = 0x0},
i_state = 1, dirtied_when = 4294956485, i_flags = 0, i_writecount = {
counter = 0}, i_security = 0x0, i_acl = 0xffffffff,
i_default_acl = 0xffffffff, i_private = 0x0}