MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Enumerations | Functions | Variables
ext2.c File Reference

EXT2 driver. More...

Classes

struct  ext2_superblock_t
 The superblock contains all the information about the configuration of the filesystem. More...
 
struct  ext2_group_descriptor_t
 Entry of the Block Group Descriptor Table (BGDT). More...
 
struct  ext2_inode_t
 The ext2 inode. More...
 
struct  ext2_dirent_t
 The header of an ext2 directory entry. More...
 
struct  ext2_filesystem_t
 The details regarding the filesystem. More...
 
struct  ext2_direntry_search_t
 Structure used when searching for a directory entry. More...
 
struct  ext2_direntry_iterator_t
 Iterator for visiting the directory entries. More...
 

Macros

#define __DEBUG_HEADER__   "[EXT2 ]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 
#define EXT2_SUPERBLOCK_MAGIC   0xEF53
 Magic value used to identify an ext2 filesystem.
 
#define EXT2_DIRECT_BLOCKS   12
 Amount of indirect blocks in an inode.
 
#define EXT2_PATH_MAX   4096
 Maximum length of a pathname.
 
#define EXT2_MAX_SYMLINK_COUNT   8
 Maximum nesting of symlinks, used to prevent a loop.
 
#define EXT2_NAME_LEN   255
 The lenght of names inside directory entries.
 
#define EXT2_S_ISUID   0x0800
 SUID.
 
#define EXT2_S_ISGID   0x0400
 SGID.
 
#define EXT2_S_ISVTX   0x0200
 Sticky Bit.
 
#define EXT2_S_IRWXU   0x01C0
 rwx----— : User can read/write/execute
 
#define EXT2_S_IRUSR   0x0100
 -r-----— : User can read
 
#define EXT2_S_IWUSR   0x0080
 –w----— : User can write
 
#define EXT2_S_IXUSR   0x0040
 —x---— : User can execute
 
#define EXT2_S_IRWXG   0x0038
 -—rwx— : Group can read/write/execute
 
#define EXT2_S_IRGRP   0x0020
 -—r--— : Group can read
 
#define EXT2_S_IWGRP   0x0010
 --—w-— : Group can write
 
#define EXT2_S_IXGRP   0x0008
 ---—x— : Group can execute
 
#define EXT2_S_IRWXO   0x0007
 ----—rwx : Others can read/write/execute
 
#define EXT2_S_IROTH   0x0004
 ----—r– : Others can read
 
#define EXT2_S_IWOTH   0x0002
 -----—w- : Others can write
 
#define EXT2_S_IXOTH   0x0001
 ------—x : Others can execute
 

Typedefs

typedef enum ext2_file_type_t ext2_file_type_t
 Types of file in an EXT2 filesystem.
 
typedef struct ext2_superblock_t ext2_superblock_t
 The superblock contains all the information about the configuration of the filesystem. More...
 
typedef struct ext2_group_descriptor_t ext2_group_descriptor_t
 Entry of the Block Group Descriptor Table (BGDT).
 
typedef struct ext2_inode_t ext2_inode_t
 The ext2 inode.
 
typedef struct ext2_dirent_t ext2_dirent_t
 The header of an ext2 directory entry.
 
typedef struct ext2_filesystem_t ext2_filesystem_t
 The details regarding the filesystem.
 
typedef struct ext2_direntry_search_t ext2_direntry_search_t
 Structure used when searching for a directory entry.
 
typedef struct ext2_direntry_iterator_t ext2_direntry_iterator_t
 Iterator for visiting the directory entries.
 

Enumerations

enum  ext2_file_type_t {
  ext2_file_type_unknown , ext2_file_type_regular_file , ext2_file_type_directory , ext2_file_type_character_device ,
  ext2_file_type_block_device , ext2_file_type_named_pipe , ext2_file_type_socket , ext2_file_type_symbolic_link
}
 Types of file in an EXT2 filesystem. More...
 

Functions

static int ext2_bitmap_check (uint8_t *buffer, uint32_t offset)
 Cheks if the bit at the given linear index is free. More...
 
static void ext2_bitmap_set (uint8_t *buffer, uint32_t offset)
 Sets the bit at the given index. More...
 
static void ext2_bitmap_clear (uint8_t *buffer, uint32_t offset)
 Clears the bit at the given index. More...
 
static int ext2_read_superblock (ext2_filesystem_t *fs)
 Reads the superblock from the block device associated with this filesystem. More...
 
static int ext2_write_superblock (ext2_filesystem_t *fs)
 Writes the superblock on the block device associated with this filesystem. More...
 
static int ext2_read_block (ext2_filesystem_t *fs, uint32_t block_index, uint8_t *buffer)
 Read a block from the block device associated with this filesystem. More...
 
static int ext2_write_block (ext2_filesystem_t *fs, uint32_t block_index, uint8_t *buffer)
 Writes a block on the block device associated with this filesystem. More...
 
static int ext2_read_bgdt (ext2_filesystem_t *fs)
 Reads the Block Group Descriptor Table (BGDT) from the block device associated with this filesystem. More...
 
static int ext2_write_bgdt (ext2_filesystem_t *fs)
 Writes the Block Group Descriptor Table (BGDT) to the block device associated with this filesystem. More...
 
static int ext2_read_inode (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index)
 Reads an inode. More...
 
static int ext2_write_inode (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index)
 Writes the inode. More...
 
static vfs_file_text2_open (const char *path, int flags, mode_t mode)
 Open the file at the given path and returns its file descriptor. More...
 
static int ext2_unlink (const char *path)
 Delete a name and possibly the file it refers to. More...
 
static int ext2_close (vfs_file_t *file)
 Closes the given file. More...
 
static ssize_t ext2_read (vfs_file_t *file, char *buffer, off_t offset, size_t nbyte)
 Reads from the file identified by the file descriptor. More...
 
static ssize_t ext2_write (vfs_file_t *file, const void *buffer, off_t offset, size_t nbyte)
 Writes the given content inside the file. More...
 
static off_t ext2_lseek (vfs_file_t *file, off_t offset, int whence)
 Repositions the file offset inside a file. More...
 
static int ext2_fstat (vfs_file_t *file, stat_t *stat)
 Retrieves information concerning the file at the given position. More...
 
static int ext2_ioctl (vfs_file_t *file, int request, void *data)
 Perform the I/O control operation specified by REQUEST on FD. One argument may follow; its presence and type depend on REQUEST. More...
 
static ssize_t ext2_getdents (vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count)
 Reads contents of the directories to a dirent buffer, updating the offset and returning the number of written bytes in the buffer, it assumes that all paths are well-formed. More...
 
