In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to call the sync source code in the linux system, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Int sys_sync (void)
{
Int i
Struct buffer_head * bh
/ / write all inode to buffer and wait for write back, as shown in the following code
Sync_inodes (); / * write out inodes into buffers * /
Bh = start_buffer
For (iTun0; ib_dirt)
/ / request the underlying layer to write to the hard disk, waiting for the underlying driver to write back to the hard disk, not necessarily immediately
Ll_rw_block (WRITE,bh)
}
Return 0
}
Let's take a look at sync_inode. This function writes the inode node in inode table, that is, the file opened by the process, to buffer.
/ / iterate through all the inode, read the data blocks including the inode from the hard disk, and then use the inode of memory to overwrite the data read in the hard disk, store it in buffer, and wait for write back.
Void sync_inodes (void)
{
Int i
Struct m_inode * inode
Inode = 0+inode_table
For (iTun0; ii_dirt & &! inode- > i_pipe)
Write_inode (inode)
}
}
/ / first read the inode from the hard disk, then overwrite it, and wait for write back
Static void write_inode (struct m_inode * inode)
{
Struct super_block * sb
Struct buffer_head * bh
Int block
Lock_inode (inode)
If (! inode- > i_dirt | |! inode- > i_dev) {
Unlock_inode (inode)
Return
}
If (! (sb=get_super (inode- > i_dev)
Panic ("trying to write inode without device")
/ / calculate the block number of inode, the relative offset of 2 + inode bitmap blocks + block bitmap blocks + inode
Block = 2 + sb- > s_imap_blocks + sb- > s_zmap_blocks +
(inode- > i_num-1) / INODES_PER_BLOCK
/ / read the entire data block containing the inode
If (! (bh=bread (inode- > iDeign block)
Panic ("unable to read i-node block")
/ / find the location of the inode in the data block, write to the cache and wait for writing back to the hard disk
((struct d_inode *) bh- > b_data)
[(inode- > i_num-1)% INODES_PER_BLOCK] =
* (struct d_inode *) inode
Bh- > b_dirt=1
Inode- > i_dirt=0
Brelse (bh)
Unlock_inode (inode)
}
The above is how to call the sync source code in the linux system. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.