Possibly dubious patch to allow writing to partitions on Windows.
authorCarl Hetherington <cth@carlh.net>
Tue, 11 Jun 2019 22:27:22 +0000 (22:27 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 11 Jun 2019 22:27:22 +0000 (22:27 +0000)
blockdev/windows/file_windows.c
blockdev/windows/file_windows.h

index 91421320e445425c1366ce721ce52d6eaba59f62..291fc114015956ceae94ede58040576ff388ef7f 100644 (file)
 /**@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
index 013d1f30ca41ce0f99ec828201a1bf071c9dc8c5..8693fddac0b0f50481efd08a1e99d4a07295c492 100644 (file)
 /**@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_ */