mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-10 13:04:53 -04:00
Implement mount program
This commit is contained in:
parent
ed3ac80eb8
commit
e4f2b64f82
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,4 +31,5 @@ programs/mkdir/mkdir
|
|||||||
programs/rm/rm
|
programs/rm/rm
|
||||||
programs/date/date
|
programs/date/date
|
||||||
programs/ls/ls
|
programs/ls/ls
|
||||||
|
programs/mount/mount
|
||||||
programs/dist/
|
programs/dist/
|
@ -51,6 +51,9 @@ void kernel_main(){
|
|||||||
//Init dynamic memory allocation
|
//Init dynamic memory allocation
|
||||||
kalloc::init();
|
kalloc::init();
|
||||||
|
|
||||||
|
//Call global constructors
|
||||||
|
_init();
|
||||||
|
|
||||||
//Install drivers
|
//Install drivers
|
||||||
timer::install();
|
timer::install();
|
||||||
//acpi::init();
|
//acpi::init();
|
||||||
@ -74,9 +77,6 @@ void kernel_main(){
|
|||||||
//Only install system calls when everything else is ready
|
//Only install system calls when everything else is ready
|
||||||
install_system_calls();
|
install_system_calls();
|
||||||
|
|
||||||
//Call global constructors
|
|
||||||
_init();
|
|
||||||
|
|
||||||
init_console();
|
init_console();
|
||||||
|
|
||||||
scheduler::init();
|
scheduler::init();
|
||||||
|
@ -334,16 +334,16 @@ int64_t vfs::mounts(char* buffer, size_t size){
|
|||||||
char* name_buffer = &(entry->name);
|
char* name_buffer = &(entry->name);
|
||||||
size_t str_pos = 0;
|
size_t str_pos = 0;
|
||||||
|
|
||||||
for(size_t j = 0; j < mp.mount_point.size(); ++j, ++str_pos){
|
for(size_t j = 0; j < mp.mount_point.size(); ++j){
|
||||||
name_buffer[str_pos] = mp.mount_point[j];
|
name_buffer[str_pos++] = mp.mount_point[j];
|
||||||
}
|
}
|
||||||
name_buffer[str_pos++] = '\0';
|
name_buffer[str_pos++] = '\0';
|
||||||
for(size_t j = 0; j < mp.device.size(); ++j, ++str_pos){
|
for(size_t j = 0; j < mp.device.size(); ++j){
|
||||||
name_buffer[str_pos] = mp.device[j];
|
name_buffer[str_pos++] = mp.device[j];
|
||||||
}
|
}
|
||||||
name_buffer[str_pos++] = '\0';
|
name_buffer[str_pos++] = '\0';
|
||||||
for(size_t j = 0; j < fs_type.size(); ++j, ++str_pos){
|
for(size_t j = 0; j < fs_type.size(); ++j){
|
||||||
name_buffer[str_pos] = fs_type[j];
|
name_buffer[str_pos++] = fs_type[j];
|
||||||
}
|
}
|
||||||
name_buffer[str_pos++] = '\0';
|
name_buffer[str_pos++] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.PHONY: dist default clean force_look
|
.PHONY: dist default clean force_look
|
||||||
|
|
||||||
PROGRAMS=one hello long loop longone longtwo keyboard tsh cpuid shutdown reboot args stat cat which readelf touch mkdir rm date ls
|
PROGRAMS=one hello long loop longone longtwo keyboard tsh cpuid shutdown reboot args stat cat which readelf touch mkdir rm date ls mount
|
||||||
|
|
||||||
default: dist
|
default: dist
|
||||||
|
|
||||||
|
15
programs/mount/Makefile
Normal file
15
programs/mount/Makefile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.PHONY: default clean
|
||||||
|
|
||||||
|
default: mount
|
||||||
|
|
||||||
|
include ../../cpp.mk
|
||||||
|
|
||||||
|
%.cpp.o: src/%.cpp
|
||||||
|
$(CC) -c $< -o $@ $(PROGRAM_FLAGS)
|
||||||
|
|
||||||
|
mount: main.cpp.o
|
||||||
|
$(CC) -o mount main.cpp.o $(PROGRAM_LINK_FLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.cpp.o
|
||||||
|
rm -rf mount
|
48
programs/mount/src/main.cpp
Normal file
48
programs/mount/src/main.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//=======================================================================
|
||||||
|
// Copyright Baptiste Wicht 2013-2014.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
#include <file.hpp>
|
||||||
|
#include <system.hpp>
|
||||||
|
#include <errors.hpp>
|
||||||
|
#include <print.hpp>
|
||||||
|
#include <mount_point.hpp>
|
||||||
|
|
||||||
|
static constexpr const size_t BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
|
int main(int, char*[]){
|
||||||
|
//TODO Add support to mount new directories
|
||||||
|
|
||||||
|
auto buffer = new char[BUFFER_SIZE];
|
||||||
|
|
||||||
|
auto mp_result = mounts(buffer, BUFFER_SIZE);
|
||||||
|
|
||||||
|
if(mp_result.valid()){
|
||||||
|
size_t position = 0;
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
auto entry = reinterpret_cast<mount_point*>(buffer + position);
|
||||||
|
|
||||||
|
auto mount_point = &entry->name;
|
||||||
|
auto device = mount_point + entry->length_mp + 1;
|
||||||
|
auto type = device + entry->length_dev + 1;
|
||||||
|
|
||||||
|
printf("%s %s %s\n", mount_point, device, type);
|
||||||
|
|
||||||
|
if(!entry->offset_next){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
position += entry->offset_next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("mount: error: %s\n", std::error_message(mp_result.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
@ -20,6 +20,7 @@ std::expected<size_t> read(size_t fd, char* buffer, size_t max);
|
|||||||
std::expected<size_t> entries(size_t fd, char* buffer, size_t max);
|
std::expected<size_t> entries(size_t fd, char* buffer, size_t max);
|
||||||
void close(size_t fd);
|
void close(size_t fd);
|
||||||
std::expected<stat_info> stat(size_t fd);
|
std::expected<stat_info> stat(size_t fd);
|
||||||
|
std::expected<size_t> mounts(char* buffer, size_t max);
|
||||||
|
|
||||||
std::string current_working_directory();
|
std::string current_working_directory();
|
||||||
void set_current_working_directory(const std::string& directory);
|
void set_current_working_directory(const std::string& directory);
|
||||||
|
@ -90,6 +90,20 @@ std::expected<size_t> entries(size_t fd, char* buffer, size_t max){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::expected<size_t> mounts(char* buffer, size_t max){
|
||||||
|
int64_t code;
|
||||||
|
asm volatile("mov rax, 309; mov rbx, %[buffer]; mov rcx, %[max]; int 50; mov %[code], rax"
|
||||||
|
: [code] "=m" (code)
|
||||||
|
: [buffer] "g" (reinterpret_cast<size_t>(buffer)), [max] "g" (max)
|
||||||
|
: "rax", "rbx", "rcx");
|
||||||
|
|
||||||
|
if(code < 0){
|
||||||
|
return std::make_expected_from_error<size_t, size_t>(-code);
|
||||||
|
} else {
|
||||||
|
return std::make_expected<size_t>(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string current_working_directory(){
|
std::string current_working_directory(){
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user