summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-06-11 22:27:22 +0000
committerCarl Hetherington <cth@carlh.net>2019-06-11 22:27:22 +0000
commitb47ab2d06e73fa7d8b9827e05b3aae6fc2c71279 (patch)
treee0c5b3d9f9eaac678e613178dead8fd96c42fc13
parent733b2c40d7121900e339bee8784977467a9fe8c9 (diff)
Possibly dubious patch to allow writing to partitions on Windows.
-rw-r--r--blockdev/windows/file_windows.c30
-rw-r--r--blockdev/windows/file_windows.h4
2 files changed, 27 insertions, 7 deletions
diff --git a/blockdev/windows/file_windows.c b/blockdev/windows/file_windows.c
index 9142132..291fc11 100644
--- a/blockdev/windows/file_windows.c
+++ b/blockdev/windows/file_windows.c
@@ -40,6 +40,11 @@
/**@brief Default filename.*/
static const char *fname = "ext2";
+/**@brief If part_length == 0 this is the offset (in bytes) of the partition to write to */
+static uint64_t part_offset = 0;
+/**@brief Size (in bytes) of the partition to write to, or 0 to use the whole disk */
+static uint64_t part_size = 0;
+
/**@brief IO block size.*/
#define EXT4_IORAW_BSIZE 512
@@ -87,14 +92,22 @@ static int file_open(struct ext4_blockdev *bdev)
return EIO;
}
- disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
- (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
-
_filedev.bdif->ph_bsize = pdg.BytesPerSector;
- _filedev.bdif->ph_bcnt = disk_size / pdg.BytesPerSector;
- _filedev.part_offset = 0;
- _filedev.part_size = disk_size;
+ if (part_size == 0) {
+ /* whole disk */
+ disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+ (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+
+ _filedev.bdif->ph_bcnt = disk_size / pdg.BytesPerSector;
+ _filedev.part_offset = 0;
+ _filedev.part_size = disk_size;
+ } else {
+ /* specified partition */
+ _filedev.bdif->ph_bcnt = part_size / pdg.BytesPerSector;
+ _filedev.part_offset = part_offset;
+ _filedev.part_size = part_size;
+ }
return EOK;
}
@@ -167,4 +180,9 @@ void file_windows_name_set(const char *n)
}
/******************************************************************************/
+void file_windows_partition_set(uint64_t offset, uint64_t size)
+{
+ part_offset = offset;
+ part_size = size;
+}
#endif
diff --git a/blockdev/windows/file_windows.h b/blockdev/windows/file_windows.h
index 013d1f3..8693fdd 100644
--- a/blockdev/windows/file_windows.h
+++ b/blockdev/windows/file_windows.h
@@ -37,8 +37,10 @@
/**@brief IO raw blockdev get.*/
struct ext4_blockdev *file_windows_dev_get(void);
-/**@brief Set filrname to open.*/
+/**@brief Set filename to open.*/
void file_windows_name_set(const char *n);
+/**@brief Set partition to use within disk */
+void file_windows_partition_set(uint64_t offset, uint64_t size);
#endif /* FILE_WINDOWS_H_ */