Remember the problem that the save mechanism cannot be written once

The problem of information not being saved after power failure is analyzed as follows.

     The OS has checked that the data partition is readable and writable, but hmi still prompts that the directory or file cannot be found
     . The

     test program is as follows, there are two points to note

1. Please pay attention to the setting of the permission mode parameter (the current system permission mask is umask 0022)
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>

void main()
{
    int fd,size;
    char s [ ]="Linux Programmer!\n", buffer[80];

    fd=open("/data/data/Persistency", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
    write(fd, s, sizeof(s));
    close(fd);
    fd=open("/data/data/Persistency", O_RDONLY);
    size=read(fd,buffer,sizeof(buffer));
    close(fd);
    printf("%ssize= %d \n", buffer, size);
}
2. Only the /data directory exists in the existing system, and the O_RDWR|O_CREAT parameter cannot directly create the /data/data/Persistency file
    You need to create a directory before opening the file
mkdir("/data/data",0777);
fd=open("/data/data/Persistency", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
The figure below is the result of the operation


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325467886&siteId=291194637