static ssize_t ext2_readlink (const char *path, char *buffer, size_t bufsize)
 Read the symbolic link, if present. More...
 
static int ext2_fsetattr (vfs_file_t *file, struct iattr *attr)
 Set attributes of the file at the given position. More...
 
static int ext2_mkdir (const char *path, mode_t permission)
 Creates a new directory at the given path. More...
 
static int ext2_rmdir (const char *path)
 Removes the given directory. More...
 
static int ext2_stat (const char *path, stat_t *stat)
 Retrieves information concerning the file at the given position. More...
 
static int ext2_setattr (const char *path, struct iattr *attr)
 Set attributes of a file. More...
 
static vfs_file_text2_creat (const char *path, mode_t mode)
 Creates a new file or rewrite an existing one. More...
 
static vfs_file_text2_mount (vfs_file_t *block_device, const char *path)
 Mounts the block device as an EXT2 filesystem. More...
 
static uint32_t ext2_get_real_block_index (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t block_index)
 Returns the real block index starting from a block index inside an inode. More...
 
static const char * uuid_to_string (uint8_t uuid[16])
 Turns an UUID to string. More...
 
static const char * ext2_file_type_to_string (ext2_file_type_t ext2_type)
 Turns an ext2_file_type to string. More...
 
static int ext2_file_type_to_vfs_file_type (int ext2_type)
 Turns the EXT2 file type to OS standard file types. More...
 
static const char * time_to_string (uint32_t time)
 Turns the time to string. More...
 
static void ext2_dump_superblock (ext2_superblock_t *sb)
 Dumps on debugging output the superblock. More...
 
static void ext2_dump_group_descriptor (ext2_group_descriptor_t *gd)
 Dumps on debugging output the group descriptor. More...
 
static void ext2_dump_inode (ext2_filesystem_t *fs, ext2_inode_t *inode)
 Dumps on debugging output the inode. More...
 
static void ext2_dump_dirent (ext2_dirent_t *dirent)
 Dumps on debugging output the dirent. More...
 
static void ext2_dump_bgdt (ext2_filesystem_t *fs)
 Dumps on debugging output the BGDT. More...
 
static void ext2_dump_filesystem (ext2_filesystem_t *fs)
 Dumps on debugging output the filesystem. More...
 
static uint8_text2_alloc_cache (ext2_filesystem_t *fs)
 Allocate cache for EXT2 operations. More...
 
static void ext2_dealloc_cache (uint8_t *cache)
 Free the cache. More...
 
static uint32_t ext2_get_rec_len_from_name (const char *name)
 Returns the rec_len from the given name. More...
 
static uint32_t ext2_get_rec_len_from_direntry (const ext2_dirent_t *direntry)
 Returns the rec_len from the given direntry. More...
 
static uint32_t ext2_is_last_directory_entry (const ext2_dirent_t *direntry)
 If the real rec_len is different from the on in attribute rec_len, this is the last directory entry. More...
 
static uint32_t ext2_inode_index_to_group_index (ext2_filesystem_t *fs, uint32_t inode_index)
 Determining which block group contains an inode. More...
 
static uint32_t ext2_inode_index_to_group_offset (ext2_filesystem_t *fs, uint32_t inode_index)
 Determining the offest of the inode inside the inode group. More...
 
static uint32_t ext2_inode_index_to_block_index (ext2_filesystem_t *fs, uint32_t inode_index)
 Determining the block index from the inode index. More...
 
static uint32_t ext2_block_index_to_group_index (ext2_filesystem_t *fs, uint32_t block_index)
 Determining which block group contains a given block. More...
 
static uint32_t ext2_block_index_to_group_offset (ext2_filesystem_t *fs, uint32_t block_index)
 Determining the offest of the block inside the block group. More...
 
static int __valid_x_permission (task_struct *task, ext2_inode_t *inode)
 Checks if the task has x-permission for a given inode. More...
 
static int ext2_find_free_inode_in_group (ext2_filesystem_t *fs, uint8_t *cache, uint32_t *group_offset, int skip_reserved)
 Searches for a free inode inside the group data loaded inside the cache. More...
 
static int ext2_find_free_inode (ext2_filesystem_t *fs, uint8_t *cache, uint32_t *group_index, uint32_t *group_offset, uint32_t preferred_group)
 Searches for a free inode inside the Block Group Descriptor Table (BGDT). More...
 
static int ext2_find_free_block_in_group (ext2_filesystem_t *fs, uint8_t *cache, uint32_t *block_offset)
 Searches for a free block inside the group data loaded inside the cache. More...
 
static int ext2_find_free_block (ext2_filesystem_t *fs, uint8_t *cache, uint32_t *group_index, uint32_t *block_offset)
 Searches for a free block. More...
 
static int ext2_allocate_inode (ext2_filesystem_t *fs, unsigned preferred_group)
 Allocate a new inode. More...
 
static uint32_t ext2_allocate_block (ext2_filesystem_t *fs)
 Allocates a new block. More...
 
static void ext2_free_block (ext2_filesystem_t *fs, uint32_t block_index)
 Frees a block. More...
 
static int ext2_free_inode (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index)
 Frees the given inode. More...
 
static int __ext2_allocate_indexing_block_for_inode (ext2_filesystem_t *fs, uint32_t *current_index)
 Allocates a new block for storing block indices, for an inode. More...
 
static int __ext2_read_and_allocate_indexing_block (ext2_filesystem_t *fs, uint32_t indexing_block, uint8_t *cache, uint32_t index)
 Allocates a new block for storing block indices, for a block containing block indices. More...
 
static int ext2_set_real_block_index (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index, uint32_t block_index, uint32_t real_index)
 Sets the real block index based on the block index inside an inode. More...
 
static int ext2_allocate_inode_block (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index, uint32_t block_index)
 Allocate a new block for an inode. More...
 
static ssize_t ext2_read_inode_block (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t block_index, uint8_t *buffer)
 Reads the real block starting from an inode and the block index inside the inode. More...
 
static ssize_t ext2_write_inode_block (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index, uint32_t block_index, uint8_t *buffer)
 Writes the real block starting from an inode and the block index inside the inode. More...
 
static ssize_t ext2_read_inode_data (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index, off_t offset, size_t nbyte, char *buffer)
 Reads the data from the given inode. More...
 
static ssize_t ext2_write_inode_data (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index, off_t offset, size_t nbyte, char *buffer)
 Writes the data on the given inode. More...
 
ext2_dirent_text2_direntry_iterator_get (ext2_direntry_iterator_t *it)
 Returns the ext2_dirent_t pointed by the iterator. More...
 
