Rename io_raw module to more appropriate file_windows
authorgkostka <kostka.grzegorz@gmail.com>
Wed, 5 Apr 2017 17:35:46 +0000 (19:35 +0200)
committergkostka <kostka.grzegorz@gmail.com>
Wed, 5 Apr 2017 17:42:52 +0000 (19:42 +0200)
blockdev/windows/file_windows.c [new file with mode: 0644]
blockdev/windows/file_windows.h [new file with mode: 0644]
blockdev/windows/io_raw.c [deleted file]
blockdev/windows/io_raw.h [deleted file]
fs_test/lwext4_generic.c
fs_test/lwext4_mbr.c
fs_test/lwext4_mkfs.c
fs_test/lwext4_server.c

diff --git a/blockdev/windows/file_windows.c b/blockdev/windows/file_windows.c
new file mode 100644 (file)
index 0000000..9178243
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <windows.h>
+#include <winioctl.h>
+
+/**@brief   Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief   IO block size.*/
+#define EXT4_IORAW_BSIZE 512
+
+/**@brief   Image file descriptor.*/
+static HANDLE dev_file;
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int io_raw_open(struct ext4_blockdev *bdev);
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                       uint32_t blk_cnt);
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                        uint64_t blk_id, uint32_t blk_cnt);
+static int io_raw_close(struct ext4_blockdev *bdev);
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
+                             io_raw_bread, io_raw_bwrite, io_raw_close, 0, 0);
+
+/******************************************************************************/
+static int io_raw_open(struct ext4_blockdev *bdev)
+{
+       char path[64];
+       DISK_GEOMETRY pdg;
+       uint64_t disk_size;
+       BOOL bResult = FALSE;
+       DWORD junk;
+
+       sprintf(path, "\\\\.\\%s", fname);
+
+       dev_file =
+           CreateFile(path, GENERIC_READ | GENERIC_WRITE,
+                      FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
+                      FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
+
+       if (dev_file == INVALID_HANDLE_VALUE) {
+               return EIO;
+       }
+
+       bResult =
+           DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+                           &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
+
+       if (bResult == FALSE) {
+               CloseHandle(dev_file);
+               return EIO;
+       }
+
+       disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+                   (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+
+       _filedev.bdif->ph_bsize = pdg.BytesPerSector;
+       _filedev.bdif->ph_bcnt = disk_size / pdg.BytesPerSector;
+
+       _filedev.part_offset = 0;
+       _filedev.part_size = disk_size;
+
+       return EOK;
+}
+
+/******************************************************************************/
+
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+                       uint32_t blk_cnt)
+{
+       long hipart = blk_id >> (32 - 9);
+       long lopart = blk_id << 9;
+       long err;
+
+       SetLastError(0);
+       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+               return EIO;
+       }
+
+       DWORD n;
+
+       if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+               err = GetLastError();
+               return EIO;
+       }
+       return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+                        uint64_t blk_id, uint32_t blk_cnt)
+{
+       long hipart = blk_id >> (32 - 9);
+       long lopart = blk_id << 9;
+       long err;
+
+       SetLastError(0);
+       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
+
+       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
+               return EIO;
+       }
+
+       DWORD n;
+
+       if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+               err = GetLastError();
+               return EIO;
+       }
+       return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_close(struct ext4_blockdev *bdev)
+{
+       CloseHandle(dev_file);
+       return EOK;
+}
+
+/******************************************************************************/
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
+/******************************************************************************/
+void ext4_io_raw_filename(const char *n) { fname = n; }
+
+/******************************************************************************/
+#endif
diff --git a/blockdev/windows/file_windows.h b/blockdev/windows/file_windows.h
new file mode 100644 (file)
index 0000000..013d1f3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef FILE_WINDOWS_H_
+#define FILE_WINDOWS_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**@brief   IO raw blockdev get.*/
+struct ext4_blockdev *file_windows_dev_get(void);
+
+/**@brief   Set filrname to open.*/
+void file_windows_name_set(const char *n);
+
+
+#endif /* FILE_WINDOWS_H_ */
diff --git a/blockdev/windows/io_raw.c b/blockdev/windows/io_raw.c
deleted file mode 100644 (file)
index 9178243..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <windows.h>
-#include <winioctl.h>
-
-/**@brief   Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief   IO block size.*/
-#define EXT4_IORAW_BSIZE 512
-
-/**@brief   Image file descriptor.*/
-static HANDLE dev_file;
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int io_raw_open(struct ext4_blockdev *bdev);
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-                       uint32_t blk_cnt);
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-                        uint64_t blk_id, uint32_t blk_cnt);
-static int io_raw_close(struct ext4_blockdev *bdev);
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
-                             io_raw_bread, io_raw_bwrite, io_raw_close, 0, 0);
-
-/******************************************************************************/
-static int io_raw_open(struct ext4_blockdev *bdev)
-{
-       char path[64];
-       DISK_GEOMETRY pdg;
-       uint64_t disk_size;
-       BOOL bResult = FALSE;
-       DWORD junk;
-
-       sprintf(path, "\\\\.\\%s", fname);
-
-       dev_file =
-           CreateFile(path, GENERIC_READ | GENERIC_WRITE,
-                      FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
-                      FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);
-
-       if (dev_file == INVALID_HANDLE_VALUE) {
-               return EIO;
-       }
-
-       bResult =
-           DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
-                           &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
-
-       if (bResult == FALSE) {
-               CloseHandle(dev_file);
-               return EIO;
-       }
-
-       disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
-                   (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
-
-       _filedev.bdif->ph_bsize = pdg.BytesPerSector;
-       _filedev.bdif->ph_bcnt = disk_size / pdg.BytesPerSector;
-
-       _filedev.part_offset = 0;
-       _filedev.part_size = disk_size;
-
-       return EOK;
-}
-
-/******************************************************************************/
-
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-                       uint32_t blk_cnt)
-{
-       long hipart = blk_id >> (32 - 9);
-       long lopart = blk_id << 9;
-       long err;
-
-       SetLastError(0);
-       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
-       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
-               return EIO;
-       }
-
-       DWORD n;
-
-       if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
-               err = GetLastError();
-               return EIO;
-       }
-       return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-                        uint64_t blk_id, uint32_t blk_cnt)
-{
-       long hipart = blk_id >> (32 - 9);
-       long lopart = blk_id << 9;
-       long err;
-
-       SetLastError(0);
-       lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
-
-       if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
-               return EIO;
-       }
-
-       DWORD n;
-
-       if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
-               err = GetLastError();
-               return EIO;
-       }
-       return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_close(struct ext4_blockdev *bdev)
-{
-       CloseHandle(dev_file);
-       return EOK;
-}
-
-/******************************************************************************/
-struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
-/******************************************************************************/
-void ext4_io_raw_filename(const char *n) { fname = n; }
-
-/******************************************************************************/
-#endif
diff --git a/blockdev/windows/io_raw.h b/blockdev/windows/io_raw.h
deleted file mode 100644 (file)
index 0953873..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef IO_RAW_H_
-#define IO_RAW_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-/**@brief   IO raw blockdev get.*/
-struct ext4_blockdev *ext4_io_raw_dev_get(void);
-
-/**@brief   Set filrname to open.*/
-void ext4_io_raw_filename(const char *n);
-
-
-#endif /* IO_RAW_H_ */
index 243194e92b4ea60696e8558c2932b1f5085fe214..1c2f302eafed9eedeeb242afc7897bf16b148ab4 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <ext4.h>
 #include "../blockdev/linux/ext4_filedev.h"
