Help with EXT3 Filesystem work


Joined
Mar 13, 2022
Messages
1
Reaction score
0
I need to program an ext3 file system, but I'm stuck,
I brought together the first requirement ,the instructions are:

#ifndef EXT3LIB_H
#define EXT3LIB_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ext3.h"
#include "tools.h"
#include <libext3.h>

#define BLOCK_SIZE 0x400
#define SUPERBLOCK_POS 0x400
#define GROUPDESC_START_POS 0x800

/* read_superblock:
superblock is read from file pointer fp to ext3_super_block structure in sb up to sb_len bytes
return value: 0 on success
*/
int read_superblock(FILE *fp, struct ext3_super_block *sb, unsigned int sb_len)
{
fseek(fp,SUPERBLOCK_POS,SEEK_SET);
int len_estimated = sb_len < BLOCK_SIZE ? sb_len : BLOCK_SIZE;
int len_read = fread(sb,sizeof(char), len_estimated,fp);
return len_read == len_estimated ? 0 : -1;
}

/* read_group_descriptor:
group descriptor number gd_num is read from file pointer fp to ext3_group_desc structure in gd up to gd_len bytes
return value: 0 on success
*/
int read_group_descriptor(FILE *fp, struct ext3_group_desc *gd, unsigned int gd_len, unsigned int gd_num)

/* read_inode_in_group:
inode number in_num in group descriptor in gd is read from file pointer fp to ext3_inode structure in inode up to in_len bytes
parameters are used from superblock in sb
return value: 0 on success
*/
int read_inode_in_group(FILE *fp, struct ext3_inode *in, unsigned int in_len, struct ext3_super_block *sb, struct ext3_group_desc *gd, unsigned int in_num);

/* read_data_block:
data block number block_num is read from file pointer fp to buffer up to buffer_len bytes
return value: number of bytes is returned on success, 0 on failure
*/
int read_data_block(FILE *fp, char* buffer, unsigned int buffer_len, unsigned int block_num);

/* get_next_directory_entry:
directory entry at position start_pos is read from buffer to ext3_dir_entry_2 strucutre dirent
return value: position of next directory entry in buffer, -1 is last entry is reached
*/
int get_next_directory_entry(char* buffer, unsigned int buffer_len, struct ext3_dir_entry_2 *dirent, unsigned int start_pos);

/* get_next_path_element:
extracts next path element from path starting at offset 0 to element if path_len >= 0
return value: position of next element in path, 1 if no element can be found
*/
int get_next_path_element(char* path, int path_len, char* element);

#endif /* EXT3LIB_H */
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top