Compare commits
No commits in common. "16b0531d42f64e5aafb39d6bb642b91ab35a39b6" and "ae0cd155c3e2266ac668b7358f06a8cab0a9fa24" have entirely different histories.
16b0531d42
...
ae0cd155c3
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,7 @@ build/
|
|||||||
initrd/boot/moon
|
initrd/boot/moon
|
||||||
env-local.sh
|
env-local.sh
|
||||||
initrd/bin/**
|
initrd/bin/**
|
||||||
base/usr/**
|
initrd/tests/**
|
||||||
|
base/
|
||||||
.fakeroot
|
.fakeroot
|
||||||
kernel/config.cmake
|
kernel/config.cmake
|
||||||
|
@ -6,10 +6,9 @@ A very basic POSIX-based operating system for personal computers, written in C++
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
- x86_64-compatible lightweight [kernel](kernel/).
|
- x86_64-compatible lightweight [kernel](kernel/).
|
||||||
- Preemptive multitasking, with a round-robin [scheduler](kernel/src/thread/).
|
- Preemptive multitasking, with a round-robin [scheduler](kernel/src/thread/) that can switch between tasks.
|
||||||
- [Virtual file system](kernel/src/fs/) with a simple [tmpfs](kernel/src/fs/tmpfs/) and read-only [ext2](kernel/src/fs/ext2/) support.
|
- [Virtual file system](kernel/src/fs/) with a simple [tmpfs](kernel/src/fs/tmpfs/) and read-only [ext2](kernel/src/fs/ext2/) support.
|
||||||
- Can [load ELF programs](kernel/src/thread/ELF.cpp) from the file system as userspace tasks.
|
- Can [load ELF programs](kernel/src/thread/ELF.cpp) from the file system as userspace tasks.
|
||||||
- Boots from an [ext2](apps/preinit.cpp) root filesystem (a bit slow for now).
|
|
||||||
- [System call](kernel/src/sys/) interface and [C Library](libc/), aiming to be mostly POSIX-compatible.
|
- [System call](kernel/src/sys/) interface and [C Library](libc/), aiming to be mostly POSIX-compatible.
|
||||||
- Designed to be [portable](kernel/src/arch), no need to be restricted to x86_64.
|
- Designed to be [portable](kernel/src/arch), no need to be restricted to x86_64.
|
||||||
- Designed around [UTF-8](libluna/include/luna/Utf8.h).
|
- Designed around [UTF-8](libluna/include/luna/Utf8.h).
|
||||||
|
@ -4,15 +4,9 @@ function(luna_app SOURCE_FILE APP_NAME)
|
|||||||
add_dependencies(${APP_NAME} libc)
|
add_dependencies(${APP_NAME} libc)
|
||||||
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
||||||
target_link_libraries(${APP_NAME} PRIVATE os)
|
target_link_libraries(${APP_NAME} PRIVATE os)
|
||||||
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_BASE}/usr/bin)
|
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
add_executable(preinit preinit.cpp)
|
|
||||||
target_compile_options(preinit PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
|
|
||||||
add_dependencies(preinit libc)
|
|
||||||
target_include_directories(preinit PRIVATE ${LUNA_BASE}/usr/include)
|
|
||||||
install(TARGETS preinit DESTINATION ${LUNA_ROOT}/initrd/bin)
|
|
||||||
|
|
||||||
luna_app(init.cpp init)
|
luna_app(init.cpp init)
|
||||||
luna_app(env.cpp env)
|
luna_app(env.cpp env)
|
||||||
luna_app(su.cpp su)
|
luna_app(su.cpp su)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
FILE* g_init_log = nullptr;
|
FILE* g_init_log;
|
||||||
|
|
||||||
struct Service
|
struct Service
|
||||||
{
|
{
|
||||||
@ -33,16 +33,6 @@ struct Service
|
|||||||
|
|
||||||
Vector<Service> g_services;
|
Vector<Service> g_services;
|
||||||
|
|
||||||
static void do_log(const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
|
|
||||||
if (g_init_log) vfprintf(g_init_log, format, ap);
|
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Result<void> service_child(const Service& service, SharedPtr<os::File> output, SharedPtr<os::File> error,
|
static Result<void> service_child(const Service& service, SharedPtr<os::File> output, SharedPtr<os::File> error,
|
||||||
SharedPtr<os::File> input)
|
SharedPtr<os::File> input)
|
||||||
{
|
{
|
||||||
@ -92,23 +82,23 @@ static Result<void> try_start_service(Service& service)
|
|||||||
auto rc = service_child(service, new_stdout, new_stderr, new_stdin);
|
auto rc = service_child(service, new_stdout, new_stderr, new_stdin);
|
||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
do_log("[child %d] failed to start service %s due to error: %s\n", getpid(), service.name.chars(),
|
fprintf(g_init_log, "[child %d] failed to start service %s due to error: %s\n", getpid(),
|
||||||
rc.error_string());
|
service.name.chars(), rc.error_string());
|
||||||
}
|
}
|
||||||
fclose(g_init_log);
|
fclose(g_init_log);
|
||||||
exit(127);
|
exit(127);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_log("[init] created new child process %d for service %s\n", pid, service.name.chars());
|
fprintf(g_init_log, "[init] created new child process %d for service %s\n", pid, service.name.chars());
|
||||||
|
|
||||||
if (service.wait)
|
if (service.wait)
|
||||||
{
|
{
|
||||||
do_log("[init] waiting for child process %d to finish\n", pid);
|
fprintf(g_init_log, "[init] waiting for child process %d to finish\n", pid);
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
TRY(os::Process::wait(pid, &status));
|
TRY(os::Process::wait(pid, &status));
|
||||||
|
|
||||||
do_log("[init] child process %d exited with code %d\n", pid, WEXITSTATUS(status));
|
fprintf(g_init_log, "[init] child process %d exited with code %d\n", pid, WEXITSTATUS(status));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
service.pid = pid;
|
service.pid = pid;
|
||||||
@ -121,13 +111,14 @@ static void start_service(Service& service)
|
|||||||
auto rc = try_start_service(service);
|
auto rc = try_start_service(service);
|
||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
do_log("[init] failed to start service %s due to error: %s\n", service.name.chars(), rc.error_string());
|
fprintf(g_init_log, "[init] failed to start service %s due to error: %s\n", service.name.chars(),
|
||||||
|
rc.error_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result<void> load_service(const os::Path& path)
|
static Result<void> load_service(const os::Path& path)
|
||||||
{
|
{
|
||||||
do_log("[init] reading service file: %s\n", path.name().chars());
|
fprintf(g_init_log, "[init] reading service file: %s\n", path.name().chars());
|
||||||
|
|
||||||
auto file = TRY(os::File::open(path, os::File::ReadOnly));
|
auto file = TRY(os::File::open(path, os::File::ReadOnly));
|
||||||
|
|
||||||
@ -144,7 +135,7 @@ static Result<void> load_service(const os::Path& path)
|
|||||||
auto parts = TRY(line.split_once('='));
|
auto parts = TRY(line.split_once('='));
|
||||||
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
|
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
|
||||||
{
|
{
|
||||||
do_log("[init] file contains invalid line, aborting: '%s'\n", line.chars());
|
fprintf(g_init_log, "[init] file contains invalid line, aborting: '%s'\n", line.chars());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,8 +149,8 @@ static Result<void> load_service(const os::Path& path)
|
|||||||
{
|
{
|
||||||
if (!service.command.is_empty())
|
if (!service.command.is_empty())
|
||||||
{
|
{
|
||||||
do_log("[init] 'Command' cannot be specified after 'Script' has already been set! (%s)\n",
|
fprintf(g_init_log, "[init] 'Command' cannot be specified after 'Script' has already been set! (%s)\n",
|
||||||
line.chars());
|
line.chars());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
service.command = move(parts[1]);
|
service.command = move(parts[1]);
|
||||||
@ -170,8 +161,8 @@ static Result<void> load_service(const os::Path& path)
|
|||||||
{
|
{
|
||||||
if (!service.command.is_empty())
|
if (!service.command.is_empty())
|
||||||
{
|
{
|
||||||
do_log("[init] 'Script' cannot be specified after 'Command' has already been set! (%s)\n",
|
fprintf(g_init_log, "[init] 'Script' cannot be specified after 'Command' has already been set! (%s)\n",
|
||||||
line.chars());
|
line.chars());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
service.command = TRY(String::format("/bin/sh -- %s"_sv, parts[1].chars()));
|
service.command = TRY(String::format("/bin/sh -- %s"_sv, parts[1].chars()));
|
||||||
@ -224,22 +215,22 @@ static Result<void> load_service(const os::Path& path)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_log("[init] skipping unknown entry name %s\n", parts[0].chars());
|
fprintf(g_init_log, "[init] skipping unknown entry name %s\n", parts[0].chars());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (service.name.is_empty())
|
if (service.name.is_empty())
|
||||||
{
|
{
|
||||||
do_log("[init] service file is missing 'Name' entry, aborting!\n");
|
fprintf(g_init_log, "[init] service file is missing 'Name' entry, aborting!\n");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (service.command.is_empty())
|
if (service.command.is_empty())
|
||||||
{
|
{
|
||||||
do_log("[init] service file is missing 'Command' or 'Script' entry, aborting!\n");
|
fprintf(g_init_log, "[init] service file is missing 'Command' or 'Script' entry, aborting!\n");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
do_log("[init] loaded service %s into memory\n", service.name.chars());
|
fprintf(g_init_log, "[init] loaded service %s into memory\n", service.name.chars());
|
||||||
|
|
||||||
TRY(g_services.try_append(move(service)));
|
TRY(g_services.try_append(move(service)));
|
||||||
|
|
||||||
@ -263,7 +254,7 @@ static Result<void> start_services()
|
|||||||
TRY(load_services());
|
TRY(load_services());
|
||||||
for (auto& service : g_services)
|
for (auto& service : g_services)
|
||||||
{
|
{
|
||||||
do_log("[init] starting service %s\n", service.name.chars());
|
fprintf(g_init_log, "[init] starting service %s\n", service.name.chars());
|
||||||
start_service(service);
|
start_service(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,16 +270,16 @@ static Result<void> set_hostname()
|
|||||||
|
|
||||||
if (sethostname(hostname.chars(), hostname.length()) < 0) return {};
|
if (sethostname(hostname.chars(), hostname.length()) < 0) return {};
|
||||||
|
|
||||||
do_log("[init] successfully set system hostname to '%s'\n", hostname.chars());
|
fprintf(g_init_log, "[init] successfully set system hostname to '%s'\n", hostname.chars());
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mount_tmpfs()
|
static void mount_devfs()
|
||||||
{
|
{
|
||||||
if (mount("/tmp", "tmpfs", "tmpfs") < 0) exit(255);
|
if (mkdir("/dev", 0755) < 0 && errno != EEXIST) exit(255);
|
||||||
|
|
||||||
if (chmod("/tmp", 01777) < 0) exit(255);
|
if (mount("/dev", "devfs", "devfs") < 0) exit(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -299,17 +290,17 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mount_devfs();
|
||||||
|
|
||||||
// Before this point, we don't even have an stdin, stdout and stderr. Set it up now so that child processes (and us)
|
// Before this point, we don't even have an stdin, stdout and stderr. Set it up now so that child processes (and us)
|
||||||
// can print stuff.
|
// can print stuff.
|
||||||
stdin = fopen("/dev/console", "r");
|
stdin = fopen("/dev/console", "r");
|
||||||
stdout = fopen("/dev/console", "w");
|
stdout = fopen("/dev/console", "w");
|
||||||
stderr = fopen("/dev/console", "w");
|
stderr = fopen("/dev/console", "w");
|
||||||
|
|
||||||
mount_tmpfs();
|
|
||||||
|
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
g_init_log = fopen("/tmp/init.log", "w+");
|
g_init_log = fopen("/init.log", "w+");
|
||||||
fcntl(fileno(g_init_log), F_SETFD, FD_CLOEXEC);
|
fcntl(fileno(g_init_log), F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
set_hostname();
|
set_hostname();
|
||||||
@ -328,11 +319,12 @@ int main()
|
|||||||
{
|
{
|
||||||
if (service.pid.has_value() && service.pid.value() == child)
|
if (service.pid.has_value() && service.pid.value() == child)
|
||||||
{
|
{
|
||||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
fprintf(g_init_log, "[init] service %s exited with status %d\n", service.name.chars(),
|
||||||
|
WEXITSTATUS(status));
|
||||||
|
|
||||||
if (service.restart)
|
if (service.restart)
|
||||||
{
|
{
|
||||||
do_log("[init] restarting service %s\n", service.name.chars());
|
fprintf(g_init_log, "[init] restarting service %s\n", service.name.chars());
|
||||||
|
|
||||||
start_service(service);
|
start_service(service);
|
||||||
}
|
}
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
// FIXME: Make this configurable.
|
|
||||||
#define LUNA_ROOT_PARTITION "/dev/cd0p2"
|
|
||||||
|
|
||||||
static void mount_devfs()
|
|
||||||
{
|
|
||||||
if (mkdir("/dev", 0755) < 0 && errno != EEXIST && errno != EROFS) exit(255);
|
|
||||||
|
|
||||||
if (mount("/dev", "devfs", "devfs") < 0) exit(255);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void open_std_streams()
|
|
||||||
{
|
|
||||||
stdin = fopen("/dev/console", "r");
|
|
||||||
stdout = fopen("/dev/console", "w");
|
|
||||||
stderr = fopen("/dev/console", "w");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fail(const char* message)
|
|
||||||
{
|
|
||||||
open_std_streams();
|
|
||||||
fprintf(stderr, "preinit: fatal error: %s\n", message);
|
|
||||||
exit(255);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fail_errno(const char* message)
|
|
||||||
{
|
|
||||||
int err = errno;
|
|
||||||
open_std_streams();
|
|
||||||
fprintf(stderr, "preinit: fatal error: %s (%s)\n", message, strerror(err));
|
|
||||||
exit(255);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mount_rootfs()
|
|
||||||
{
|
|
||||||
if (mkdir("/osroot", 0755) < 0 && errno != EEXIST) exit(255);
|
|
||||||
|
|
||||||
if (mount("/osroot", "ext2", LUNA_ROOT_PARTITION) < 0) fail_errno("Cannot mount the root partition");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
if (getpid() != 1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error: preinit must be run as the init process.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_devfs();
|
|
||||||
mount_rootfs();
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
if (stat("/osroot/mnt", &st) < 0 || !S_ISDIR(st.st_mode)) fail("No suitable temporary mountpoint for pivot_root");
|
|
||||||
|
|
||||||
// Now that we have mounted the root file system, remove the /dev mount on the current ramfs root.
|
|
||||||
umount("/dev");
|
|
||||||
|
|
||||||
long rc = syscall(SYS_pivot_root, "/osroot", "/osroot/mnt");
|
|
||||||
if (rc < 0) exit(255);
|
|
||||||
|
|
||||||
chdir("/");
|
|
||||||
umount("/mnt");
|
|
||||||
|
|
||||||
// Now, mount the /dev file system on the new root.
|
|
||||||
mount_devfs();
|
|
||||||
|
|
||||||
/*setenv("PATH", "/bin:/usr/bin", 1);
|
|
||||||
char* argv[] = { "init", nullptr };
|
|
||||||
char* envp[] = { nullptr };
|
|
||||||
execvpe(argv[0], argv, envp);*/
|
|
||||||
|
|
||||||
char* argv[] = { "/usr/bin/init", nullptr };
|
|
||||||
execv(argv[0], argv);
|
|
||||||
|
|
||||||
fail_errno("Failed to execute init");
|
|
||||||
|
|
||||||
return 255;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
Name=motd
|
|
||||||
Command=/usr/bin/cat /etc/motd
|
|
||||||
Wait=true
|
|
@ -1,3 +0,0 @@
|
|||||||
Name=selene
|
|
||||||
Script=/etc/startup/selene-home.sh
|
|
||||||
Wait=true
|
|
@ -1,2 +0,0 @@
|
|||||||
mount -t tmpfs tmpfs /home/selene
|
|
||||||
chown selene:selene /home/selene
|
|
3
initrd/etc/init/00-tmpfs
Normal file
3
initrd/etc/init/00-tmpfs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=tmpfs
|
||||||
|
Script=/sbin/mount-tmpfs
|
||||||
|
Wait=true
|
3
initrd/etc/init/01-motd
Normal file
3
initrd/etc/init/01-motd
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=motd
|
||||||
|
Command=/bin/cat /etc/motd
|
||||||
|
Wait=true
|
3
initrd/etc/init/02-ext2fs
Normal file
3
initrd/etc/init/02-ext2fs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=ext2fs
|
||||||
|
Script=/sbin/mount-ext2fs
|
||||||
|
Wait=true
|
@ -1,3 +1,3 @@
|
|||||||
Name=login
|
Name=login
|
||||||
Command=/usr/bin/login
|
Command=/bin/login
|
||||||
Restart=true
|
Restart=true
|
5
initrd/sbin/mount-tmpfs
Normal file
5
initrd/sbin/mount-tmpfs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p /tmp
|
||||||
|
mount -t tmpfs tmpfs /tmp
|
||||||
|
chmod 1777 /tmp
|
@ -105,8 +105,7 @@ if(MOON_DEBUG)
|
|||||||
include(debug.cmake)
|
include(debug.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/config.cmake)
|
if(EXISTS config.cmake)
|
||||||
message(STATUS "Using custom config.cmake file")
|
|
||||||
include(config.cmake)
|
include(config.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -10,5 +10,4 @@ target_compile_definitions(moon PRIVATE PCI_DEBUG)
|
|||||||
target_compile_definitions(moon PRIVATE EXT2_DEBUG)
|
target_compile_definitions(moon PRIVATE EXT2_DEBUG)
|
||||||
target_compile_definitions(moon PRIVATE DEVICE_REGISTRY_DEBUG)
|
target_compile_definitions(moon PRIVATE DEVICE_REGISTRY_DEBUG)
|
||||||
target_compile_definitions(moon PRIVATE FORK_DEBUG)
|
target_compile_definitions(moon PRIVATE FORK_DEBUG)
|
||||||
target_compile_definitions(moon PRIVATE MOUNT_DEBUG)
|
|
||||||
target_compile_options(moon PRIVATE -fsanitize=undefined)
|
target_compile_options(moon PRIVATE -fsanitize=undefined)
|
||||||
|
@ -65,12 +65,9 @@ namespace ATA
|
|||||||
|
|
||||||
if (command_new != command_old) PCI::write16(m_device.address, PCI::Command, command_new);
|
if (command_new != command_old) PCI::write16(m_device.address, PCI::Command, command_new);
|
||||||
|
|
||||||
bool success = false;
|
if (!m_primary_channel.initialize()) return false;
|
||||||
|
|
||||||
if (m_primary_channel.initialize()) success = true;
|
return m_secondary_channel.initialize();
|
||||||
if (m_secondary_channel.initialize()) success = true;
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::irq_handler(Registers* regs)
|
void Controller::irq_handler(Registers* regs)
|
||||||
|
@ -233,9 +233,7 @@ namespace VFS
|
|||||||
auto parent_path = TRY(PathParser::dirname(path));
|
auto parent_path = TRY(PathParser::dirname(path));
|
||||||
auto child = TRY(PathParser::basename(path));
|
auto child = TRY(PathParser::basename(path));
|
||||||
|
|
||||||
#ifdef MOUNT_DEBUG
|
kinfoln("vfs: Mounting filesystem on target %s", path);
|
||||||
kdbgln("vfs: Mounting filesystem on target %s", path);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));
|
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));
|
||||||
|
|
||||||
@ -247,8 +245,6 @@ namespace VFS
|
|||||||
|
|
||||||
TRY(parent_inode->replace_entry(mount, child.chars()));
|
TRY(parent_inode->replace_entry(mount, child.chars()));
|
||||||
|
|
||||||
kinfoln("vfs: Successfully mounted filesystem on target %s", path);
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,9 @@ void reap_thread()
|
|||||||
mark_critical(InitRD::populate_vfs(), "Failed to load files from the initial ramdisk");
|
mark_critical(InitRD::populate_vfs(), "Failed to load files from the initial ramdisk");
|
||||||
mark_critical(DeviceRegistry::init(), "Failed to register initial devices");
|
mark_critical(DeviceRegistry::init(), "Failed to register initial devices");
|
||||||
|
|
||||||
auto init =
|
auto init = mark_critical(VFS::resolve_path("/bin/init", Credentials {}), "Can't find init in the initial ramfs!");
|
||||||
mark_critical(VFS::resolve_path("/bin/preinit", Credentials {}), "Can't find init in the initial ramfs!");
|
|
||||||
auto init_thread =
|
auto init_thread =
|
||||||
mark_critical(Scheduler::new_userspace_thread(init, "/bin/preinit"), "Failed to create PID 1 process for init");
|
mark_critical(Scheduler::new_userspace_thread(init, "/bin/init"), "Failed to create PID 1 process for init");
|
||||||
|
|
||||||
auto reap = mark_critical(Scheduler::new_kernel_thread(reap_thread, "[reap]"),
|
auto reap = mark_critical(Scheduler::new_kernel_thread(reap_thread, "[reap]"),
|
||||||
"Failed to create the process reaper kernel thread");
|
"Failed to create the process reaper kernel thread");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include "Log.h"
|
|
||||||
#include "arch/CPU.h"
|
#include "arch/CPU.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
@ -52,7 +51,5 @@ Result<u64> sys_sethostname(Registers*, SyscallArgs args)
|
|||||||
|
|
||||||
s_hostname.adopt(new_hostname);
|
s_hostname.adopt(new_hostname);
|
||||||
|
|
||||||
kinfoln("System hostname updated to '%s'", s_hostname.chars());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ namespace Scheduler
|
|||||||
g_idle.is_kernel = true;
|
g_idle.is_kernel = true;
|
||||||
g_idle.parent = nullptr;
|
g_idle.parent = nullptr;
|
||||||
g_idle.name = "[idle]";
|
g_idle.name = "[idle]";
|
||||||
g_idle.active_directory = nullptr;
|
|
||||||
|
|
||||||
g_idle.ticks_left = 1;
|
g_idle.ticks_left = 1;
|
||||||
|
|
||||||
@ -87,7 +86,6 @@ namespace Scheduler
|
|||||||
thread->name = name;
|
thread->name = name;
|
||||||
|
|
||||||
thread->is_kernel = true;
|
thread->is_kernel = true;
|
||||||
thread->active_directory = MMU::kernel_page_directory();
|
|
||||||
|
|
||||||
thread->auth = Credentials { .uid = 0, .euid = 0, .suid = 0, .gid = 0, .egid = 0, .sgid = 0 };
|
thread->auth = Credentials { .uid = 0, .euid = 0, .suid = 0, .gid = 0, .egid = 0, .sgid = 0 };
|
||||||
|
|
||||||
@ -235,7 +233,7 @@ namespace Scheduler
|
|||||||
{
|
{
|
||||||
switch_context(old_thread, new_thread, regs);
|
switch_context(old_thread, new_thread, regs);
|
||||||
if (!old_thread->is_kernel) old_thread->fp_data.save();
|
if (!old_thread->is_kernel) old_thread->fp_data.save();
|
||||||
if (old_thread->state != ThreadState::Idle && MMU::get_page_directory() != MMU::kernel_page_directory())
|
if (MMU::get_page_directory() != MMU::kernel_page_directory())
|
||||||
old_thread->active_directory = MMU::get_page_directory();
|
old_thread->active_directory = MMU::get_page_directory();
|
||||||
if (new_thread->active_directory) MMU::switch_page_directory(new_thread->active_directory);
|
if (new_thread->active_directory) MMU::switch_page_directory(new_thread->active_directory);
|
||||||
if (!new_thread->is_kernel)
|
if (!new_thread->is_kernel)
|
||||||
|
@ -71,7 +71,6 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
|||||||
|
|
||||||
[[noreturn]] void Thread::exit_and_signal_parent(u8 _status)
|
[[noreturn]] void Thread::exit_and_signal_parent(u8 _status)
|
||||||
{
|
{
|
||||||
if (this->id == 1) fail("the init process exited");
|
|
||||||
if (is_kernel) state = ThreadState::Dying;
|
if (is_kernel) state = ThreadState::Dying;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"diskguid": "00000000-0000-0000-0000-000000000000",
|
"diskguid": "00000000-0000-0000-0000-000000000000",
|
||||||
"disksize": 32,
|
"disksize": 20,
|
||||||
"align": 1024,
|
"align": 1024,
|
||||||
"iso9660": true,
|
"iso9660": true,
|
||||||
"config": "initrd/sys/config",
|
"config": "initrd/sys/config",
|
||||||
@ -12,7 +12,7 @@
|
|||||||
"partitions": [
|
"partitions": [
|
||||||
{
|
{
|
||||||
"type": "boot",
|
"type": "boot",
|
||||||
"size": 8
|
"size": 16
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "ext2",
|
"type": "ext2",
|
||||||
|
@ -9,7 +9,7 @@ function(luna_test SOURCE_FILE APP_NAME)
|
|||||||
add_dependencies(${APP_NAME} libc)
|
add_dependencies(${APP_NAME} libc)
|
||||||
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
|
||||||
target_link_libraries(${APP_NAME} PRIVATE test os)
|
target_link_libraries(${APP_NAME} PRIVATE test os)
|
||||||
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_BASE}/usr/bin/tests)
|
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin/tests)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
|
@ -17,17 +17,14 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chown -R root:root base
|
chown -R root:root initrd
|
||||||
|
|
||||||
cmake --install $LUNA_BUILD_DIR
|
cmake --install $LUNA_BUILD_DIR
|
||||||
|
|
||||||
chmod a+s base/usr/bin/su
|
chmod 400 initrd/boot/moon
|
||||||
|
chmod a+s initrd/bin/su
|
||||||
|
|
||||||
mkdir -p base/home/selene
|
mkdir -p initrd/home/selene
|
||||||
|
chown 1000:1000 initrd/home/selene
|
||||||
|
|
||||||
mkdir -p base/dev
|
mkdir -p initrd/dev
|
||||||
mkdir -p base/mnt
|
|
||||||
mkdir -p base/tmp
|
|
||||||
|
|
||||||
rm -f base/bin
|
|
||||||
ln -s usr/bin base/bin
|
|
||||||
|
@ -7,6 +7,6 @@ cd $LUNA_ROOT
|
|||||||
|
|
||||||
fakeroot -u -s $LUNA_ROOT/.fakeroot -- tools/install.sh
|
fakeroot -u -s $LUNA_ROOT/.fakeroot -- tools/install.sh
|
||||||
|
|
||||||
fakeroot -u -i $LUNA_ROOT/.fakeroot -- genext2fs -d base -B 4096 -b 1024 -L luna-rootfs -N 1024 build/ext2fs.bin
|
genext2fs -d base -B 4096 -b 1024 -L luna-rootfs -U -N 1024 build/ext2fs.bin
|
||||||
|
|
||||||
mkbootimg luna.json Luna.iso
|
fakeroot -u -i $LUNA_ROOT/.fakeroot mkbootimg luna.json Luna.iso
|
||||||
|
Loading…
Reference in New Issue
Block a user