FreeNOS
LinnCreate.cpp
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 #include <BitArray.h>
19 #include <List.h>
20 #include <ListIterator.h>
21 #include <String.h>
22 #include <Types.h>
23 #include <Macros.h>
24 #include <FileSystem.h>
25 #include "LinnCreate.h"
26 #include "LinnSuperBlock.h"
27 #include "LinnGroup.h"
28 #include "LinnInode.h"
29 #include "LinnDirectoryEntry.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <dirent.h>
33 #include <time.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <libgen.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 
43 {
44  prog = ZERO;
45  image = ZERO;
46  super = ZERO;
47  input = ZERO;
48  verbose = false;
49 }
50 
52  FileSystem::FileModes mode, UserID uid, GroupID gid)
53 {
54  LinnGroup *group;
55  LinnInode *inode;
56  BitArray inodeMap(super->inodesPerGroup);
57 
58  // Point to the correct group
60  group += inodeNum / super->inodesPerGroup;
61 
62  // Use it to find the inode
63  inode = BLOCKPTR(LinnInode, group->inodeTable);
64  inode += inodeNum % super->inodesPerGroup;
65 
66  // Initialize the inode
67  inode->type = type;
68  inode->mode = mode;
69  inode->uid = uid;
70  inode->gid = gid;
71  inode->size = ZERO;
72  inode->accessTime = ZERO;
73  inode->createTime = time(ZERO);
74  inode->modifyTime = inode->createTime;
75  inode->changeTime = inode->createTime;
76  inode->links = 1;
77 
78  // Update inode BitArray, if needed
79  inodeMap.setArray(BLOCKPTR(u8, group->inodeMap),
81  inodeMap.set(inodeNum % super->inodesPerGroup);
82 
83  // Update superblock
85  group->freeInodesCount--;
86 
87  // Done
88  return inode;
89 }
90 
91 le32 LinnCreate::createInode(char *inputFile, struct stat *st)
92 {
93  LinnGroup *group;
94  LinnInode *inode;
95  BitArray inodeMap(super->inodesPerGroup);
96  u32 gn, in;
97 
98  // Loop all available LinnGroups
99  for (gn = 0; gn < LINN_GROUP_COUNT(super); gn++)
100  {
101  // Point to the correct LinnGroup
102  group = BLOCKPTR(LinnGroup, super->groupsTable) + gn;
103 
104  // Does it have any free inodes?
105  if (!group->freeInodesCount)
106  {
107  group = ZERO;
108  continue;
109  }
110  else
111  break;
112  }
113 
114  // Did we find an appropriate group?
115  if (!group)
116  {
117  printf("%s: no free inode available for `%s'\n",
118  prog, inputFile);
120  }
121 
122  // Find an empty inode number
123  inodeMap.setArray(BLOCKPTR(u8, group->inodeMap),
125  inodeMap.setNext(&in);
126 
127  // Instantiate the inode
128  inode = createInode(in, FILETYPE_FROM_ST(st),
129  FILEMODE_FROM_ST(st), st->st_uid, st->st_gid);
130 
131  // Insert file contents
132  if (S_ISREG(st->st_mode))
133  {
134  insertFile(inputFile, inode, st);
135  }
136 
137  // Debug out
138  if (verbose)
139  {
140  printf("%s inode=%u size=%u\n", inputFile, in, inode->size);
141  }
142  return in;
143 }
144 
145 le32 LinnCreate::insertIndirect(le32 *ptr, const le32 blockIndexNumber, const Size depth)
146 {
147  Size remain = 1;
148 
149  // Does the block map itself have a block?
150  if (!*ptr)
151  {
152  *ptr = BLOCK(super);
153  }
154 
155  // Point to the block map
156  ptr = BLOCKPTR(u32, *ptr);
157 
158  // Calculate the number of blocks remaining per entry
159  for (Size i = 0; i < depth - 1; i++)
160  {
161  remain *= LINN_SUPER_NUM_PTRS(super);
162  }
163 
164  // More indirection?
165  if (remain == 1)
166  {
167  const le32 blockValue = BLOCK(super);
168  ptr[blockIndexNumber % LINN_SUPER_NUM_PTRS(super)] = blockValue;
169  return blockValue;
170  }
171  // Traverse indirection
172  else
173  {
174  return insertIndirect(&ptr[blockIndexNumber / remain],
175  blockIndexNumber, depth - 1);
176  }
177 }
178 
179 void LinnCreate::insertFile(char *inputFile, LinnInode *inode,
180  struct stat *st)
181 {
182  int fd, bytes;
183  le32 blockNr;
184 
185  // Open the local file
186  if ((fd = open(inputFile, O_RDONLY)) < 0)
187  {
188  printf("%s: failed to fopen() `%s': %s\n",
189  prog, inputFile, strerror(errno));
191  }
192 
193  // Read blocks from the file
194  while (inode->size < st->st_size)
195  {
196  // Insert the block (direct)
197  if (LINN_INODE_NUM_BLOCKS(super, inode) <
199  {
200  blockNr = BLOCK(super);
201  inode->block[LINN_INODE_NUM_BLOCKS(super,inode)] = blockNr;
202  }
203  // Insert the block (indirect)
204  else if (LINN_INODE_NUM_BLOCKS(super, inode) <
206  {
207  blockNr = insertIndirect(&inode->block[LINN_INODE_IND_BLOCKS-1],
208  LINN_INODE_NUM_BLOCKS(super, inode) -
210  }
211  // Insert the block (double indirect)
212  else if (LINN_INODE_NUM_BLOCKS(super, inode) <
215  {
216  blockNr = insertIndirect(&inode->block[LINN_INODE_DIND_BLOCKS-1],
217  LINN_INODE_NUM_BLOCKS(super, inode) -
219  }
220  // Insert the blck (triple indirect)
221  else if (LINN_INODE_NUM_BLOCKS(super, inode) <
225  {
226  blockNr = insertIndirect(&inode->block[LINN_INODE_TIND_BLOCKS-1],
227  LINN_INODE_NUM_BLOCKS(super, inode) -
229  }
230  // Maximum file capacity reached
231  else
232  {
233  printf("%s: maximum file size reached for `%s'\n",
234  prog, inputFile);
235  break;
236  }
237 
238  // Read block contents
239  if ((bytes = read(fd, BLOCKPTR(u8, blockNr), super->blockSize)) < 0)
240  {
241  printf("%s: failed to read() `%s': %s\n",
242  prog, inputFile, strerror(errno));
244  }
245 
246  // Increment size appropriately
247  inode->size += bytes;
248  }
249  // Cleanup
250  close(fd);
251 }
252 
253 void LinnCreate::insertEntry(le32 dirInode, le32 entryInode,
254  const char *name, FileSystem::FileType type)
255 {
256  LinnGroup *group;
257  LinnInode *inode;
259  le32 entryNum, blockNum;
260 
261  // Point to the correct group
262  group = BLOCKPTR(LinnGroup, super->groupsTable);
263  if (dirInode != ZERO)
264  {
265  group += (dirInode / super->inodesPerGroup);
266  }
267  // Fetch inode
268  inode = BLOCKPTR(LinnInode, group->inodeTable) +
269  (dirInode % super->inodesPerGroup);
270 
271  // Calculate entry and block number
272  entryNum = inode->size / sizeof(LinnDirectoryEntry);
273  blockNum = (entryNum * sizeof(LinnDirectoryEntry)) /
274  super->blockSize;
275 
276  // Direct block
277  if (blockNum < LINN_INODE_DIR_BLOCKS)
278  {
279  // Allocate a new block, if needed
280  if (!inode->block[blockNum])
281  {
282  inode->block[blockNum] = BLOCK(super);
283  }
284  // Point to the fresh entry
285  entry = BLOCKPTR(LinnDirectoryEntry, inode->block[blockNum]) +
286  (entryNum % super->blockSize);
287  // Fill it
288  entry->inode = entryInode;
289  entry->type = type;
290  strncpy(entry->name, name, LINN_DIRENT_NAME_LEN);
291  entry->name[LINN_DIRENT_NAME_LEN - 1] = ZERO;
292  }
293  // Indirect block
294  else
295  {
296  printf("%s: indirect blocks not (yet) supported for directories\n",
297  prog);
299  }
300  // Increment directory size
301  inode->size += sizeof(LinnDirectoryEntry);
302 }
303 
304 void LinnCreate::insertDirectory(char *inputDir, le32 inodeNum, le32 parentNum)
305 {
306  struct dirent *ent;
307  struct stat st;
308  DIR *dir;
309  char path[255];
310  le32 child;
311  bool skip = false;
312 
313  // Create '.' and '..'
314  insertEntry(inodeNum, inodeNum, ".", FileSystem::DirectoryFile);
315  insertEntry(inodeNum, parentNum, "..", FileSystem::DirectoryFile);
316 
317  // Open the input directory
318  if ((dir = opendir(inputDir)) == NULL)
319  {
320  printf("%s: failed to opendir() `%s': %s\n",
321  prog, inputDir, strerror(errno));
323  }
324  // Read all it's entries
325  while ((ent = readdir(dir)))
326  {
327  // Hidden files
328  skip = ent->d_name[0] == '.';
329 
330  // Excluded files
331  for (ListIterator<String *> e(&excludes); e.hasCurrent(); e++)
332  {
333  String dent = (const char *) ent->d_name;
334 
335  if (dent.match(**e.current()))
336  {
337  skip = true;
338  break;
339  }
340  }
341  // Skip file?
342  if (skip) continue;
343 
344  // Construct local path
345  snprintf(path, sizeof(path), "%s/%s",
346  inputDir, ent->d_name);
347 
348  // Stat the file
349  if (stat(path, &st) != 0)
350  {
351  printf("%s: failed to stat() `%s': %s\n",
352  prog, path, strerror(errno));
354  }
355  // Create an inode for the child
356  child = createInode(path, &st);
357 
358  // Insert directory entry
359  insertEntry(inodeNum, child, ent->d_name,
360  FILETYPE_FROM_ST(&st));
361 
362  // Traverse down
363  if (S_ISDIR(st.st_mode))
364  {
365  insertDirectory(path, child, inodeNum);
366  }
367  }
368  // All done
369  closedir(dir);
370 }
371 
372 int LinnCreate::create(Size blockSize, Size blockNum, Size inodeNum)
373 {
374  LinnGroup *group;
375  BitArray map(128);
376 
377  assert(image != ZERO);
378  assert(prog != ZERO);
379  assert(blockNum >= 2);
380  assert(inodeNum > 0);
381 
382  // Allocate blocks
383  blocks = new u8[blockSize * blockNum];
384  memset(blocks, 0, blockSize * blockNum);
385 
386  // Create a superblock
393  super->blockSize = blockSize;
395  super->inodesCount = inodeNum;
396  super->blocksCount = blockNum;
399  super->freeBlocksCount = blockNum - 3;
400  super->creationTime = time(ZERO);
401  super->mountTime = ZERO;
402  super->mountCount = ZERO;
403  super->lastCheck = ZERO;
404  super->groupsTable = 2;
405 
406  // Allocate LinnGroups
407  for (Size i = 0; i < LINN_GROUP_COUNT(super); i++)
408  {
409  // Point to the correct LinnGroup
410  group = BLOCKPTR(LinnGroup, 2) + i;
411 
412  // Fill the group
418  }
419 
420  // Create special inodes
423 
424  // Insert into directory contents, if set
425  if (input)
426  {
429  }
430  // Mark blocks used
431  for (le32 block = 0; block < super->freeBlocksCount; block++)
432  {
433  // Point to group
434  group = BLOCKPTR(LinnGroup, super->groupsTable) +
435  (block / super->blocksPerGroup);
436  group->freeBlocksCount--;
437 
438  // Mark the block used
439  map.setArray(BLOCKPTR(u8, group->blockMap),
441  map.set(block % super->blocksPerGroup);
442  }
443  // Write the final image
444  return writeImage();
445 }
446 
448 {
449  FILE *fp;
450 
451  // Open output image
452  if ((fp = fopen(image, "w")) == NULL)
453  {
454  printf("%s: failed to fopen() `%s' for writing: %s\r\n",
455  prog, image, strerror(errno));
456  return EXIT_FAILURE;
457  }
458 
459  // Write all blocks at once
460  if (fwrite(blocks, super->blockSize *
461  (super->blocksCount - super->freeBlocksCount), 1, fp) != 1)
462  {
463  printf("%s: failed to fwrite() `%s': %s\r\n",
464  prog, image, strerror(errno));
465  fclose(fp);
466  return EXIT_FAILURE;
467  }
468  // All done
469  fclose(fp);
470  return EXIT_SUCCESS;
471 }
472 
473 void LinnCreate::setProgram(char *progName)
474 {
475  this->prog = progName;
476 }
477 
478 void LinnCreate::setImage(char *imageName)
479 {
480  this->image = imageName;
481 }
482 
483 void LinnCreate::setInput(char *inputName)
484 {
485  this->input = inputName;
486 }
487 
488 void LinnCreate::setExclude(char *pattern)
489 {
490  this->excludes.append(new String(pattern));
491 }
492 
493 void LinnCreate::setVerbose(bool newVerbose)
494 {
495  this->verbose = newVerbose;
496 }
497 
498 int main(int argc, char **argv)
499 {
500  LinnCreate fs;
501  Size blockSize = LINN_CREATE_BLOCK_SIZE;
502  Size blockNum = LINN_CREATE_BLOCK_NUM;
503  Size inodeNum = LINN_CREATE_INODE_NUM;
504 
505  // Verify command-line arguments
506  if (argc < 2)
507  {
508  printf("usage: %s IMAGE [OPTIONS...]\r\n"
509  "Creates a new Linnenbank FileSystem\r\n"
510  "\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",
518  argv[0]);
519  return EXIT_FAILURE;
520  }
521  // Process command-line arguments
522  fs.setProgram(argv[0]);
523  fs.setImage(argv[1]);
524 
525  // Process command-line options
526  for (int i = 0; i < argc - 2; i++)
527  {
528  // Exclude files matching the given pattern
529  if (!strcmp(argv[i + 2], "-e") && i < argc - 3)
530  {
531  fs.setExclude(argv[i + 3]);
532  i++;
533  }
534  // Verbose output
535  else if (!strcmp(argv[i + 2], "-v"))
536  {
537  fs.setVerbose(true);
538  }
539  // Input directory
540  else if (!strcmp(argv[i + 2], "-d") && i < argc - 3)
541  {
542  fs.setInput(argv[i + 3]);
543  i++;
544  }
545  // Block size
546  else if (!strcmp(argv[i + 2], "-b") && i < argc - 3)
547  {
548  blockSize = atoi(argv[i + 3]);
549  i++;
550  }
551  // Maximum block count
552  else if (!strcmp(argv[i + 2], "-n") && i < argc - 3)
553  {
554  if ((blockNum = atoi(argv[i + 3])) < 2)
555  {
556  printf("%s: block count must be >= 2\r\n",
557  argv[0]);
558  return EXIT_FAILURE;
559  }
560  i++;
561  }
562  // Inode count
563  else if (!strcmp(argv[i + 2], "-i") && i < argc - 3)
564  {
565  if ((inodeNum = atoi(argv[i + 3])) < 1)
566  {
567  printf("%s: inode count must be >= 1\r\n",
568  argv[0]);
569  return EXIT_FAILURE;
570  };
571  i++;
572  }
573  // Unknown argument
574  else
575  {
576  printf("%s: unknown option `%s'\r\n",
577  argv[0], argv[i + 2]);
578  return EXIT_FAILURE;
579  }
580  }
581  // Create a new Linnenbank FileSystem
582  return fs.create(blockSize, blockNum, inodeNum);
583 }
LinnInode::modifyTime
le32 modifyTime
Modification time.
Definition: LinnInode.h:101
EXIT_FAILURE
#define EXIT_FAILURE
Unsuccessful termination.
Definition: stdlib.h:36
stat::st_size
off_t st_size
For regular files, the file size in bytes.
Definition: stat.h:226
S_ISDIR
#define S_ISDIR(m)
Test for a directory.
Definition: stat.h:155
LinnSuperBlock::state
le16 state
Describes the current status.
Definition: LinnSuperBlock.h:119
LinnInode::changeTime
le32 changeTime
Status change timestamp.
Definition: LinnInode.h:102
BitArray::set
void set(const Size bit, const bool value=true)
Sets the given bit to the given value.
Definition: BitArray.cpp:50
FILETYPE_FROM_ST
#define FILETYPE_FROM_ST(st)
Convert from a (host system's) POSIX struct stat into a FileType.
Definition: LinnCreate.h:101
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
LinnSuperBlock::lastCheck
le32 lastCheck
Timestamp of the last check.
Definition: LinnSuperBlock.h:133
LinnSuperBlock::freeInodesCount
le32 freeInodesCount
Free inodes remaining.
Definition: LinnSuperBlock.h:128
LINN_GROUP_NUM_INODETAB
#define LINN_GROUP_NUM_INODETAB(sb)
Calculate the number of blocks needed for the inodes table.
Definition: LinnGroup.h:97
FileSystem.h
LINN_CREATE_BLOCK_SIZE
#define LINN_CREATE_BLOCK_SIZE
Default block size.
Definition: LinnCreate.h:40
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
LinnSuperBlock::majorRevision
le16 majorRevision
Filesystem major revision level.
Definition: LinnSuperBlock.h:117
LINN_GROUP_NUM_BLOCKMAP
#define LINN_GROUP_NUM_BLOCKMAP(sb)
Calculate the number of blocks needed for the blocks bitmap.
Definition: LinnGroup.h:75
Macros.h
fcntl.h
FileSystem::OtherRX
@ OtherRX
Definition: FileSystem.h:103
Types.h
errno
C int errno
The lvalue errno is used by many functions to return error values.
types.h
stat::st_uid
uid_t st_uid
User ID of file.
Definition: stat.h:209
LinnSuperBlock::magic0
le32 magic0
Allows detection of valid superblocks.
Definition: LinnSuperBlock.h:115
LINN_INODE_NUM_BLOCKS
#define LINN_INODE_NUM_BLOCKS(super, inode)
Calculate the number of blocks used in an LinnInode.
Definition: LinnInode.h:80
LinnInode::accessTime
le32 accessTime
Access time.
Definition: LinnInode.h:99
LINN_DIRENT_NAME_LEN
#define LINN_DIRENT_NAME_LEN
Length of the name field in an directory entry.
Definition: LinnDirectoryEntry.h:39
fopen
FILE * fopen(const char *filename, const char *mode)
Open a stream.
Definition: fopen.cpp:24
string.h
LINN_CREATE_BLOCKS_PER_GROUP
#define LINN_CREATE_BLOCKS_PER_GROUP
Default number of data blocks per group descriptor.
Definition: LinnCreate.h:46
LINN_SUPER_MAJOR
#define LINN_SUPER_MAJOR
Current major revision number.
Definition: LinnSuperBlock.h:52
FileSystem::FileType
FileType
All possible filetypes.
Definition: FileSystem.h:70
LinnGroup.h
String
Abstraction of strings.
Definition: String.h:41
atoi
C int atoi(const char *nptr)
Convert a string to an integer.
Definition: atoi.cpp:21
closedir
int closedir(DIR *dirp)
Close a directory stream.
Definition: closedir.cpp:22
LinnCreate::LinnCreate
LinnCreate()
Class constructor.
Definition: LinnCreate.cpp:42
FileSystem::GroupRX
@ GroupRX
Definition: FileSystem.h:97
LinnInode::block
le32 block[LINN_INODE_BLOCKS]
Pointers to blocks.
Definition: LinnInode.h:104
readdir
struct dirent * readdir(DIR *dirp)
Read a directory.
Definition: readdir.cpp:21
LinnSuperBlock::magic1
le32 magic1
Allows detection of valid superblocks.
Definition: LinnSuperBlock.h:116
libgen.h
GroupID
unsigned short GroupID
Group Identity.
Definition: Types.h:137
LinnSuperBlock::mountTime
le32 mountTime
Last time we where mounted (seconds since 1970).
Definition: LinnSuperBlock.h:131
LinnDirectoryEntry
Struct of an directory entry in LinnFS.
Definition: LinnDirectoryEntry.h:44
LinnGroup
Structure of a group descriptor.
Definition: LinnGroup.h:129
LINN_INODE_DIND_BLOCKS
#define LINN_INODE_DIND_BLOCKS
Double indirect blocks.
Definition: LinnInode.h:55
LINN_INODE_TIND_BLOCKS
#define LINN_INODE_TIND_BLOCKS
Triple indirect blocks.
Definition: LinnInode.h:58
open
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
Definition: open.cpp:26
opendir
DIR * opendir(const char *dirname)
Open directory associated with file descriptor.
Definition: opendir.cpp:27
LinnCreate::input
char * input
Path to the input directory.
Definition: LinnCreate.h:273
BLOCK
#define BLOCK(sb)
Retrieve one free block.
Definition: LinnCreate.h:91
LinnInode::links
le16 links
Links count.
Definition: LinnInode.h:103
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
LinnSuperBlock::inodesCount
le32 inodesCount
Total number of inodes.
Definition: LinnSuperBlock.h:125
BLOCKS
#define BLOCKS(sb, count)
Retrieve a given number of free contiguous blocks.
Definition: LinnCreate.h:72
LinnSuperBlock::blocksPerGroup
le32 blocksPerGroup
Number of blocks per group.
Definition: LinnSuperBlock.h:122
LinnCreate::insertIndirect
le32 insertIndirect(le32 *ptr, const le32 blockIndexNumber, const Size depth)
Inserts an indirect block address.
Definition: LinnCreate.cpp:145
LinnGroup::blockMap
le32 blockMap
Block bitmap.
Definition: LinnGroup.h:138
fwrite
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...
Definition: fwrite.cpp:24
LINN_GROUP_NUM_INODEMAP
#define LINN_GROUP_NUM_INODEMAP(sb)
Calculate the number of blocks needed for the inodes bitmap.
Definition: LinnGroup.h:86
read
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
Definition: read.cpp:22
main
int main(int argc, char **argv)
Program entry point.
Definition: LinnCreate.cpp:498
dirent.h
LinnGroup::inodeTable
le32 inodeTable
Inode table contains pre-allocated inodes.
Definition: LinnGroup.h:144
LinnSuperBlock::freeBlocksCount
le32 freeBlocksCount
Number of free data blocks.
Definition: LinnSuperBlock.h:127
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
LINN_SUPER_NUM_PTRS
#define LINN_SUPER_NUM_PTRS(sb)
Calculate the number of block address pointers fitting in one block.
Definition: LinnSuperBlock.h:103
LinnGroup::freeBlocksCount
le32 freeBlocksCount
The number of free blocks in this group.
Definition: LinnGroup.h:132
LINN_INODE_IND_BLOCKS
#define LINN_INODE_IND_BLOCKS
Indirect blocks.
Definition: LinnInode.h:52
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
dirent
Represents a directory entry.
Definition: dirent.h:64
String::match
bool match(const char *mask) const
Matches the String against a mask.
Definition: String.cpp:267
LINN_SUPER_OFFSET
#define LINN_SUPER_OFFSET
Fixed offset in storage of the superblock.
Definition: LinnSuperBlock.h:85
LINN_SUPER_VALID
#define LINN_SUPER_VALID
Filesystem is consistent.
Definition: LinnSuperBlock.h:67
close
int close(int fildes)
Close a file descriptor.
Definition: close.cpp:22
ListIterator::hasCurrent
virtual bool hasCurrent() const
Check if there is a current item on the List.
Definition: ListIterator.h:104
LinnSuperBlock
Linnenbank Filesystem (LinnFS) super block.
Definition: LinnSuperBlock.h:113
LinnInode.h
LINN_SUPER_MAGIC1
#define LINN_SUPER_MAGIC1
Second magic number (randomly chosen bytes).
Definition: LinnSuperBlock.h:40
List::append
void append(T t)
Insert an item at the end of the list.
Definition: List.h:139
LINN_SUPER_MAGIC0
#define LINN_SUPER_MAGIC0
First magic number ('Linn').
Definition: LinnSuperBlock.h:37
strcmp
int strcmp(const char *dest, const char *src)
Compare two strings.
Definition: strcmp.cpp:20
stdio.h
strerror
char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
Definition: strerror.cpp:20
NULL
#define NULL
NULL means zero.
Definition: Macros.h:39
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
BitArray::setNext
Result setNext(Size *bit, const Size count=1, const Size offset=0, const Size boundary=1)
Sets the next unset bit(s).
Definition: BitArray.cpp:97
S_ISREG
#define S_ISREG(m)
Test for a regular file.
Definition: stat.h:161
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
stat::st_mode
mode_t st_mode
Mode of file.
Definition: stat.h:203
LinnCreate::setImage
void setImage(char *imageName)
Set the output image file name.
Definition: LinnCreate.cpp:478
stat
int stat(const char *path, struct stat *buf)
Get file status.
Definition: stat.cpp:25
LinnSuperBlock::groupsTable
le32 groupsTable
Block address of the LinnGroup table.
Definition: LinnSuperBlock.h:135
LinnInode::uid
le16 uid
User Identity.
Definition: LinnInode.h:96
LinnInode::gid
le16 gid
Group Identity.
Definition: LinnInode.h:97
LINN_GROUP_COUNT
#define LINN_GROUP_COUNT(sb)
Calculate the number of LinnGroups in a filesystem.
Definition: LinnGroup.h:64
FileSystem::DirectoryFile
@ DirectoryFile
Definition: FileSystem.h:73
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
LINN_INODE_ROOT
#define LINN_INODE_ROOT
Root inode.
Definition: LinnInode.h:37
LinnSuperBlock::creationTime
le32 creationTime
Time when the filesystem was created.
Definition: LinnSuperBlock.h:130
FileSystem::FileModes
u16 FileModes
Multiple FileMode values combined.
Definition: FileSystem.h:108
stat.h
DIR
A type representing a directory stream.
Definition: dirent.h:94
le32
u32 BITWISE le32
Unsigned 32-bit little endian number.
Definition: Types.h:106
LINN_INODE_DIR_BLOCKS
#define LINN_INODE_DIR_BLOCKS
Direct blocks.
Definition: LinnInode.h:49
EXIT_SUCCESS
#define EXIT_SUCCESS
Successful termination.
Definition: stdlib.h:33
unistd.h
ListIterator.h
LinnInode::mode
le16 mode
Access permissions, as an FileMode.
Definition: LinnInode.h:95
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
assert
#define assert(exp)
Insert program diagnostics.
Definition: assert.h:60
UserID
unsigned short UserID
User Identity.
Definition: Types.h:134
entry
u32 entry[]
Definition: IntelACPI.h:64
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
LinnGroup::freeInodesCount
le32 freeInodesCount
Number of free inodes in this group.
Definition: LinnGroup.h:135
BLOCKPTR
#define BLOCKPTR(type, nr)
Returns a pointer to the correct in-memory block.
Definition: LinnCreate.h:62
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
LINN_CREATE_BLOCK_NUM
#define LINN_CREATE_BLOCK_NUM
Default number of blocks to allocate.
Definition: LinnCreate.h:43
LinnCreate::blocks
u8 * blocks
Array of blocks available in the filesystem.
Definition: LinnCreate.h:285
String.h
memset
void * memset(void *dest, int ch, size_t count)
Fill memory with a constant byte.
Definition: memset.cpp:20
LinnInode::type
le16 type
Type of file, as an FileType.
Definition: LinnInode.h:94
BitArray::setArray
void setArray(u8 *array, const Size bitCount=ZERO)
Use the given pointer as the BitArray buffer.
Definition: BitArray.cpp:170
LinnInode::createTime
le32 createTime
Creation time.
Definition: LinnInode.h:100
LinnSuperBlock::blocksCount
le32 blocksCount
Total number of data blocks.
Definition: LinnSuperBlock.h:126
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
LinnSuperBlock::blockSize
le32 blockSize
Size of each data block.
Definition: LinnSuperBlock.h:121
LinnSuperBlock::mountCount
le16 mountCount
Number of times we where mounted.
Definition: LinnSuperBlock.h:132
LinnCreate
Class for creating new Linnenbank FileSystems.
Definition: LinnCreate.h:132
LinnSuperBlock::minorRevision
le16 minorRevision
Filesystem minor revision level.
Definition: LinnSuperBlock.h:118
stat::st_gid
gid_t st_gid
Group ID of file.
Definition: stat.h:212
dirent::d_name
char d_name[DIRLEN]
Name of entry.
Definition: dirent.h:67
FILE
A structure containing information about a file.
Definition: stdio.h:60
stdlib.h
LinnCreate::setVerbose
void setVerbose(bool newVerbose)
Output verbose messages during the construction.
Definition: LinnCreate.cpp:493
fclose
int fclose(FILE *stream)
Close a stream.
Definition: fclose.cpp:23
type
u8 type
Definition: IntelACPI.h:63
strncpy
int strncpy(char *dest, const char *src, size_t sz)
Copy a string, given a maximum number of bytes.
Definition: strncpy.cpp:20
FILEMODE_FROM_ST
#define FILEMODE_FROM_ST(st)
Converts an (host system's) POSIX struct st into a FileMode.
Definition: LinnCreate.h:126
LinnDirectoryEntry.h
LinnInode::size
le32 size
Size in bytes.
Definition: LinnInode.h:98
LINN_CREATE_INODE_NUM
#define LINN_CREATE_INODE_NUM
Default number of inodes to allocate.
Definition: LinnCreate.h:49
exit
C void exit(int status)
Terminate a process.
Definition: exit.cpp:21
LinnGroup::inodeMap
le32 inodeMap
Inode bitmap.
Definition: LinnGroup.h:141
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
LinnDirectoryEntry
struct LinnDirectoryEntry LinnDirectoryEntry
Struct of an directory entry in LinnFS.
BitArray.h
snprintf
int snprintf(char *buffer, unsigned int size, const char *fmt,...)
Write a formatted string into a buffer.
Definition: snprintf.cpp:22
FileSystem::OwnerRWX
@ OwnerRWX
Definition: FileSystem.h:92
O_RDONLY
#define O_RDONLY
Open for reading only.
Definition: fcntl.h:81
BitArray
Represents an array of bits.
Definition: BitArray.h:36
LinnSuperBlock::inodesPerGroup
le32 inodesPerGroup
Number of inodes per group.
Definition: LinnSuperBlock.h:123
errno.h
LinnSuperBlock.h
LinnCreate.h
List.h
ListIterator
Iterate through a List.
Definition: ListIterator.h:37
LINN_SUPER_MINOR
#define LINN_SUPER_MINOR
Current minor revision number.
Definition: LinnSuperBlock.h:55