commit
d081ba790e
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -52,3 +52,6 @@
|
|||
[submodule "libstd_real/openlibm"]
|
||||
path = libstd/openlibm
|
||||
url = https://github.com/redox-os/openlibm.git
|
||||
[submodule "programs/binutils"]
|
||||
path = programs/binutils
|
||||
url = https://github.com/redox-os/binutils.git
|
||||
|
|
|
@ -26,6 +26,10 @@ arch_arm = { path = "arch/arm" }
|
|||
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||
arch_x86_64 = { path = "arch/x86_64" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
live = []
|
||||
|
||||
[profile.dev]
|
||||
panic = "unwind"
|
||||
|
||||
|
|
129
Makefile
129
Makefile
|
@ -19,9 +19,11 @@ CARGO=RUSTC="$(RUSTC)" RUSTDOC="$(RUSTDOC)" cargo
|
|||
CARGOFLAGS=--target $(TARGET).json --release --
|
||||
|
||||
# Default targets
|
||||
.PHONY: all clean doc ref test update qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE
|
||||
.PHONY: all live clean doc ref test update qemu bochs drivers schemes binutils coreutils extrautils netutils userutils wireshark FORCE
|
||||
|
||||
all: $(KBUILD)/harddrive.bin
|
||||
all: build/harddrive.bin
|
||||
|
||||
live: build/livedisk.bin
|
||||
|
||||
FORCE:
|
||||
|
||||
|
@ -38,6 +40,7 @@ clean:
|
|||
cargo clean --manifest-path programs/contain/Cargo.toml
|
||||
cargo clean --manifest-path programs/init/Cargo.toml
|
||||
cargo clean --manifest-path programs/ion/Cargo.toml
|
||||
cargo clean --manifest-path programs/binutils/Cargo.toml
|
||||
cargo clean --manifest-path programs/coreutils/Cargo.toml
|
||||
cargo clean --manifest-path programs/extrautils/Cargo.toml
|
||||
cargo clean --manifest-path programs/netutils/Cargo.toml
|
||||
|
@ -55,7 +58,7 @@ clean:
|
|||
cargo clean --manifest-path schemes/redoxfs/Cargo.toml
|
||||
cargo clean --manifest-path schemes/tcpd/Cargo.toml
|
||||
cargo clean --manifest-path schemes/udpd/Cargo.toml
|
||||
-$(FUMOUNT) $(BUILD)/filesystem/
|
||||
-$(FUMOUNT) build/filesystem/
|
||||
rm -rf initfs/bin
|
||||
rm -rf filesystem/bin
|
||||
rm -rf build
|
||||
|
@ -74,6 +77,7 @@ doc-std: $(BUILD)/libstd.rlib FORCE
|
|||
ref: FORCE
|
||||
rm -rf filesystem/ref/
|
||||
mkdir -p filesystem/ref/
|
||||
cargo run --manifest-path crates/docgen/Cargo.toml -- programs/binutils/src/bin/ filesystem/ref/
|
||||
cargo run --manifest-path crates/docgen/Cargo.toml -- programs/coreutils/src/bin/ filesystem/ref/
|
||||
cargo run --manifest-path crates/docgen/Cargo.toml -- programs/extrautils/src/bin/ filesystem/ref/
|
||||
cargo run --manifest-path crates/docgen/Cargo.toml -- programs/netutils/src/ filesystem/ref/
|
||||
|
@ -91,6 +95,7 @@ test:
|
|||
cargo test --manifest-path programs/contain/Cargo.toml
|
||||
cargo test --manifest-path programs/init/Cargo.toml
|
||||
cargo test --manifest-path programs/ion/Cargo.toml
|
||||
cargo test --manifest-path programs/binutils/Cargo.toml
|
||||
cargo test --manifest-path programs/coreutils/Cargo.toml
|
||||
cargo test --manifest-path programs/extrautils/Cargo.toml
|
||||
cargo test --manifest-path programs/netutils/Cargo.toml
|
||||
|
@ -122,6 +127,7 @@ update:
|
|||
cargo update --manifest-path programs/contain/Cargo.toml
|
||||
cargo update --manifest-path programs/init/Cargo.toml
|
||||
cargo update --manifest-path programs/ion/Cargo.toml
|
||||
cargo update --manifest-path programs/binutils/Cargo.toml
|
||||
cargo update --manifest-path programs/coreutils/Cargo.toml
|
||||
cargo update --manifest-path programs/extrautils/Cargo.toml
|
||||
cargo update --manifest-path programs/netutils/Cargo.toml
|
||||
|
@ -151,10 +157,10 @@ ifeq ($(ARCH),arm)
|
|||
%.list: %
|
||||
$(ARCH)-none-eabi-objdump -C -D $< > $@
|
||||
|
||||
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel
|
||||
build/harddrive.bin: $(KBUILD)/kernel
|
||||
cp $< $@
|
||||
|
||||
qemu: $(KBUILD)/harddrive.bin
|
||||
qemu: build/harddrive.bin
|
||||
$(QEMU) $(QEMUFLAGS) -kernel $<
|
||||
else
|
||||
QEMUFLAGS+=-smp 4 -m 1024
|
||||
|
@ -166,16 +172,11 @@ else
|
|||
ifeq ($(net),no)
|
||||
QEMUFLAGS+=-net none
|
||||
else
|
||||
QEMUFLAGS+=-net nic,model=e1000 -net user -net dump,file=$(KBUILD)/network.pcap
|
||||
QEMUFLAGS+=-net nic,model=e1000 -net user -net dump,file=build/network.pcap
|
||||
ifeq ($(net),redir)
|
||||
QEMUFLAGS+=-redir tcp:8080::8080
|
||||
endif
|
||||
endif
|
||||
ifeq ($(storage),usb)
|
||||
QEMUFLAGS+=-device usb-ehci,id=flash_bus -drive id=flash_drive,file=$(KBUILD)/harddrive.bin,format=raw,if=none -device usb-storage,drive=flash_drive,bus=flash_bus.0
|
||||
else
|
||||
QEMUFLAGS+=-drive file=$(KBUILD)/harddrive.bin,format=raw
|
||||
endif
|
||||
ifeq ($(vga),no)
|
||||
QEMUFLAGS+=-nographic -vga none
|
||||
endif
|
||||
|
@ -213,20 +214,30 @@ else
|
|||
%.list: %
|
||||
objdump -C -M intel -D $< > $@
|
||||
|
||||
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel bootloader/$(ARCH)/** $(BUILD)/filesystem.bin
|
||||
build/harddrive.bin: $(KBUILD)/kernel bootloader/$(ARCH)/** build/filesystem.bin
|
||||
nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ bootloader/$(ARCH)/harddrive.asm
|
||||
|
||||
qemu: $(KBUILD)/harddrive.bin
|
||||
$(QEMU) $(QEMUFLAGS)
|
||||
build/livedisk.bin: $(KBUILD)/kernel_live bootloader/$(ARCH)/**
|
||||
nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ bootloader/$(ARCH)/livedisk.asm
|
||||
|
||||
qemu: build/harddrive.bin
|
||||
$(QEMU) $(QEMUFLAGS) -drive file=$<,format=raw
|
||||
|
||||
qemu_no_build:
|
||||
$(QEMU) $(QEMUFLAGS)
|
||||
$(QEMU) $(QEMUFLAGS) -drive file=build/harddrive.bin,format=raw
|
||||
|
||||
qemu_live: build/livedisk.bin
|
||||
$(QEMU) $(QEMUFLAGS) -device usb-ehci,id=flash_bus -drive id=flash_drive,file=$<,format=raw,if=none -device usb-storage,drive=flash_drive,bus=flash_bus.0
|
||||
|
||||
qemu_live_no_build:
|
||||
$(QEMU) $(QEMUFLAGS) -device usb-ehci,id=flash_bus -drive id=flash_drive,file=build/livedisk.bin,format=raw,if=none -device usb-storage,drive=flash_drive,bus=flash_bus.0
|
||||
|
||||
endif
|
||||
|
||||
bochs: $(KBUILD)/harddrive.bin
|
||||
bochs: build/harddrive.bin
|
||||
bochs -f bochs.$(ARCH)
|
||||
|
||||
virtualbox: $(KBUILD)/harddrive.bin
|
||||
virtualbox: build/harddrive.bin
|
||||
echo "Delete VM"
|
||||
-$(VBM) unregistervm Redox --delete; \
|
||||
if [ $$? -ne 0 ]; \
|
||||
|
@ -248,19 +259,19 @@ virtualbox: $(KBUILD)/harddrive.bin
|
|||
$(VBM) modifyvm Redox --nictype1 82540EM
|
||||
$(VBM) modifyvm Redox --cableconnected1 on
|
||||
$(VBM) modifyvm Redox --nictrace1 on
|
||||
$(VBM) modifyvm Redox --nictracefile1 $(KBUILD)/network.pcap
|
||||
$(VBM) modifyvm Redox --nictracefile1 build/network.pcap
|
||||
$(VBM) modifyvm Redox --uart1 0x3F8 4
|
||||
$(VBM) modifyvm Redox --uartmode1 file $(KBUILD)/serial.log
|
||||
$(VBM) modifyvm Redox --uartmode1 file build/serial.log
|
||||
$(VBM) modifyvm Redox --usb off # on
|
||||
$(VBM) modifyvm Redox --keyboard ps2
|
||||
$(VBM) modifyvm Redox --mouse ps2
|
||||
$(VBM) modifyvm Redox --audio $(VB_AUDIO)
|
||||
$(VBM) modifyvm Redox --audiocontroller ac97
|
||||
echo "Create Disk"
|
||||
$(VBM) convertfromraw $< $(KBUILD)/harddrive.vdi
|
||||
$(VBM) convertfromraw $< build/harddrive.vdi
|
||||
echo "Attach Disk"
|
||||
$(VBM) storagectl Redox --name ATA --add sata --controller IntelAHCI --bootable on --portcount 1
|
||||
$(VBM) storageattach Redox --storagectl ATA --port 0 --device 0 --type hdd --medium $(KBUILD)/harddrive.vdi
|
||||
$(VBM) storageattach Redox --storagectl ATA --port 0 --device 0 --type hdd --medium build/harddrive.vdi
|
||||
echo "Run VM"
|
||||
$(VBM) startvm Redox
|
||||
|
||||
|
@ -284,9 +295,15 @@ $(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore.
|
|||
$(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs
|
||||
$(KCARGO) rustc $(KCARGOFLAGS) -C lto -o $@
|
||||
|
||||
$(KBUILD)/libkernel_live.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs build/filesystem.bin
|
||||
$(KCARGO) rustc --lib $(KCARGOFLAGS) --cfg 'feature="live"' -C lto --emit obj=$@
|
||||
|
||||
$(KBUILD)/kernel: $(KBUILD)/libkernel.a
|
||||
$(LD) $(LDFLAGS) -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $<
|
||||
|
||||
$(KBUILD)/kernel_live: $(KBUILD)/libkernel_live.a
|
||||
$(LD) $(LDFLAGS) -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $<
|
||||
|
||||
# Userspace recipes
|
||||
$(BUILD)/libcore.rlib: rust/src/libcore/lib.rs
|
||||
mkdir -p $(BUILD)
|
||||
|
@ -369,6 +386,12 @@ filesystem/bin/%: programs/%/Cargo.toml programs/%/src/** $(BUILD)/libstd.rlib
|
|||
filesystem/bin/sh: filesystem/bin/ion
|
||||
cp $< $@
|
||||
|
||||
filesystem/bin/%: programs/binutils/Cargo.toml programs/binutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
||||
mkdir -p filesystem/bin
|
||||
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||
strip $@
|
||||
rm $@.d
|
||||
|
||||
filesystem/bin/%: programs/coreutils/Cargo.toml programs/coreutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
||||
mkdir -p filesystem/bin
|
||||
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||
|
@ -399,7 +422,6 @@ filesystem/bin/%: programs/pkgutils/Cargo.toml programs/pkgutils/src/%/**.rs $(B
|
|||
strip $@
|
||||
rm $@.d
|
||||
|
||||
|
||||
filesystem/bin/%: programs/userutils/Cargo.toml programs/userutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
||||
mkdir -p filesystem/bin
|
||||
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
||||
|
@ -416,6 +438,11 @@ drivers: \
|
|||
filesystem/bin/e1000d \
|
||||
filesystem/bin/rtl8168d
|
||||
|
||||
binutils: \
|
||||
filesystem/bin/hex \
|
||||
filesystem/bin/hexdump \
|
||||
filesystem/bin/strings
|
||||
|
||||
coreutils: \
|
||||
filesystem/bin/basename \
|
||||
filesystem/bin/cat \
|
||||
|
@ -508,7 +535,7 @@ schemes: \
|
|||
filesystem/bin/tcpd \
|
||||
filesystem/bin/udpd
|
||||
|
||||
$(BUILD)/filesystem.bin: \
|
||||
build/filesystem.bin: \
|
||||
drivers \
|
||||
coreutils \
|
||||
extrautils \
|
||||
|
@ -523,45 +550,45 @@ $(BUILD)/filesystem.bin: \
|
|||
filesystem/bin/sh \
|
||||
filesystem/bin/smith \
|
||||
filesystem/bin/tar
|
||||
-$(FUMOUNT) $(BUILD)/filesystem/
|
||||
rm -rf $@ $(BUILD)/filesystem/
|
||||
echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ 256
|
||||
mkdir -p $(BUILD)/filesystem/
|
||||
-$(FUMOUNT) build/filesystem/
|
||||
rm -rf $@ build/filesystem/
|
||||
echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ 128
|
||||
mkdir -p build/filesystem/
|
||||
cargo build --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse --release
|
||||
schemes/redoxfs/target/release/redoxfs-fuse $@ $(BUILD)/filesystem/ &
|
||||
schemes/redoxfs/target/release/redoxfs-fuse $@ build/filesystem/ &
|
||||
sleep 2
|
||||
pgrep redoxfs-fuse
|
||||
cp -RL filesystem/* $(BUILD)/filesystem/
|
||||
chown -R 0:0 $(BUILD)/filesystem
|
||||
chown -R 1000:1000 $(BUILD)/filesystem/home/user
|
||||
chmod -R uog+rX $(BUILD)/filesystem
|
||||
chmod -R u+w $(BUILD)/filesystem
|
||||
chmod -R og-w $(BUILD)/filesystem
|
||||
chmod -R 755 $(BUILD)/filesystem/bin
|
||||
chmod -R u+rwX $(BUILD)/filesystem/root
|
||||
chmod -R og-rwx $(BUILD)/filesystem/root
|
||||
chmod -R u+rwX $(BUILD)/filesystem/home/user
|
||||
chmod -R og-rwx $(BUILD)/filesystem/home/user
|
||||
chmod +s $(BUILD)/filesystem/bin/passwd
|
||||
chmod +s $(BUILD)/filesystem/bin/su
|
||||
chmod +s $(BUILD)/filesystem/bin/sudo
|
||||
mkdir $(BUILD)/filesystem/tmp
|
||||
chmod 1777 $(BUILD)/filesystem/tmp
|
||||
cp -RL filesystem/* build/filesystem/
|
||||
chown -R 0:0 build/filesystem
|
||||
chown -R 1000:1000 build/filesystem/home/user
|
||||
chmod -R uog+rX build/filesystem
|
||||
chmod -R u+w build/filesystem
|
||||
chmod -R og-w build/filesystem
|
||||
chmod -R 755 build/filesystem/bin
|
||||
chmod -R u+rwX build/filesystem/root
|
||||
chmod -R og-rwx build/filesystem/root
|
||||
chmod -R u+rwX build/filesystem/home/user
|
||||
chmod -R og-rwx build/filesystem/home/user
|
||||
chmod +s build/filesystem/bin/passwd
|
||||
chmod +s build/filesystem/bin/su
|
||||
chmod +s build/filesystem/bin/sudo
|
||||
mkdir build/filesystem/tmp
|
||||
chmod 1777 build/filesystem/tmp
|
||||
sync
|
||||
-$(FUMOUNT) $(BUILD)/filesystem/
|
||||
rm -rf $(BUILD)/filesystem/
|
||||
-$(FUMOUNT) build/filesystem/
|
||||
rm -rf build/filesystem/
|
||||
|
||||
mount: FORCE
|
||||
mkdir -p $(BUILD)/filesystem/
|
||||
mkdir -p build/filesystem/
|
||||
cargo build --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse --release
|
||||
schemes/redoxfs/target/release/redoxfs-fuse $(KBUILD)/harddrive.bin $(BUILD)/filesystem/ &
|
||||
schemes/redoxfs/target/release/redoxfs-fuse build/harddrive.bin build/filesystem/ &
|
||||
sleep 2
|
||||
pgrep redoxfs-fuse
|
||||
|
||||
unmount: FORCE
|
||||
sync
|
||||
-$(FUMOUNT) $(BUILD)/filesystem/
|
||||
rm -rf $(BUILD)/filesystem/
|
||||
-$(FUMOUNT) build/filesystem/
|
||||
rm -rf build/filesystem/
|
||||
|
||||
wireshark: FORCE
|
||||
wireshark $(KBUILD)/network.pcap
|
||||
wireshark build/network.pcap
|
||||
|
|
|
@ -37,7 +37,7 @@ pub extern crate x86;
|
|||
/// Offset to kernel heap
|
||||
pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET + PML4_SIZE/2;
|
||||
/// Size of kernel heap
|
||||
pub const KERNEL_HEAP_SIZE: usize = 64 * 1024 * 1024; // 64 MB
|
||||
pub const KERNEL_HEAP_SIZE: usize = 256 * 1024 * 1024; // 256 MB
|
||||
|
||||
/// Offset to kernel percpu variables
|
||||
//TODO: Use 64-bit fs offset to enable this pub const KERNEL_PERCPU_OFFSET: usize = KERNEL_HEAP_OFFSET - PML4_SIZE;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ata0-master: type=disk, path="build/kernel/harddrive.bin", mode=flat
|
||||
ata0-master: type=disk, path="build/harddrive.bin", mode=flat
|
||||
boot: disk
|
||||
com1: enabled=1, mode=file, dev=build/kernel/serial.log
|
||||
com1: enabled=1, mode=file, dev=build/serial.log
|
||||
megs: 1024
|
||||
|
||||
magic_break: enabled=1
|
||||
|
|
|
@ -18,4 +18,4 @@ kernel_file:
|
|||
.length equ kernel_file.end - kernel_file
|
||||
.length_sectors equ .length / 512
|
||||
|
||||
incbin "build/userspace/filesystem.bin"
|
||||
incbin "build/filesystem.bin"
|
||||
|
|
19
bootloader/x86_64/livedisk.asm
Normal file
19
bootloader/x86_64/livedisk.asm
Normal file
|
@ -0,0 +1,19 @@
|
|||
%include "bootsector.asm"
|
||||
|
||||
startup_start:
|
||||
%ifdef ARCH_i386
|
||||
%include "startup-i386.asm"
|
||||
%endif
|
||||
|
||||
%ifdef ARCH_x86_64
|
||||
%include "startup-x86_64.asm"
|
||||
%endif
|
||||
align 512, db 0
|
||||
startup_end:
|
||||
|
||||
kernel_file:
|
||||
incbin "build/kernel/kernel_live"
|
||||
align 512, db 0
|
||||
.end:
|
||||
.length equ kernel_file.end - kernel_file
|
||||
.length_sectors equ .length / 512
|
|
@ -70,17 +70,29 @@ kernel_base equ 0x100000
|
|||
mov ecx, (kernel_file.length_sectors % buffer_size_bytes) / 4
|
||||
a32 rep movsd
|
||||
finished_loading:
|
||||
|
||||
|
||||
call memory_map
|
||||
|
||||
call vesa
|
||||
|
||||
mov si, init_fpu_msg
|
||||
call printrm
|
||||
call initialize.fpu
|
||||
|
||||
mov si, init_sse_msg
|
||||
call printrm
|
||||
call initialize.sse
|
||||
|
||||
mov si, init_pit_msg
|
||||
call printrm
|
||||
call initialize.pit
|
||||
|
||||
mov si, init_pic_msg
|
||||
call printrm
|
||||
call initialize.pic
|
||||
|
||||
mov si, startup_arch_msg
|
||||
call printrm
|
||||
|
||||
jmp startup_arch
|
||||
|
||||
%include "config.asm"
|
||||
|
@ -90,3 +102,9 @@ finished_loading:
|
|||
%include "memory_map.asm"
|
||||
%include "vesa.asm"
|
||||
%include "initialize.asm"
|
||||
|
||||
init_fpu_msg: db "Init FPU",13,10,0
|
||||
init_sse_msg: db "Init SSE",13,10,0
|
||||
init_pit_msg: db "Init PIT",13,10,0
|
||||
init_pic_msg: db "Init PIC",13,10,0
|
||||
startup_arch_msg: db "Startup Arch",13,10,0
|
||||
|
|
|
@ -57,7 +57,7 @@ impl Scheme for InitFsScheme {
|
|||
seek: 0
|
||||
});
|
||||
|
||||
return Ok(id)
|
||||
return Ok(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
160
kernel/scheme/live.rs
Normal file
160
kernel/scheme/live.rs
Normal file
|
@ -0,0 +1,160 @@
|
|||
/// Disk scheme replacement when making live disk
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use collections::{BTreeMap, Vec};
|
||||
use core::cmp;
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use spin::RwLock;
|
||||
|
||||
use syscall::data::Stat;
|
||||
use syscall::error::*;
|
||||
use syscall::flag::{MODE_FILE, SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
use syscall::scheme::Scheme;
|
||||
|
||||
static FILESYSTEM: &'static [u8] = include_bytes!("../../build/filesystem.bin");
|
||||
|
||||
struct Handle {
|
||||
path: &'static [u8],
|
||||
data: Arc<RwLock<Vec<u8>>>,
|
||||
mode: u16,
|
||||
seek: usize
|
||||
}
|
||||
|
||||
pub struct DiskScheme {
|
||||
next_id: AtomicUsize,
|
||||
data: Arc<RwLock<Vec<u8>>>,
|
||||
handles: RwLock<BTreeMap<usize, Handle>>
|
||||
}
|
||||
|
||||
impl DiskScheme {
|
||||
pub fn new() -> DiskScheme {
|
||||
DiskScheme {
|
||||
next_id: AtomicUsize::new(0),
|
||||
data: Arc::new(RwLock::new(FILESYSTEM.to_vec())),
|
||||
handles: RwLock::new(BTreeMap::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Scheme for DiskScheme {
|
||||
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
||||
self.handles.write().insert(id, Handle {
|
||||
path: b"0",
|
||||
data: self.data.clone(),
|
||||
mode: MODE_FILE | 0o744,
|
||||
seek: 0
|
||||
});
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
||||
let (path, data, mode, seek) = {
|
||||
let handles = self.handles.read();
|
||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
(handle.path, handle.data.clone(), handle.mode, handle.seek)
|
||||
};
|
||||
|
||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
||||
self.handles.write().insert(id, Handle {
|
||||
path: path,
|
||||
data: data,
|
||||
mode: mode,
|
||||
seek: seek
|
||||
});
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let data = handle.data.read();
|
||||
|
||||
let mut i = 0;
|
||||
while i < buffer.len() && handle.seek < data.len() {
|
||||
buffer[i] = data[handle.seek];
|
||||
i += 1;
|
||||
handle.seek += 1;
|
||||
}
|
||||
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
fn write(&self, id: usize, buffer: &[u8]) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let mut data = handle.data.write();
|
||||
|
||||
let mut i = 0;
|
||||
while i < buffer.len() && handle.seek < data.len() {
|
||||
data[handle.seek] = buffer[i];
|
||||
i += 1;
|
||||
handle.seek += 1;
|
||||
}
|
||||
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let mut handles = self.handles.write();
|
||||
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
let data = handle.data.read();
|
||||
|
||||
handle.seek = match whence {
|
||||
SEEK_SET => cmp::min(data.len(), pos),
|
||||
SEEK_CUR => cmp::max(0, cmp::min(data.len() as isize, handle.seek as isize + pos as isize)) as usize,
|
||||
SEEK_END => cmp::max(0, cmp::min(data.len() as isize, data.len() as isize + pos as isize)) as usize,
|
||||
_ => return Err(Error::new(EINVAL))
|
||||
};
|
||||
|
||||
Ok(handle.seek)
|
||||
}
|
||||
|
||||
fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let handles = self.handles.read();
|
||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
//TODO: Copy scheme part in kernel
|
||||
let mut i = 0;
|
||||
let scheme_path = b"disk:";
|
||||
while i < buf.len() && i < scheme_path.len() {
|
||||
buf[i] = scheme_path[i];
|
||||
i += 1;
|
||||
}
|
||||
|
||||
let mut j = 0;
|
||||
while i < buf.len() && j < handle.path.len() {
|
||||
buf[i] = handle.path[j];
|
||||
i += 1;
|
||||
j += 1;
|
||||
}
|
||||
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
|
||||
let handles = self.handles.read();
|
||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
let data = handle.data.read();
|
||||
|
||||
stat.st_mode = handle.mode;
|
||||
stat.st_uid = 0;
|
||||
stat.st_gid = 0;
|
||||
stat.st_size = data.len() as u64;
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn fsync(&self, id: usize) -> Result<usize> {
|
||||
let handles = self.handles.read();
|
||||
let _handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn close(&self, id: usize) -> Result<usize> {
|
||||
self.handles.write().remove(&id).ok_or(Error::new(EBADF)).and(Ok(0))
|
||||
}
|
||||
}
|
|
@ -41,6 +41,10 @@ pub mod initfs;
|
|||
/// `irq:` - allows userspace handling of IRQs
|
||||
pub mod irq;
|
||||
|
||||
/// When compiled with "live" feature - `disk:` - embedded filesystem for live disk
|
||||
#[cfg(feature="live")]
|
||||
pub mod live;
|
||||
|
||||
/// `null:` - a scheme that will discard all writes, and read no bytes
|
||||
pub mod null;
|
||||
|
||||
|
@ -111,6 +115,7 @@ impl SchemeList {
|
|||
}
|
||||
|
||||
/// Initialize the root namespace
|
||||
#[cfg(not(feature="live"))]
|
||||
fn new_root(&mut self) {
|
||||
// Do common namespace initialization
|
||||
let ns = self.new_ns();
|
||||
|
@ -122,6 +127,20 @@ impl SchemeList {
|
|||
self.insert(ns, Box::new(*b"pipe"), |scheme_id| Arc::new(Box::new(PipeScheme::new(scheme_id)))).unwrap();
|
||||
}
|
||||
|
||||
/// Initialize the root namespace - with live disk
|
||||
#[cfg(feature="live")]
|
||||
fn new_root(&mut self) {
|
||||
// Do common namespace initialization
|
||||
let ns = self.new_ns();
|
||||
|
||||
// Debug, Disk, Initfs and IRQ are only available in the root namespace. Pipe is special
|
||||
self.insert(ns, Box::new(*b"debug"), |scheme_id| Arc::new(Box::new(DebugScheme::new(scheme_id)))).unwrap();
|
||||
self.insert(ns, Box::new(*b"disk"), |_| Arc::new(Box::new(self::live::DiskScheme::new()))).unwrap();
|
||||
self.insert(ns, Box::new(*b"initfs"), |_| Arc::new(Box::new(InitFsScheme::new()))).unwrap();
|
||||
self.insert(ns, Box::new(*b"irq"), |scheme_id| Arc::new(Box::new(IrqScheme::new(scheme_id)))).unwrap();
|
||||
self.insert(ns, Box::new(*b"pipe"), |scheme_id| Arc::new(Box::new(PipeScheme::new(scheme_id)))).unwrap();
|
||||
}
|
||||
|
||||
pub fn setns(&mut self, from: SchemeNamespace, names: &[&[u8]]) -> Result<SchemeNamespace> {
|
||||
// Create an empty namespace
|
||||
let to = self.new_ns();
|
||||
|
|
1
programs/binutils
Submodule
1
programs/binutils
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 5599724eab8b28705f6b2b66145fdcb7e4ce2d4d
|
|
@ -1 +1 @@
|
|||
Subproject commit b3d8bf61860cd4c7c2263b2798779aa182cab1d6
|
||||
Subproject commit 63f27dccc12184a4eb73efa0a065fea65650c664
|
|
@ -1 +1 @@
|
|||
Subproject commit 6fc98a77b691ea1fa2a4c463103ede76af7970c7
|
||||
Subproject commit bdd3ce629ee7679cf4f96ced6f81f014f00f19c4
|
|
@ -1 +1 @@
|
|||
Subproject commit 8187b2aa0bfb202fd52a4bac5adae4217c254e7e
|
||||
Subproject commit fa422ec992f0ce80238643400cb2df8d2381522e
|
Loading…
Reference in a new issue