Linux kernel research: my virtual file system (linux)
Source: Internet
Author: User
Article title: linux kernel research: my virtual file system (linux ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Hello. c
Code:
Int hello_readdir (struct file * filp, void * dirent, filldir_t filldir)
{
Printk ("hello_readdir \ n ");
Struct hello_dir_entry * de;
Unsigned int ino;
Int I;
Struct inode * inode = filp-> f_dentry-> d_inode;
Ino = inode-> I _ino;
De = (struct hello_dir_entry *) inode-> u. generic_ip;
If (! De)
Return-EINVAL;
I = filp-> f_pos;
Switch (I ){
Case 0:
If (filldir (dirent, ".", 1, I, ino, DT_DIR) <0)
Return 0;
I ++;
Filp-> f_pos ++;
/* Fall through */
Case 1:
If (filldir (dirent, "..", 2, I,
Filp-> f_dentry-> d_parent-> d_inode-> I _ino,
DT_DIR) <0)
Return 0;
I ++;
Filp-> f_pos ++;
/* Fall through */
Default:
De = de-> subdir;
I-= 2;
For (;;){
If (! De)
Return 1;
If (! I)
Break;
De = de-> next;
I --;
}
Do {
If (filldir (dirent, de-> name, de-> namelen, filp-> f_pos,
De-> low_ino, de-> mode> 12) <0)
Return 0;
Filp-> f_pos ++;
De = de-> next;
} While (de );
}
Return 1;
}
Error =-ENOENT;
Inode = NULL;
De = (struct hello_dir_entry *) dir-> u. generic_ip;
If (de ){
For (de = de-> subdir; de = de-> next ){
If (! De |! De-> low_ino)
Continue;
If (de-> namelen! = Dentry-> d_name.len)
Continue;
If (! Memcmp (dentry-> d_name.name, de-> name, de-> namelen )){
Int ino = de-> low_ino;
Error =-EINVAL;
Inode = hello_get_inode (dir-> I _sb, ino, de );
Break;
}
}
}
Struct dentry * d_alloc_root (struct inode * root_inode)
{
Struct dentry * res = NULL;
Printk ("d_alloc_root \ n ");
If (root_inode ){
Res = d_alloc (NULL, & (const struct qstr) {"/", 1, 0 });
If (res ){
Res-> d_sb = root_inode-> I _sb;
Res-> d_parent = res;
D_instantiate (res, root_inode );
}
}
Return res;
}
Void force_delete (struct inode * inode)
{
Printk ("force_delete \ n ");
Struct hello_dir_entry * de = inode-> u. generic_ip;
If (atomic_read (& inode-> I _count) = 1)
Inode-> I _nlink = 0;
If (atomic_dec_and_test (& de-> count ))
Printk ("hello_root.count: % d \ n", atomic_read (& de-> count ));
}
Static void hello_delete_inode (struct inode * inode)
{
Printk ("hello_delete_inode \ n ");
Struct hello_dir_entry * de = inode-> u. generic_ip;
Inode-> I _state = I _CLEAR;
/* If (de ){
If (de-> owner)
_ MOD_DEC_USE_COUNT (de-> owner );
De_put (de );
}*/
}
Static void hello_read_inode (struct inode * inode)
{
Printk ("hello_read_inode \ n ");
Inode-> I _mtime = inode-> I _atime = inode-> I _ctime = CURRENT_TIME;
}
Static int hello_statfs (struct super_block * sb, struct statfs * buf)
{
Printk ("hello_statfs \ n ");
Return 0;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.