1

我已经在用户空间上编写了主管应用程序c,我将白名单 id 保留在超级块上。它从 superblock 读取数据: filepath = "/dev/flashSSD"

        char soz[15];
        int i=1;
        fp = open(filepath,O_RDONLY);
        if (fp<0) {printf("Unable to open %s block.\n",filepath);exit(EXIT_FAILURE);}

        off_t off = lseek(fp,0,SEEK_SET);
        ssize_t len = read(fp,prc,sizeof prc);
        sscanf(prc[0],"%d",sany);

并在管理(插入,删除)ID后,它在退出时写回超级块:

        fp = open(filepath,O_RDWR);
        if (fp<0) {printf("Unable to open %s block.\n",filepath);exit(EXIT_FAILURE);}

        if (lseek(fp,0,SEEK_SET)<0) {perror("write1: ");}
        if (write(fp,&prc,sizeof(prc))<0) {perror("write2: ");}
        close(fp);

现在,我如何从超级块中读取数据kernel

4

1 回答 1

1

感谢@Tsyvarev,我了解到我们可以像从文件中一样从超级块中读取。

int read_sb() {
  int fd;
  char magl[1024];
  
  fd = open("/dev/flashSSD", O_RDONLY);

  /* Reads the boot section and the superblock */
  read(fd, magl, 1024);
  
  close(fd);

  return 0;
}
于 2021-05-18T05:59:32.573 回答