The function Linux syscall.Mount requires a file system type.
If you try to run it with the file system auto, like this:
func main(){
if err := syscall.Mount("/dev/sda1", "/mnt1", "auto", 0, "w"); err != nil {
log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"rw\")\n","/dev/sda1","/mnt1")
log.Fatal(err)
}
}
It will fail with no such device. It was already described here that Linux syscall.Mount just wraps mount(2), which doesn't itself support the concept of an "auto" fstype.
I know how to find it using bash:
root@ubuntu:~/go/src# blkid /dev/sda1
/dev/sda1: UUID="527c895c-864e-4f4c-8fba-460754181173" TYPE="ext4" PARTUUID="db5c2e63-01"
or
root@ubuntu:~/go/src# file -sL /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=527c895c-864e-4f4c-8fba-460754181173 (needs journal recovery) (extents) (large files) (huge files)
In both cases you get the ext4 file system type.
Replacing auto with ext4 in Go will solve the problem, but what I am interested in is, how can I use Go to get the file system type of, for example, /dev/sda1?
Is there a function similar to blkid or file that can show the file system type of the device?