My linux kernel is "5.11.0-36-generic".
I want to read parameter from a file named "myTest.txt".
after make
, terminal says:
error: implicit declaration of function ‘get_fs’; did you mean ‘sget_fc’? [-Werror=implicit-function-declaration]
I have searched for answers, and found that article: Saying goodbye to set_fs()..
Can anyone tell me how to replace it?
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/slab.h>
int __init hello_init(void)
{
unsigned char buf1[12]="hello world.";
unsigned char buf2[12]="kernel file.";
struct file *fp;
mm_segment_t fs;
loff_t pos;
printk("hello enter\n");
fp = filp_open("/home/kernel_file", O_RDWR | O_CREAT, 0644);
if (IS_ERR(fp)) {
printk("create file error\n");
return -1;
}
fs = get_fs(); //------------------------wrong !!
set_fs(KERNEL_DS);//------------------------wrong !!
pos = fp->f_pos;
vfs_write(fp, buf1, sizeof(buf1), &pos);
fp->f_pos = pos;
pos = fp->f_pos;
vfs_write(fp, buf2, sizeof(buf2), &pos);
fp->f_pos = pos;
set_fs(fs); //------------------------wrong !!
filp_close(fp, NULL);
return 0;
}
void __exit hello_exit(void)
{
printk(" exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");