FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
LinnCreate Class Reference

Class for creating new Linnenbank FileSystems. More...

#include <LinnCreate.h>

Public Member Functions

 LinnCreate ()
 Class constructor. More...
 
int create (Size blockSize, Size blockNum, Size inodeNum)
 Creates the LinnFS FileSystem. More...
 
void setProgram (char *progName)
 Set the program name we are invoked with. More...
 
void setImage (char *imageName)
 Set the output image file name. More...
 
void setInput (char *inputName)
 Set the input directory name. More...
 
void setExclude (char *pattern)
 Exclude files matching the given pattern from the image. More...
 
void setVerbose (bool newVerbose)
 Output verbose messages during the construction. More...
 

Private Member Functions

LinnInodecreateInode (le32 inodeNum, FileSystem::FileType type, FileSystem::FileModes mode, UserID uid=ZERO, GroupID gid=ZERO)
 Creates an empty LinnInode. More...
 
le32 createInode (char *inputFile, struct stat *st)
 Copies a local file contents into an LinnInode. More...
 
void insertEntry (le32 dirInode, le32 entryInode, const char *name, FileSystem::FileType type)
 Inserts an LinnDirectoryEntry to the given directory inode. More...
 
void insertDirectory (char *inputFile, le32 inodeNum, le32 parentNum)
 Inserts the given directory and it's childs to the filesystem image. More...
 
void insertFile (char *inputFile, LinnInode *inode, struct stat *st)
 Inserts the contents of a local file into an LinnInode. More...
 
le32 insertIndirect (le32 *ptr, const le32 blockIndexNumber, const Size depth)
 Inserts an indirect block address. More...
 
int writeImage ()
 Writes the final image to disk. More...
 

Private Attributes

char * prog
 Program name we are invoked with. More...
 
char * image
 Path to the output image. More...
 
char * input
 Path to the input directory. More...
 
bool verbose
 Output verbose messages. More...
 
List< String * > excludes
 List of file patterns to ignore. More...
 
LinnSuperBlocksuper
 Pointer to the superblock. More...
 
u8blocks
 Array of blocks available in the filesystem. More...
 

Detailed Description

Class for creating new Linnenbank FileSystems.

Definition at line 132 of file LinnCreate.h.

Constructor & Destructor Documentation

◆ LinnCreate()

LinnCreate::LinnCreate ( )

Class constructor.

Definition at line 42 of file LinnCreate.cpp.

References image, input, prog, super, verbose, and ZERO.

Member Function Documentation

◆ create()

int LinnCreate::create ( Size  blockSize,
Size  blockNum,
Size  inodeNum 
)

◆ createInode() [1/2]

le32 LinnCreate::createInode ( char *  inputFile,
struct stat st 
)
private

Copies a local file contents into an LinnInode.

Parameters
inputFilePath to the local file to insert.
stPOSIX stat pointer for the local file.
Returns
Inode number of the inserted file.

Definition at line 91 of file LinnCreate.cpp.

References BLOCKPTR, createInode(), exit(), EXIT_FAILURE, FILEMODE_FROM_ST, FILETYPE_FROM_ST, LinnGroup::freeInodesCount, LinnSuperBlock::groupsTable, LinnGroup::inodeMap, LinnSuperBlock::inodesPerGroup, insertFile(), LINN_GROUP_COUNT, printf(), prog, S_ISREG, BitArray::setArray(), BitArray::setNext(), LinnInode::size, stat::st_gid, stat::st_mode, stat::st_uid, super, verbose, and ZERO.

◆ createInode() [2/2]

LinnInode * LinnCreate::createInode ( le32  inodeNum,
FileSystem::FileType  type,
FileSystem::FileModes  mode,
UserID  uid = ZERO,
GroupID  gid = ZERO 
)
private

◆ insertDirectory()

void LinnCreate::insertDirectory ( char *  inputFile,
le32  inodeNum,
le32  parentNum 
)
private

Inserts the given directory and it's childs to the filesystem image.

Parameters
inputFilePath to a local directory.
inodeNumInode number for the input directory.
parentNumInode number of our parent.
Note
This function is recursive.

Definition at line 304 of file LinnCreate.cpp.

References closedir(), createInode(), dirent::d_name, FileSystem::DirectoryFile, errno, excludes, exit(), EXIT_FAILURE, FILETYPE_FROM_ST, ListIterator< T >::hasCurrent(), insertEntry(), String::match(), NULL, opendir(), printf(), prog, readdir(), S_ISDIR, snprintf(), stat::st_mode, stat(), and strerror().

Referenced by create().

◆ insertEntry()

void LinnCreate::insertEntry ( le32  dirInode,
le32  entryInode,
const char *  name,
FileSystem::FileType  type 
)
private

Inserts an LinnDirectoryEntry to the given directory inode.

Parameters
dirInodeInode number of the directory.
entryInodeInode number of the entry to create.
nameUnique name (inside this directory) for the entry.
typeFileType for the entry to insert.

Definition at line 253 of file LinnCreate.cpp.

