errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen) { errcode_t retval = 0; if (getenv("EXT2FS_PRETEND_RO_MOUNT")) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_READONLY; if (getenv("EXT2FS_PRETEND_ROOTFS")) *mount_flags = EXT2_MF_ISROOT; return 0; } if (getenv("EXT2FS_PRETEND_RW_MOUNT")) { *mount_flags = EXT2_MF_MOUNTED; if (getenv("EXT2FS_PRETEND_ROOTFS")) *mount_flags = EXT2_MF_ISROOT; return 0; } if (is_swap_device(device)) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; strncpy(mtpt, "<swap>", mtlen); } else { #ifdef HAVE_SETMNTENT retval = check_mntent(device, mount_flags, mtpt, mtlen); #else #ifdef HAVE_GETMNTINFO retval = check_getmntinfo(device, mount_flags, mtpt, mtlen); #else #ifdef __GNUC__ #warning "Can't use getmntent or getmntinfo to check for mounted filesystems!" #endif *mount_flags = 0; #endif /* HAVE_GETMNTINFO */ #endif /* HAVE_SETMNTENT */ } if (retval) return retval; #ifdef __linux__ /* This only works on Linux 2.6+ systems */ { struct stat st_buf; if (stat(device, &st_buf) == 0 && S_ISBLK(st_buf.st_mode)) { int fd = open(device, O_RDONLY | O_EXCL); if (fd >= 0) close(fd); else if (errno == EBUSY) *mount_flags |= EXT2_MF_BUSY; } } #endif return 0; }
errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen) { struct stat st_buf; errcode_t retval = 0; int fd; if (is_swap_device(device)) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; strncpy(mtpt, "<swap>", mtlen); } else { #ifdef HAVE_SETMNTENT retval = check_mntent(device, mount_flags, mtpt, mtlen); #else #ifdef HAVE_GETMNTINFO retval = check_getmntinfo(device, mount_flags, mtpt, mtlen); #else #ifdef __GNUC__ #warning "Can't use getmntent or getmntinfo to check for mounted filesystems!" #endif *mount_flags = 0; #endif /* HAVE_GETMNTINFO */ #endif /* HAVE_MNTENT_H */ } if (retval) return retval; #ifdef __linux__ /* This only works on Linux 2.6+ systems */ if ((stat(device, &st_buf) != 0) || !S_ISBLK(st_buf.st_mode)) return 0; fd = open(device, O_RDONLY | O_EXCL); if (fd < 0) { if (errno == EBUSY) *mount_flags |= EXT2_MF_BUSY; } else close(fd); #endif return 0; }
errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen) { if (is_swap_device(device)) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; strncpy(mtpt, "<swap>", mtlen); return 0; } #ifdef HAVE_MNTENT_H return check_mntent(device, mount_flags, mtpt, mtlen); #else #ifdef HAVE_GETMNTINFO return check_getmntinfo(device, mount_flags, mtpt, mtlen); #else #ifdef __GNUC__ #warning "Can't use getmntent or getmntinfo to check for mounted filesystems!" #endif *mount_flags = 0; return 0; #endif /* HAVE_GETMNTINFO */ #endif /* HAVE_MNTENT_H */ }