Ext
 All Files Functions
Functions
superblock.h File Reference

Contains superblock struct and its methods. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

struct __attribute__ ((__packed__)) fs_info
 Contains main information about FS. More...
 
size_t sizeof_superblock (const struct superblock *superblock)
 
void init_super_block (struct superblock *superblock)
 Constructor of superblock. More...
 
void destroy_super_block (struct superblock *superblock)
 Destructor of superblock. More...
 
ssize_t read_super_block (int fd, struct superblock *superblock)
 Read sb from memory. More...
 
ssize_t write_super_block (int fd, struct superblock *superblock)
 Write sb to memory. More...
 
uint16_t reserve_inode (const struct superblock *superblock)
 Reserve free inode. More...
 
uint16_t free_inode (const struct superblock *superblock, uint16_t inode_id)
 Release inode. More...
 
uint16_t reserve_block (const struct superblock *superblock)
 Reserve block. More...
 
uint16_t free_block (const struct superblock *superblock, uint16_t block_id)
 Release block. More...
 

Detailed Description

Contains superblock struct and its methods.

Author
yaishenka
Date
13.03.2021

Definition in file superblock.h.

Function Documentation

struct __attribute__ ( (__packed__)  )

Contains main information about FS.

Main suberblock struct Contains fs_info and masks for blocks and inodes.

Definition at line 16 of file superblock.h.

void destroy_super_block ( struct superblock *  superblock)

Destructor of superblock.

Parameters
superblock

Definition at line 41 of file superblock.c.

uint16_t free_block ( const struct superblock *  superblock,
uint16_t  block_id 
)

Release block.

Parameters
superblock
block_idid of block to release
Returns
id of block if all ok; -1 if block was already released

Definition at line 149 of file superblock.c.

uint16_t free_inode ( const struct superblock *  superblock,
uint16_t  inode_id 
)

Release inode.

Parameters
superblock
inode_idid of inode to release
Returns
id of inode if all ok; superblock->fs_info->blocks_count_in_inode if inode was already released

Definition at line 128 of file superblock.c.

void init_super_block ( struct superblock *  superblock)

Constructor of superblock.

Construct superblock with default params defined in core/defines.h

Parameters
superblock

Definition at line 29 of file superblock.c.

ssize_t read_super_block ( int  fd,
struct superblock *  superblock 
)

Read sb from memory.

Parameters
fdopened fd
superblockempty instance of superblock
Returns
sizeof(superblock) if reading is ok; -1 otherwise and destruct superblock object
Warning
printf strerror(errno) to stderr

Definition at line 47 of file superblock.c.

uint16_t reserve_block ( const struct superblock *  superblock)

Reserve block.

Parameters
superblock
Returns
block_id if all ok; superblock->fs_info->blocks_count_in_inode if all block are reserved

Definition at line 138 of file superblock.c.

uint16_t reserve_inode ( const struct superblock *  superblock)

Reserve free inode.

Parameters
superblock
Returns
Id of first free inode if it exists; superblock->fs_info->inodes_count if all inodes are reserved

Definition at line 117 of file superblock.c.

size_t sizeof_superblock ( const struct superblock *  superblock)

Count blocks_count_in_inode of inode in bytes

Parameters
superblock
Returns
blocks_count_in_inode of superblock in FS

Definition at line 23 of file superblock.c.

ssize_t write_super_block ( int  fd,
struct superblock *  superblock 
)

Write sb to memory.

Parameters
fdopened fd
superblock
Returns
sizeof(superblock) if writing is ok; -1 otherwise
Warning
printf strerror(errno) to stderr

Definition at line 85 of file superblock.c.