-#include "../blockdev/windows/io_raw.h"
+#include "../blockdev/windows/file_windows.h"
 #include "common/test_lwext4.h"
 
 #ifdef WIN32
index fdb90507aa541af352dc029ad5c77ed2db8db4ab..0a1cf1e7b53aa0da3753657f083b21ef17e5aff8 100644 (file)
@@ -40,7 +40,7 @@
 #include <ext4.h>
 #include <ext4_mbr.h>
 #include "../blockdev/linux/ext4_filedev.h"
-#include "../blockdev/windows/io_raw.h"
+#include "../blockdev/windows/file_windows.h"
 
 /**@brief   Input stream name.*/
 const char *input_name = NULL;
index ac6b4fa099ae459ae0c039ac108babb2b071a6e2..0edb0e9dc18e8cd56a9da17c23a9ff902a07f21b 100644 (file)
@@ -40,7 +40,7 @@
 #include <ext4.h>
 #include <ext4_mkfs.h>
 #include "../blockdev/linux/ext4_filedev.h"
-#include "../blockdev/windows/io_raw.h"
+#include "../blockdev/windows/file_windows.h"
 
 /**@brief   Input stream name.*/
 const char *input_name = NULL;
index 7494b005194f2ae911812c05d98da4c65c556dde..e2a71afb071f0ebe7fe7a1897612b65d6b6ff206 100644 (file)
@@ -50,7 +50,7 @@
 
 #include <ext4.h>
 #include "../blockdev/linux/ext4_filedev.h"
-#include "../blockdev/windows/io_raw.h"
+#include "../blockdev/windows/file_windows.h"
 
 
 static int winsock_init(void);