FreeNOS
Main.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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 <Types.h>
19 #include <Assert.h>
20 #include <KernelLog.h>
21 #include <FileStorage.h>
22 #include <BootImageStorage.h>
23 #include <BootSymbolStorage.h>
24 #include "LinnFileSystem.h"
25 
26 int main(int argc, char **argv)
27 {
28  KernelLog log;
29  Storage *storage = ZERO;
30  const char *path = "/";
31  SystemInformation info;
32 
33  // Only run on core0
34  if (info.coreId != 0)
35  return 0;
36 
37  // Mount the given file, or try to use the BootImage embedded rootfs
38  if (argc > 3)
39  {
40  const String offsetStr(argv[2], false);
41  const Size offset = offsetStr.toLong();
42  NOTICE("file storage: " << argv[1] << " at offset " << offset);
43  storage = new FileStorage(argv[1], offset);
44  assert(storage != NULL);
45  path = argv[3];
46  }
47  else
48  {
49  // Allocate BootImage
51  assert(bm != NULL);
52 
53  // Load BootImage
54  const FileSystem::Result imageResult = bm->initialize();
55  if (imageResult != FileSystem::Success)
56  {
57  FATAL("unable to load BootImage: result = " << (int) imageResult);
58  }
59 
60  // Allocate BootSymbol
62  assert(bs != NULL);
63 
64  // Load BootSymbol
65  const FileSystem::Result symbolResult = bs->initialize();
66  if (symbolResult != FileSystem::Success)
67  {
68  FATAL("unable to load BootSymbol '" << LINNFS_ROOTFS_FILE <<
69  "': result = " << (int) symbolResult);
70  }
71 
72  storage = bs;
73  NOTICE("boot image: " << LINNFS_ROOTFS_FILE);
74  }
75 
76  // Mount, then start serving requests.
77  if (storage)
78  {
79  LinnFileSystem server(path, storage);
80  server.mount();
81  return server.run();
82  }
83 
84  ERROR("no usable storage found");
85  return 1;
86 }
Types.h
NOTICE
#define NOTICE(msg)
Output a notice message.
Definition: Log.h:75
LinnFileSystem
Linnenbank FileSystem (LinnFS).
Definition: LinnFileSystem.h:73
String
Abstraction of strings.
Definition: String.h:41
BootImageStorage
Uses a BootImage as a storage provider.
Definition: BootImageStorage.h:38
LINNFS_ROOTFS_FILE
#define LINNFS_ROOTFS_FILE
Default filename of the embedded root filesystem (ramfs)
Definition: LinnFileSystem.h:40
Assert.h
ChannelServer::run
int run()
Enters an infinite loop, serving incoming requests.
Definition: ChannelServer.h:161
BootSymbolStorage.h
SystemInformation::coreId
uint coreId
Core Identifier.
Definition: SystemInfo.h:105
FileSystem::Success
@ Success
Definition: FileSystem.h:54
main
int main(int argc, char **argv)
Program entry point.
Definition: Main.cpp:20
KernelLog
Log to the kernel using PrivExec().
Definition: KernelLog.h:34
FATAL
#define FATAL(msg)
Output a critical message and terminate program immediatly.
Definition: Log.h:50
NULL
#define NULL
NULL means zero.
Definition: Macros.h:39
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
BootSymbolStorage::initialize
virtual FileSystem::Result initialize()
Initialize the Storage device.
Definition: BootSymbolStorage.cpp:30
BootImageStorage::initialize
virtual FileSystem::Result initialize()
Initialize the Storage device.
Definition: BootImageStorage.cpp:34
FileSystemServer::mount
FileSystem::Result mount()
Mount the FileSystem.
Definition: FileSystemServer.cpp:77
BootSymbolStorage
Uses a BootSymbol inside a BootImage as a storage provider.
Definition: BootSymbolStorage.h:39
FileStorage
Use a file as Storage provider.
Definition: FileStorage.h:38
assert
#define assert(exp)
Insert program diagnostics.
Definition: assert.h:60
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
SystemInformation
System information structure.
Definition: SystemInfo.h:79
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
FileStorage.h
BootImageStorage.h
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
Storage
Provides a storage device to build filesystems on top.
Definition: Storage.h:35
LinnFileSystem.h
KernelLog.h
String::toLong
long toLong(const Number::Base base=Number::Dec) const
Convert the String to a signed long integer.
Definition: String.cpp:456