在看battery驱动时,遇到get_fs()和set_fs(KERNEL_DS),以下是具体函数:
void 厂商名_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 ==
厂商名_bat) {
printk(DBGMSK_BAT_ERR"[BAT]%s(), null ptr \r\n", __FUNCTION__);
return;
}
used = snprintf(bat_cap_s, sizeof(bat_cap_s) ,"%d", 厂商名_bat->phone_b.capacity);
pr_debug( "[BAT] %s(), phone bat capacity:%d, write bat capcity string:%s, used:%d \r\n",
__FUNCTION__,
厂商名_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;
}