MCPcopy
hub / github.com/lxc/incus / BlockDiskSizeBytes

Function BlockDiskSizeBytes

internal/server/storage/drivers/utils.go:805–832  ·  view source on GitHub ↗

BlockDiskSizeBytes returns the size of a block disk (path can be either block device or raw file).

(blockDiskPath string)

Source from the content-addressed store, hash-verified

803
804// BlockDiskSizeBytes returns the size of a block disk (path can be either block device or raw file).
805func BlockDiskSizeBytes(blockDiskPath string) (int64, error) {
806 if linux.IsBlockdevPath(blockDiskPath) {
807 // Attempt to open the device path.
808 f, err := os.Open(blockDiskPath)
809 if err != nil {
810 return -1, err
811 }
812
813 defer logger.WarnOnError(f.Close, "Failed to close file")
814 fd := int(f.Fd())
815
816 // Retrieve the block device size.
817 res, err := unix.IoctlGetInt(fd, unix.BLKGETSIZE64)
818 if err != nil {
819 return -1, err
820 }
821
822 return int64(res), nil
823 }
824
825 // Block device is assumed to be a raw file.
826 fi, err := os.Lstat(blockDiskPath)
827 if err != nil {
828 return -1, err
829 }
830
831 return fi.Size(), nil
832}
833
834// GetPhysicalBlockSize returns the physical block size for the device.
835func GetPhysicalBlockSize(blockDiskPath string) (int, error) {

Callers 15

ImageUnpackFunction · 0.92
InstanceDiskBlockSizeFunction · 0.92
RefreshCustomVolumeMethod · 0.92
GetInstanceNBDMethod · 0.92
GetCustomVolumeNBDMethod · 0.92
ConnectQemuNbdFunction · 0.85
SetVolumeQuotaMethod · 0.85
enlargeVolumeBlockFileFunction · 0.85
BackupVolumeFunction · 0.85

Calls 4

IsBlockdevPathFunction · 0.92
WarnOnErrorFunction · 0.92
SizeMethod · 0.80
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…