int ext2_direntry_iterator_valid (ext2_direntry_iterator_t *it)
 Check if the iterator is valid. More...
 
ext2_direntry_iterator_t ext2_direntry_iterator_begin (ext2_filesystem_t *fs, uint8_t *cache, ext2_inode_t *inode)
 Initializes the iterator and reads the first block. More...
 
void ext2_direntry_iterator_next (ext2_direntry_iterator_t *it)
 Moves to the next direntry, and moves to the next block if necessary. More...
 
static int ext2_directory_is_empty (ext2_filesystem_t *fs, uint8_t *cache, ext2_inode_t *inode)
 Checks if the directory is empty. More...
 
static int ext2_clean_inode_content (ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t inode_index)
 Cleans the inode content. More...
 
static void ext2_initialize_direntry (ext2_dirent_t *direntry, const char *name, ino_t inode_index, uint32_t rec_len, uint8_t file_type)
 Initializes a directory entry. More...
 
static int ext2_initialize_new_direntry_block (ext2_filesystem_t *fs, uint32_t inode_index, uint32_t block_index)
 Initializes a new directory entry block for the specified inode. More...
 
static void ext2_dump_direntries (ext2_filesystem_t *fs, uint8_t *cache, ext2_inode_t *parent_inode)
 Dumps the directory entries inside the parent directory. More...
 
static int ext2_get_free_direntry (ext2_filesystem_t *fs, uint8_t *cache, ino_t parent_inode_index, const char *name, ino_t inode_index, uint8_t file_type)
 Searches for a free unused directory entry (inode == 0). More...
 
static int ext2_append_new_direntry (ext2_filesystem_t *fs, uint8_t *cache, ino_t parent_inode_index, const char *name, ino_t inode_index, uint8_t file_type)
 Appends the new directory entry at the end of the last used block, if there is enough space. More...
 
static int ext2_create_new_direntry (ext2_filesystem_t *fs, uint8_t *cache, ino_t parent_inode_index, const char *name, ino_t inode_index, uint8_t file_type)
 Allocates a new block, and creates a new directory entry inside that new block. More...
 
static int ext2_allocate_direntry (ext2_filesystem_t *fs, uint32_t parent_inode_index, uint32_t direntry_inode_index, const char *name, uint8_t file_type)
 Allocates a directory entry. More...
 
static int ext2_destroy_direntry (ext2_filesystem_t *fs, ext2_inode_t parent, ext2_inode_t inode, uint32_t parent_index, uint32_t inode_index, uint32_t block_index, uint32_t block_offset)
 Destroys a directory entry in the parent directory. More...
 
static int ext2_find_direntry (ext2_filesystem_t *fs, ino_t ino, const char *name, ext2_direntry_search_t *search)
 Finds the entry with the given name inside the directory. More...
 
static int ext2_resolve_path (vfs_file_t *directory, const char *path, ext2_direntry_search_t *search)
 Searches the entry specified in path starting from directory. More...
 
static ext2_filesystem_tget_ext2_filesystem (const char *absolute_path)
 Get the ext2 filesystem object starting from a path. More...
 
static int ext2_init_vfs_file (ext2_filesystem_t *fs, vfs_file_t *file, ext2_inode_t *inode, uint32_t inode_index, const char *name, size_t name_len)
 Initializes the VFS file. More...
 
static vfs_file_text2_find_vfs_file_with_inode (ext2_filesystem_t *fs, ino_t inode)
 Finds the VFS file that is associated with the given inode index. More...
 
static int ext2_create_inode (ext2_filesystem_t *fs, ext2_inode_t *inode, mode_t mode, uint32_t preferred_group)
 Creates and initializes a new inode. More...
 
static int __ext2_stat (ext2_inode_t *inode, stat_t *stat)
 Saves the information concerning the file. More...
 
static int __ext2_setattr (ext2_inode_t *inode, struct iattr *attr)
 Sets the attributes of an inode and saves it. More...
 
static int __ext2_check_setattr_permission (uid_t file_owner)
 Checks the attributes permission. More...
 
static vfs_file_text2_mount_callback (const char *path, const char *device)
 The mount call-back, which prepares everything and calls the actual EXT2 mount function. More...
 
int ext2_initialize (void)
 Initializes the EXT2 drivers. More...
 
int ext2_finalize (void)
 De-initializes the EXT2 drivers. More...
 

Variables

static vfs_sys_operations_t ext2_sys_operations
 Filesystem general operations. More...
 
static vfs_file_operations_t ext2_fs_operations
 Filesystem file operations. More...
 
static file_system_type ext2_file_system_type
 Filesystem information. More...
 

Detailed Description

EXT2 driver.

Typedef Documentation

◆ ext2_superblock_t

The superblock contains all the information about the configuration of the filesystem.

The primary copy of the superblock is stored at an offset of 1024 bytes from the start of the device, and it is essential to mounting the filesystem. Since it is so important, backup copies of the superblock are stored in block groups throughout the filesystem.

Enumeration Type Documentation

◆ ext2_file_type_t

Types of file in an EXT2 filesystem.

Enumerator
ext2_file_type_unknown 

Unknown type.

ext2_file_type_regular_file 

Regular file.

ext2_file_type_directory 

Directory.

ext2_file_type_character_device 

Character device.

ext2_file_type_block_device 

Block device.

ext2_file_type_named_pipe 

Named pipe.

ext2_file_type_socket 

Socket.

ext2_file_type_symbolic_link 

Symbolic link.

Function Documentation

◆ __ext2_allocate_indexing_block_for_inode()

static int __ext2_allocate_indexing_block_for_inode ( ext2_filesystem_t fs,
uint32_t current_index 
)
static

Allocates a new block for storing block indices, for an inode.

Parameters
fsthe filesystem.
current_indexthe current index, or if 0, where we store the new one.
Returns
0 on success, -1 on failure.

◆ __ext2_check_setattr_permission()

static int __ext2_check_setattr_permission ( uid_t  file_owner)
static

Checks the attributes permission.

Parameters
file_ownerthe file owner we are checking against.
Returns
1 if it has permission, 0 otherwise.

◆ __ext2_read_and_allocate_indexing_block()

static int __ext2_read_and_allocate_indexing_block ( ext2_filesystem_t fs,
uint32_t  indexing_block,
uint8_t cache,
uint32_t  index 
)
static

Allocates a new block for storing block indices, for a block containing block indices.

Parameters
fsthe filesystem.
indexing_blockthe index of block that contains the indices.
cachethe cache were we load the block content.
indexthe index inside the list of indices.
Returns
0 on success, -1 on failure.

