From 962ffbcfbf20a197505cd45ffa973a4b171e8fc7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 15 Mar 2021 04:01:36 +0000 Subject: [PATCH] Add support for printing Darwin's statfs(2) flags. --- setter/src/darwin/CMakeLists.txt | 2 +- setter/src/darwin/darwin.h | 3 + setter/src/darwin/volume.c | 182 +++++++++++++++++++++++++++++++ setter/src/darwin/volume.h | 130 ++++++++++++++++++++++ setter/src/linux/CMakeLists.txt | 2 +- setter/src/linux/linux.h | 3 + setter/src/linux/volume.c | 102 +++++++++++++++++ setter/src/linux/volume.h | 72 ++++++++++++ setter/src/unix/unix.h | 44 -------- setter/src/unix/volume.c | 84 +++----------- 10 files changed, 508 insertions(+), 116 deletions(-) create mode 100644 setter/src/darwin/volume.c create mode 100644 setter/src/darwin/volume.h create mode 100644 setter/src/linux/volume.c create mode 100644 setter/src/linux/volume.h diff --git a/setter/src/darwin/CMakeLists.txt b/setter/src/darwin/CMakeLists.txt index d664dec..ffc8a6d 100644 --- a/setter/src/darwin/CMakeLists.txt +++ b/setter/src/darwin/CMakeLists.txt @@ -33,7 +33,7 @@ project( add_definitions(-DHAVE_SYS_MOUNT_H) -set(PLATFORM_SOURCES os.c darwin.h) +set(PLATFORM_SOURCES os.c darwin.h volume.c volume.h) set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") diff --git a/setter/src/darwin/darwin.h b/setter/src/darwin/darwin.h index d8b43ad..974320b 100644 --- a/setter/src/darwin/darwin.h +++ b/setter/src/darwin/darwin.h @@ -5,6 +5,9 @@ #ifndef SETTER_SRC_DARWIN_DARWIN_H_ #define SETTER_SRC_DARWIN_DARWIN_H_ +#include + void DarwinGetOsInfo(); +void DarwinPrintStatfsFlags(uint32_t flags); #endif // SETTER_SRC_DARWIN_DARWIN_H_ diff --git a/setter/src/darwin/volume.c b/setter/src/darwin/volume.c new file mode 100644 index 0000000..0345733 --- /dev/null +++ b/setter/src/darwin/volume.c @@ -0,0 +1,182 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#include "volume.h" + +#include "../log.h" + +void DarwinPrintStatfsFlags(uint32_t flags) +{ + if(flags & MNT_RDONLY) + { + log_write("\t\tVolume is read-only.\n"); + flags -= MNT_RDONLY; + } + + if(flags & MNT_SYNCHRONOUS) + { + log_write("\t\tVolume is written to synchronously.\n"); + flags -= MNT_SYNCHRONOUS; + } + + if(flags & MNT_NOEXEC) + { + log_write("\t\tCannot exec from volume.\n"); + flags -= MNT_NOEXEC; + } + + if(flags & MNT_NOSUID) + { + log_write("\t\tVolume does not honor setuid bits.\n"); + flags -= MNT_NOSUID; + } + + if(flags & MNT_NODEV) + { + log_write("\t\tVolume doesn't interpret special files.\n"); + flags -= MNT_NODEV; + } + + if(flags & MNT_UNION) + { + log_write("\t\tMount point is a union.\n"); + flags -= MNT_UNION; + } + + if(flags & MNT_ASYNC) + { + log_write("\t\tVolume is written to asynchronously.\n"); + flags -= MNT_ASYNC; + } + + if(flags & MNT_CPROTECT) + { + log_write("\t\tVolume supports per-file encryption.\n"); + flags -= MNT_CPROTECT; + } + + if(flags & MNT_EXPORTED) + { + log_write("\t\tVolume is exported by NFS.\n"); + flags -= MNT_EXPORTED; + } + + if(flags & MNT_REMOVABLE) + { + log_write("\t\tVolume is removable.\n"); + flags -= MNT_REMOVABLE; + } + + if(flags & MNT_QUARANTINE) + { + log_write("\t\tVolume is quarantined.\n"); + flags -= MNT_QUARANTINE; + } + + if(flags & MNT_LOCAL) + { + log_write("\t\tVolume is local.\n"); + flags -= MNT_LOCAL; + } + + if(flags & MNT_QUOTA) + { + log_write("\t\tVolume supports quotas.\n"); + flags -= MNT_QUOTA; + } + + if(flags & MNT_ROOTFS) + { + log_write("\t\tVolume is the root of the filesystem.\n"); + flags -= MNT_ROOTFS; + } + + if(flags & MNT_DOVOLFS) + { + log_write("\t\tVolume supports volfs.\n"); + flags -= MNT_DOVOLFS; + } + + if(flags & MNT_DONTBROWSE) + { + log_write("\t\tVolume is not appropriate for user data.\n"); + flags -= MNT_DONTBROWSE; + } + + if(flags & MNT_IGNORE_OWNERSHIP) + { + log_write("\t\tVolume does not respect ownership.\n"); + flags -= MNT_IGNORE_OWNERSHIP; + } + + if(flags & MNT_AUTOMOUNTED) + { + log_write("\t\tVolume was mounted by automounter.\n"); + flags -= MNT_AUTOMOUNTED; + } + + if(flags & MNT_JOURNALED) + { + log_write("\t\tVolume is journaled.\n"); + flags -= MNT_JOURNALED; + } + + if(flags & MNT_NOUSERXATTR) + { + log_write("\t\tVolume does not allow user extended attributes.\n"); + flags -= MNT_NOUSERXATTR; + } + + if(flags & MNT_DEFWRITE) + { + log_write("\t\tVolume defers writes.\n"); + flags -= MNT_DEFWRITE; + } + + if(flags & MNT_MULTILABEL) + { + log_write("\t\tVolume supports MAC for individual labels.\n"); + flags -= MNT_MULTILABEL; + } + + if(flags & MNT_NOATIME) + { + log_write("\t\tVolume does not update access time.\n"); + flags -= MNT_NOATIME; + } + + if(flags & MNT_SNAPSHOT) + { + log_write("\t\tMountpoint is a snapshot.\n"); + flags -= MNT_SNAPSHOT; + } + + if(flags & MNT_STRICTATIME) + { + log_write("\t\tVolume strictly updates access time.\n"); + flags -= MNT_STRICTATIME; + } + + if(flags) { log_write("\t\tRemaining flags: 0x%08lX\n", flags); } +} \ No newline at end of file diff --git a/setter/src/darwin/volume.h b/setter/src/darwin/volume.h new file mode 100644 index 0000000..f553509 --- /dev/null +++ b/setter/src/darwin/volume.h @@ -0,0 +1,130 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_SETTER_SRC_DARWIN_VOLUME_H_ +#define AARU_FSTESTER_SETTER_SRC_DARWIN_VOLUME_H_ + +#include + +#ifndef MNT_RDONLY +#define MNT_RDONLY 0x00000001 +#endif + +#ifndef MNT_SYNCHRONOUS +#define MNT_SYNCHRONOUS 0x00000002 +#endif + +#ifndef MNT_NOEXEC +#define MNT_NOEXEC 0x00000004 +#endif + +#ifndef MNT_NOSUID +#define MNT_NOSUID 0x00000008 +#endif + +#ifndef MNT_NODEV +#define MNT_NODEV 0x00000010 +#endif + +#ifndef MNT_UNION +#define MNT_UNION 0x00000020 +#endif + +#ifndef MNT_ASYNC +#define MNT_ASYNC 0x00000040 +#endif + +#ifndef MNT_CPROTECT +#define MNT_CPROTECT 0x00000080 +#endif + +#ifndef MNT_EXPORTED +#define MNT_EXPORTED 0x00000100 +#endif + +#ifndef MNT_REMOVABLE +#define MNT_REMOVABLE 0x00000200 +#endif + +#ifndef MNT_QUARANTINE +#define MNT_QUARANTINE 0x00000400 +#endif + +#ifndef MNT_LOCAL +#define MNT_LOCAL 0x00001000 +#endif + +#ifndef MNT_QUOTA +#define MNT_QUOTA 0x00002000 +#endif + +#ifndef MNT_ROOTFS +#define MNT_ROOTFS 0x00004000 +#endif + +#ifndef MNT_DOVOLFS +#define MNT_DOVOLFS 0x00008000 +#endif + +#ifndef MNT_DONTBROWSE +#define MNT_DONTBROWSE 0x00100000 +#endif + +#ifndef MNT_IGNORE_OWNERSHIP +#define MNT_IGNORE_OWNERSHIP 0x00200000 +#endif + +#ifndef MNT_AUTOMOUNTED +#define MNT_AUTOMOUNTED 0x00400000 +#endif + +#ifndef MNT_JOURNALED +#define MNT_JOURNALED 0x00800000 +#endif + +#ifndef MNT_NOUSERXATTR +#define MNT_NOUSERXATTR 0x01000000 +#endif + +#ifndef MNT_DEFWRITE +#define MNT_DEFWRITE 0x02000000 +#endif + +#ifndef MNT_MULTILABEL +#define MNT_MULTILABEL 0x04000000 +#endif + +#ifndef MNT_NOATIME +#define MNT_NOATIME 0x10000000 +#endif + +#ifndef MNT_SNAPSHOT +#define MNT_SNAPSHOT 0x40000000 +#endif + +#ifndef MNT_STRICTATIME +#define MNT_STRICTATIME 0x80000000 +#endif + +#endif // AARU_FSTESTER_SETTER_SRC_DARWIN_VOLUME_H_ diff --git a/setter/src/linux/CMakeLists.txt b/setter/src/linux/CMakeLists.txt index c7a9ac8..cdb8b18 100644 --- a/setter/src/linux/CMakeLists.txt +++ b/setter/src/linux/CMakeLists.txt @@ -31,7 +31,7 @@ project( DESCRIPTION "Filesystem test creator for Linux" LANGUAGES C) -set(PLATFORM_SOURCES attr.c sparse.c xattr.c) +set(PLATFORM_SOURCES attr.c sparse.c xattr.c volume.c volume.h) set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") diff --git a/setter/src/linux/linux.h b/setter/src/linux/linux.h index 81f9a81..834ee42 100644 --- a/setter/src/linux/linux.h +++ b/setter/src/linux/linux.h @@ -25,9 +25,12 @@ Copyright (C) 2011-2021 Natalia Portillo #ifndef AARU_FSTESTER_SETTER_LINUX_H #define AARU_FSTESTER_SETTER_LINUX_H +#include + void LinuxExtendedAttributes(const char* path); void LinuxSparse(const char* path); void LinuxFileAttributes(const char* path); +void LinuxPrintStatfsFlags(__fsword_t flags); static unsigned char CommentsEA[72] = { 0x45, 0x00, 0x00, 0x00, 0x00, 0x09, 0x33, 0x00, 0x2E, 0x43, 0x4F, 0x4D, 0x4D, 0x45, 0x4E, 0x54, 0x53, 0x00, diff --git a/setter/src/linux/volume.c b/setter/src/linux/volume.c new file mode 100644 index 0000000..2a316f5 --- /dev/null +++ b/setter/src/linux/volume.c @@ -0,0 +1,102 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#include + +#include "volume.h" + +#include "../log.h" + +void LinuxPrintStatfsFlags(__fsword_t flags) +{ + log_write("\tFlags:\n"); + + if(flags & ST_RDONLY) + { + log_write("\t\tVolume is read-only.\n"); + flags -= ST_RDONLY; + } + + if(flags & ST_NOSUID) + { + log_write("\t\tVolume ignores suid and sgid bits.\n"); + flags -= ST_NOSUID; + } + + if(flags & ST_NODEV) + { + log_write("\t\tVolume disallows access to device special files.\n"); + flags -= ST_NODEV; + } + + if(flags & ST_NOEXEC) + { + log_write("\t\tVolume disallows program execution.\n"); + flags -= ST_NOEXEC; + } + + if(flags & ST_SYNCHRONOUS) + { + log_write("\t\tVolume writes are synced at once.\n"); + flags -= ST_SYNCHRONOUS; + } + + if(flags & ST_MANDLOCK) + { + log_write("\t\tVolume allows mandatory locks.\n"); + flags -= ST_MANDLOCK; + } + + if(flags & ST_WRITE) + { + log_write("\t\tVolume writes on file/directory/symlink.\n"); + flags -= ST_WRITE; + } + + if(flags & ST_APPEND) + { + log_write("\t\tVolume appends.\n"); + flags -= ST_APPEND; + } + + if(flags & ST_IMMUTABLE) + { + log_write("\t\tVolume is immutable.\n"); + flags -= ST_IMMUTABLE; + } + + if(flags & ST_NOATIME) + { + log_write("\t\tVolume does not update access times.\n"); + flags -= ST_NOATIME; + } + + if(flags & ST_NODIRATIME) + { + log_write("\t\tVolume does not update directory access times.\n"); + flags -= ST_NODIRATIME; + } + + if(flags) { log_write("\t\tRemaining flags: 0x%08lX\n", flags); } +} \ No newline at end of file diff --git a/setter/src/linux/volume.h b/setter/src/linux/volume.h new file mode 100644 index 0000000..2f63025 --- /dev/null +++ b/setter/src/linux/volume.h @@ -0,0 +1,72 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_SETTER_SRC_LINUX_VOLUME_H_ +#define AARU_FSTESTER_SETTER_SRC_LINUX_VOLUME_H_ + +#ifndef ST_RDONLY +#define ST_RDONLY 1 +#endif + +#ifndef ST_NOSUID +#define ST_NOSUID 2 +#endif + +#ifndef ST_NODEV +#define ST_NODEV 4 +#endif + +#ifndef ST_NOEXEC +#define ST_NOEXEC 8 +#endif + +#ifndef ST_SYNCHRONOUS +#define ST_SYNCHRONOUS 16 +#endif + +#ifndef ST_MANDLOCK +#define ST_MANDLOCK 64 +#endif + +#ifndef ST_WRITE +#define ST_WRITE 128 +#endif + +#ifndef ST_APPEND +#define ST_APPEND 256 +#endif + +#ifndef ST_IMMUTABLE +#define ST_IMMUTABLE 512 +#endif + +#ifndef ST_NOATIME +#define ST_NOATIME 1024 +#endif + +#ifndef ST_NODIRATIME +#define ST_NODIRATIME 2048 +#endif + +#endif // AARU_FSTESTER_SETTER_SRC_LINUX_VOLUME_H_ diff --git a/setter/src/unix/unix.h b/setter/src/unix/unix.h index e8f6609..412b02e 100644 --- a/setter/src/unix/unix.h +++ b/setter/src/unix/unix.h @@ -349,50 +349,6 @@ Copyright (C) 2011-2021 Natalia Portillo #define _XIAFS_SUPER_MAGIC 0x012fd16d #endif -#ifndef ST_RDONLY -#define ST_RDONLY 1 -#endif - -#ifndef ST_NOSUID -#define ST_NOSUID 2 -#endif - -#ifndef ST_NODEV -#define ST_NODEV 4 -#endif - -#ifndef ST_NOEXEC -#define ST_NOEXEC 8 -#endif - -#ifndef ST_SYNCHRONOUS -#define ST_SYNCHRONOUS 16 -#endif - -#ifndef ST_MANDLOCK -#define ST_MANDLOCK 64 -#endif - -#ifndef ST_WRITE -#define ST_WRITE 128 -#endif - -#ifndef ST_APPEND -#define ST_APPEND 256 -#endif - -#ifndef ST_IMMUTABLE -#define ST_IMMUTABLE 512 -#endif - -#ifndef ST_NOATIME -#define ST_NOATIME 1024 -#endif - -#ifndef ST_NODIRATIME -#define ST_NODIRATIME 2048 -#endif - #define DATETIME_FORMAT "This file is dated %s for %s\n" #define LESSDATETIME "2106/02/07 06:28:15 or unknown" #define MAXDATETIME "2038/01/19 03:14:07" diff --git a/setter/src/unix/volume.c b/setter/src/unix/volume.c index 1bbf624..5fa5772 100644 --- a/setter/src/unix/volume.c +++ b/setter/src/unix/volume.c @@ -26,7 +26,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include -#ifdef HAVE_SYS_STAT_H +#ifdef HAVE_SYS_STATFS_H #include #endif @@ -39,6 +39,12 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../log.h" #include "unix.h" +#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux) +#include "../linux/linux.h" +#elif defined(__APPLE__) && defined(__MACH__) +#include "../darwin/darwin.h" +#endif + void GetVolumeInfo(const char* path, size_t* clusterSize) { struct statfs buf; @@ -159,75 +165,13 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(buf.f_flags) { - log_write("\tFlags:\n"); - - if(buf.f_flags & ST_RDONLY) - { - log_write("\t\tVolume is read-only.\n"); - buf.f_flags -= ST_RDONLY; - } - - if(buf.f_flags & ST_NOSUID) - { - log_write("\t\tVolume ignores suid and sgid bits.\n"); - buf.f_flags -= ST_NOSUID; - } - - if(buf.f_flags & ST_NODEV) - { - log_write("\t\tVolume disallows access to device special files.\n"); - buf.f_flags -= ST_NODEV; - } - - if(buf.f_flags & ST_NOEXEC) - { - log_write("\t\tVolume disallows program execution.\n"); - buf.f_flags -= ST_NOEXEC; - } - - if(buf.f_flags & ST_SYNCHRONOUS) - { - log_write("\t\tVolume writes are synced at once.\n"); - buf.f_flags -= ST_SYNCHRONOUS; - } - - if(buf.f_flags & ST_MANDLOCK) - { - log_write("\t\tVolume allows mandatory locks.\n"); - buf.f_flags -= ST_MANDLOCK; - } - - if(buf.f_flags & ST_WRITE) - { - log_write("\t\tVolume writes on file/directory/symlink.\n"); - buf.f_flags -= ST_WRITE; - } - - if(buf.f_flags & ST_APPEND) - { - log_write("\t\tVolume appends.\n"); - buf.f_flags -= ST_APPEND; - } - - if(buf.f_flags & ST_IMMUTABLE) - { - log_write("\t\tVolume is immutable.\n"); - buf.f_flags -= ST_IMMUTABLE; - } - - if(buf.f_flags & ST_NOATIME) - { - log_write("\t\tVolume does not update access times.\n"); - buf.f_flags -= ST_NOATIME; - } - - if(buf.f_flags & ST_NODIRATIME) - { - log_write("\t\tVolume does not update directory access times.\n"); - buf.f_flags -= ST_NODIRATIME; - } - - if(buf.f_flags) { log_write("\t\tRemaining flags: 0x%08lX\n", buf.f_flags); } +#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux) + LinuxPrintStatfsFlags(buf.f_flags); +#elif defined(__APPLE__) && defined(__MACH__) + DarwinPrintStatfsFlags(buf.f_flags); +#else + log_write("\tFlags: 0x%08lX\n", buf.f_flags); +#endif } *clusterSize = buf.f_bsize;