ref: ec44609460479138e9f4b506b32a45670208af64
parent: d34f46d428de69a5d4bbbb52a16d7f37c2481dfe
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Jun 16 06:33:17 EDT 2015
clang-format: blockdev modules
--- a/blockdev/filedev/ext4_filedev.c
+++ b/blockdev/filedev/ext4_filedev.c
@@ -40,7 +40,7 @@
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;
@@ -47,26 +47,17 @@
#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)
@@ -73,13 +64,13 @@
{
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;
@@ -89,13 +80,13 @@
/******************************************************************************/
-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;
@@ -105,7 +96,7 @@
{
#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
int fd;
- char* data = "3";
+ char *data = "3";
sync();
fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
@@ -116,12 +107,12 @@
/******************************************************************************/
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();
@@ -128,7 +119,7 @@
return EOK;
}
/******************************************************************************/
-static int filedev_close(struct ext4_blockdev *bdev)
+static int filedev_close(struct ext4_blockdev *bdev)
{
fclose(dev_file);
return EOK;
@@ -135,14 +126,8 @@
}
/******************************************************************************/
-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; }
/******************************************************************************/
--- a/blockdev/filedev/ext4_filedev.h
+++ b/blockdev/filedev/ext4_filedev.h
@@ -35,7 +35,7 @@
#include <stdbool.h>
/**@brief File blockdev get.*/
-struct ext4_blockdev* ext4_filedev_get(void);
+struct ext4_blockdev *ext4_filedev_get(void);
/**@brief Set filename to open.*/
void ext4_filedev_filename(const char *n);
--- a/blockdev/filedev_win/io_raw.c
+++ b/blockdev/filedev_win/io_raw.c
@@ -37,107 +37,84 @@
#include <windows.h>
#include <winioctl.h>
-
/**@brief Default filename.*/
static const char *fname = "ext2";
/**@brief IO block size.*/
-#define EXT4_IORAW_BSIZE 512
+#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);
+ 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);
+ 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
-);
+EXT4_BLOCKDEV_STATIC_INSTANCE(_filedev, EXT4_IORAW_BSIZE, 0, io_raw_open,
+ io_raw_bread, io_raw_bwrite, io_raw_close);
/******************************************************************************/
static int io_raw_open(struct ext4_blockdev *bdev)
{
char path[64];
- DISK_GEOMETRY pdg;
+ DISK_GEOMETRY pdg;
uint64_t disk_size;
- BOOL bResult = FALSE;
+ 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);
+ 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){
+ 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);
+ bResult = DeviceIoControl(dev_file, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+ &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL);
- if(bResult == FALSE){
+ if (bResult == FALSE) {
CloseHandle(dev_file);
return EIO;
}
-
disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
- (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+ (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
_filedev.ph_bsize = pdg.BytesPerSector;
- _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
+ _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
-
return EOK;
}
/******************************************************************************/
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
+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 hipart = blk_id >> (32 - 9);
long lopart = blk_id << 9;
long err;
- SetLastError (0);
- lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
+ SetLastError(0);
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
- if (lopart == -1 && NO_ERROR != (err = GetLastError ()))
- {
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
return EIO;
}
- DWORD n;
+ DWORD n;
- if (!ReadFile (dev_file, buf, blk_cnt * 512, &n, NULL))
- {
- err = GetLastError ();
+ if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+ err = GetLastError();
return EIO;
}
return EOK;
@@ -145,25 +122,23 @@
/******************************************************************************/
static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
- uint64_t blk_id, uint32_t blk_cnt)
+ uint64_t blk_id, uint32_t blk_cnt)
{
- long hipart = blk_id >> (32-9);
+ long hipart = blk_id >> (32 - 9);
long lopart = blk_id << 9;
long err;
- SetLastError (0);
- lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
+ SetLastError(0);
+ lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN);
- if (lopart == -1 && NO_ERROR != (err = GetLastError ()))
- {
+ if (lopart == -1 && NO_ERROR != (err = GetLastError())) {
return EIO;
}
- DWORD n;
+ DWORD n;
- if (!WriteFile (dev_file, buf, blk_cnt * 512, &n, NULL))
- {
- err = GetLastError ();
+ if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) {
+ err = GetLastError();
return EIO;
}
return EOK;
@@ -170,7 +145,7 @@
}
/******************************************************************************/
-static int io_raw_close(struct ext4_blockdev *bdev)
+static int io_raw_close(struct ext4_blockdev *bdev)
{
CloseHandle(dev_file);
return EOK;
@@ -177,16 +152,9 @@
}
/******************************************************************************/
-struct ext4_blockdev* ext4_io_raw_dev_get(void)
-{
- return &_filedev;
-}
+struct ext4_blockdev *ext4_io_raw_dev_get(void) { return &_filedev; }
/******************************************************************************/
-void ext4_io_raw_filename(const char *n)
-{
- fname = n;
-}
+void ext4_io_raw_filename(const char *n) { fname = n; }
/******************************************************************************/
#endif
-
--- a/blockdev/filedev_win/io_raw.h
+++ b/blockdev/filedev_win/io_raw.h
@@ -34,11 +34,10 @@
#include <stdint.h>
#include <stdbool.h>
-
/**@brief IO raw blockdev get.*/
-struct ext4_blockdev* ext4_io_raw_dev_get(void);
+struct ext4_blockdev *ext4_io_raw_dev_get(void);
/**@brief Set filrname to open.*/
-void ext4_io_raw_filename(const char *n);
+void ext4_io_raw_filename(const char *n);
#endif /* IO_RAW_H_ */