-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect block device size using platform-specific IOCTL on Mac & Linux (…
…#173) * build: Move os-specific diskfs dependencies to explicit modules Darwin and Windows specific diskfs features already live in their own module. Linux support however remains in a catch-all "unix" modules that builds only for Linux in practice. This commit makes the Unix module only target Linux and introduces a new catch-all-other module to stub out block device specific functions. This paves the road for using platform-specific IOCTL to get the physical block device size and ultimately help with the Windows port of block device support. Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr> * diskfs: Move to platform-specific IOCTL to get block device size Currently, diskfs attempts to detect the size of a block device using a "seek" based approach. Unfortunately, while this looks generic, it does not work on Mac, at least not in a VM. Based on the previous commit, this commit adds a Mac and Linux implementation for getting the size of a Block device through IOCTL inspired by https://github.com/tytso/e2fsprogs/blob/master/lib/ext2fs/getsize.c This was manually tested using a Linux loopback device and in a Mac virtual machine. Closes #171 Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr> --------- Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr>
- Loading branch information
Showing
6 changed files
with
79 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !windows && !linux && !darwin | ||
|
||
package diskfs | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
// getBlockDeviceSize get the size of an opened block device in Bytes. | ||
func getBlockDeviceSize(f *os.File) (int64, error) { | ||
return 0, errors.New("block devices not supported on this platform") | ||
} | ||
|
||
// getSectorSizes get the logical and physical sector sizes for a block device | ||
func getSectorSizes(f *os.File) (logicalSectorSize, physicalSectorSize int64, err error) { | ||
return 0, 0, errors.New("block devices not supported on this platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters