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 
276  bool verbose;
277 
280 
283 
286 };
287 
294 #endif /* __FILESYSTEM_LINN_CREATE_H */
stat
The <sys/stat.h> header shall define the stat structure.
Definition: stat.h:176
LinnCreate::prog
char * prog
Program name we are invoked with.
Definition: LinnCreate.h:267
FileSystem.h
LinnCreate::createInode
LinnInode * createInode(le32 inodeNum, FileSystem::FileType type, FileSystem::FileModes mode, UserID uid=ZERO, GroupID gid=ZERO)
Creates an empty LinnInode.
Definition: LinnCreate.cpp:51
LinnCreate::image
char * image
Path to the output image.
Definition: LinnCreate.h:270
FileSystem::FileType
FileType
All possible filetypes.
Definition: FileSystem.h:70
LinnCreate::LinnCreate
LinnCreate()
Class constructor.
Definition: LinnCreate.cpp:42
GroupID
unsigned short GroupID
Group Identity.
Definition: Types.h:137
LinnCreate::input
char * input
Path to the input directory.
Definition: LinnCreate.h:273
LinnCreate::writeImage
int writeImage()
Writes the final image to disk.
Definition: LinnCreate.cpp:447
LinnCreate::super
LinnSuperBlock * super
Pointer to the superblock.
Definition: LinnCreate.h:282
LinnCreate::create
int create(Size blockSize, Size blockNum, Size inodeNum)
Creates the LinnFS FileSystem.
Definition: LinnCreate.cpp:372
LinnCreate::insertIndirect
le32 insertIndirect(le32 *ptr, const le32 blockIndexNumber, const Size depth)
Inserts an indirect block address.
Definition: LinnCreate.cpp:145
LinnCreate::setProgram
void setProgram(char *progName)
Set the program name we are invoked with.
Definition: LinnCreate.cpp:473
LinnCreate::setInput
void setInput(char *inputName)
Set the input directory name.
Definition: LinnCreate.cpp:483
LinnSuperBlock
Linnenbank Filesystem (LinnFS) super block.
Definition: LinnSuperBlock.h:113
LinnInode.h
LinnInode
Structure of an inode on the disk in the LinnFS filesystem.
Definition: LinnInode.h:92
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
LinnCreate::setImage
void setImage(char *imageName)
Set the output image file name.
Definition: LinnCreate.cpp:478
LinnCreate::insertFile
void insertFile(char *inputFile, LinnInode *inode, struct stat *st)
Inserts the contents of a local file into an LinnInode.
Definition: LinnCreate.cpp:179
FileSystem::FileModes
u16 FileModes
Multiple FileMode values combined.
Definition: FileSystem.h:108
le32
u32 BITWISE le32
Unsigned 32-bit little endian number.
Definition: Types.h:106
LinnCreate::excludes
List< String * > excludes
List of file patterns to ignore.
Definition: LinnCreate.h:279
LinnCreate::verbose
bool verbose
Output verbose messages.
Definition: LinnCreate.h:276
UserID
unsigned short UserID
User Identity.
Definition: Types.h:134
LinnCreate::insertDirectory
void insertDirectory(char *inputFile, le32 inodeNum, le32 parentNum)
Inserts the given directory and it's childs to the filesystem image.
Definition: LinnCreate.cpp:304
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
LinnCreate::blocks
u8 * blocks
Array of blocks available in the filesystem.
Definition: LinnCreate.h:285
String.h
LinnCreate::setExclude
void setExclude(char *pattern)
Exclude files matching the given pattern from the image.
Definition: LinnCreate.cpp:488
LinnCreate::insertEntry
void insertEntry(le32 dirInode, le32 entryInode, const char *name, FileSystem::FileType type)
Inserts an LinnDirectoryEntry to the given directory inode.
Definition: LinnCreate.cpp:253
LinnCreate
Class for creating new Linnenbank FileSystems.
Definition: LinnCreate.h:132
List< String * >
LinnCreate::setVerbose
void setVerbose(bool newVerbose)
Output verbose messages during the construction.
Definition: LinnCreate.cpp:493
type
u8 type
Definition: IntelACPI.h:63
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
BitArray.h
LinnSuperBlock.h
List.h