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)