readdir が RamDisk を認識しないバグ修正

diff --git a/mona/core/file_server/ISO9660/ISO9660FileSystem.cpp b/mona/core/file_server/ISO9660/ISO9660FileSystem.cpp
index bad34a7..5f0f3f5 100644
--- a/mona/core/file_server/ISO9660/ISO9660FileSystem.cpp
+++ b/mona/core/file_server/ISO9660/ISO9660FileSystem.cpp
@@ -111,7 +111,6 @@ int ISO9660FileSystem::read(Vnode* file, struct io::Context* context)
     }
 
     context->memory = monapi_cmemoryinfo_new();
-    _logprintf("%s %s:%d\n", __func__, __FILE__, __LINE__);
 
     if (!monapi_cmemoryinfo_create(context->memory, readSize, MONAPI_FALSE))
     {
diff --git a/mona/core/file_server/VnodeCacher.cpp b/mona/core/file_server/VnodeCacher.cpp
index c368b78..8ca0e99 100644
--- a/mona/core/file_server/VnodeCacher.cpp
+++ b/mona/core/file_server/VnodeCacher.cpp
@@ -40,6 +40,18 @@ VnodeCacher::~VnodeCacher()
     delete directories_;
 }
 
+void VnodeCacher::enumCaches(Vnode* directory, std::vector<std::string>& caches)
+{
+    DirectoriesMap::iterator it = directories_->find(directory);
+    if (it == directories_->end()) {
+        return;
+    }
+    EntriesMap* entries = it->second;
+    for (EntriesMap::const_iterator eit = entries->begin(); eit != entries->end(); ++eit) {
+        caches.push_back(eit->first);
+    }
+}
+
 Vnode* VnodeCacher::lookup(Vnode* directory, const string& name)
 {
     if (directory->type != Vnode::DIRECTORY) return NULL;
diff --git a/mona/core/file_server/VnodeCacher.h b/mona/core/file_server/VnodeCacher.h
index 086e74c..e9531af 100644
--- a/mona/core/file_server/VnodeCacher.h
+++ b/mona/core/file_server/VnodeCacher.h
@@ -18,6 +18,7 @@ public:
     virtual ~VnodeCacher();
 
 public:
+    void enumCaches(Vnode* directory, std::vector<std::string>& caches);
     Vnode* lookup(Vnode* directory, const std::string& name);
     void add(Vnode* directory, const std::string& name, Vnode* entry);
     void remove(Vnode* directory, const std::string& name);
diff --git a/mona/core/file_server/VnodeManager.cpp b/mona/core/file_server/VnodeManager.cpp
index cc6fba3..95d96a7 100644
--- a/mona/core/file_server/VnodeManager.cpp
+++ b/mona/core/file_server/VnodeManager.cpp
@@ -65,7 +65,50 @@ int VnodeManager::readdir(const std::string&name, monapi_cmemoryinfo** mem)
             return MONA_ERROR_ENTRY_NOT_FOUND;
         }
     }
-    if (dir->fs->readdir(dir, mem) != MONA_SUCCESS) return MONA_FAILURE;
+    if (dir->fs->readdir(dir, mem) != MONA_SUCCESS) {
+        return MONA_FAILURE;
+    }
+
+    // check mounted directories on caches.
+    typedef std::vector<std::string> strings;
+    strings caches;
+    cacher_->enumCaches(dir, caches);
+    if (!caches.empty()) {
+        std::map<std::string, bool> seen;
+        for (size_t i = sizeof(int); i < (*mem)->Size; i += sizeof(monapi_directoryinfo)) {
+            monapi_directoryinfo* p = (monapi_directoryinfo*)(&((*mem)->Data[i]));
+            seen.insert(std::pair<std::string, bool>(p->name, true));
+        }
+
+        strings diff;
+        for (strings::const_iterator it = caches.begin(); it != caches.end(); ++it) {
+            if (seen.find(*it) == seen.end()) {
+                diff.push_back(*it);
+            }
+        }
+
+        if (!diff.empty()) {
+            monapi_cmemoryinfo* ret = monapi_cmemoryinfo_new();
+            int size = (*mem)->Size + diff.size() * sizeof(monapi_directoryinfo);
+            if (!monapi_cmemoryinfo_create(ret, size, MONAPI_FALSE)) {
+                monapi_cmemoryinfo_delete(ret);
+                return MONA_FAILURE;
+            }
+            memcpy(ret->Data, (*mem)->Data, (*mem)->Size);
+            int entriesNum = *((int*)(*mem)->Data) + diff.size();
+            memcpy(ret->Data, &entriesNum, sizeof(int));
+            for (size_t i = 0; i < diff.size(); i++) {
+                monapi_directoryinfo di;
+                di.size = 0;
+                strcpy(di.name, diff[i].c_str());
+                di.attr = ATTRIBUTE_DIRECTORY;
+                memcpy(&(ret->Data[(*mem)->Size + i * sizeof(monapi_directoryinfo)]), &di, sizeof(monapi_directoryinfo));
+            }
+            monapi_cmemoryinfo_dispose(*mem);
+            monapi_cmemoryinfo_delete(*mem);
+            *mem = ret;
+        }
+    }
     return MONA_SUCCESS;
 }
 
