From 00706e2838b81b2f354f9bbde29182388aaaa463 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 9 Mar 2021 04:50:49 +0000 Subject: [PATCH] Split Linux code. --- setter/CMakeLists.txt | 2 +- setter/src/linux/{linux.c => attr.c} | 199 +-------------------------- setter/src/linux/sparse.c | 156 +++++++++++++++++++++ setter/src/linux/xattr.c | 109 +++++++++++++++ 4 files changed, 271 insertions(+), 195 deletions(-) rename setter/src/linux/{linux.c => attr.c} (71%) create mode 100644 setter/src/linux/sparse.c create mode 100644 setter/src/linux/xattr.c diff --git a/setter/CMakeLists.txt b/setter/CMakeLists.txt index f6f6a57..626bb93 100644 --- a/setter/CMakeLists.txt +++ b/setter/CMakeLists.txt @@ -3,4 +3,4 @@ project(setter C) set(CMAKE_C_STANDARD 90) -add_executable(setter src/include/consts.h src/include/defs.h src/main.h src/dosos2.h src/os2_16.h src/os2_32.h src/main.c src/dos.c src/os2_16.c src/os2_32.c src/win32.c src/win32.h src/unix/unix.c src/macos.c src/macos.h src/unix/unix.h src/linux/linux.c src/linux/linux.h src/netware.c src/netware.h src/linux/xattr.c) \ No newline at end of file +add_executable(setter src/include/consts.h src/include/defs.h src/main.h src/dosos2.h src/os2_16.h src/os2_32.h src/main.c src/dos.c src/os2_16.c src/os2_32.c src/win32.c src/win32.h src/unix/unix.c src/macos.c src/macos.h src/unix/unix.h src/linux/linux.h src/netware.c src/netware.h src/linux/xattr.c src/linux/xattr.c src/linux/sparse.c src/linux/attr.c) \ No newline at end of file diff --git a/setter/src/linux/linux.c b/setter/src/linux/attr.c similarity index 71% rename from setter/src/linux/linux.c rename to setter/src/linux/attr.c index 7074006..dbceae2 100644 --- a/setter/src/linux/linux.c +++ b/setter/src/linux/attr.c @@ -29,210 +29,21 @@ Copyright (C) 2011-2021 Natalia Portillo #if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux) -#include "../include/consts.h" -#define _GNU_SOURCE #include -#include -#include +#include #include -#include #include +#include +#include #include #include "linux.h" -#include -#include -#include - -#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2) -#include -#include -#endif - -void LinuxExtendedAttributes(const char *path) -{ -#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2) - int ret; - FILE *file; - int rc; - int cRc; - - ret = chdir(path); - - if(ret) - { - printf("Error %d changing to specified path.\n", errno); - return; - } - - ret = mkdir("XATTRS", 0755); - - if(ret) - { - printf("Error %d creating working directory.\n", errno); - return; - } - - ret = chdir("XATTRS"); - - if(ret) - { - printf("Error %d changing to working directory.\n", errno); - return; - } - - printf("Creating files with extended attributes.\n"); - - rc = 0; - cRc = 0; - file = fopen("com.ibm.os2.comment", "w+"); - if(file == NULL) - rc = errno; - else - { - fprintf(file, "This file has an extended attribute called \"com.ibm.os2.comment\" that is 72 bytes long.\n"); - fclose(file); - ret = setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, XATTR_CREATE); - - if(ret) cRc = errno; - } - printf("\tFile with an extended attribute called \"com.ibm.os2.comment\", rc = %d, cRc = %d\n", rc, cRc); - - rc = 0; - cRc = 0; - file = fopen("com.ibm.os2.icon", "w+"); - if(file == NULL) - rc = errno; - else - { - fprintf(file, "This file has an extended attribute called \"com.ibm.os2.icon\" that is 3516 bytes long.\n"); - fclose(file); - ret = setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, XATTR_CREATE); - - if(ret) cRc = errno; - } - printf("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc); -#endif -} - -void LinuxSparse(const char *path) -{ - int ret; - int rc, wRc, cRc, zRc; - FILE * h; - unsigned char *buffer; - int i; - int fd; - - ret = chdir(path); - - if(ret) - { - printf("Error %d changing to specified path.\n", errno); - return; - } - - ret = mkdir("SPARSE", 0755); - - if(ret) - { - printf("Error %d creating working directory.\n", errno); - return; - } - - ret = chdir("SPARSE"); - - if(ret) - { - printf("Error %d changing to working directory.\n", errno); - return; - } - - printf("Creating sparse files.\n"); - - h = fopen("SMALL", "w+"); - rc = 0; - wRc = 0; - cRc = 0; - zRc = 0; - if(h == NULL) { rc = errno; } - else - { - buffer = malloc(4096 * 3); - memset(buffer, 0, 4096 * 3); - - for(i = 0; i < 4096 * 3; i += CLAUNIA_SIZE) - { - ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h); - if(ret < 0) - { - wRc = errno; - break; - } - } - - fd = fileno(h); - ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096, 8192); - if(ret) { zRc = errno; } - - ret = fclose(h); - if(ret) { cRc = errno; } - free(buffer); - } - - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", - "SMALL", - 4096 * 3, - rc, - wRc, - cRc, - zRc); - - h = fopen("BIG", "w+"); - rc = 0; - wRc = 0; - cRc = 0; - zRc = 0; - if(h == NULL) { rc = errno; } - else - { - buffer = malloc(4096 * 30); - memset(buffer, 0, 4096 * 30); - - for(i = 0; i < 4096 * 30; i += CLAUNIA_SIZE) - { - ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h); - if(ret < 0) - { - wRc = errno; - break; - } - } - - fd = fileno(h); - ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 32768, 81920); - if(ret) { zRc = errno; } - - ret = fclose(h); - if(ret) { cRc = errno; } - free(buffer); - } - - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", - "BIG", - 4096 * 30, - rc, - wRc, - cRc, - zRc); -} - -void LinuxFileAttributes(const char *path) +void LinuxFileAttributes(const char* path) { int ret; int fd; - FILE *h; + FILE* h; int rc; int wRc; int sRc; diff --git a/setter/src/linux/sparse.c b/setter/src/linux/sparse.c new file mode 100644 index 0000000..745d389 --- /dev/null +++ b/setter/src/linux/sparse.c @@ -0,0 +1,156 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + +Filename : sparse.c +Author(s) : Natalia Portillo + +--[ Description ] ----------------------------------------------------------- + +Contains Linux implementations + +--[ 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 +*****************************************************************************/ + +#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux) + +#include "../include/consts.h" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "linux.h" + +void LinuxSparse(const char* path) +{ + int ret; + int rc, wRc, cRc, zRc; + FILE* h; + unsigned char* buffer; + int i; + int fd; + + ret = chdir(path); + + if(ret) + { + printf("Error %d changing to specified path.\n", errno); + return; + } + + ret = mkdir("SPARSE", 0755); + + if(ret) + { + printf("Error %d creating working directory.\n", errno); + return; + } + + ret = chdir("SPARSE"); + + if(ret) + { + printf("Error %d changing to working directory.\n", errno); + return; + } + + printf("Creating sparse files.\n"); + + h = fopen("SMALL", "w+"); + rc = 0; + wRc = 0; + cRc = 0; + zRc = 0; + if(h == NULL) { rc = errno; } + else + { + buffer = malloc(4096 * 3); + memset(buffer, 0, 4096 * 3); + + for(i = 0; i < 4096 * 3; i += CLAUNIA_SIZE) + { + ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h); + if(ret < 0) + { + wRc = errno; + break; + } + } + + fd = fileno(h); + ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096, 8192); + if(ret) { zRc = errno; } + + ret = fclose(h); + if(ret) { cRc = errno; } + free(buffer); + } + + printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", + "SMALL", + 4096 * 3, + rc, + wRc, + cRc, + zRc); + + h = fopen("BIG", "w+"); + rc = 0; + wRc = 0; + cRc = 0; + zRc = 0; + if(h == NULL) { rc = errno; } + else + { + buffer = malloc(4096 * 30); + memset(buffer, 0, 4096 * 30); + + for(i = 0; i < 4096 * 30; i += CLAUNIA_SIZE) + { + ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h); + if(ret < 0) + { + wRc = errno; + break; + } + } + + fd = fileno(h); + ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 32768, 81920); + if(ret) { zRc = errno; } + + ret = fclose(h); + if(ret) { cRc = errno; } + free(buffer); + } + + printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", + "BIG", + 4096 * 30, + rc, + wRc, + cRc, + zRc); +} + +#endif \ No newline at end of file diff --git a/setter/src/linux/xattr.c b/setter/src/linux/xattr.c new file mode 100644 index 0000000..560f1ec --- /dev/null +++ b/setter/src/linux/xattr.c @@ -0,0 +1,109 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + +Filename : xattr.c +Author(s) : Natalia Portillo + +--[ Description ] ----------------------------------------------------------- + +Contains Linux implementations + +--[ 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 +*****************************************************************************/ + +#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux) + +#include +#include +#include +#include +#include +#include + +#include "linux.h" + +#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2) +#include +#endif + +void LinuxExtendedAttributes(const char* path) +{ +#if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2) + int ret; + FILE* file; + int rc; + int cRc; + + ret = chdir(path); + + if(ret) + { + printf("Error %d changing to specified path.\n", errno); + return; + } + + ret = mkdir("XATTRS", 0755); + + if(ret) + { + printf("Error %d creating working directory.\n", errno); + return; + } + + ret = chdir("XATTRS"); + + if(ret) + { + printf("Error %d changing to working directory.\n", errno); + return; + } + + printf("Creating files with extended attributes.\n"); + + rc = 0; + cRc = 0; + file = fopen("com.ibm.os2.comment", "w+"); + if(file == NULL) rc = errno; + else + { + fprintf(file, "This file has an extended attribute called \"com.ibm.os2.comment\" that is 72 bytes long.\n"); + fclose(file); + ret = setxattr("com.ibm.os2.comment", "user.com.ibm.os2.comment", CommentsEA, 72, XATTR_CREATE); + + if(ret) cRc = errno; + } + printf("\tFile with an extended attribute called \"com.ibm.os2.comment\", rc = %d, cRc = %d\n", rc, cRc); + + rc = 0; + cRc = 0; + file = fopen("com.ibm.os2.icon", "w+"); + if(file == NULL) rc = errno; + else + { + fprintf(file, "This file has an extended attribute called \"com.ibm.os2.icon\" that is 3516 bytes long.\n"); + fclose(file); + ret = setxattr("com.ibm.os2.icon", "user.com.ibm.os2.icon", IconEA, 3516, XATTR_CREATE); + + if(ret) cRc = errno; + } + printf("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc); +#endif +} + +#endif \ No newline at end of file