◆ __ext2_setattr()

static int __ext2_setattr ( ext2_inode_t inode,
struct iattr attr 
)
static

Sets the attributes of an inode and saves it.

Parameters
inodeThe inode to set the attributes
attrThe structure where the attributes are stored.
Returns
0 if success.

◆ __ext2_stat()

static int __ext2_stat ( ext2_inode_t inode,
stat_t stat 
)
static

Saves the information concerning the file.

Parameters
inodeThe inode containing the data.
statThe structure where the information are stored.
Returns
0 if success.

◆ __valid_x_permission()

static int __valid_x_permission ( task_struct task,
ext2_inode_t inode 
)
static

Checks if the task has x-permission for a given inode.

Parameters
taskthe task to check permission for.
inodethe inode to check permission.
Returns
1 on success, 0 otherwise.

◆ ext2_alloc_cache()

static uint8_t* ext2_alloc_cache ( ext2_filesystem_t fs)
inlinestatic

Allocate cache for EXT2 operations.

Parameters
fsfile system we are working with.
Returns
a pointer to the cache.

◆ ext2_allocate_block()

static uint32_t ext2_allocate_block ( ext2_filesystem_t fs)
static

Allocates a new block.

Parameters
fsthe filesystem.
Returns
0 on failure, or the index of the new block on success.

◆ ext2_allocate_direntry()

static int ext2_allocate_direntry ( ext2_filesystem_t fs,
uint32_t  parent_inode_index,
uint32_t  direntry_inode_index,
const char *  name,
uint8_t  file_type 
)
static

Allocates a directory entry.

Parameters
fsa pointer to the filesystem.
parent_inode_indexthe inode index of the parent.
direntry_inode_indexthe inode index of the new entry.
namethe name of the new entry.
file_typethe type of file.
Returns
0 on success, a negative value on failure.

◆ ext2_allocate_inode()

static int ext2_allocate_inode ( ext2_filesystem_t fs,
unsigned  preferred_group 
)
static

Allocate a new inode.

Parameters
fsthe filesystem.
preferred_groupthe preferred group.
Returns
index of the inode.

Here are the rules used to allocate new inodes:

  • the inode for a new file is allocated in the same group of the inode of its parent directory.
  • inodes are allocated equally between groups.

◆ ext2_allocate_inode_block()

static int ext2_allocate_inode_block ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index,
uint32_t  block_index 
)
static

Allocate a new block for an inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexThe index of the inode.
block_indexThe index of the block within the inode.
Returns
0 on success, -1 on failure.

◆ ext2_append_new_direntry()

static int ext2_append_new_direntry ( ext2_filesystem_t fs,
uint8_t cache,
ino_t  parent_inode_index,
const char *  name,
ino_t  inode_index,
uint8_t  file_type 
)
inlinestatic

Appends the new directory entry at the end of the last used block, if there is enough space.

Parameters
fsa pointer to the filesystem.
cachecache for memory EXT2 operations.
parent_inode_indexthe parent inode index.
namethe name of the new entry.
inode_indexits inode index.
file_typeits file type.
Returns
1 on success, 0 on failure.

◆ ext2_bitmap_check()

static int ext2_bitmap_check ( uint8_t buffer,
uint32_t  offset 
)
inlinestatic

Cheks if the bit at the given linear index is free.

Parameters
bufferthe buffer containing the bitmap
offsetthe linear index we want to check.
Returns
if the bit is 0 or 1.

How we access the specific bits inside the bitmap takes inspiration from the mailman's algorithm.

◆ ext2_bitmap_clear()

static void ext2_bitmap_clear ( uint8_t buffer,
uint32_t  offset 
)
inlinestatic

Clears the bit at the given index.

Parameters
bufferthe buffer containing the bitmap
offsetthe bit index we want to clear.

◆ ext2_bitmap_set()

static void ext2_bitmap_set ( uint8_t buffer,
uint32_t  offset 
)
inlinestatic

Sets the bit at the given index.

Parameters
bufferthe buffer containing the bitmap
offsetthe bit index we want to set.

◆ ext2_block_index_to_group_index()

static uint32_t ext2_block_index_to_group_index ( ext2_filesystem_t fs,
uint32_t  block_index 
)
static

Determining which block group contains a given block.

Parameters
fsthe ext2 filesystem structure.
block_indexthe block index.
Returns
the block group index.

◆ ext2_block_index_to_group_offset()

static uint32_t ext2_block_index_to_group_offset ( ext2_filesystem_t fs,
uint32_t  block_index 
)
static

Determining the offest of the block inside the block group.

Parameters
fsthe ext2 filesystem structure.
block_indexthe block index.
Returns
the offset of the block inside the group.

◆ ext2_clean_inode_content()

static int ext2_clean_inode_content ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index 
)
static

Cleans the inode content.

Parameters
fsa pointer to the filesystem.
inodethe inode.
inode_indexthe inode index.
Returns
0 on success, 1 on failure.

◆ ext2_close()

static int ext2_close ( vfs_file_t file)
static

Closes the given file.

Parameters
fileThe file structure.
Returns
0 on success, -errno on failure.

◆ ext2_creat()

static vfs_file_t * ext2_creat ( const char *  path,
mode_t  mode 
)
static

Creates a new file or rewrite an existing one.

Parameters
pathpath to the file.
modemode for file creation.
Returns
file descriptor number, -1 otherwise and errno is set to indicate the error.

It is equivalent to: open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)

◆ ext2_create_inode()

static int ext2_create_inode ( ext2_filesystem_t fs,
ext2_inode_t inode,
mode_t  mode,
uint32_t  preferred_group 
)
static

Creates and initializes a new inode.

Parameters
fsthe filesystem.
inodethe inode we use to initialize the root of the filesystem.
modethe creat mode.
preferred_groupthe preferred group where the inode should be allocated.
Returns
the inode index on success, -1 on failure.

◆ ext2_create_new_direntry()

static int ext2_create_new_direntry ( ext2_filesystem_t fs,
uint8_t cache,
ino_t  parent_inode_index,
const char *  name,
ino_t  inode_index,
uint8_t  file_type 
)
inlinestatic

Allocates a new block, and creates a new directory entry inside that new block.

Parameters
fsa pointer to the filesystem.
cachecache for memory EXT2 operations.
parent_inode_indexthe parent inode index.
namethe name of the new entry.
inode_indexits inode index.
file_typeits file type.
Returns
1 on success, 0 on failure.

◆ ext2_dealloc_cache()