References BLOCK, LinnInode::block, BLOCKPTR, LinnSuperBlock::blockSize, entry, exit(), EXIT_FAILURE, LinnSuperBlock::groupsTable, LinnSuperBlock::inodesPerGroup, LinnGroup::inodeTable, LINN_DIRENT_NAME_LEN, LINN_INODE_DIR_BLOCKS, printf(), prog, LinnInode::size, strncpy(), super, type, and ZERO.

Referenced by insertDirectory().

◆ insertFile()

void LinnCreate::insertFile ( char *  inputFile,
LinnInode inode,
struct stat st 
)
private

Inserts the contents of a local file into an LinnInode.

Parameters
inputFilePath to the local file.
inodePointer to the inode to fill.
stPOSIX stats structure of inputFile.

Definition at line 179 of file LinnCreate.cpp.

References BLOCK, LinnInode::block, BLOCKPTR, LinnSuperBlock::blockSize, close(), errno, exit(), EXIT_FAILURE, insertIndirect(), LINN_INODE_DIND_BLOCKS, LINN_INODE_DIR_BLOCKS, LINN_INODE_IND_BLOCKS, LINN_INODE_NUM_BLOCKS, LINN_INODE_TIND_BLOCKS, LINN_SUPER_NUM_PTRS, O_RDONLY, open(), printf(), prog, read(), LinnInode::size, stat::st_size, strerror(), and super.

Referenced by createInode().

◆ insertIndirect()

le32 LinnCreate::insertIndirect ( le32 ptr,
const le32  blockIndexNumber,
const Size  depth 
)
private

Inserts an indirect block address.

Parameters
ptrBuffer containing block addresses.
blockIndexNumberBlock index number to insert in the buffer, minus LINN_INODE_DIR_BLOCKS
depthLevel of indirection.
Returns
Newly allocated block address

Definition at line 145 of file LinnCreate.cpp.

References BLOCK, BLOCKPTR, LINN_SUPER_NUM_PTRS, and super.

Referenced by insertFile().

◆ setExclude()

void LinnCreate::setExclude ( char *  pattern)

Exclude files matching the given pattern from the image.

Parameters
patternPattern to match against.

Definition at line 488 of file LinnCreate.cpp.

References List< T >::append(), and excludes.

Referenced by main().

◆ setImage()

void LinnCreate::setImage ( char *  imageName)

Set the output image file name.

Parameters
imageNameImage name to use.

Definition at line 478 of file LinnCreate.cpp.

References image.

Referenced by main().

◆ setInput()

void LinnCreate::setInput ( char *  inputName)

Set the input directory name.

Parameters
inputNameInput directory to use.

Definition at line 483 of file LinnCreate.cpp.

References input.

Referenced by main().

◆ setProgram()

void LinnCreate::setProgram ( char *  progName)

Set the program name we are invoked with.

Parameters
progNameprogram name.

Definition at line 473 of file LinnCreate.cpp.

References prog.

Referenced by main().

◆ setVerbose()

void LinnCreate::setVerbose ( bool  newVerbose)

Output verbose messages during the construction.

Parameters
newVerboseTrue to turn on, false to turn off verbose messages.

Definition at line 493 of file LinnCreate.cpp.

References verbose.

Referenced by main().

◆ writeImage()

int LinnCreate::writeImage ( )
private

Writes the final image to disk.

Returns
EXIT_SUCCESS if successful and EXIT_FAILURE otherwise.

Definition at line 447 of file LinnCreate.cpp.

References blocks, LinnSuperBlock::blocksCount, LinnSuperBlock::blockSize, errno, EXIT_FAILURE, EXIT_SUCCESS, fclose(), fopen(), LinnSuperBlock::freeBlocksCount, fwrite(), image, NULL, printf(), prog, strerror(), and super.

Referenced by create().

Field Documentation

◆ blocks

u8* LinnCreate::blocks
private

Array of blocks available in the filesystem.

Definition at line 285 of file LinnCreate.h.

Referenced by create(), and writeImage().

◆ excludes

List<String *> LinnCreate::excludes
private

List of file patterns to ignore.

Definition at line 279 of file LinnCreate.h.

Referenced by insertDirectory(), and setExclude().

◆ image

char* LinnCreate::image
private

Path to the output image.

Definition at line 270 of file LinnCreate.h.

Referenced by create(), LinnCreate(), setImage(), and writeImage().

◆ input

char* LinnCreate::input
private

Path to the input directory.

Definition at line 273 of file LinnCreate.h.

Referenced by create(), LinnCreate(), and setInput().

◆ prog

char* LinnCreate::prog
private

Program name we are invoked with.

Definition at line 267 of file LinnCreate.h.

Referenced by create(), createInode(), insertDirectory(), insertEntry(), insertFile(), LinnCreate(), setProgram(), and writeImage().

◆ super

LinnSuperBlock* LinnCreate::super
private

Pointer to the superblock.

Definition at line 282 of file LinnCreate.h.

Referenced by create(), createInode(), insertEntry(), insertFile(), insertIndirect(), LinnCreate(), and writeImage().

◆ verbose

bool LinnCreate::verbose
private

Output verbose messages.

Definition at line 276 of file LinnCreate.h.

Referenced by createInode(), LinnCreate(), and setVerbose().


The documentation for this class was generated from the following files: