From 2d54c6dc4f2100679b23fd6d2e1a446333b53585 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Sun, 20 Mar 2016 22:20:10 -0600
Subject: [PATCH] WIP: Fixes for IDE

---
 Makefile               | 16 ++++++++--------
 kernel/disk/ide.rs     | 12 ++++++------
 kernel/syscall/file.rs |  5 +++--
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index fae7053..9841f3c 100644
--- a/Makefile
+++ b/Makefile
@@ -528,22 +528,22 @@ virtualbox: $(BUILD)/harddrive.bin
 	echo "Set Configuration"
 	$(VBM) modifyvm Redox --memory 1024
 	$(VBM) modifyvm Redox --vram 16
-	$(VBM) modifyvm Redox --nic1 nat
-	$(VBM) modifyvm Redox --nictype1 82540EM
-	$(VBM) modifyvm Redox --nictrace1 on
-	$(VBM) modifyvm Redox --nictracefile1 $(BUILD)/network.pcap
+	# $(VBM) modifyvm Redox --nic1 nat
+	# $(VBM) modifyvm Redox --nictype1 82540EM
+	# $(VBM) modifyvm Redox --nictrace1 on
+	# $(VBM) modifyvm Redox --nictracefile1 $(BUILD)/network.pcap
 	$(VBM) modifyvm Redox --uart1 0x3F8 4
 	$(VBM) modifyvm Redox --uartmode1 file $(BUILD)/serial.log
-	$(VBM) modifyvm Redox --usb on
+	$(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
+	# $(VBM) modifyvm Redox --audio $(VB_AUDIO)
+	# $(VBM) modifyvm Redox --audiocontroller ac97
 	echo "Create Disk"
 	$(VBM) convertfromraw $< $(BUILD)/harddrive.vdi
 	echo "Attach Disk"
 	#PATA
-	#$(VBM) storagectl Redox --name ATA --add ide --controller PIIX4 --bootable on
+	# $(VBM) storagectl Redox --name ATA --add ide --controller PIIX4 --bootable on
 	#SATA
 	$(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 $(BUILD)/harddrive.vdi
diff --git a/kernel/disk/ide.rs b/kernel/disk/ide.rs
index 7665f49..90c7263 100644
--- a/kernel/disk/ide.rs
+++ b/kernel/disk/ide.rs
@@ -295,11 +295,11 @@ impl IdeDisk {
         for word in 10..20 {
             let d = destination.read(word);
             let a = ((d >> 8) as u8) as char;
-            if a != ' ' {
+            if a != ' ' && a != '\0' {
                 debug!("{}", a);
             }
             let b = (d as u8) as char;
-            if b != ' ' {
+            if b != ' ' && b != '\0' {
                 debug!("{}", b);
             }
         }
@@ -308,11 +308,11 @@ impl IdeDisk {
         for word in 23..27 {
             let d = destination.read(word);
             let a = ((d >> 8) as u8) as char;
-            if a != ' ' {
+            if a != ' ' && a != '\0' {
                 debug!("{}", a);
             }
             let b = (d as u8) as char;
-            if b != ' ' {
+            if b != ' ' && b != '\0' {
                 debug!("{}", b);
             }
         }
@@ -321,11 +321,11 @@ impl IdeDisk {
         for word in 27..47 {
             let d = destination.read(word);
             let a = ((d >> 8) as u8) as char;
-            if a != ' ' {
+            if a != ' ' && a != '\0' {
                 debug!("{}", a);
             }
             let b = (d as u8) as char;
-            if b != ' ' {
+            if b != ' ' && b != '\0' {
                 debug!("{}", b);
             }
         }
diff --git a/kernel/syscall/file.rs b/kernel/syscall/file.rs
index 86e681e..6258f81 100644
--- a/kernel/syscall/file.rs
+++ b/kernel/syscall/file.rs
@@ -118,10 +118,11 @@ pub fn do_sys_mkdir(path: *const u8, flags: usize) -> Result<usize> {
     ::env().mkdir(try!(Url::from_str(&path_string)), flags).and(Ok(0))
 }
 
-pub fn do_sys_open(path: *const u8, flags: usize) -> Result<usize> {
+pub fn do_sys_open(path_c: *const u8, flags: usize) -> Result<usize> {
     let contexts = ::env().contexts.lock();
     let current = try!(contexts.current());
-    let path = current.canonicalize(c_string_to_str(path));
+    let path = current.canonicalize(c_string_to_str(path_c));
+    //debugln!("{}: {}: open {}", current.pid, current.name, path);
     let url = try!(Url::from_str(&path));
     let resource = try!(::env().open(url, flags));
     let fd = current.next_fd();
