In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people have no idea about how to implement the function in Linux APM structure. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
It should be noted that Linux APM and acpi are conflicting modules, and users can only load one of them at the same time, and if they find that one of them is loaded when they are loading, they will exit automatically.
Function implementation in Linux APM structure
When a user process opens an apm_bios device, it calls this function
Static int apm_open (struct inode * inode, struct file * filp)
{
/ / this key is the Linux APM_user structure variable as, which is a bridge between the user and the Linux APM kernel. When a Linux APM event occurs, the event is hung on the queue of apm_user, so that when the user reads the event, it will read the relevant event and deal with it.
Struct apm_user * as
Lock_kernel ()
/ / assign a Linux APM_user structure to represent a user process
As = kzalloc (sizeof (* as), GFP_KERNEL)
/ / permissions settings such as read and write
If (as) {
As- > suser = capable (CAP_SYS_ADMIN)
As- > writer = (filp- > f_mode & FMODE_WRITE) = = FMODE_WRITE
As- > reader = (filp- > f_mode & FMODE_READ) = = FMODE_READ
/ / add this user to the user queue
Down_write & user_list_lock)
List_add (& as- > list, & apm_user_list)
Up_write & user_list_lock)
/ / this is a common way to pass private data
Filp- > private_data = as
}
Unlock_kernel ()
Return as? 0:-ENOMEM
}
This function is called when the user space process reads the device. The main function of this function is to read events into user space.
Static ssize_t apm_read (struct file * fp, char _ _ user * buf, size_t count, loff_t * ppos)
{
Struct apm_user * as = fp- > private_data
Apm_event_t event
Int I = count, ret = 0
If (count
< sizeof(apm_event_t)) return -EINVAL; //队列空, 且进程非阻塞读, 立刻返回 if (queue_empty(&as->Queue) & & fp- > f_flags & O_NONBLOCK)
Return-EAGAIN
/ / otherwise wait until the queue is not empty
Wait_event_interruptible (apm_waitqueue,! queue_empty (& as- > queue))
/ / copy the events in the queue to user space
While ((I > = sizeof (event)) & &! queue_empty (& as- > queue)) {
Event = queue_get_event (& as- > queue)
Ret =-EFAULT
If (copy_to_user (buf, & event, sizeof (event)
Break
After reading the above, have you mastered how to implement the functions in the Linux APM structure? 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.
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.