I know it's not worth doing but I have to. I want to delete information from a specific text file that called file1.text after i read from this file , How can i do that in my module. Many thanks to all the helpers.
static int checkDOS(char *name)
{
//get the path to this file
char path[2000];
strncat(path,"/home/daniel/count/should/",1000);
strncat(path,name,1000);
struct file * file_dos;
//Open this file
file_dos=filp_open(path,O_RDONLY,0);
char count[1];//save the first character of file
//check if the file is exists
if(IS_ERR(file_dos) == 0)
{
file_read(file_dos,0,count,1);//Read this file
if(count[0]=='0')
{
return 0;
}
char count2[200];//Stores the number listed in the file
filp_close(file_dos,NULL);//close the this text file
file_sync(file_dos);
//Takes the character stored in the count variable converts
// it to a number and then subtracts one from it, then
file_dos=filp_open(path,O_WRONLY, 0);
long count_dos;
kstrtol(count,0,&count_dos);
count_dos=count_dos-1;
//converts it to a string, then writes in a file
sprintf(count2, "%d", count_dos);
file_write(file_dos,1,count2,1);
filp_close(file_dos,NULL);
return 1;
}
return 0;
}