Implement GetVolumeInfo() for UNIX et al.

This commit is contained in:
2019-04-28 20:38:11 +01:00
parent 2e12861413
commit f9e63b73cf
3 changed files with 566 additions and 2 deletions

View File

@@ -3,4 +3,4 @@ project(setter C)
set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD 90)
add_executable(setter consts.h defs.h main.h dosos2.h os2_16.h os2_32.h main.c dos.c os2_16.c os2_32.c win32.c win32.h unix.c macos.c macos.h) add_executable(setter consts.h defs.h main.h dosos2.h os2_16.h os2_32.h main.c dos.c os2_16.c os2_32.c win32.c win32.h unix.c macos.c macos.h unix.h)

View File

@@ -31,11 +31,15 @@ Copyright (C) 2011-2018 Natalia Portillo
#if defined(unix) || defined(UNIX) || defined(__unix) || defined(__unix__) || defined(__UNIX__) #if defined(unix) || defined(UNIX) || defined(__unix) || defined(__unix__) || defined(__UNIX__)
#include "unix.h"
#include "defs.h" #include "defs.h"
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/statfs.h>
#include <sys/utsname.h> #include <sys/utsname.h>
void GetOsInfo() void GetOsInfo()
@@ -60,7 +64,187 @@ void GetOsInfo()
void GetVolumeInfo(const char *path, size_t *clusterSize) void GetVolumeInfo(const char *path, size_t *clusterSize)
{ {
// TODO: Implement struct statfs buf;
int ret;
ret = statfs(path, &buf);
if(ret)
{
printf("Error %d querying volume information.\n", errno);
return;
}
printf("Volume information:\n");
printf("\tPath: %s\n", path);
printf("\tFilesystem: ");
switch(buf.f_type)
{
case ADFS_SUPER_MAGIC: printf("ADFS"); break;
case AFFS_SUPER_MAGIC: printf("Amiga FFS"); break;
case AFS_SUPER_MAGIC: printf("AFS"); break;
case ANON_INODE_FS_MAGIC: printf("anonymous inode fs"); break;
case AUTOFS_SUPER_MAGIC: printf("autofs"); break;
case BDEVFS_MAGIC: printf("bdevfs"); break;
case BEFS_SUPER_MAGIC: printf("BeFS"); break;
case BFS_MAGIC: printf("bfs"); break;
case BINFMTFS_MAGIC: printf("binfmtfs"); break;
case BPF_FS_MAGIC: printf("bpffs"); break;
case BTRFS_SUPER_MAGIC:
case BTRFS_TEST_MAGIC: printf("btrfs"); break;
case CGROUP_SUPER_MAGIC: printf("cgroup"); break;
case CGROUP2_SUPER_MAGIC: printf("cgroup2"); break;
case CIFS_MAGIC_NUMBER: printf("CIFS"); break;
case CODA_SUPER_MAGIC: printf("CODA"); break;
case COH_SUPER_MAGIC: printf("Coherent"); break;
case CRAMFS_MAGIC: printf("cramfs"); break;
case DEBUGFS_MAGIC: printf("debufs"); break;
case DEVFS_SUPER_MAGIC: printf("devfs"); break;
case DEVPTS_SUPER_MAGIC: printf("devpts"); break;
case ECRYPTFS_SUPER_MAGIC: printf("ecryptfs"); break;
case EFIVARFS_MAGIC: printf("efivars"); break;
case EFS_SUPER_MAGIC: printf("EFS"); break;
case EXT_SUPER_MAGIC: printf("ext"); break;
case EXT2_OLD_SUPER_MAGIC: printf("ext2"); break;
case EXT2_SUPER_MAGIC: printf("ext2/3/4"); break;
case F2FS_SUPER_MAGIC: printf("f2fs"); break;
case FUSE_SUPER_MAGIC: printf("fuse"); break;
case FUTEXFS_SUPER_MAGIC: printf("futexfs"); break;
case HFS_SUPER_MAGIC: printf("HFS"); break;
case HOSTFS_SUPER_MAGIC: printf("hostfs"); break;
case HPFS_SUPER_MAGIC: printf("HPFS"); break;
case HUGETLBFS_MAGIC: printf("hugetlbfs"); break;
case ISOFS_SUPER_MAGIC: printf("ISO9660"); break;
case JFFS2_SUPER_MAGIC: printf("jffs2"); break;
case JFS_SUPER_MAGIC: printf("JFS"); break;
case MINIX_SUPER_MAGIC:
case MINIX_SUPER_MAGIC2: printf("minix"); break;
case MINIX2_SUPER_MAGIC:
case MINIX2_SUPER_MAGIC2: printf("minix2"); break;
case MINIX3_SUPER_MAGIC: printf("minix3"); break;
case MQUEUE_MAGIC: printf("mqueue"); break;
case MSDOS_SUPER_MAGIC: printf("msdos/vfat"); break;
case MTD_INODE_FS_MAGIC: printf("mtd inodefs"); break;
case NCP_SUPER_MAGIC: printf("NCP"); break;
case NFS_SUPER_MAGIC: printf("NFS"); break;
case NILFS_SUPER_MAGIC: printf("nilfs"); break;
case NSFS_MAGIC: printf("nsfs"); break;
case NTFS_SB_MAGIC: printf("NTFS"); break;
case OCFS2_SUPER_MAGIC: printf("OCFS2"); break;
case OPENPROM_SUPER_MAGIC: printf("OpenPROM"); break;
case OVERLAYFS_SUPER_MAGIC: printf("overlayfs"); break;
case PIPEFS_MAGIC: printf("pipefs"); break;
case PROC_SUPER_MAGIC: printf("proc"); break;
case PSTOREFS_MAGIC: printf("pstorefs"); break;
case QNX4_SUPER_MAGIC: printf("qnx4"); break;
case QNX6_SUPER_MAGIC: printf("qnx6"); break;
case RAMFS_MAGIC: printf("ramfs"); break;
case REISERFS_SUPER_MAGIC: printf("Reiser"); break;
case ROMFS_MAGIC: printf("romfs"); break;
case SECURITYFS_MAGIC: printf("securityfs"); break;
case SELINUX_MAGIC: printf("SELinux"); break;
case SMACK_MAGIC: printf("smack"); break;
case SMB_SUPER_MAGIC: printf("SMB"); break;
case SOCKFS_MAGIC: printf("sockfs"); break;
case SQUASHFS_MAGIC: printf("squashfs"); break;
case SYSFS_MAGIC: printf("sysfs"); break;
case SYSV2_SUPER_MAGIC: printf("System V Release 2"); break;
case SYSV4_SUPER_MAGIC: printf("System V Release 4"); break;
case TMPFS_MAGIC: printf("tmpfs"); break;
case TRACEFS_MAGIC: printf("tracefs"); break;
case UDF_SUPER_MAGIC: printf("UDF"); break;
case UFS_MAGIC: printf("UFS"); break;
case USBDEVICE_SUPER_MAGIC: printf("usbdevice"); break;
case V9FS_MAGIC: printf("V9"); break;
case VXFS_SUPER_MAGIC: printf("vxfs"); break;
case XENFS_SUPER_MAGIC: printf("xenfs"); break;
case XENIX_SUPER_MAGIC: printf("XENIX"); break;
case XFS_SUPER_MAGIC: printf("XFS"); break;
case _XIAFS_SUPER_MAGIC: printf("xia"); break;
default: printf("unknown type -> 0x%lX", buf.f_type);
}
printf("\n");
printf("\tBytes per block: %ld\n", buf.f_bsize);
printf("\tVolume size: %llu bytes\n", ((unsigned long long)buf.f_blocks) * buf.f_bsize);
printf("\tVolume free: %llu bytes\n", ((unsigned long long)buf.f_bfree) * buf.f_bsize);
printf("\tMaximum component length: %ld\n", buf.f_namelen);
if(buf.f_flags)
{
printf("\tFlags:\n");
if(buf.f_flags & ST_RDONLY)
{
printf("\t\tVolume is read-only.\n");
buf.f_flags -= ST_RDONLY;
}
if(buf.f_flags & ST_NOSUID)
{
printf("\t\tVolume ignores suid and sgid bits.\n");
buf.f_flags -= ST_NOSUID;
}
if(buf.f_flags & ST_NODEV)
{
printf("\t\tVolume disallows access to device special files.\n");
buf.f_flags -= ST_NODEV;
}
if(buf.f_flags & ST_NOEXEC)
{
printf("\t\tVolume disallows program execution.\n");
buf.f_flags -= ST_NOEXEC;
}
if(buf.f_flags & ST_SYNCHRONOUS)
{
printf("\t\tVolume writes are synced at once.\n");
buf.f_flags -= ST_SYNCHRONOUS;
}
if(buf.f_flags & ST_MANDLOCK)
{
printf("\t\tVolume allows mandatory locks.\n");
buf.f_flags -= ST_MANDLOCK;
}
if(buf.f_flags & ST_WRITE)
{
printf("\t\tVolume writes on file/directory/symlink.\n");
buf.f_flags -= ST_WRITE;
}
if(buf.f_flags & ST_APPEND)
{
printf("\t\tVolume appends.\n");
buf.f_flags -= ST_APPEND;
}
if(buf.f_flags & ST_IMMUTABLE)
{
printf("\t\tVolume is immutable.\n");
buf.f_flags -= ST_IMMUTABLE;
}
if(buf.f_flags & ST_NOATIME)
{
printf("\t\tVolume does not update access times.\n");
buf.f_flags -= ST_NOATIME;
}
if(buf.f_flags & ST_NODIRATIME)
{
printf("\t\tVolume does not update directory access times.\n");
buf.f_flags -= ST_NODIRATIME;
}
if(buf.f_flags) { printf("\t\tRemaining flags: 0x%08lX\n", buf.f_flags); }
}
*clusterSize = buf.f_bsize;
} }
void FileAttributes(const char *path) void FileAttributes(const char *path)

