mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Check where statfs is defined and the members it defines before using them.
This commit is contained in:
@@ -26,6 +26,32 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES
|
||||
return()
|
||||
endif()
|
||||
|
||||
include(CheckSymbolExists)
|
||||
include(CheckStructHasMember)
|
||||
|
||||
CHECK_SYMBOL_EXISTS(statfs "sys/statfs.h" HAVE_SYS_STATFS)
|
||||
CHECK_SYMBOL_EXISTS(statfs "sys/mount.h" HAVE_SYS_MOUNT)
|
||||
|
||||
# Linux and FreeBSD
|
||||
if(HAVE_SYS_STATFS)
|
||||
message("-- Found statfs in sys/statfs.h")
|
||||
add_definitions(-DHAVE_SYS_STATFS_H)
|
||||
CHECK_STRUCT_HAS_MEMBER(statfs "f_namelen" "sys/statfs.h" HAVE_STATFS_FNAMELEN)
|
||||
endif()
|
||||
|
||||
# Darwin and most other BSDs
|
||||
if(HAVE_SYS_MOUNT)
|
||||
message("-- Found statfs in sys/mount.h")
|
||||
add_definitions(-DHAVE_SYS_MOUNT_H)
|
||||
CHECK_STRUCT_HAS_MEMBER(statfs "f_namelen" "sys/statfs.h" HAVE_STATFS_FNAMELEN)
|
||||
endif()
|
||||
|
||||
if(HAVE_STATFS_FNAMELEN)
|
||||
message("-- statfs has f_namelen member")
|
||||
add_definitions(-DUSE_STATFS_FNAMELEN)
|
||||
CHECK_STRUCT_HAS_MEMBER(statfs "f_namelen" "sys/statfs.h" HAVE_STATFS_FNAMELEN)
|
||||
endif()
|
||||
|
||||
set(UNIX_SOURCES attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c rsrcfork.c sparse.c time.c volume.c xattr.c)
|
||||
|
||||
add_library(unix ${UNIX_SOURCES})
|
||||
add_library(unix ${UNIX_SOURCES})
|
||||
@@ -22,10 +22,19 @@ Aaru Data Preservation Suite
|
||||
Copyright (C) 2011-2021 Natalia Portillo
|
||||
*****************************************************************************/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_MOUNT_H)
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include "../include/defs.h"
|
||||
#include "../log.h"
|
||||
@@ -138,7 +147,10 @@ void GetVolumeInfo(const char* path, size_t* clusterSize)
|
||||
log_write("\tBytes per block: %ld\n", buf.f_bsize);
|
||||
log_write("\tVolume size: %llu bytes\n", ((unsigned long long)buf.f_blocks) * buf.f_bsize);
|
||||
log_write("\tVolume free: %llu bytes\n", ((unsigned long long)buf.f_bfree) * buf.f_bsize);
|
||||
|
||||
#if defined(USE_STATFS_FNAMELEN)
|
||||
log_write("\tMaximum component length: %ld\n", buf.f_namelen);
|
||||
#endif
|
||||
|
||||
if(buf.f_flags)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user