一、苏格拉底挑战
二、遇见的困难
三、实践截图和代码
课堂笔记:
man 3 printf
man -k sort //会找到含有sort功能的命令或函数
man -k sort | grep 3 //缩小查找范围到C语言命令
课本练习:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define BLOCK_SIZE 1024
// 读取位图数据的函数
void read_bitmap(FILE *file, uint32_t block_number, uint8_t *bitmap_data) {
fseek(file, block_number * BLOCK_SIZE, SEEK_SET);
fread(bitmap_data, 1, BLOCK_SIZE, file);
}
int main() {
FILE *ext2_image = fopen("your_ext2_image.img", "rb"); // 请替换为你的文件系统镜像文件
if (ext2_image == NULL) {
perror("Error opening the EXT2 image file");
return 1;
}
// 读取超级块
fseek(ext2_image, BLOCK_SIZE, SEEK_SET);
uint8_t superblock_data[BLOCK_SIZE];
fread(superblock_data, 1, BLOCK_SIZE, ext2_image);
// 从超级块中获取块位图和索引节点位图的块号
uint32_t block_bitmap_block = *(uint32_t*)(superblock_data + 0x20);
uint32_t inode_bitmap_block = *(uint32_t*)(superblock_data + 0x24);
// 读取块位图和索引节点位图数据
uint8_t block_bitmap_data[BLOCK_SIZE];
uint8_t inode_bitmap_data[BLOCK_SIZE];
read_bitmap(ext2_image, block_bitmap_block, block_bitmap_data);
read_bitmap(ext2_image, inode_bitmap_block, inode_bitmap_data);
// 打印块位图数据
printf("Block Bitmap:\n");
for (int i = 0; i < BLOCK_SIZE; i++) {
for (int j = 0; j < 8; j++) {
uint8_t byte = block_bitmap_data[i];
printf("%d", (byte >> j) & 1);
}
printf(" ");
}
// 打印索引节点位图数据
printf("\n\nInode Bitmap:\n");
for (int i = 0; i < BLOCK_SIZE; i++) {
for (int j = 0; j < 8; j++) {
uint8_t byte = inode_bitmap_data[i];
printf("%d", (byte >> j) & 1);
}
printf(" ");
}
fclose(ext2_image);
return 0;
}
标签:截图,代码,笔记,bitmap,BLOCK,data,image,block,SIZE
From: https://www.cnblogs.com/yuanyi23/p/17765947.html