Implement mount program

This commit is contained in:
Baptiste Wicht 2014-03-01 11:11:49 +01:00
parent ed3ac80eb8
commit e4f2b64f82
8 changed files with 89 additions and 10 deletions

1
.gitignore vendored
View File

@ -31,4 +31,5 @@ programs/mkdir/mkdir
programs/rm/rm
programs/date/date
programs/ls/ls
programs/mount/mount
programs/dist/

View File

@ -51,6 +51,9 @@ void kernel_main(){
//Init dynamic memory allocation
kalloc::init();
//Call global constructors
_init();
//Install drivers
timer::install();
//acpi::init();
@ -74,9 +77,6 @@ void kernel_main(){
//Only install system calls when everything else is ready
install_system_calls();
//Call global constructors
_init();
init_console();
scheduler::init();

View File

@ -334,16 +334,16 @@ int64_t vfs::mounts(char* buffer, size_t size){
char* name_buffer = &(entry->name);
size_t str_pos = 0;
for(size_t j = 0; j < mp.mount_point.size(); ++j, ++str_pos){
name_buffer[str_pos] = mp.mount_point[j];
for(size_t j = 0; j < mp.mount_point.size(); ++j){
name_buffer[str_pos++] = mp.mount_point[j];
}
name_buffer[str_pos++] = '\0';
for(size_t j = 0; j < mp.device.size(); ++j, ++str_pos){
name_buffer[str_pos] = mp.device[j];
for(size_t j = 0; j < mp.device.size(); ++j){
name_buffer[str_pos++] = mp.device[j];
}
name_buffer[str_pos++] = '\0';
for(size_t j = 0; j < fs_type.size(); ++j, ++str_pos){
name_buffer[str_pos] = fs_type[j];
for(size_t j = 0; j < fs_type.size(); ++j){
name_buffer[str_pos++] = fs_type[j];
}
name_buffer[str_pos++] = '\0';
}

View File

@ -1,6 +1,6 @@
.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

15
programs/mount/Makefile Normal file
View 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

View 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);
}

View File

@ -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);
void close(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();
void set_current_working_directory(const std::string& directory);

View File

@ -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(){
char buffer[128];
buffer[0] = '\0';