I'm writing a iso to usb creation tool and am trying to figure out how to view the total size of the usb. getFileInfo returns a zero value for file size in this case so that's obviously the wrong approach. Any ideas?
let path = "/dev/sdd"
var usb: File
if not open(usb, path, fmReadWriteExisting):
raise newException(OSError, "error opening usb")
echo getFileInfo(usb).size
usb.close()
This works for me on linux using the BLKGETSIZE64 ioctl
import std/posix
let BLKGETSIZE64 {.importc: "BLKGETSIZE64", header: "linux/fs.h".}: uint
let path = "/dev/sdd"
var usb: File
var size: int
if not open(usb, path, fmReadWriteExisting):
raise newException(OSError, "error opening usb")
if ioctl(usb.getOsFileHandle, BLKGETSIZE64, addr size) != 0:
raise newException(OSError, "error reading size of usb")
echo "usb size: ", size, " bytes"
usb.close()