static void ext2_dealloc_cache ( uint8_t cache)
inlinestatic

Free the cache.

Parameters
cachepointer to the cache.

◆ ext2_destroy_direntry()

static int ext2_destroy_direntry ( ext2_filesystem_t fs,
ext2_inode_t  parent,
ext2_inode_t  inode,
uint32_t  parent_index,
uint32_t  inode_index,
uint32_t  block_index,
uint32_t  block_offset 
)
static

Destroys a directory entry in the parent directory.

Parameters
fsA pointer to the filesystem structure.
parentThe inode of the parent directory.
inodeThe inode of the directory entry to be destroyed.
parent_indexThe index of the parent inode.
inode_indexThe index of the directory entry's inode.
block_indexThe block index where the directory entry resides.
block_offsetThe offset within the block where the directory entry is located.
Returns
0 on success, a negative value on failure.

◆ ext2_directory_is_empty()

static int ext2_directory_is_empty ( ext2_filesystem_t fs,
uint8_t cache,
ext2_inode_t inode 
)
inlinestatic

Checks if the directory is empty.

Parameters
fsa pointer to the filesystem.
cacheused for reading.
inodethe inode of the directory.
Returns
1 if empty, 0 if not empty.

◆ ext2_direntry_iterator_begin()

ext2_direntry_iterator_t ext2_direntry_iterator_begin ( ext2_filesystem_t fs,
uint8_t cache,
ext2_inode_t inode 
)

Initializes the iterator and reads the first block.

Parameters
fspointer to the filesystem.
cacheused for reading.
inodepointer to the directory inode.
Returns
The initialized directory iterator.

◆ ext2_direntry_iterator_get()

ext2_dirent_t* ext2_direntry_iterator_get ( ext2_direntry_iterator_t it)

Returns the ext2_dirent_t pointed by the iterator.

Parameters
itthe iterator.
Returns
pointer to the ext2_dirent_t

◆ ext2_direntry_iterator_next()

void ext2_direntry_iterator_next ( ext2_direntry_iterator_t it)

Moves to the next direntry, and moves to the next block if necessary.

Parameters
itthe iterator.

◆ ext2_direntry_iterator_valid()

int ext2_direntry_iterator_valid ( ext2_direntry_iterator_t it)

Check if the iterator is valid.

Parameters
itthe iterator to check.
Returns
1 if valid, 0 otherwise.

◆ ext2_dump_bgdt()

static void ext2_dump_bgdt ( ext2_filesystem_t fs)
static

Dumps on debugging output the BGDT.

Parameters
fsthe filesystem of which we print the BGDT.

◆ ext2_dump_dirent()

static void ext2_dump_dirent ( ext2_dirent_t dirent)
static

Dumps on debugging output the dirent.

Parameters
direntthe object to dump.

◆ ext2_dump_direntries()

static void ext2_dump_direntries ( ext2_filesystem_t fs,
uint8_t cache,
ext2_inode_t parent_inode 
)
inlinestatic

Dumps the directory entries inside the parent directory.

Parameters
fsA pointer to the filesystem structure.
cacheA pointer to a memory cache used for EXT2 operations.
parent_inodeA pointer to the parent inode whose directory entries are to be dumped.

Initialize the directory entry iterator for the parent directory

Iterate through all directory entries in the parent directory

Dump debug information for the directory entry's block index and offset

Dump detailed information about the current directory entry

◆ ext2_dump_filesystem()

static void ext2_dump_filesystem ( ext2_filesystem_t fs)
static

Dumps on debugging output the filesystem.

Parameters
fsthe object to dump.

◆ ext2_dump_group_descriptor()

static void ext2_dump_group_descriptor ( ext2_group_descriptor_t gd)
static

Dumps on debugging output the group descriptor.

Parameters
gdthe object to dump.

◆ ext2_dump_inode()

static void ext2_dump_inode ( ext2_filesystem_t fs,
ext2_inode_t inode 
)
static

Dumps on debugging output the inode.

Parameters
fsa pointer to the filesystem.
inodethe object to dump.

◆ ext2_dump_superblock()

static void ext2_dump_superblock ( ext2_superblock_t sb)
static

Dumps on debugging output the superblock.

Parameters
sbthe object to dump.

◆ ext2_file_type_to_string()

static const char* ext2_file_type_to_string ( ext2_file_type_t  ext2_type)
static

Turns an ext2_file_type to string.

Parameters
ext2_typethe ext2_file_type to turn to string.
Returns
the string representing the ext2_file_type.

◆ ext2_file_type_to_vfs_file_type()

static int ext2_file_type_to_vfs_file_type ( int  ext2_type)
static

Turns the EXT2 file type to OS standard file types.

Parameters
ext2_typethe EXT2 file type.
Returns
the OS standard file types.

◆ ext2_finalize()

int ext2_finalize ( void  )

De-initializes the EXT2 drivers.

Returns
0 on success, 1 on error.

◆ ext2_find_direntry()

static int ext2_find_direntry ( ext2_filesystem_t fs,
ino_t  ino,
const char *  name,
ext2_direntry_search_t search 
)
static

Finds the entry with the given name inside the directory.

Parameters
fsa pointer to the filesystem.
inothe inodex of the directory entry.
namethe name of the entry we are looking for.
searchthe output variable where we save the info about the entry.
Returns
0 on success, -errno on failure.

◆ ext2_find_free_block()

static int ext2_find_free_block ( ext2_filesystem_t fs,
uint8_t cache,
uint32_t group_index,
uint32_t block_offset 
)
inlinestatic

Searches for a free block.

Parameters
fsthe ext2 filesystem structure.
cachethe cache from which we read the bgdt data.
group_indexthe output variable where we store the group index.
block_offsetthe output variable where we store the linear indes to the free block.
Returns
1 if we found a free block, 0 otherwise.

◆ ext2_find_free_block_in_group()

static int ext2_find_free_block_in_group ( ext2_filesystem_t fs,
uint8_t cache,
uint32_t block_offset 
)
inlinestatic

Searches for a free block inside the group data loaded inside the cache.

Parameters
fsthe ext2 filesystem structure.
cachethe cache from which we read the bgdt data.
block_offsetthe output variable where we store the linear indes to the free block.
Returns
1 if we found a free block, 0 otherwise.

◆ ext2_find_free_inode()

static int ext2_find_free_inode ( ext2_filesystem_t fs,
uint8_t cache,
uint32_t group_index,
uint32_t group_offset,
uint32_t  preferred_group 
)
inlinestatic

Searches for a free inode inside the Block Group Descriptor Table (BGDT).

