[freenos] r320 committed - Separated writing to FileSystemMounts table in FileSystem::mount()....

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Tue, 18 Aug 2009 20:56:52 +0000

Revision: 320
Author: nieklinnenbank
Date: Tue Aug 18 13:56:08 2009
Log: Separated writing to FileSystemMounts table in FileSystem::mount().
The old code from the FileSystem::FileSystem() constructor has been
removed, and existing FileSystem implementations now use mount(). This
has the advantage that FileSystem() can be called before fork() is
(internally) executed. Obviously FileSystems do not need to explicitely
call fork() anymore.

http://code.google.com/p/freenos/source/detail?r=320

Modified:
 /trunk/srv/filesystem/FileSystem.h
 /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp
 /trunk/srv/filesystem/linn/LinnFileSystem.cpp
 /trunk/srv/filesystem/proc/Main.cpp
 /trunk/srv/filesystem/tmp/Main.cpp

=======================================
--- /trunk/srv/filesystem/FileSystem.h  Thu Aug 13 13:24:37 2009
+++ /trunk/srv/filesystem/FileSystem.h  Tue Aug 18 13:56:08 2009
@@ -101,30 +101,51 @@
            addIPCHandler(WriteFile,  &FileSystem::fileDescriptorHandler);
            addIPCHandler(CloseFile,  &FileSystem::fileDescriptorHandler);
            addIPCHandler(SeekFile,   &FileSystem::fileDescriptorHandler);
-
+       }
+
+       /**
+        * Destructor function.
+        */
+       virtual ~FileSystem()
+       {
+       }
+
+       /**
+        * @brief Mount the FileSystem.
+        *
+        * This function is responsible for mounting the
+        * FileSystem. This happends by creating a new entry
+        * in the FileSystemMounts table, which is a Shared object.
+        *
+        * @param background Set to true to run as a background process 
(default).
+        * @return True if mounted successfully, false otherwise.
+        */
+       bool mount(bool background = true)
+       {
            /* Load shared tables. */
            procs.load(USER_PROCESS_KEY, MAX_PROCS);
            mounts.load(FILE_SYSTEM_MOUNT_KEY, MAX_MOUNTS);
            files = new Array<Shared<FileDescriptor> >(MAX_PROCS);

+           /*
+            * Fork in the background first, if requested.
+            */
+           if (background && fork())
+           {
+               exit(EXIT_SUCCESS);
+           }
            /* Mount ourselves. */
            for (Size i = 0; i < MAX_MOUNTS; i++)
            {
-               if (!mounts[i]->path[0] || !strcmp(mounts[i]->path, path))
-               {
-                   strlcpy(mounts[i]->path, path, PATHLEN);
+               if (!mounts[i]->path[0] || !strcmp(mounts[i]->path, mountPath))
+               {
+                   strlcpy(mounts[i]->path, mountPath, PATHLEN);
                    mounts[i]->procID  = getpid();
                    mounts[i]->options = ZERO;
                    break;
                }
            }
-       }
-
-       /**
-        * Destructor function.
-        */
-       virtual ~FileSystem()
-       {
+           return true;
        }

        /**
=======================================
--- /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp       Fri Aug  7 05:42:20 2009
+++ /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp       Tue Aug 18 13:56:08 2009
@@ -32,13 +32,23 @@
 int main(int argc, char **argv)
 {
     BootModule module("/boot/boot.ext2");
+
+    /*
+     * Load the GRUB filesystem image from memory.
+     */
     if (module.load())
     {
         Ext2FileSystem server("/img", &module);
-        return server.run();
-    }
-    exit(1);
-    return 1;
+
+        /*
+        * Mount, then start serving requests.
+         */
+       if (server.mount(false))
+       {
+           return server.run();
+       }
+    }
+    return EXIT_FAILURE;
 }

 Ext2FileSystem::Ext2FileSystem(const char *p, Storage *s)
=======================================
--- /trunk/srv/filesystem/linn/LinnFileSystem.cpp       Fri Aug  7 05:42:20 2009
+++ /trunk/srv/filesystem/linn/LinnFileSystem.cpp       Tue Aug 18 13:56:08 2009
@@ -29,10 +29,20 @@
 {
     BootModule module("/boot/boot.linn.gz");

+    /*
+     * Load the GRUB filesystem image from memory.
+     */
     if (module.load())
     {
         LinnFileSystem server("/", &module);
-        return server.run();
+
+        /*
+        * Mount, then start serving requests.
+         */
+       if (server.mount(false))
+       {
+           return server.run();
+       }
     }
     return EXIT_FAILURE;
 }
=======================================
--- /trunk/srv/filesystem/proc/Main.cpp Sun Jun 28 17:23:04 2009
+++ /trunk/srv/filesystem/proc/Main.cpp Tue Aug 18 13:56:08 2009
@@ -21,9 +21,13 @@

 int main(int argc, char **argv)
 {
-    if (!fork())
-    {
-       ProcFileSystem server("/proc");
+    ProcFileSystem server("/proc");
+
+    /*
+     * Mount, then start serving requests.
+     */
+    if (server.mount())
+    {
        return server.run();
     }
     return EXIT_SUCCESS;
=======================================
--- /trunk/srv/filesystem/tmp/Main.cpp  Mon Mar 16 15:59:24 2009
+++ /trunk/srv/filesystem/tmp/Main.cpp  Tue Aug 18 13:56:08 2009
@@ -20,5 +20,12 @@
 int main(int argc, char **argv)
 {
     TmpFileSystem server("/dev");
-    return server.run();
-}
+
+    /*
+     * Mount, then start serving requests.
+     */
+    if (server.mount(false))
+    {
+       return server.run();
+    }
+}

Other related posts:

  • » [freenos] r320 committed - Separated writing to FileSystemMounts table in FileSystem::mount().... - codesite-noreply