@@ -233,9 +276,9 @@ int VnodeManager::seek(uint32_t fileID, uint32_t offset, uint32_t origin)
     switch (origin)
     {
         case SEEK_SET: fileInfo->context.offset = offset; break;
-	case SEEK_CUR: fileInfo->context.offset +=offset; break;
-	case SEEK_END: fileInfo->context.offset = st.size-offset; break;
-	default: break;
+    case SEEK_CUR: fileInfo->context.offset +=offset; break;
+    case SEEK_END: fileInfo->context.offset = st.size-offset; break;
+    default: break;
     }
 //    fileInfo->context.offset = offset;
     fileInfo->context.origin = origin;
@@ -254,7 +297,10 @@ void VnodeManager::split(string str, char ch, vector<string>& v)
     uint32_t next = 0;
     while ((index = str.find_first_of(ch, next)) != string::npos)
     {
-        v.push_back(string(str.begin() + next, str.begin() + index));
+        string t = string(str.begin() + next, str.begin() + index);
+        if (!t.empty()) {
+            v.push_back(t);
+        }
         next = index + 1;
     }
     v.push_back(string(str.begin() + next, str.end()));
diff --git a/mona/core/file_server/ram_disk/RamDisk.h b/mona/core/file_server/ram_disk/RamDisk.h
index caf8941..6279971 100644
--- a/mona/core/file_server/ram_disk/RamDisk.h
+++ b/mona/core/file_server/ram_disk/RamDisk.h
@@ -312,7 +312,7 @@ namespace RamDisk {
                   return MONA_FAILURE;
 
                 
-                memcpy(name, (*currentIt_).first.c_str(), (*currentIt_).first.size());
+                strcpy(name, (*currentIt_).first.c_str());
                 *size = (*currentIt_).second.size;
                 
                 currentIt_++;
diff --git a/mona/core/scheme/lib/conf.scm.in b/mona/core/scheme/lib/conf.scm.in
index 383db57..158d9f4 100644
--- a/mona/core/scheme/lib/conf.scm.in
+++ b/mona/core/scheme/lib/conf.scm.in
@@ -1,5 +1,5 @@
 ;(define mona-gui-auto-start #f)
-(define mona-gui-auto-start #t)
+(define mona-gui-auto-start #f)
 
 ;; (define (mona-gui-enum-windows) (list "GUI Shell" "/APPS"))
 ;; (define (mona-gui-get-window-title w) w)
diff --git a/mona/test/monapi/ram_disk/ram_disk.cpp b/mona/test/monapi/ram_disk/ram_disk.cpp
index 44af953..55773a8 100644
--- a/mona/test/monapi/ram_disk/ram_disk.cpp
+++ b/mona/test/monapi/ram_disk/ram_disk.cpp
@@ -115,7 +115,7 @@ static void testWriteFile_Content()
 {
     const char* data = "test data";
     int len = strlen(data)+1;
-    
+
     const char* path = "/MEM/TESTFILE";
     writeContentToPath(path, data);
 
@@ -146,7 +146,7 @@ static void testWriteTwice()
 {
     const char* expect = "second";
     int expect_len = strlen(expect)+1;
-    
+
     const char* path = "/MEM/TESTFILE";
     writeContentToPath(path, "first");
     writeContentToPath(path, expect, false);
@@ -212,8 +212,26 @@ static void testReadDirectory_TwoFile()
     monapi_file_delete("/MEM/TEST1.TXT");
 }
 
+static void testReadDirectory_Root()
+{
+    monapi_cmemoryinfo* ci = monapi_file_read_directory("/");
+    EXPECT_TRUE(ci != NULL);
+
+    int size = *(int*)ci->Data;
+    monapi_directoryinfo* p = (monapi_directoryinfo*)&ci->Data[sizeof(int)];
 
+    bool ramdiskFound = false;
+    for (int i = 0; i < size; i++) {
+        if (CString(p[i].name) == "MEM") {
+            ramdiskFound = true;
+            break;
+        }
+    }
+    EXPECT_TRUE(ramdiskFound);
 
+    monapi_cmemoryinfo_dispose(ci);
+    monapi_cmemoryinfo_delete(ci);
+}
 
 int main(int argc, char *argv[])
 {
@@ -228,6 +246,7 @@ int main(int argc, char *argv[])
     testReadDirectory_Empty();
     testReadDirectory_OneFile();
     testReadDirectory_TwoFile();
+    testReadDirectory_Root();
 
     TEST_RESULTS(ram_disk);
     return 0;