380
setter/unix.h Normal file
View File

@@ -0,0 +1,380 @@
//
// Created by claunia on 28/04/19.
//
#ifndef SETTER_UNIX_H
#define SETTER_UNIX_H
#if defined(unix) || defined(UNIX) || defined(__unix) || defined(__unix__) || defined(__UNIX__)
#ifndef ADFS_SUPER_MAGIC
#define ADFS_SUPER_MAGIC 0xadf5
#endif
#ifndef AFFS_SUPER_MAGIC
#define AFFS_SUPER_MAGIC 0xadff
#endif
#ifndef AFS_SUPER_MAGIC
#define AFS_SUPER_MAGIC 0x5346414f
#endif
#ifndef ANON_INODE_FS_MAGIC
#define ANON_INODE_FS_MAGIC 0x09041934
#endif
#ifndef AUTOFS_SUPER_MAGIC
#define AUTOFS_SUPER_MAGIC 0x0187
#endif
#ifndef BDEVFS_MAGIC
#define BDEVFS_MAGIC 0x62646576
#endif
#ifndef BEFS_SUPER_MAGIC
#define BEFS_SUPER_MAGIC 0x42465331
#endif
#ifndef BFS_MAGIC
#define BFS_MAGIC 0x1badface
#endif
#ifndef BINFMTFS_MAGIC
#define BINFMTFS_MAGIC 0x42494e4d
#endif
#ifndef BPF_FS_MAGIC
#define BPF_FS_MAGIC 0xcafe4a11
#endif
#ifndef BTRFS_SUPER_MAGIC
#define BTRFS_SUPER_MAGIC 0x9123683e
#endif
#ifndef BTRFS_TEST_MAGIC
#define BTRFS_TEST_MAGIC 0x73727279
#endif
#ifndef CGROUP_SUPER_MAGIC
#define CGROUP_SUPER_MAGIC 0x27e0eb
#endif
#ifndef CGROUP2_SUPER_MAGIC
#define CGROUP2_SUPER_MAGIC 0x63677270
#endif
#ifndef CIFS_MAGIC_NUMBER
#define CIFS_MAGIC_NUMBER 0xff534d42
#endif
#ifndef CODA_SUPER_MAGIC
#define CODA_SUPER_MAGIC 0x73757245
#endif
#ifndef COH_SUPER_MAGIC
#define COH_SUPER_MAGIC 0x012ff7b7
#endif
#ifndef CRAMFS_MAGIC
#define CRAMFS_MAGIC 0x28cd3d45
#endif
#ifndef DEBUGFS_MAGIC
#define DEBUGFS_MAGIC 0x64626720
#endif
#ifndef DEVFS_SUPER_MAGIC
#define DEVFS_SUPER_MAGIC 0x1373
#endif
#ifndef DEVPTS_SUPER_MAGIC
#define DEVPTS_SUPER_MAGIC 0x1cd1
#endif
#ifndef ECRYPTFS_SUPER_MAGIC
#define ECRYPTFS_SUPER_MAGIC 0xf15f
#endif
#ifndef EFIVARFS_MAGIC
#define EFIVARFS_MAGIC 0xde5e81e4
#endif
#ifndef EFS_SUPER_MAGIC
#define EFS_SUPER_MAGIC 0x00414a53
#endif
#ifndef EXT_SUPER_MAGIC
#define EXT_SUPER_MAGIC 0x137d
#endif
#ifndef EXT2_OLD_SUPER_MAGIC
#define EXT2_OLD_SUPER_MAGIC 0xef51
#endif
#ifndef EXT2_SUPER_MAGIC
#define EXT2_SUPER_MAGIC 0xef53
#endif
#ifndef F2FS_SUPER_MAGIC
#define F2FS_SUPER_MAGIC 0xf2f52010
#endif
#ifndef FUSE_SUPER_MAGIC
#define FUSE_SUPER_MAGIC 0x65735546
#endif
#ifndef FUTEXFS_SUPER_MAGIC
#define FUTEXFS_SUPER_MAGIC 0xbad1dea
#endif
#ifndef HFS_SUPER_MAGIC
#define HFS_SUPER_MAGIC 0x4244
#endif
#ifndef HOSTFS_SUPER_MAGIC
#define HOSTFS_SUPER_MAGIC 0x00c0ffee
#endif
#ifndef HPFS_SUPER_MAGIC
#define HPFS_SUPER_MAGIC 0xf995e849
#endif
#ifndef HUGETLBFS_MAGIC
#define HUGETLBFS_MAGIC 0x958458f6
#endif
#ifndef ISOFS_SUPER_MAGIC
#define ISOFS_SUPER_MAGIC 0x9660
#endif
#ifndef JFFS2_SUPER_MAGIC
#define JFFS2_SUPER_MAGIC 0x72b6
#endif
#ifndef JFS_SUPER_MAGIC
#define JFS_SUPER_MAGIC 0x3153464a
#endif
#ifndef MINIX_SUPER_MAGIC
#define MINIX_SUPER_MAGIC 0x137f
#endif
#ifndef MINIX_SUPER_MAGIC2
#define MINIX_SUPER_MAGIC2 0x138f
#endif
#ifndef MINIX2_SUPER_MAGIC
#define MINIX2_SUPER_MAGIC 0x2468
#endif
#ifndef MINIX2_SUPER_MAGIC2
#define MINIX2_SUPER_MAGIC2 0x2478
#endif
#ifndef MINIX3_SUPER_MAGIC
#define MINIX3_SUPER_MAGIC 0x4d5a
#endif
#ifndef MQUEUE_MAGIC
#define MQUEUE_MAGIC 0x19800202
#endif
#ifndef MSDOS_SUPER_MAGIC
#define MSDOS_SUPER_MAGIC 0x4d44
#endif
#ifndef MTD_INODE_FS_MAGIC
#define MTD_INODE_FS_MAGIC 0x11307854
#endif
#ifndef NCP_SUPER_MAGIC
#define NCP_SUPER_MAGIC 0x564c
#endif
#ifndef NFS_SUPER_MAGIC
#define NFS_SUPER_MAGIC 0x6969
#endif
#ifndef NILFS_SUPER_MAGIC
#define NILFS_SUPER_MAGIC 0x3434
#endif
#ifndef NSFS_MAGIC
#define NSFS_MAGIC 0x6e736673
#endif
#ifndef NTFS_SB_MAGIC
#define NTFS_SB_MAGIC 0x5346544e
#endif
#ifndef OCFS2_SUPER_MAGIC
#define OCFS2_SUPER_MAGIC 0x7461636f
#endif
#ifndef OPENPROM_SUPER_MAGIC
#define OPENPROM_SUPER_MAGIC 0x9fa1
#endif
#ifndef OVERLAYFS_SUPER_MAGIC
#define OVERLAYFS_SUPER_MAGIC 0x794c7630
#endif
#ifndef PIPEFS_MAGIC
#define PIPEFS_MAGIC 0x50495045
#endif
#ifndef PROC_SUPER_MAGIC
#define PROC_SUPER_MAGIC 0x9fa0
#endif
#ifndef PSTOREFS_MAGIC
#define PSTOREFS_MAGIC 0x6165676c
#endif
#ifndef QNX4_SUPER_MAGIC
#define QNX4_SUPER_MAGIC 0x002f
#endif
#ifndef QNX6_SUPER_MAGIC
#define QNX6_SUPER_MAGIC 0x68191122
#endif
#ifndef RAMFS_MAGIC
#define RAMFS_MAGIC 0x858458f6
#endif
#ifndef REISERFS_SUPER_MAGIC
#define REISERFS_SUPER_MAGIC 0x52654973
#endif
#ifndef ROMFS_MAGIC
#define ROMFS_MAGIC 0x7275
#endif
#ifndef SECURITYFS_MAGIC
#define SECURITYFS_MAGIC 0x73636673
#endif
#ifndef SELINUX_MAGIC
#define SELINUX_MAGIC 0xf97cff8c
#endif
#ifndef SMACK_MAGIC
#define SMACK_MAGIC 0x43415d53
#endif
#ifndef SMB_SUPER_MAGIC
#define SMB_SUPER_MAGIC 0x517b
#endif
#ifndef SOCKFS_MAGIC
#define SOCKFS_MAGIC 0x534f434b
#endif
#ifndef SQUASHFS_MAGIC
#define SQUASHFS_MAGIC 0x73717368
#endif
#ifndef SYSFS_MAGIC
#define SYSFS_MAGIC 0x62656572
#endif
#ifndef SYSV2_SUPER_MAGIC
#define SYSV2_SUPER_MAGIC 0x012ff7b6
#endif
#ifndef SYSV4_SUPER_MAGIC
#define SYSV4_SUPER_MAGIC 0x012ff7b5
#endif
#ifndef TMPFS_MAGIC
#define TMPFS_MAGIC 0x01021994
#endif
#ifndef TRACEFS_MAGIC
#define TRACEFS_MAGIC 0x74726163
#endif
#ifndef UDF_SUPER_MAGIC
#define UDF_SUPER_MAGIC 0x15013346
#endif
#ifndef UFS_MAGIC
#define UFS_MAGIC 0x00011954
#endif
#ifndef USBDEVICE_SUPER_MAGIC
#define USBDEVICE_SUPER_MAGIC 0x9fa2
#endif
#ifndef V9FS_MAGIC
#define V9FS_MAGIC 0x01021997
#endif
#ifndef VXFS_SUPER_MAGIC
#define VXFS_SUPER_MAGIC 0xa501fcf5
#endif
#ifndef XENFS_SUPER_MAGIC
#define XENFS_SUPER_MAGIC 0xabba1974
#endif
#ifndef XENIX_SUPER_MAGIC
#define XENIX_SUPER_MAGIC 0x012ff7b4
#endif
#ifndef XFS_SUPER_MAGIC
#define XFS_SUPER_MAGIC 0x58465342
#endif
#ifndef _XIAFS_SUPER_MAGIC
#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
#endif
#endif // SETTER_UNIX_H