Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call sys_unlink in linux system

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people have no idea about how to call sys_unlink in linux system. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Sys_unlink is a system call to delete hard links. When the number of references is 0, the underlying files will be deleted. Sys_unlink is a system call to delete hard links, and when the number of references is 0, the underlying files will be deleted.

/ / remove hard links

Int sys_unlink (const char * name)

{

Const char * basename

Int namelen

Struct m_inode * dir, * inode

Struct buffer_head * bh

Struct dir_entry * de

/ / find out the inode of the last level directory of the path and the file name in the path

If (! (dir = dir_namei (name,&namelen,&basename)

Return-ENOENT

/ / the path passed in is a directory

If (! namelen) {

Iput (dir)

Return-ENOENT

}

/ / permissions

If (! permission (dir,MAY_WRITE)) {

Iput (dir)

Return-EPERM

}

/ / find the directory entry of the file corresponding to the path

Bh = find_entry (& dir,basename,namelen,&de)

/ / does not exist

If (! bh) {

Iput (dir)

Return-ENOENT

}

/ / read the inode node corresponding to the directory entry

If (! (inode = iget (dir- > i_dev, de- > inode)) {

Iput (dir)

Brelse (bh)

Return-ENOENT

}

/ / permissions

If ((dir- > i_mode & S_ISVTX) & &! suser () & &

Current- > euid! = inode- > i_uid & &

Current- > euid! = dir- > i_uid) {

Iput (dir)

Iput (inode)

Brelse (bh)

Return-EPERM

}

/ / hard links cannot be directories

If (S_ISDIR (inode- > i_mode)) {

Iput (inode)

Iput (dir)

Brelse (bh)

Return-EPERM

}

/ / No process references the inode

If (! inode- > i_nlinks) {

Printk ("Deleting nonexistent file (XRV% d),% d\ n"

Inode- > iSigu _

Inode- > i_nlinks=1

}

/ / dereferencing, inode is set to 0

De- > inode = 0

/ / need to write back the hard disk

Bh- > b_dirt = 1

Brelse (bh)

/ / the number of references is reduced by one, and files with 0 references will be deleted in iput

Inode- > iTunes Linkage-

Inode- > i_dirt = 1

Inode- > i_ctime = CURRENT_TIME

Iput (inode)

Iput (dir)

Return 0

}

After reading the above, have you mastered how to call sys_unlink in the linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report