#ifdef CONFIG_LINUX
#include <sys/vfs.h>
+#include <linux/magic.h>
#endif
-size_t qemu_fd_getpagesize(int fd)
+QemuFsType qemu_fd_getfs(int fd)
{
#ifdef CONFIG_LINUX
struct statfs fs;
int ret;
- if (fd != -1) {
- do {
- ret = fstatfs(fd, &fs);
- } while (ret != 0 && errno == EINTR);
+ if (fd < 0) {
+ return QEMU_FS_TYPE_UNKNOWN;
+ }
- if (ret == 0 && fs.f_type == HUGETLBFS_MAGIC) {
- return fs.f_bsize;
- }
+ do {
+ ret = fstatfs(fd, &fs);
+ } while (ret != 0 && errno == EINTR);
+
+ switch (fs.f_type) {
+ case TMPFS_MAGIC:
+ return QEMU_FS_TYPE_TMPFS;
+ case HUGETLBFS_MAGIC:
+ return QEMU_FS_TYPE_HUGETLBFS;
+ default:
+ return QEMU_FS_TYPE_UNKNOWN;
}
-#ifdef __sparc__
- /* SPARC Linux needs greater alignment than the pagesize */
- return QEMU_VMALLOC_ALIGN;
-#endif
+#else
+ return QEMU_FS_TYPE_UNKNOWN;
#endif
-
- return qemu_real_host_page_size;
}
-size_t qemu_mempath_getpagesize(const char *mem_path)
+size_t qemu_fd_getpagesize(int fd)
{
#ifdef CONFIG_LINUX
struct statfs fs;
int ret;
- if (mem_path) {
+ if (fd != -1) {
do {
- ret = statfs(mem_path, &fs);
+ ret = fstatfs(fd, &fs);
} while (ret != 0 && errno == EINTR);
- if (ret != 0) {
- fprintf(stderr, "Couldn't statfs() memory path: %s\n",
- strerror(errno));
- exit(1);
- }
-
- if (fs.f_type == HUGETLBFS_MAGIC) {
- /* It's hugepage, return the huge page size */
+ if (ret == 0 && fs.f_type == HUGETLBFS_MAGIC) {
return fs.f_bsize;
}
}
#endif
#endif
- return qemu_real_host_page_size;
+ return qemu_real_host_page_size();
}
#define OVERCOMMIT_MEMORY_PATH "/proc/sys/vm/overcommit_memory"
* MAP_NORESERVE.
* b) MAP_NORESERVE is not affected by /proc/sys/vm/overcommit_memory.
*/
- if (qemu_fd_getpagesize(fd) != qemu_real_host_page_size) {
+ if (qemu_fd_getpagesize(fd) != qemu_real_host_page_size()) {
return true;
}
* We do this unless we are using the system page size, in which case
* anonymous memory is OK.
*/
- if (fd == -1 || qemu_fd_getpagesize(fd) == qemu_real_host_page_size) {
+ if (fd == -1 || qemu_fd_getpagesize(fd) == qemu_real_host_page_size()) {
fd = -1;
flags |= MAP_ANONYMOUS;
} else {
/* Mappings in the same segment must share the same page size */
return qemu_fd_getpagesize(fd);
#else
- return qemu_real_host_page_size;
+ return qemu_real_host_page_size();
#endif
}