【发布时间】:2012-12-08 06:21:34
【问题描述】:
我将使用 c++ 获取 linux inode 位图。我已经使用此代码首先获取超级块:
#include <cstdlib>
#include <linux/ext2_fs.h>
#include <linux/fs.h>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <fcntl.h>
#include <linux/fs.h>
using namespace std;
/*
*
*/
int main() {
int fd;
char boot[1024];
struct ext2_super_block super_block;
fd = open("/dev/sda1", O_RDONLY);
/* Reads the boot section and the superblock */
read(fd, boot, 1024);
read(fd, &super_block, sizeof (struct ext2_super_block));
/* Prints the Magic Number */
printf("%x\n", super_block.s_magic);
close(fd);
return 0;
}
但是每次我运行它,我都会得到一个错误:
In file included from main.cpp:2:0:
/usr/include/linux/ext2_fs.h:181:18: error: ‘S_ISDIR’ was not declared in this scope
/usr/include/linux/ext2_fs.h:183:23: error: ‘S_ISREG’ was not declared in this scope
我找不到任何好的示例或教程。有人可以帮助我吗?
编辑:
我已经包含了<linux/stat.h>,但仍然出现同样的错误。
【问题讨论】:
-
你无法读取 linux inode table:没有这样的东西,因为每个文件系统都有自己的格式(ext2,3,4 / reiserfs / xfs / btrfs / etc. )
-
顺便说一句,要读取 ext2、ext3 或 ext4,您可能需要使用 e2fsprogs 包中的 libext2fs 提供的函数。
-
你能帮我用这个包吗?
标签: c++ c linux inode superblock