[freenos] r355 committed - FileStorage now supports an offset argument as base for file I/O....

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Sat, 05 Sep 2009 09:07:51 +0000

Revision: 355
Author: nieklinnenbank
Date: Sat Sep  5 02:04:56 2009
Log: FileStorage now supports an offset argument as base for file I/O.
LinnFS and Ext2FS now accept the offset number as the second
command-line argument. Using the offset, we can seek to an offset
in e.g. /dev/ata0, effectively allowing us to simulate a "partition"
on the disk.

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

Modified:
 /trunk/srv/filesystem/FileStorage.h
 /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp
 /trunk/srv/filesystem/linn/LinnFileSystem.cpp

=======================================
--- /trunk/srv/filesystem/FileStorage.h Fri Sep  4 15:50:53 2009
+++ /trunk/srv/filesystem/FileStorage.h Sat Sep  5 02:04:56 2009
@@ -36,10 +36,12 @@
        /**
         * @brief Constructor function.
         * @param path Full path to the file to use.
+        * @param offset Offset in the file as a base for I/O.
         */
-       FileStorage(const char *path)
-       {
-           file = open(path, O_RDWR);
+       FileStorage(const char *path, Size offset = ZERO)
+       {
+           this->file   = open(path, O_RDWR);
+           this->offset = offset;
            stat(path, &st);
        }

@@ -63,7 +65,7 @@

            if (file >= 0)
            {
-               lseek(file, offset, SEEK_SET);
+               lseek(file, this->offset + offset, SEEK_SET);
                result = ::read(file, buffer, size);

                return result >= 0 ? result : errno;
@@ -84,7 +86,7 @@

            if (file >= 0)
            {
-               lseek(file, offset, SEEK_SET);
+               lseek(file, this->offset + offset, SEEK_SET);
                result = ::write(file, buffer, size);

                return result >= 0 ? result : errno;
@@ -109,6 +111,9 @@

        /** @brief Status of the file for Storage I/O. */
        struct stat st;
+
+       /** @brief Offset used as a base for I/O. */
+       Size offset;
 };

 #endif /* __FILESYSTEM_STORAGE_H */
=======================================
--- /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp       Sat Sep  5 01:49:38 2009
+++ /trunk/srv/filesystem/ext2/Ext2FileSystem.cpp       Sat Sep  5 02:04:56 2009
@@ -39,11 +39,11 @@
     /*
      * Mount the given file, or use the default GRUB boot module.
      */
-    if (argc > 2)
-    {
-        storage    = new FileStorage(argv[1]);
+    if (argc > 3)
+    {
+        storage    = new FileStorage(argv[1], atoi(argv[2]));
         background = true;
-        path       = argv[2];
+        path       = argv[3];
     }
     else
     {
=======================================
--- /trunk/srv/filesystem/linn/LinnFileSystem.cpp       Sat Sep  5 01:50:26 2009
+++ /trunk/srv/filesystem/linn/LinnFileSystem.cpp       Sat Sep  5 02:04:56 2009
@@ -34,11 +34,11 @@
     /*
      * Mount the given file, or use the default GRUB boot module.
      */
-    if (argc > 2)
-    {
-       storage    = new FileStorage(argv[1]);
+    if (argc > 3)
+    {
+       storage    = new FileStorage(argv[1], atoi(argv[2]));
        background = true;
-       path       = argv[2];
+       path       = argv[3];
     }
     else
     {

Other related posts:

  • » [freenos] r355 committed - FileStorage now supports an offset argument as base for file I/O.... - codesite-noreply