diff options
| author | gkostka <kostka.grzegorz@gmail.com> | 2015-06-16 10:33:17 +0100 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2015-06-16 13:14:13 +0200 |
| commit | 63e88926bd518a530e14cb6b2186d642b9abfe18 (patch) | |
| tree | d7788e237327bb9787af57783607fe96a60f7c00 /blockdev | |
| parent | e3ada742d6c1ad82faf4c14aa31cccf4e3dd76fb (diff) | |
clang-format: blockdev modules
Diffstat (limited to 'blockdev')
| -rw-r--r-- | blockdev/filedev/ext4_filedev.c | 53 | ||||
| -rw-r--r-- | blockdev/filedev/ext4_filedev.h | 2 | ||||
| -rw-r--r-- | blockdev/filedev_win/io_raw.c | 108 | ||||
| -rw-r--r-- | blockdev/filedev_win/io_raw.h | 5 |
4 files changed, 60 insertions, 108 deletions
diff --git a/blockdev/filedev/ext4_filedev.c b/blockdev/filedev/ext4_filedev.c index aa63600..3a21995 100644 --- a/blockdev/filedev/ext4_filedev.c +++ b/blockdev/filedev/ext4_filedev.c @@ -40,46 +40,37 @@ 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; @@ -89,13 +80,13 @@ 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) +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 @@ static void drop_cache(void) { #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,33 +107,27 @@ static void drop_cache(void) /******************************************************************************/ 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; } /******************************************************************************/ diff --git a/blockdev/filedev/ext4_filedev.h b/blockdev/filedev/ext4_filedev.h index cbd8aa5..8f13d9a 100644 --- 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); diff --git a/blockdev/filedev_win/io_raw.c b/blockdev/filedev_win/io_raw.c index 6af3861..c85fe1d 100644 --- 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,48 +122,39 @@ static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, /******************************************************************************/
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;
}
/******************************************************************************/
-static int io_raw_close(struct ext4_blockdev *bdev)
+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;
-}
+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
-
diff --git a/blockdev/filedev_win/io_raw.h b/blockdev/filedev_win/io_raw.h index 742f49e..cfd6561 100644 --- 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_ */
|
