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
26int main(int argc, char **argv)
27{
28 KernelLog log;
29 Storage *storage = ZERO;
30 const char *path = "/";
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}
Uses a BootImage as a storage provider.
virtual FileSystem::Result initialize()
Initialize the Storage device.
Uses a BootSymbol inside a BootImage as a storage provider.
virtual FileSystem::Result initialize()
Initialize the Storage device.
int run()
Enters an infinite loop, serving incoming requests.
Use a file as Storage provider.
Definition FileStorage.h:39
FileSystem::Result mount()
Mount the FileSystem.
Log to the kernel using PrivExec().
Definition KernelLog.h:35
Linnenbank FileSystem (LinnFS).
Provides a storage device to build filesystems on top.
Definition Storage.h:36
Abstraction of strings.
Definition String.h:42
long toLong(const Number::Base base=Number::Dec) const
Convert the String to a signed long integer.
Definition String.cpp:456
#define assert(exp)
Insert program diagnostics.
Definition assert.h:60
int main(int argc, char **argv)
Program entry point.
Definition Main.cpp:20
#define NULL
NULL means zero.
Definition Macros.h:39
#define ERROR(msg)
Output an error message.
Definition Log.h:61
#define NOTICE(msg)
Output a notice message.
Definition Log.h:75
#define FATAL(msg)
Output a critical message and terminate program immediatly.
Definition Log.h:50
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
#define LINNFS_ROOTFS_FILE
Default filename of the embedded root filesystem (ramfs)
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
System information structure.
Definition SystemInfo.h:80
uint coreId
Core Identifier.
Definition SystemInfo.h:105