summaryrefslogtreecommitdiff
path: root/blockdev
diff options
context:
space:
mode:
authorgkostka <kostka.grzegorz@gmail.com>2015-09-16 23:23:38 +0200
committergkostka <kostka.grzegorz@gmail.com>2015-09-16 23:29:12 +0200
commit2651b659e1ad76ad7b5980573643b513b571be9e (patch)
tree8d83ae1ee3212803f47015e03b8775f8c0226db7 /blockdev
parent2a1d5f53b73e5626183a02d2a2af9567bd3e012e (diff)
Linux codestyle format (tabs indenation)
Diffstat (limited to 'blockdev')
-rw-r--r--blockdev/filedev/ext4_filedev.c66
-rw-r--r--blockdev/filedev_win/io_raw.c119
2 files changed, 93 insertions, 92 deletions
diff --git a/blockdev/filedev/ext4_filedev.c b/blockdev/filedev/ext4_filedev.c
index 3a21995..14fae75 100644
--- a/blockdev/filedev/ext4_filedev.c
+++ b/blockdev/filedev/ext4_filedev.c
@@ -50,79 +50,79 @@ static FILE *dev_file;
/**********************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);
+ 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);
+ filedev_bread, filedev_bwrite, filedev_close);
/******************************************************************************/
static int filedev_open(struct ext4_blockdev *bdev)
{
- dev_file = fopen(fname, "r+b");
+ dev_file = fopen(fname, "r+b");
- if (!dev_file)
- return EIO;
+ if (!dev_file)
+ return EIO;
- /*No buffering at file.*/
- setbuf(dev_file, 0);
+ /*No buffering at file.*/
+ setbuf(dev_file, 0);
- if (fseek(dev_file, 0, SEEK_END))
- return EFAULT;
+ if (fseek(dev_file, 0, SEEK_END))
+ return EFAULT;
- _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
+ _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
- return EOK;
+ return EOK;
}
/******************************************************************************/
static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
+ uint32_t blk_cnt)
{
- if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
- return EIO;
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ return EIO;
- if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
- return EIO;
+ if (!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ return EIO;
- return EOK;
+ return EOK;
}
static void drop_cache(void)
{
#if defined(__linux__) && DROP_LINUXCACHE_BUFFERS
- int fd;
- char *data = "3";
+ int fd;
+ char *data = "3";
- sync();
- fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
- write(fd, data, sizeof(char));
- close(fd);
+ sync();
+ fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+ write(fd, data, sizeof(char));
+ close(fd);
#endif
}
/******************************************************************************/
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))
- return EIO;
+ if (fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
+ return EIO;
- if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
- return EIO;
+ if (!fwrite(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
+ return EIO;
- drop_cache();
- return EOK;
+ drop_cache();
+ return EOK;
}
/******************************************************************************/
static int filedev_close(struct ext4_blockdev *bdev)
{
- fclose(dev_file);
- return EOK;
+ fclose(dev_file);
+ return EOK;
}
/******************************************************************************/
diff --git a/blockdev/filedev_win/io_raw.c b/blockdev/filedev_win/io_raw.c
index c85fe1d..902cd4f 100644
--- a/blockdev/filedev_win/io_raw.c
+++ b/blockdev/filedev_win/io_raw.c
@@ -49,106 +49,107 @@ 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);
+ 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);
+ io_raw_bread, io_raw_bwrite, io_raw_close);
/******************************************************************************/
static int io_raw_open(struct ext4_blockdev *bdev)
{
- char path[64];
- DISK_GEOMETRY pdg;
- uint64_t disk_size;
- BOOL bResult = FALSE;
- DWORD junk;
+ char path[64];
+ DISK_GEOMETRY pdg;
+ uint64_t disk_size;
+ BOOL bResult = FALSE;
+ DWORD junk;
- sprintf(path, "\\\\.\\%s", fname);
+ 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) {
- return EIO;
- }
+ 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) {
- CloseHandle(dev_file);
- return EIO;
- }
+ if (bResult == FALSE) {
+ CloseHandle(dev_file);
+ return EIO;
+ }
- disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
- (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+ disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+ (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
- _filedev.ph_bsize = pdg.BytesPerSector;
- _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
+ _filedev.ph_bsize = pdg.BytesPerSector;
+ _filedev.ph_bcnt = disk_size / pdg.BytesPerSector;
- return EOK;
+ return EOK;
}
/******************************************************************************/
static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
- uint32_t blk_cnt)
+ uint32_t blk_cnt)
{
- long hipart = blk_id >> (32 - 9);
- long lopart = blk_id << 9;
- long err;
+ 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())) {
- return EIO;
- }
+ 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();
- return EIO;
- }
- return EOK;
+ 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)
+ uint64_t blk_id, uint32_t blk_cnt)
{
- long hipart = blk_id >> (32 - 9);
- long lopart = blk_id << 9;
- long err;
+ 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())) {
- return EIO;
- }
+ 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();
- return EIO;
- }
- return EOK;
+ 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;
+ CloseHandle(dev_file);
+ return EOK;
}
/******************************************************************************/