mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Add support for Cygwin.
This commit is contained in:
@@ -22,8 +22,8 @@
|
|||||||
# Copyright (C) 2011-2021 Natalia Portillo
|
# Copyright (C) 2011-2021 Natalia Portillo
|
||||||
# *****************************************************************************/
|
# *****************************************************************************/
|
||||||
|
|
||||||
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND NOT CYGWIN)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_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 attr.h rsrcfork.h xattr.h links.h volume.h timew32.h os.h sparse.h)
|
add_sources(attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c perms.h rsrcfork.c sparse.c time.c volume.c xattr.c attr.h rsrcfork.h xattr.h links.h volume.h timew32.h os.h sparse.h)
|
||||||
|
|||||||
@@ -32,12 +32,16 @@ Copyright (C) 2011-2021 Natalia Portillo
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
#include <limits.h>
|
||||||
|
#include <sys/cygwin.h>
|
||||||
|
#include <sys/unistd.h>
|
||||||
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
#include "links.h"
|
|
||||||
|
|
||||||
#include "../include/defs.h"
|
#include "../include/defs.h"
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
#include "links.h"
|
||||||
|
|
||||||
extern DWORD oldVersion;
|
extern DWORD oldVersion;
|
||||||
|
|
||||||
@@ -70,11 +74,14 @@ void Links(const char* path)
|
|||||||
else if(oldVersion == 0)
|
else if(oldVersion == 0)
|
||||||
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
|
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
|
||||||
|
|
||||||
|
// If we are not in Cygwin, do not proceed unless we are in Windows NT
|
||||||
|
#if !defined(__CYGWIN__)
|
||||||
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
|
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
|
||||||
{
|
{
|
||||||
// Not supported on Windows 9x
|
// Not supported on Windows 9x
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif // !__CYGWIN__
|
||||||
|
|
||||||
lpRootPathName = malloc(dwMaxNameSize);
|
lpRootPathName = malloc(dwMaxNameSize);
|
||||||
|
|
||||||
@@ -116,6 +123,17 @@ void Links(const char* path)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are not in Cygwin, call it, but do not proceed further unless we are in Windows NT
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
CygwinLinks(path);
|
||||||
|
|
||||||
|
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
|
||||||
|
{
|
||||||
|
// Not supported on Windows 9x
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
kernel32 = LoadLibraryA("kernel32.dll");
|
kernel32 = LoadLibraryA("kernel32.dll");
|
||||||
|
|
||||||
if(!kernel32)
|
if(!kernel32)
|
||||||
@@ -209,3 +227,60 @@ void Links(const char* path)
|
|||||||
|
|
||||||
FreeLibrary(kernel32);
|
FreeLibrary(kernel32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
void CygwinLinks(const char* path)
|
||||||
|
{
|
||||||
|
char cyg_path[PATH_MAX];
|
||||||
|
FILE* h;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
memset(cyg_path, 0, PATH_MAX);
|
||||||
|
|
||||||
|
cygwin_conv_path(CCP_WIN_A_TO_POSIX, path, cyg_path, PATH_MAX);
|
||||||
|
|
||||||
|
ret = chdir(cyg_path);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to specified path.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = chdir("LINKS");
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to working directory.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_write("Creating cygwin links.\n");
|
||||||
|
|
||||||
|
log_write("\tCreating cygwin target file.\n");
|
||||||
|
|
||||||
|
h = fopen("CYGTARGET", "w+");
|
||||||
|
|
||||||
|
if(h == NULL)
|
||||||
|
{
|
||||||
|
log_write("\tError %d creating cygwin target file.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(h, "This is the target for the links.\n");
|
||||||
|
|
||||||
|
fclose(h);
|
||||||
|
|
||||||
|
log_write("\tCreating cygwin symbolic link.\n");
|
||||||
|
|
||||||
|
ret = link("CYGTARGET", "CYGHARD");
|
||||||
|
|
||||||
|
if(ret) log_write("\tError %d creating cygwin hard link.\n", errno);
|
||||||
|
|
||||||
|
log_write("\tCreating cygwin hard link.\n");
|
||||||
|
|
||||||
|
ret = symlink("CYGTARGET", "CYGSYMBOLIC");
|
||||||
|
|
||||||
|
if(ret) log_write("\tError %d creating cygwin symbolic link.\n", errno);
|
||||||
|
}
|
||||||
|
#endif // __CYGWIN__
|
||||||
@@ -27,6 +27,10 @@ Copyright (C) 2011-2021 Natalia Portillo
|
|||||||
|
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
void CygwinLinks(const char* path);
|
||||||
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
static BOOL(WINAPI* WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES);
|
static BOOL(WINAPI* WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES);
|
||||||
static BOOL(WINAPI* WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD);
|
static BOOL(WINAPI* WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD);
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,14 @@ Copyright (C) 2011-2021 Natalia Portillo
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#include "../include/defs.h"
|
#include "../include/defs.h"
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
DWORD oldVersion;
|
DWORD oldVersion;
|
||||||
|
|
||||||
@@ -47,6 +49,9 @@ void GetOsInfo()
|
|||||||
DWORD error;
|
DWORD error;
|
||||||
void* func;
|
void* func;
|
||||||
HINSTANCE kernel32;
|
HINSTANCE kernel32;
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
struct utsname utsname;
|
||||||
|
#endif
|
||||||
kernel32 = LoadLibraryA("KERNEL32.DLL");
|
kernel32 = LoadLibraryA("KERNEL32.DLL");
|
||||||
|
|
||||||
memset(&verInfo, 0, sizeof(WIN_OSVERSIONINFO));
|
memset(&verInfo, 0, sizeof(WIN_OSVERSIONINFO));
|
||||||
@@ -194,4 +199,11 @@ void GetOsInfo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
FreeLibrary(kernel32);
|
FreeLibrary(kernel32);
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
memset(&utsname, 0, sizeof(struct utsname));
|
||||||
|
uname(&utsname);
|
||||||
|
|
||||||
|
printf("\tRunning under Cygwin release %s version %s.\n", utsname.release, utsname.version);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,78 @@ Copyright (C) 2011-2021 Natalia Portillo
|
|||||||
// ReSharper disable CppJoinDeclarationAndAssignment
|
// ReSharper disable CppJoinDeclarationAndAssignment
|
||||||
// ReSharper disable CppDeprecatedEntity
|
// ReSharper disable CppDeprecatedEntity
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/cygwin.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/unistd.h>
|
||||||
|
|
||||||
|
#include "perms.h"
|
||||||
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
#include "../include/defs.h"
|
#include "../include/defs.h"
|
||||||
|
#include "../log.h"
|
||||||
|
|
||||||
void FilePermissions(const char* path)
|
void FilePermissions(const char* path)
|
||||||
{ /* Do nothing, not supported by target operating system */
|
{
|
||||||
|
// Only supported by Cygwin, Windows uses normal attributes
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
int ret;
|
||||||
|
FILE* file;
|
||||||
|
int rc;
|
||||||
|
int cRc;
|
||||||
|
int i;
|
||||||
|
char cyg_path[PATH_MAX];
|
||||||
|
|
||||||
|
memset(cyg_path, 0, PATH_MAX);
|
||||||
|
|
||||||
|
cygwin_conv_path(CCP_WIN_A_TO_POSIX, path, cyg_path, PATH_MAX);
|
||||||
|
|
||||||
|
ret = chdir(cyg_path);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to specified path.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mkdir("PERMS", 0755);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d creating working directory.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = chdir("PERMS");
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to working directory.\n", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_write("Creating attributes files.\n");
|
||||||
|
|
||||||
|
for(i = 0; i < KNOWN_CYGWIN_PERMS; i++)
|
||||||
|
{
|
||||||
|
file = fopen(cygwin_perms[i].filename, "w+");
|
||||||
|
rc = 0;
|
||||||
|
cRc = 0;
|
||||||
|
|
||||||
|
if(!file) rc = errno;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(file, "%s.\n", cygwin_perms[i].description);
|
||||||
|
fclose(file);
|
||||||
|
cRc = chmod(cygwin_perms[i].filename, cygwin_perms[i].mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_write(
|
||||||
|
"\t%s: name = \"%s\", rc = %d, cRc = %d\n", cygwin_perms[i].description, cygwin_perms[i].filename, rc, cRc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
55
setter/src/win32/perms.h
Normal file
55
setter/src/win32/perms.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2011-2021 Natalia Portillo
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AARU_FSTESTER_SETTER_SRC_WIN32_PERMS_H_
|
||||||
|
#define AARU_FSTESTER_SETTER_SRC_WIN32_PERMS_H_
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char filename[256];
|
||||||
|
char description[256];
|
||||||
|
mode_t mode;
|
||||||
|
} cygwin_perms_tests_t;
|
||||||
|
|
||||||
|
#define KNOWN_CYGWIN_PERMS 13
|
||||||
|
|
||||||
|
static const cygwin_perms_tests_t cygwin_perms[KNOWN_CYGWIN_PERMS] = {
|
||||||
|
{"NONE", "File with no permissions", 0},
|
||||||
|
{"04000", "File with set-user-ID", 04000},
|
||||||
|
{"02000", "File with set-group-ID", 02000},
|
||||||
|
{"01000", "File with sticky bit", 01000},
|
||||||
|
{"00400", "File with read by owner", 00400},
|
||||||
|
{"00200", "File with write by owner", 00200},
|
||||||
|
{"00100", "File with execute by owner", 00100},
|
||||||
|
{"00040", "File with read by group", 00040},
|
||||||
|
{"00020", "File with write by group", 00020},
|
||||||
|
{"00010", "File with execute by group", 00010},
|
||||||
|
{"00004", "File with read by others", 00004},
|
||||||
|
{"00002", "File with write by others", 00002},
|
||||||
|
{"00001", "File with execute by others", 00001},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // AARU_FSTESTER_SETTER_SRC_WIN32_PERMS_H_
|
||||||
Reference in New Issue
Block a user