From f68de3f672ff10899c5abb15d3ca9813ffce8b70 Mon Sep 17 00:00:00 2001 From: Baruch Even Date: Fri, 13 Nov 2015 15:08:11 +0200 Subject: [PATCH] Add mount point check for FreeBSD --- arch/arch-freebsd.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/arch/arch-freebsd.c b/arch/arch-freebsd.c index eb81fe8..73de44f 100644 --- a/arch/arch-freebsd.c +++ b/arch/arch-freebsd.c @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include "arch-posix.c" #include @@ -33,6 +36,37 @@ int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_si return 0; } +disk_mount_e disk_dev_mount_state(const char *path) +{ + int num_mounts; + struct statfs *mntbuf; + disk_mount_e last_state; + int i; + + num_mounts = getmntinfo(&mntbuf, MNT_WAIT); + if (num_mounts == 0) { + ERROR("Failed to get the mount information, errno=%d", errno); + return DISK_MOUNTED_RW; + } + + last_state = DISK_NOT_MOUNTED; + for (i = 0; i < num_mounts; i++) { + struct statfs *mnt = &mntbuf[i]; + + if (strncmp(path, mnt->f_mntfromname, strlen(path)) == 0) { + disk_mount_e cur_state = DISK_NOT_MOUNTED; + if (mnt->f_flags == MNT_RDONLY) + cur_state = DISK_MOUNTED_RO; + else + cur_state = DISK_MOUNTED_RW; + + if (cur_state > last_state) + last_state = cur_state; + } + } + + return last_state; +} void mac_read(unsigned char *buf, int len) { struct ifreq ifr;