Parameters
fsthe ext2 filesystem structure.
cachethe cache from which we read the bgdt data.
group_indexthe output variable where we store the group index.
group_offsetthe output variable where we store the linear indes to the free inode.
preferred_groupwe accept a preferred group, but only if available.
Returns
1 if we found a free inode, 0 otherwise.

◆ ext2_find_free_inode_in_group()

static int ext2_find_free_inode_in_group ( ext2_filesystem_t fs,
uint8_t cache,
uint32_t group_offset,
int  skip_reserved 
)
inlinestatic

Searches for a free inode inside the group data loaded inside the cache.

Parameters
fsthe ext2 filesystem structure.
cachethe cache from which we read the bgdt data.
group_offsetthe output variable where we store the linear indes to the free inode.
skip_reservedshould we skip reserved inodes.
Returns
1 if we found a free inode, 0 otherwise.

◆ ext2_find_vfs_file_with_inode()

static vfs_file_t* ext2_find_vfs_file_with_inode ( ext2_filesystem_t fs,
ino_t  inode 
)
static

Finds the VFS file that is associated with the given inode index.

Parameters
fsa pointer to the fileystem.
inodethe inode index.
Returns
a pointer to the VFS file.

◆ ext2_free_block()

static void ext2_free_block ( ext2_filesystem_t fs,
uint32_t  block_index 
)
static

Frees a block.

Parameters
fsthe filesystem.
block_indexthe index of the block we are freeing.

◆ ext2_free_inode()

static int ext2_free_inode ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index 
)
static

Frees the given inode.

Parameters
fsa pointer to the filesystem.
inodethe inode we free.
inode_indexits index.
Returns
0 on success, otherwise it is a failure.

◆ ext2_fsetattr()

static int ext2_fsetattr ( vfs_file_t file,
struct iattr attr 
)
static

Set attributes of the file at the given position.

Parameters
fileThe file struct.
attrThe structure where the attributes are stored.
Returns
0 if success.

◆ ext2_fstat()

static int ext2_fstat ( vfs_file_t file,
stat_t stat 
)
static

Retrieves information concerning the file at the given position.

Parameters
fileThe file struct.
statThe structure where the information are stored.
Returns
0 if success.

ID of device containing file.

◆ ext2_get_free_direntry()

static int ext2_get_free_direntry ( ext2_filesystem_t fs,
uint8_t cache,
ino_t  parent_inode_index,
const char *  name,
ino_t  inode_index,
uint8_t  file_type 
)
inlinestatic

Searches for a free unused directory entry (inode == 0).

Parameters
fsa pointer to the filesystem.
cachecache for memory EXT2 operations.
parent_inode_indexthe parent inode index.
namethe name of the new entry.
inode_indexits inode index.
file_typeits file type.
Returns
1 on success, 0 on failure.

◆ ext2_get_real_block_index()

static uint32_t ext2_get_real_block_index ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  block_index 
)
static

Returns the real block index starting from a block index inside an inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
block_indexthe block index inside the inode.
Returns
the real block number.

◆ ext2_get_rec_len_from_direntry()

static uint32_t ext2_get_rec_len_from_direntry ( const ext2_dirent_t direntry)
inlinestatic

Returns the rec_len from the given direntry.

Parameters
direntrythe direntry we use to compute the rec_len.
Returns
the rec_len value.

◆ ext2_get_rec_len_from_name()

static uint32_t ext2_get_rec_len_from_name ( const char *  name)
inlinestatic

Returns the rec_len from the given name.

Parameters
namethe name we use to compute the rec_len.
Returns
the rec_len value.

◆ ext2_getdents()

static ssize_t ext2_getdents ( vfs_file_t file,
dirent_t dirp,
off_t  doff,
size_t  count 
)
static

Reads contents of the directories to a dirent buffer, updating the offset and returning the number of written bytes in the buffer, it assumes that all paths are well-formed.

Parameters
fileThe directory handler.
dirpThe buffer where the data should be written.
doffThe offset inside the buffer where the data should be written.
countThe maximum length of the buffer.
Returns
The number of written bytes in the buffer.

◆ ext2_init_vfs_file()

static int ext2_init_vfs_file ( ext2_filesystem_t fs,
vfs_file_t file,
ext2_inode_t inode,
uint32_t  inode_index,
const char *  name,
size_t  name_len 
)
static

Initializes the VFS file.

Parameters
fsa pointer to the filesystem.
filethe file we want to initialize.
inodethe inode we use to initialize the VFS file.
inode_indexthe inode index.
namethe name of the file.
name_lenthe length of the name.
Returns
0 on success, -errno on failure.

◆ ext2_initialize()

int ext2_initialize ( void  )

Initializes the EXT2 drivers.

Returns
0 on success, 1 on error.

◆ ext2_initialize_direntry()

static void ext2_initialize_direntry ( ext2_dirent_t direntry,
const char *  name,
ino_t  inode_index,
uint32_t  rec_len,
uint8_t  file_type 
)
inlinestatic

Initializes a directory entry.

Parameters
direntrya pointer to the directory entry we want to initialize.
namethe name of the new entry.
inode_indexits inode index.
rec_lenthe length of the new entry.
file_typeits file type.

◆ ext2_initialize_new_direntry_block()

static int ext2_initialize_new_direntry_block ( ext2_filesystem_t fs,
uint32_t  inode_index,
uint32_t  block_index 
)
inlinestatic

Initializes a new directory entry block for the specified inode.

Parameters
fsPointer to the ext2 filesystem structure.
inode_indexThe index of the inode for which the directory entry block is to be initialized.
block_indexThe index of the block to be allocated.
Returns
1 on success, 0 on failure.

◆ ext2_inode_index_to_block_index()

static uint32_t ext2_inode_index_to_block_index ( ext2_filesystem_t fs,
uint32_t  inode_index 
)
static

Determining the block index from the inode index.

Parameters
fsthe ext2 filesystem structure.
inode_indexthe inode index.
Returns
the block index.

◆ ext2_inode_index_to_group_index()

static uint32_t ext2_inode_index_to_group_index ( ext2_filesystem_t fs,
uint32_t  inode_index 
)
static

Determining which block group contains an inode.

Parameters
fsthe ext2 filesystem structure.
inode_indexthe inode index.
Returns
the group index.

Remember that inode addressing starts from 1.

◆ ext2_inode_index_to_group_offset()

static uint32_t ext2_inode_index_to_group_offset ( ext2_filesystem_t fs,
uint32_t  inode_index 
)
static

Determining the offest of the inode inside the inode group.

