FreeNOS
LinnCreate.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __FILESYSTEM_LINN_CREATE_H
19#define __FILESYSTEM_LINN_CREATE_H
20
21#include <BitArray.h>
22#include <List.h>
23#include <String.h>
24#include <FileSystem.h>
25#include "LinnSuperBlock.h"
26#include "LinnInode.h"
27
40#define LINN_CREATE_BLOCK_SIZE 2048
41
43#define LINN_CREATE_BLOCK_NUM 8192
44
46#define LINN_CREATE_BLOCKS_PER_GROUP 8192
47
49#define LINN_CREATE_INODE_NUM 1024
50
52#define LINN_CREATE_INODES_PER_GROUP 1024
53
62#define BLOCKPTR(type,nr) (type *)(blocks + (super->blockSize * (nr)))
63
72#define BLOCKS(sb,count) \
73 ({ \
74 if ((sb)->freeBlocksCount < (count)) \
75 { \
76 printf("%s: not enough free blocks remaining (%lu needed)\n", \
77 prog, (ulong)(count)); \
78 exit(EXIT_FAILURE); \
79 } \
80 (sb)->freeBlocksCount -= (count); \
81 ((sb)->blocksCount - (sb)->freeBlocksCount - (count)); \
82 })
83
91#define BLOCK(sb) \
92 BLOCKS(sb, (ulong)1)
93
101#define FILETYPE_FROM_ST(st) \
102({ \
103 FileSystem::FileType t = FileSystem::UnknownFile; \
104 \
105 switch ((st)->st_mode & S_IFMT) \
106 { \
107 case S_IFBLK: t = FileSystem::BlockDeviceFile; break; \
108 case S_IFCHR: t = FileSystem::CharacterDeviceFile; break; \
109 case S_IFIFO: t = FileSystem::FIFOFile; break; \
110 case S_IFREG: t = FileSystem::RegularFile; break; \
111 case S_IFDIR: t = FileSystem::DirectoryFile; break; \
112 case S_IFLNK: t = FileSystem::SymlinkFile; break; \
113 case S_IFSOCK: t = FileSystem::SocketFile; break; \
114 default: break; \
115 } \
116 t; \
117})
118
126#define FILEMODE_FROM_ST(st) \
127 (FileSystem::FileMode)((st)->st_mode & 0777)
128
133{
134 public:
135
139 LinnCreate();
140
150 int create(Size blockSize, Size blockNum, Size inodeNum);
151
157 void setProgram(char *progName);
158
164 void setImage(char *imageName);
165
171 void setInput(char *inputName);
172
178 void setExclude(char *pattern);
179
185 void setVerbose(bool newVerbose);
186
187 private:
188
201 UserID uid = ZERO, GroupID gid = ZERO);
202
211 le32 createInode(char *inputFile, struct stat *st);
212
221 void insertEntry(le32 dirInode, le32 entryInode,
222 const char *name, FileSystem::FileType type);
223
233 void insertDirectory(char *inputFile, le32 inodeNum, le32 parentNum);
234
242 void insertFile(char *inputFile, LinnInode *inode,
243 struct stat *st);
244
255 le32 insertIndirect(le32 *ptr, const le32 blockIndexNumber, const Size depth);
256
262 int writeImage();
263
264 private:
265
267 char *prog;
268
270 char *image;
271
273 char *input;
274
277
280
283
286};
287
294#endif /* __FILESYSTEM_LINN_CREATE_H */
u8 type
Definition IntelACPI.h:0
Class for creating new Linnenbank FileSystems.
Definition LinnCreate.h:133
void setImage(char *imageName)
Set the output image file name.
LinnSuperBlock * super
Pointer to the superblock.
Definition LinnCreate.h:282
LinnCreate()
Class constructor.
u8 * blocks
Array of blocks available in the filesystem.
Definition LinnCreate.h:285
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.
Definition LinnCreate.h:270
char * prog
Program name we are invoked with.
Definition LinnCreate.h:267
bool verbose
Output verbose messages.
Definition LinnCreate.h:276
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.
Definition LinnCreate.h:279
void setExclude(char *pattern)
Exclude files matching the given pattern from the image.
char * input
Path to the input directory.
Definition LinnCreate.h:273
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.
Simple linked list template class.
Definition List.h:37
unsigned short UserID
User Identity.
Definition Types.h:134
u32 BITWISE le32
Unsigned 32-bit little endian number.
Definition Types.h:106
unsigned short GroupID
Group Identity.
Definition Types.h:137
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
FileType
All possible filetypes.
Definition FileSystem.h:71
u16 FileModes
Multiple FileMode values combined.
Definition FileSystem.h:108
Structure of an inode on the disk in the LinnFS filesystem.
Definition LinnInode.h:93
Linnenbank Filesystem (LinnFS) super block.
The <sys/stat.h> header shall define the stat structure.
Definition stat.h:177