Go to the documentation of this file.
117 printf(
"%s: no free inode available for `%s'\n",
140 printf(
"%s inode=%u size=%u\n", inputFile, in, inode->
size);
159 for (
Size i = 0; i < depth - 1; i++)
175 blockIndexNumber, depth - 1);
188 printf(
"%s: failed to fopen() `%s': %s\n",
233 printf(
"%s: maximum file size reached for `%s'\n",
241 printf(
"%s: failed to read() `%s': %s\n",
247 inode->
size += bytes;
259 le32 entryNum, blockNum;
263 if (dirInode !=
ZERO)
280 if (!inode->
block[blockNum])
288 entry->inode = entryInode;
296 printf(
"%s: indirect blocks not (yet) supported for directories\n",
320 printf(
"%s: failed to opendir() `%s': %s\n",
328 skip = ent->
d_name[0] ==
'.';
335 if (dent.
match(**e.current()))
345 snprintf(path,
sizeof(path),
"%s/%s",
349 if (
stat(path, &st) != 0)
351 printf(
"%s: failed to stat() `%s': %s\n",
383 blocks =
new u8[blockSize * blockNum];
454 printf(
"%s: failed to fopen() `%s' for writing: %s\r\n",
463 printf(
"%s: failed to fwrite() `%s': %s\r\n",
475 this->
prog = progName;
480 this->
image = imageName;
485 this->
input = inputName;
498 int main(
int argc,
char **argv)
508 printf(
"usage: %s IMAGE [OPTIONS...]\r\n"
509 "Creates a new Linnenbank FileSystem\r\n"
511 " -h Show this help message.\r\n"
512 " -v Output verbose messages.\r\n"
513 " -d DIRECTORY Insert files from the given directory into the image\r\n"
514 " -e PATTERN Exclude matching files from the created filesystem\r\n"
515 " -b SIZE Specifies the blocksize in bytes.\r\n"
516 " -n COUNT Specifies the maximum number of blocks.\r\n"
517 " -i COUNT Specifies the number of inodes to allocate.\r\n",
526 for (
int i = 0; i < argc - 2; i++)
529 if (!
strcmp(argv[i + 2],
"-e") && i < argc - 3)
535 else if (!
strcmp(argv[i + 2],
"-v"))
540 else if (!
strcmp(argv[i + 2],
"-d") && i < argc - 3)
546 else if (!
strcmp(argv[i + 2],
"-b") && i < argc - 3)
548 blockSize =
atoi(argv[i + 3]);
552 else if (!
strcmp(argv[i + 2],
"-n") && i < argc - 3)
554 if ((blockNum =
atoi(argv[i + 3])) < 2)
556 printf(
"%s: block count must be >= 2\r\n",
563 else if (!
strcmp(argv[i + 2],
"-i") && i < argc - 3)
565 if ((inodeNum =
atoi(argv[i + 3])) < 1)
567 printf(
"%s: inode count must be >= 1\r\n",
576 printf(
"%s: unknown option `%s'\r\n",
577 argv[0], argv[i + 2]);
582 return fs.
create(blockSize, blockNum, inodeNum);
le32 modifyTime
Modification time.
#define EXIT_FAILURE
Unsuccessful termination.
off_t st_size
For regular files, the file size in bytes.
#define S_ISDIR(m)
Test for a directory.
le16 state
Describes the current status.
le32 changeTime
Status change timestamp.
void set(const Size bit, const bool value=true)
Sets the given bit to the given value.
#define FILETYPE_FROM_ST(st)
Convert from a (host system's) POSIX struct stat into a FileType.
The <sys/stat.h> header shall define the stat structure.
char * prog
Program name we are invoked with.
le32 lastCheck
Timestamp of the last check.
le32 freeInodesCount
Free inodes remaining.
#define LINN_GROUP_NUM_INODETAB(sb)
Calculate the number of blocks needed for the inodes table.
#define LINN_CREATE_BLOCK_SIZE
Default block size.
LinnInode * createInode(le32 inodeNum, FileSystem::FileType type, FileSystem::FileModes mode, UserID uid=ZERO, GroupID gid=ZERO)
Creates an empty LinnInode.
char * image
Path to the output image.
le16 majorRevision
Filesystem major revision level.
#define LINN_GROUP_NUM_BLOCKMAP(sb)
Calculate the number of blocks needed for the blocks bitmap.
C int errno
The lvalue errno is used by many functions to return error values.
uid_t st_uid
User ID of file.
le32 magic0
Allows detection of valid superblocks.
#define LINN_INODE_NUM_BLOCKS(super, inode)
Calculate the number of blocks used in an LinnInode.
le32 accessTime
Access time.
#define LINN_DIRENT_NAME_LEN
Length of the name field in an directory entry.
FILE * fopen(const char *filename, const char *mode)
Open a stream.
#define LINN_CREATE_BLOCKS_PER_GROUP
Default number of data blocks per group descriptor.
#define LINN_SUPER_MAJOR
Current major revision number.
FileType
All possible filetypes.
C int atoi(const char *nptr)
Convert a string to an integer.
int closedir(DIR *dirp)
Close a directory stream.
LinnCreate()
Class constructor.
le32 block[LINN_INODE_BLOCKS]
Pointers to blocks.
struct dirent * readdir(DIR *dirp)
Read a directory.
le32 magic1
Allows detection of valid superblocks.
unsigned short GroupID
Group Identity.
le32 mountTime
Last time we where mounted (seconds since 1970).
Struct of an directory entry in LinnFS.
Structure of a group descriptor.
#define LINN_INODE_DIND_BLOCKS
Double indirect blocks.
#define LINN_INODE_TIND_BLOCKS
Triple indirect blocks.
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
DIR * opendir(const char *dirname)
Open directory associated with file descriptor.
char * input
Path to the input directory.
#define BLOCK(sb)
Retrieve one free block.
int writeImage()
Writes the final image to disk.
LinnSuperBlock * super
Pointer to the superblock.
int create(Size blockSize, Size blockNum, Size inodeNum)
Creates the LinnFS FileSystem.
le32 inodesCount
Total number of inodes.
#define BLOCKS(sb, count)
Retrieve a given number of free contiguous blocks.
le32 blocksPerGroup
Number of blocks per group.
le32 insertIndirect(le32 *ptr, const le32 blockIndexNumber, const Size depth)
Inserts an indirect block address.
le32 blockMap
Block bitmap.
size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
The fwrite() function shall write, from the array pointed to by ptr, up to nitems elements whose size...
#define LINN_GROUP_NUM_INODEMAP(sb)
Calculate the number of blocks needed for the inodes bitmap.
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
int main(int argc, char **argv)
Program entry point.
le32 inodeTable
Inode table contains pre-allocated inodes.
le32 freeBlocksCount
Number of free data blocks.
void setProgram(char *progName)
Set the program name we are invoked with.
void setInput(char *inputName)
Set the input directory name.
#define LINN_SUPER_NUM_PTRS(sb)
Calculate the number of block address pointers fitting in one block.
le32 freeBlocksCount
The number of free blocks in this group.
#define LINN_INODE_IND_BLOCKS
Indirect blocks.
int printf(const char *format,...)
Output a formatted string to standard output.
Represents a directory entry.
bool match(const char *mask) const
Matches the String against a mask.
#define LINN_SUPER_OFFSET
Fixed offset in storage of the superblock.
#define LINN_SUPER_VALID
Filesystem is consistent.
int close(int fildes)
Close a file descriptor.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Linnenbank Filesystem (LinnFS) super block.
#define LINN_SUPER_MAGIC1
Second magic number (randomly chosen bytes).
void append(T t)
Insert an item at the end of the list.
#define LINN_SUPER_MAGIC0
First magic number ('Linn').
int strcmp(const char *dest, const char *src)
Compare two strings.
char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
#define NULL
NULL means zero.
unsigned int u32
Unsigned 32-bit number.
Result setNext(Size *bit, const Size count=1, const Size offset=0, const Size boundary=1)
Sets the next unset bit(s).
#define S_ISREG(m)
Test for a regular file.
Structure of an inode on the disk in the LinnFS filesystem.
unsigned int Size
Any sane size indicator cannot go negative.
mode_t st_mode
Mode of file.
void setImage(char *imageName)
Set the output image file name.
int stat(const char *path, struct stat *buf)
Get file status.
le32 groupsTable
Block address of the LinnGroup table.
#define LINN_GROUP_COUNT(sb)
Calculate the number of LinnGroups in a filesystem.
void insertFile(char *inputFile, LinnInode *inode, struct stat *st)
Inserts the contents of a local file into an LinnInode.
#define LINN_INODE_ROOT
Root inode.
le32 creationTime
Time when the filesystem was created.
u16 FileModes
Multiple FileMode values combined.
A type representing a directory stream.
u32 BITWISE le32
Unsigned 32-bit little endian number.
#define LINN_INODE_DIR_BLOCKS
Direct blocks.
#define EXIT_SUCCESS
Successful termination.
le16 mode
Access permissions, as an FileMode.
List< String * > excludes
List of file patterns to ignore.
bool verbose
Output verbose messages.
#define assert(exp)
Insert program diagnostics.
unsigned short UserID
User Identity.
void insertDirectory(char *inputFile, le32 inodeNum, le32 parentNum)
Inserts the given directory and it's childs to the filesystem image.
le32 freeInodesCount
Number of free inodes in this group.
#define BLOCKPTR(type, nr)
Returns a pointer to the correct in-memory block.
unsigned char u8
Unsigned 8-bit number.
#define LINN_CREATE_BLOCK_NUM
Default number of blocks to allocate.
u8 * blocks
Array of blocks available in the filesystem.
void * memset(void *dest, int ch, size_t count)
Fill memory with a constant byte.
le16 type
Type of file, as an FileType.
void setArray(u8 *array, const Size bitCount=ZERO)
Use the given pointer as the BitArray buffer.
le32 createTime
Creation time.
le32 blocksCount
Total number of data blocks.
void setExclude(char *pattern)
Exclude files matching the given pattern from the image.
void insertEntry(le32 dirInode, le32 entryInode, const char *name, FileSystem::FileType type)
Inserts an LinnDirectoryEntry to the given directory inode.
le32 blockSize
Size of each data block.
le16 mountCount
Number of times we where mounted.
Class for creating new Linnenbank FileSystems.
le16 minorRevision
Filesystem minor revision level.
gid_t st_gid
Group ID of file.
char d_name[DIRLEN]
Name of entry.
A structure containing information about a file.
void setVerbose(bool newVerbose)
Output verbose messages during the construction.
int fclose(FILE *stream)
Close a stream.
int strncpy(char *dest, const char *src, size_t sz)
Copy a string, given a maximum number of bytes.
#define FILEMODE_FROM_ST(st)
Converts an (host system's) POSIX struct st into a FileMode.
#define LINN_CREATE_INODE_NUM
Default number of inodes to allocate.
C void exit(int status)
Terminate a process.
le32 inodeMap
Inode bitmap.
struct LinnDirectoryEntry LinnDirectoryEntry
Struct of an directory entry in LinnFS.
int snprintf(char *buffer, unsigned int size, const char *fmt,...)
Write a formatted string into a buffer.
#define O_RDONLY
Open for reading only.
Represents an array of bits.
le32 inodesPerGroup
Number of inodes per group.
#define LINN_SUPER_MINOR
Current minor revision number.