Parameters
fsthe ext2 filesystem structure.
inode_indexthe inode index.
Returns
the offset of the inode inside the group.

Remember that inode addressing starts from 1.

◆ ext2_ioctl()

static int ext2_ioctl ( vfs_file_t file,
int  request,
void *  data 
)
static

Perform the I/O control operation specified by REQUEST on FD. One argument may follow; its presence and type depend on REQUEST.

Parameters
filethe file on which we perform the operations.
requestthe device-dependent request code
dataan untyped pointer to memory.
Returns
Return value depends on REQUEST. Usually -1 indicates error.

◆ ext2_is_last_directory_entry()

static uint32_t ext2_is_last_directory_entry ( const ext2_dirent_t direntry)
inlinestatic

If the real rec_len is different from the on in attribute rec_len, this is the last directory entry.

Parameters
direntrythe directory entry to check.
Returns
1 if it is the last, 0 otherwise.

◆ ext2_lseek()

static off_t ext2_lseek ( vfs_file_t file,
off_t  offset,
int  whence 
)
static

Repositions the file offset inside a file.

Parameters
filethe file we are working with.
offsetthe offest to use for the operation.
whencethe type of operation.
Returns
Upon successful completion, returns the resulting offset location as measured in bytes from the beginning of the file. On error, the value (off_t) -1 is returned and errno is set to indicate the error.

◆ ext2_mkdir()

static int ext2_mkdir ( const char *  path,
mode_t  permission 
)
static

Creates a new directory at the given path.

Parameters
pathThe path of the new directory.
permissionThe permission of the new directory.
Returns
Returns a negative value on failure.

◆ ext2_mount()

static vfs_file_t * ext2_mount ( vfs_file_t block_device,
const char *  path 
)
static

Mounts the block device as an EXT2 filesystem.

Parameters
block_devicethe block device formatted as EXT2.
pathlocation where we mount the filesystem.
Returns
the VFS root node of the EXT2 filesystem.

◆ ext2_mount_callback()

static vfs_file_t* ext2_mount_callback ( const char *  path,
const char *  device 
)
static

The mount call-back, which prepares everything and calls the actual EXT2 mount function.

Parameters
paththe path where the filesystem should be mounted.
devicethe device we mount.
Returns
the VFS file of the filesystem.

◆ ext2_open()

static vfs_file_t * ext2_open ( const char *  path,
int  flags,
mode_t  mode 
)
static

Open the file at the given path and returns its file descriptor.

Parameters
pathThe path to the file.
flagsThe flags used to determine the behavior of the function.
modeThe mode with which we open the file.
Returns
The file descriptor of the opened file, otherwise returns -1.

◆ ext2_read()

static ssize_t ext2_read ( vfs_file_t file,
char *  buffer,
off_t  offset,
size_t  nbyte 
)
static

Reads from the file identified by the file descriptor.

Parameters
fileThe file.
bufferBuffer where the read content must be placed.
offsetOffset from which we start reading from the file.
nbyteThe number of bytes to read.
Returns
The number of red bytes.

◆ ext2_read_bgdt()

static int ext2_read_bgdt ( ext2_filesystem_t fs)
static

Reads the Block Group Descriptor Table (BGDT) from the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
Returns
0 on success, -1 on failure.

◆ ext2_read_block()

static int ext2_read_block ( ext2_filesystem_t fs,
uint32_t  block_index,
uint8_t buffer 
)
static

Read a block from the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
block_indexthe index of the block we want to read.
bufferthe buffer where the content will be placed.
Returns
the amount of data we read, or negative value for an error.

◆ ext2_read_inode()

static int ext2_read_inode ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index 
)
static

Reads an inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexThe index of the inode.
Returns
0 on success, -1 on failure.

◆ ext2_read_inode_block()

static ssize_t ext2_read_inode_block ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  block_index,
uint8_t buffer 
)
static

Reads the real block starting from an inode and the block index inside the inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
block_indexthe index of the block within the inode.
bufferthe buffer where to put the data.
Returns
the amount of data we read, or negative value for an error.

◆ ext2_read_inode_data()

static ssize_t ext2_read_inode_data ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index,
off_t  offset,
size_t  nbyte,
char *  buffer 
)
static

Reads the data from the given inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexthe index of the inode.
offsetthe offset from which we start reading the data.
nbytethe number of bytes to read.
bufferthe buffer containing the data.
Returns
the amount we read.

◆ ext2_read_superblock()

static int ext2_read_superblock ( ext2_filesystem_t fs)
static

Reads the superblock from the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
Returns
the amount of data we read, or negative value for an error.

◆ ext2_readlink()

static ssize_t ext2_readlink ( const char *  path,
char *  buffer,
size_t  bufsize 
)
static

Read the symbolic link, if present.

Parameters
pathThe path to the file for which we want to read the symbolic link information.
bufferThe buffer where we will store the symbolic link path.
bufsizeThe size of the buffer.
Returns
The number of read characters on success, -1 on failure, with errno set to indicate the error.

◆ ext2_resolve_path()

static int ext2_resolve_path ( vfs_file_t directory,
const char *  path,
ext2_direntry_search_t search 
)
static

Searches the entry specified in path starting from directory.

Parameters
directorythe directory from which we start performing the search.
paththe path of the entry we are looking for, it can be a relative path.
searchthe output variable where we save the entry information.
Returns
0 on success, -errno on failure.

◆ ext2_rmdir()

static int ext2_rmdir ( const char *  path)
static

Removes the given directory.

Parameters
pathThe path to the directory to remove.
Returns
Returns a negative value on failure.

◆ ext2_set_real_block_index()

static int ext2_set_real_block_index ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index,
uint32_t  block_index,
uint32_t  real_index 
)
static

Sets the real block index based on the block index inside an inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexthwe inode index.
block_indexthe block index inside the inode.
real_indexthe real block number.
Returns
0 on success, a negative value on failure.

◆ ext2_setattr()

static int ext2_setattr ( const char *  path,
struct iattr attr 
)
static

Set attributes of a file.

Parameters
pathThe path where the file resides.
attrThe structure where the information are stored.
Returns
0 if success.

◆ ext2_stat()

static int ext2_stat ( const char *  path,
stat_t stat 
)
static

Retrieves information concerning the file at the given position.

Parameters
pathThe path where the file resides.
statThe structure where the information are stored.
Returns
0 if success.

ID of device containing file.

◆ ext2_unlink()

static int ext2_unlink ( const char *  path)
static

Delete a name and possibly the file it refers to.

Parameters
pathThe path to the file.
Returns
0 on success, -errno on failure.

◆ ext2_write()

static ssize_t ext2_write ( vfs_file_t file,
const void *  buffer,
off_t  offset,
size_t  nbyte 
)
static

Writes the given content inside the file.

Parameters
fileThe file descriptor of the file.
bufferThe content to write.
offsetOffset from which we start writing in the file.
nbyteThe number of bytes to write.
Returns
The number of written bytes.

◆ ext2_write_bgdt()

static int ext2_write_bgdt ( ext2_filesystem_t fs)
static

Writes the Block Group Descriptor Table (BGDT) to the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
Returns
0 on success, -1 on failure.

◆ ext2_write_block()

static int ext2_write_block ( ext2_filesystem_t fs,
uint32_t  block_index,
uint8_t buffer 
)
static

Writes a block on the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
block_indexthe index of the block we want to read.
bufferthe buffer where the content will be placed.
Returns
the amount of data we wrote, or negative value for an error.

◆ ext2_write_inode()

static int ext2_write_inode ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index 
)
static

Writes the inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexThe index of the inode.
Returns
0 on success, -1 on failure.

◆ ext2_write_inode_block()

static ssize_t ext2_write_inode_block ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index,
uint32_t  block_index,
uint8_t buffer 
)
static

Writes the real block starting from an inode and the block index inside the inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexThe index of the inode.
block_indexthe index of the block within the inode.
bufferthe buffer where to put the data.
Returns
the amount of data we wrote, or negative value for an error.

◆ ext2_write_inode_data()

static ssize_t ext2_write_inode_data ( ext2_filesystem_t fs,
ext2_inode_t inode,
uint32_t  inode_index,
off_t  offset,
size_t  nbyte,
char *  buffer 
)
static

Writes the data on the given inode.

Parameters
fsthe filesystem.
inodethe inode which we are working with.
inode_indexthe index of the inode.
offsetthe offset from which we start writing the data.
nbytethe number of bytes to write.
bufferthe buffer containing the data.
Returns
the amount written.

◆ ext2_write_superblock()

static int ext2_write_superblock ( ext2_filesystem_t fs)
static

Writes the superblock on the block device associated with this filesystem.

Parameters
fsthe ext2 filesystem structure.
Returns
the amount of data we wrote, or negative value for an error.

◆ get_ext2_filesystem()

static ext2_filesystem_t* get_ext2_filesystem ( const char *  absolute_path)
static

Get the ext2 filesystem object starting from a path.

Parameters
absolute_paththe absolute path for which we want to find the associated EXT2 filesystem.
Returns
a pointer to the EXT2 filesystem, NULL otherwise.

◆ time_to_string()

static const char* time_to_string ( uint32_t  time)
static

Turns the time to string.

Parameters
timethe UNIX time to turn to string.
Returns
time turned to string.

◆ uuid_to_string()

static const char* uuid_to_string ( uint8_t  uuid[16])
static

Turns an UUID to string.

Parameters
uuidthe UUID to turn to string.
Returns
the string representing the UUID.

Variable Documentation

◆ ext2_file_system_type

file_system_type ext2_file_system_type
static
Initial value:
= {
.name = "ext2",
.fs_flags = 0,
}
static vfs_file_t * ext2_mount_callback(const char *path, const char *device)
The mount call-back, which prepares everything and calls the actual EXT2 mount function.
Definition: ext2.c:3683

Filesystem information.

◆ ext2_fs_operations

vfs_file_operations_t ext2_fs_operations
static
Initial value:
= {
.open_f = ext2_open,
.unlink_f = ext2_unlink,
.close_f = ext2_close,
.read_f = ext2_read,
.write_f = ext2_write,
.lseek_f = ext2_lseek,
.stat_f = ext2_fstat,
.ioctl_f = ext2_ioctl,
.getdents_f = ext2_getdents,
.readlink_f = ext2_readlink,
.setattr_f = ext2_fsetattr,
}
static off_t ext2_lseek(vfs_file_t *file, off_t offset, int whence)
Repositions the file offset inside a file.
Definition: ext2.c:3064
static ssize_t ext2_read(vfs_file_t *file, char *buffer, off_t offset, size_t nbyte)
Reads from the file identified by the file descriptor.
Definition: ext2.c:2998
static ssize_t ext2_write(vfs_file_t *file, const void *buffer, off_t offset, size_t nbyte)
Writes the given content inside the file.
Definition: ext2.c:3029
static int ext2_fsetattr(vfs_file_t *file, struct iattr *attr)
Set attributes of the file at the given position.
Definition: ext2.c:3474
static vfs_file_t * ext2_open(const char *path, int flags, mode_t mode)
Open the file at the given path and returns its file descriptor.
Definition: ext2.c:2799
static ssize_t ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count)
Reads contents of the directories to a dirent buffer, updating the offset and returning the number of...
Definition: ext2.c:3208
static int ext2_close(vfs_file_t *file)
Closes the given file.
Definition: ext2.c:2972
static ssize_t ext2_readlink(const char *path, char *buffer, size_t bufsize)
Read the symbolic link, if present.
Definition: ext2.c:3262
static int ext2_fstat(vfs_file_t *file, stat_t *stat)
Retrieves information concerning the file at the given position.
Definition: ext2.c:3124
static int ext2_unlink(const char *path)
Delete a name and possibly the file it refers to.
Definition: ext2.c:2886
static int ext2_ioctl(vfs_file_t *file, int request, void *data)
Perform the I/O control operation specified by REQUEST on FD. One argument may follow; its presence a...
Definition: ext2.c:3195

Filesystem file operations.

◆ ext2_sys_operations

vfs_sys_operations_t ext2_sys_operations
static
Initial value:
= {
.mkdir_f = ext2_mkdir,
.rmdir_f = ext2_rmdir,
.stat_f = ext2_stat,
.creat_f = ext2_creat,
.symlink_f = NULL,
.setattr_f = ext2_setattr,
}
static vfs_file_t * ext2_creat(const char *path, mode_t permission)
Creates a new file or rewrite an existing one.
Definition: ext2.c:2698
static int ext2_setattr(const char *path, struct iattr *attr)
Set attributes of a file.
Definition: ext2.c:3500
static int ext2_rmdir(const char *path)
Removes the given directory.
Definition: ext2.c:3396
static int ext2_stat(const char *path, stat_t *stat)
Retrieves information concerning the file at the given position.
Definition: ext2.c:3159
static int ext2_mkdir(const char *path, mode_t mode)
Creates a new directory at the given path.
Definition: ext2.c:3322
#define NULL
Define NULL.
Definition: stddef.h:10

Filesystem general operations.