How to manipulate files in the Linux kernel-using GET_FS () and Set_fs (Kernel_ds)

Source: Internet
Author: User

When looking at the battery driver, Get_fs () and Set_fs (Kernel_ds) are encountered, the following are the specific functions:

void Vendor name _bat_write_phone_bat_capacity_tofile (void)
{
struct file *fp_bat_sts = NULL;
int used = 0;
mm_segment_t Old_fs;
unsigned char bat_cap_s[4];
loff_t pos_bat = 0;

if (NULL = =Manufacturer name _bat) {
PRINTK (Dbgmsk_bat_err "[bat]%s (), null PTR \ r \ n", __function__);
Return
}

used = snprintf (bat_cap_s, sizeof (bat_cap_s), "%d", manufacturer name _bat->phone_b.capacity);
Pr_debug ("[BAT]%s (), phone BAT capacity:%d, write BAT capcity string:%s, used:%d \ r \ n",
__FUNCTION__, manufacturer name _bat->phone_b.capacity, bat_cap_s, used);
    
     old_fs = Get_fs ();
     set_fs (Kernel_ds);

    fp_bat_sts = Filp_open (Bat_status_txt, o_wronly| O_creat, 0640);
    if (!is_err (fp_bat_sts)) {
        fp_bat_sts->f_op-> Write (fp_bat_sts, bat_cap_s, used, &pos_bat);
        set_fs (OLD_FS);
        filp_close (fp_bat_sts, NULL);
    } else {
        printk (dbgmsk_bat_err "[BAT] error!! Bat_status Filp Open failed. \ r \ n ");
    }

    return;
}

How to manipulate files in the Linux kernel-using GET_FS () and Set_fs (Kernel_ds)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.