Implement setting file attributes in Darwin.

This commit is contained in:
2021-03-15 04:17:16 +00:00
parent 962ffbcfbf
commit c0c52aa887
3 changed files with 199 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ project(
add_definitions(-DHAVE_SYS_MOUNT_H)
set(PLATFORM_SOURCES os.c darwin.h volume.c volume.h)
set(PLATFORM_SOURCES os.c darwin.h volume.c volume.h attr.c attr.h)
set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")

105
setter/src/darwin/attr.c Normal file
View File

@@ -0,0 +1,105 @@
/****************************************************************************
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
*****************************************************************************/
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include "attr.h"
#include "../log.h"
void DarwinFileAttributes(const char* path)
{
int ret;
int fd;
FILE* h;
int rc;
int wRc;
int sRc;
int cRc;
int attr;
int i;
ret = chdir(path);
if(ret)
{
log_write("Error %d changing to specified path.\n", errno);
return;
}
ret = mkdir("ATTRS", 0755);
if(ret)
{
log_write("Error %d creating working directory.\n", errno);
return;
}
ret = chdir("ATTRS");
if(ret)
{
log_write("Error %d changing to working directory.\n", errno);
return;
}
log_write("Creating files with different flags (attributes).\n");
for(i = 0; i < KNOWN_DARWIN_ATTRS; i++)
{
h = fopen(darwin_attrs[i].filename, "w+");
rc = 0;
wRc = 0;
sRc = 0;
cRc = 0;
attr = 0;
if(h == NULL) { rc = errno; }
else
{
fd = fileno(h);
ret = fchflags(fd, darwin_attrs[i].attr);
if(ret)
{
sRc = errno;
unlink(darwin_attrs[i].filename);
}
else
{
ret = fprintf(h, "%s", darwin_attrs[i].contents);
if(ret < 1)
{
wRc = errno;
unlink(darwin_attrs[i].filename);
}
}
ret = fclose(h);
if(ret) { cRc = errno; }
}
log_write("\t%s, rc = %d, wRc = %d, sRc = %d, cRc = %d\n", darwin_attrs[i].description, rc, wRc, sRc, cRc);
}
}

93
setter/src/darwin/attr.h Normal file
View File

@@ -0,0 +1,93 @@
/****************************************************************************
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_DARWIN_ATTR_H_
#define AARU_FSTESTER_SETTER_SRC_DARWIN_ATTR_H_
#include <sys/stat.h>
typedef struct
{
char filename[16];
char contents[256];
char description[256];
unsigned int attr;
} darwin_attr_tests_t;
#define KNOWN_DARWIN_ATTRS 9
#ifndef UF_NODUMP
#define UF_NODUMP 0x00000001 /* Do not dump the file. */
#endif
#ifndef UF_IMMUTABLE
#define UF_IMMUTABLE 0x00000002 /* The file may not be changed. */
#endif
#ifndef UF_APPEND
#define UF_APPEND 0x00000004 /* The file may only be appended to. */
#endif
#ifndef UF_OPAQUE
#define UF_OPAQUE 0x00000008 /* The directory is opaque when viewed through a union stack. */
#endif
#ifndef UF_HIDDEN
#define UF_HIDDEN 0x00000010 /* The file or directory is not intended to be displayed to the user. */
#endif
#ifndef SF_ARCHIVED
#define SF_ARCHIVED 0x00000020 /* The file has been archived. */
#endif
#ifndef SF_IMMUTABLE
#define SF_IMMUTABLE 0x00000040 /* The file may not be changed. */
#endif
#ifndef SF_APPEND
#define SF_APPEND 0x00000080 /* The file may only be appended to. */
#endif
#ifndef SF_DATALESS
#define SF_DATALESS 0x00004000 /* The file is a dataless placeholder. */
#endif
static const darwin_attr_tests_t darwin_attrs[KNOWN_DARWIN_ATTRS] = {
{"NODUMP", "This file is now not dumpable", "File with no dump flag", UF_NODUMP},
{"IMMUTABLE", "This file is now immutable", "File with immutable flag", UF_IMMUTABLE},
{"APPEND", "This file is now append only", "File with append only flag", UF_APPEND},
{"OPAQUE", "This directory is opaque when viewed through a union stack", "File with opaque flag", UF_OPAQUE},
{"HIDDEN", "This file is hidden from user view", "File with hidden flag", UF_HIDDEN},
{"ARCHIVED", "This file is now archived", "File with archived flag", SF_ARCHIVED},
{"SF_IMMUTABLE",
"This file is now immutable, and only the super-user change change that",
"File with super-usr immutable flag",
SF_IMMUTABLE},
{"SF_APPEND",
"This file is now append only, and only the super-user change change that",
"File with super-user append only flag",
SF_APPEND},
{"SF_DATALESS", "This file is a dataless placeholder", "File with dataless flag", SF_DATALESS},
};
#endif // AARU_FSTESTER_SETTER_SRC_DARWIN_ATTR_H_