static const char *fname = "ext2";
/**@brief Image block size.*/
-#define EXT4_FILEDEV_BSIZE 512
+#define EXT4_FILEDEV_BSIZE 512
/**@brief Image file descriptor.*/
static FILE *dev_file;
#define DROP_LINUXCACHE_BUFFERS 0
-
/**********************BLOCKDEV INTERFACE**************************************/
static int filedev_open(struct ext4_blockdev *bdev);
static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt);
+ uint32_t blk_cnt);
static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt);
-static int filedev_close(struct ext4_blockdev *bdev);
-
+ uint64_t blk_id, uint32_t blk_cnt);
+static int filedev_close(struct ext4_blockdev *bdev);
/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(
- _filedev,
- EXT4_FILEDEV_BSIZE,
- 0,
- filedev_open,
- filedev_bread,
- filedev_bwrite,
- filedev_close
-);
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_FILEDEV_BSIZE, 0, filedev_open,
+ filedev_bread, filedev_bwrite, filedev_close);
/******************************************************************************/
static int filedev_open(struct ext4_blockdev *bdev)
{
dev_file = fopen(fname, "r+b");
- if(!dev_file)
+ if (!dev_file)
return EIO;
/*No buffering at file.*/
setbuf(dev_file, 0);
- if(fseek(dev_file, 0, SEEK_END))
+ if (fseek(dev_file, 0, SEEK_END))
return EFAULT;
_filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
/******************************************************************************/
-static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
+static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+ uint32_t blk_cnt)
{
- if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
return EIO;
- if(!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
return EIO;
return EOK;
{
#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
int fd;
- char* data = "3";
+ char *data = "3";
sync();
fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
/******************************************************************************/
static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
+ uint64_t blk_id, uint32_t blk_cnt)
{
- if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
return EIO;
- if(!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
return EIO;
drop_cache();
return EOK;
}
/******************************************************************************/
-static int filedev_close(struct ext4_blockdev *bdev)
+static int filedev_close(struct ext4_blockdev *bdev)
{
fclose(dev_file);
return EOK;
}
/******************************************************************************/
-struct ext4_blockdev* ext4_filedev_get(void)
-{
- return &_filedev;
-}
+struct ext4_blockdev *ext4_filedev_get(void) { return &_filedev; }
/******************************************************************************/
-void ext4_filedev_filename(const char *n)
-{
- fname = n;
-}
+void ext4_filedev_filename(const char *n) { fname = n; }
/******************************************************************************/
#include <windows.h>\r
#include <winioctl.h>\r
\r
-\r
/**@brief Default filename.*/\r
static const char *fname = "ext2";\r
\r
/**@brief IO block size.*/\r
-#define EXT4_IORAW_BSIZE 512\r
+#define EXT4_IORAW_BSIZE 512\r
\r
/**@brief Image file descriptor.*/\r
static HANDLE dev_file;\r
\r
-\r
/**********************BLOCKDEV INTERFACE**************************************/\r
static int io_raw_open(struct ext4_blockdev *bdev);\r
static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
- uint32_t blk_cnt);\r
+ uint32_t blk_cnt);\r
static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
- uint64_t blk_id, uint32_t blk_cnt);\r
-static int io_raw_close(struct ext4_blockdev *bdev);\r
-\r
-\r
-\r
+ uint64_t blk_id, uint32_t blk_cnt);\r
+static int io_raw_close(struct ext4_blockdev *bdev);\r
\r
/******************************************************************************/\r
-EXT4_BLOCKDEV_STATIC_INSTANCE(\r
- _filedev,\r
- EXT4_IORAW_BSIZE,\r
- 0,\r
- io_raw_open,\r
- io_raw_bread,\r
- io_raw_bwrite,\r
- io_raw_close\r
-);\r
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,\r
+ io_raw_bread, io_raw_bwrite, io_raw_close);\r
\r
/******************************************************************************/\r
static int io_raw_open(struct ext4_blockdev *bdev)\r
{\r
char path[64];\r
- DISK_GEOMETRY pdg;\r
+ DISK_GEOMETRY pdg;\r
uint64_t disk_size;\r
- BOOL bResult = FALSE;\r
+ BOOL bResult = FALSE;\r
DWORD junk;\r
\r
sprintf(path, "\\\\.\\%s", fname);\r
\r
- dev_file = CreateFile (path,\r
- GENERIC_READ | GENERIC_WRITE,\r
- FILE_SHARE_WRITE | FILE_SHARE_READ,\r
- NULL,\r
- OPEN_EXISTING,\r
- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,\r
- NULL);\r
+ dev_file =\r
+ CreateFile(path, GENERIC_READ | GENERIC_WRITE,\r
+ FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,\r
+ FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL);\r
\r
- if (dev_file == INVALID_HANDLE_VALUE){\r
+ if (dev_file == INVALID_HANDLE_VALUE) {\r
return EIO;\r
}\r
\r
- bResult = DeviceIoControl(dev_file,\r
- IOCTL_DISK_GET_DRIVE_GEOMETRY,\r
- NULL, 0,\r
- &pdg, sizeof(pdg),\r
- &junk,\r
- (LPOVERLAPPED) NULL);\r
+ bResult = DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,\r
+ &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);\r
\r
- if(bResult == FALSE){\r
+ if (bResult == FALSE) {\r
CloseHandle(dev_file);\r
return EIO;\r
}\r
\r
-\r
disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *\r
- (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;\r
+ (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;\r
\r
_filedev.ph_bsize = pdg.BytesPerSector;\r
- _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;\r
-\r
+ _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;\r
\r
return EOK;\r
}\r
\r
/******************************************************************************/\r
\r
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
- uint32_t blk_cnt)\r
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,\r
+ uint32_t blk_cnt)\r
{\r
- long hipart = blk_id >> (32-9);\r
+ long hipart = blk_id >> (32 - 9);\r
long lopart = blk_id << 9;\r
long err;\r
\r
- SetLastError (0);\r
- lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);\r
+ SetLastError(0);\r
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
\r
- if (lopart == -1 && NO_ERROR != (err = GetLastError ()))\r
- {\r
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
return EIO;\r
}\r
\r
- DWORD n;\r
+ DWORD n;\r
\r
- if (!ReadFile (dev_file, buf, blk_cnt * 512, &n, NULL))\r
- {\r
- err = GetLastError ();\r
+ if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
+ err = GetLastError();\r
return EIO;\r
}\r
return EOK;\r
\r
/******************************************************************************/\r
static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,\r
- uint64_t blk_id, uint32_t blk_cnt)\r
+ uint64_t blk_id, uint32_t blk_cnt)\r
{\r
- long hipart = blk_id >> (32-9);\r
+ long hipart = blk_id >> (32 - 9);\r
long lopart = blk_id << 9;\r
long err;\r
\r
- SetLastError (0);\r
- lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);\r
+ SetLastError(0);\r
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);\r
\r
- if (lopart == -1 && NO_ERROR != (err = GetLastError ()))\r
- {\r
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {\r
return EIO;\r
}\r
\r
- DWORD n;\r
+ DWORD n;\r
\r
- if (!WriteFile (dev_file, buf, blk_cnt * 512, &n, NULL))\r
- {\r
- err = GetLastError ();\r
+ if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {\r
+ err = GetLastError();\r
return EIO;\r
}\r
return EOK;\r
}\r
\r
/******************************************************************************/\r
-static int io_raw_close(struct ext4_blockdev *bdev)\r
+static int io_raw_close(struct ext4_blockdev *bdev)\r
{\r
CloseHandle(dev_file);\r
return EOK;\r
}\r
\r
/******************************************************************************/\r
-struct ext4_blockdev* ext4_io_raw_dev_get(void)\r
-{\r
- return &_filedev;\r
-}\r
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }\r
/******************************************************************************/\r
-void ext4_io_raw_filename(const char *n)\r
-{\r
- fname = n;\r
-}\r
+void ext4_io_raw_filename(const char *n) { fname = n; }\r
\r
/******************************************************************************/\r
#endif\r
-\r