Browse Source

clang-format: blockdev modules

pull/1/head
gkostka 10 years ago
parent
commit
ec44609460
  1. 53
      blockdev/filedev/ext4_filedev.c
  2. 2
      blockdev/filedev/ext4_filedev.h
  3. 108
      blockdev/filedev_win/io_raw.c
  4. 5
      blockdev/filedev_win/io_raw.h

53
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; }
/******************************************************************************/

2
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);

108
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

5
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_ */

Loading…
Cancel
Save