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