Set DOS attributes using a for loop instead of repeating code.

This commit is contained in:
2021-03-11 04:20:58 +00:00
parent 55a32327b1
commit dc69ae015a
15 changed files with 105 additions and 294 deletions

View File

@@ -6,7 +6,7 @@ project(fssetter-dos
DESCRIPTION "Filesystem test creator for DOS"
LANGUAGES C)
set(PLATFORM_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 dos.c)
set(PLATFORM_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 dos.c attr.h)
set(EXECUTABLE_NAME "fssetter")

View File

@@ -40,7 +40,7 @@ Copyright (C) 2011-2021 Natalia Portillo
#endif
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "attr.h"
#include "dos.h"
void FileAttributes(const char* path)
@@ -48,6 +48,7 @@ void FileAttributes(const char* path)
char driveNo = path[0] - '@';
unsigned total, actionTaken;
int rc, wRc, cRc, handle;
int i;
if(driveNo > 32) driveNo -= 32;
@@ -66,243 +67,19 @@ void FileAttributes(const char* path)
printf("Creating attributes files.\n");
rc = _dos_creat("NONE", 0, &handle);
if(!rc)
for(i = 0; i < KNOWN_DOS_ATTRS; i++)
{
wRc = _dos_write(handle, (void*)noAttributeText, strlen(noAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("NONE", _A_NORMAL);
rc = _dos_creat(dos_attrs[i].filename, _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)dos_attrs[i].contents, strlen(dos_attrs[i].contents), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr(dos_attrs[i].filename, dos_attrs[i].attr);
}
printf("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", dos_attrs[i].description, dos_attrs[i].filename, rc, wRc, cRc);
}
printf("\tFile with no attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "NONE", rc, wRc, cRc);
rc = _dos_creat("ARCHIVE", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCHIVE", _A_ARCH);
}
printf("\tFile with archived attribute: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "ARCHIVE", rc, wRc, cRc);
rc = _dos_creat("SYSTEM", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("SYSTEM", _A_SYSTEM);
}
printf("\tFile with system attribute: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "SYSTEM", rc, wRc, cRc);
rc = _dos_creat("HIDDEN", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("HIDDEN", _A_HIDDEN);
}
printf("\tFile with hidden attribute: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "HIDDEN", rc, wRc, cRc);
rc = _dos_creat("READONLY", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("READONLY", _A_RDONLY);
}
printf("\tFile with read-only attribute: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "READONLY", rc, wRc, cRc);
rc = _dos_creat("HIDDREAD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("HIDDREAD", _A_HIDDEN | _A_RDONLY);
}
printf("\tFile with hidden, read-only attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"HIDDREAD",
rc,
wRc,
cRc);
rc = _dos_creat("SYSTREAD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("SYSTREAD", _A_SYSTEM | _A_RDONLY);
}
printf("\tFile with system, read-only attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"SYSTREAD",
rc,
wRc,
cRc);
rc = _dos_creat("SYSTHIDD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("SYSTHIDD", _A_SYSTEM | _A_HIDDEN);
}
printf("\tFile with system, hidden attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"SYSTHIDD",
rc,
wRc,
cRc);
rc = _dos_creat("SYSRDYHD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("SYSRDYHD", _A_SYSTEM | _A_RDONLY | _A_HIDDEN);
}
printf("\tFile with system, read-only, hidden attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"SYSRDYHD",
rc,
wRc,
cRc);
rc = _dos_creat("ARCHREAD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCHREAD", _A_ARCH | _A_RDONLY);
}
printf("\tFile with archived, read-only attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARCHREAD",
rc,
wRc,
cRc);
rc = _dos_creat("ARCHHIDD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCHHIDD", _A_ARCH | _A_HIDDEN);
}
printf("\tFile with archived, hidden attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARCHHIDD",
rc,
wRc,
cRc);
rc = _dos_creat("ARCHDRDY", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCHDRDY", _A_ARCH | _A_HIDDEN | _A_RDONLY);
}
printf("\tFile with archived, hidden, read-only attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARCHDRDY",
rc,
wRc,
cRc);
rc = _dos_creat("ARCHSYST", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCHSYST", _A_ARCH | _A_SYSTEM);
}
printf("\tFile with archived, system attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARCHSYST",
rc,
wRc,
cRc);
rc = _dos_creat("ARSYSRDY", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARSYSRDY", _A_ARCH | _A_SYSTEM | _A_RDONLY);
}
printf("\tFile with archived, system, read-only attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARSYSRDY",
rc,
wRc,
cRc);
rc = _dos_creat("ARCSYSHD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARCSYSHD", _A_ARCH | _A_SYSTEM | _A_HIDDEN);
}
printf("\tFile with archived, system, hidden attributes: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n",
"ARCSYSHD",
rc,
wRc,
cRc);
rc = _dos_creat("ARSYHDRD", _A_NORMAL, &handle);
if(!rc)
{
wRc = _dos_write(handle, (void*)archivedAttributeText, strlen(archivedAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)systemAttributeText, strlen(systemAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)hiddenAttributeText, strlen(hiddenAttributeText), &actionTaken);
wRc = _dos_write(handle, (void*)readonlyAttributeText, strlen(readonlyAttributeText), &actionTaken);
cRc = _dos_close(handle);
rc = _dos_setfileattr("ARSYHDRD", _A_ARCH | _A_SYSTEM | _A_HIDDEN | _A_RDONLY);
}
printf("\tFile with all (archived, system, hidden, read-only) attributes: name = \"%s\", rc = %d, wRc = %d, cRc = "
"%d\n",
"ARSYHDRD",
rc,
wRc,
cRc);
}
#endif

85
setter/src/dos/attr.h Normal file
View File

@@ -0,0 +1,85 @@
/****************************************************************************
Aaru Data Preservation Suite
-----------------------------------------------------------------------------
Filename : dos.h
Author(s) : Natalia Portillo
--[ Description ] -----------------------------------------------------------
Contains DOS definitions
--[ 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
*****************************************************************************/
#if defined(__DOS__) || defined(MSDOS)
#ifndef SETTER_SRC_DOS_ATTR_H_
#define SETTER_SRC_DOS_ATTR_H_
#include <dos.h>
typedef struct
{
char filename[9];
char contents[170];
char description[63];
unsigned int attr;
} dos_attr_tests_t;
#define KNOWN_DOS_ATTRS 16
static const dos_attr_tests_t dos_attrs[KNOWN_DOS_ATTRS] = {
{"NONE", "This file has no attribute set.\n", "File with no attributes", _A_NORMAL},
{"ARCHIVE", "This file has the archived attribute set.\n", "File with archived attribute", _A_ARCH},
{"SYSTEM", "This file has the system attribute set.\n", "File with system attribute", _A_SYSTEM},
{"HIDDEN", "This file has the hidden attribute set.\n", "File with hidden attribute", _A_HIDDEN},
{"READONLY", "This file has the read-only attribute set.\n", "File with read-only attribute", _A_RDONLY},
{"HIDDREAD", "This file has the hidden attribute set.\n"
"This file has the read-only attribute set.\n", "File with hidden, read-only attributes", _A_HIDDEN | _A_RDONLY},
{"SYSTREAD", "This file has the system attribute set.\n"
"This file has the read-only attribute set.\n", "File with system, read-only attributes", _A_SYSTEM | _A_RDONLY},
{"SYSTHIDD", "This file has the system attribute set.\n"
"This file has the hidden attribute set.\n", "File with system, hidden attributes", _A_SYSTEM | _A_HIDDEN},
{"SYSRDYHD", "This file has the system attribute set.\n"
"This file has the read-only attribute set.\n"
"This file has the hidden attribute set.\n", "File with system, read-only, hidden attributes", _A_SYSTEM | _A_RDONLY | _A_HIDDEN},
{"ARCHREAD", "This file has the archived attribute set.\n"
"This file has the read-only attribute set.\n", "File with archived, read-only attributes", _A_ARCH | _A_RDONLY},
{"ARCHHIDD", "This file has the archived attribute set.\n"
"This file has the hidden attribute set.\n", "File with archived, hidden attributes", _A_ARCH | _A_HIDDEN},
{"ARCHDRDY", "This file has the archived attribute set.\n"
"This file has the hidden attribute set.\n"
"This file has the read-only attribute set.\n", "File with archived, hidden, read-only attributes", _A_ARCH | _A_HIDDEN | _A_RDONLY},
{"ARCHSYST", "This file has the archived attribute set.\n"
"This file has the system attribute set.\n", "File with archived, system attributes", _A_ARCH | _A_SYSTEM},
{"ARSYSRDY", "This file has the archived attribute set.\n"
"This file has the system attribute set.\n"
"This file has the read-only attribute set.\n", "File with archived, system, read-only attributes", _A_ARCH | _A_SYSTEM | _A_RDONLY},
{"ARCSYSHD", "This file has the archived attribute set.\n"
"This file has the system attribute set.\n"
"This file has the hidden attribute set.\n", "File with archived, system, hidden attributes", _A_ARCH | _A_SYSTEM | _A_HIDDEN},
{"ARSYHDRD", "This file has the archived attribute set.\n"
"This file has the system attribute set.\n"
"This file has the hidden attribute set.\n"
"This file has the read-only attribute set.\n", "File with all (archived, system, hidden, read-only) attributes", _A_ARCH | _A_SYSTEM | _A_HIDDEN | _A_RDONLY},
};
#endif // SETTER_SRC_DOS_ATTR_H_
#endif

View File

@@ -40,7 +40,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#endif
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void DeleteFiles(const char* path)

View File

@@ -29,12 +29,8 @@ Copyright (C) 2011-2021 Natalia Portillo
#if defined(__DOS__) || defined(MSDOS)
#include <direct.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__WATCOM__)
@@ -45,7 +41,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include "../include/consts.h"
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void DirectoryDepth(const char* path)

View File

@@ -41,7 +41,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include "../include/consts.h"
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void Filenames(const char* path)

View File

@@ -40,7 +40,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#endif
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void MillionFiles(const char* path)

View File

@@ -43,7 +43,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include "../include/consts.h"
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void Fragmentation(const char* path, size_t clusterSize)

View File

@@ -39,7 +39,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#endif
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void GetOsInfo()

View File

@@ -41,7 +41,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#endif
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
#define DATETIME_FORMAT "This file is dated %04d/%02d/%02d %02d:%02d:%02d for %s\n"

View File

@@ -36,7 +36,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include <errno.h>
#include "../include/defs.h"
#include "../include/dosos2.h"
#include "dos.h"
void GetVolumeInfo(const char* path, size_t* clusterSize)

View File

@@ -1,43 +0,0 @@
/****************************************************************************
Aaru Data Preservation Suite
-----------------------------------------------------------------------------
Filename : dosos2.h
Author(s) : Natalia Portillo
--[ Description ] -----------------------------------------------------------
Contains definitions common to DOS and OS/2
--[ 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
*****************************************************************************/
#if defined(__OS2__) || defined(__os2__) || defined(__DOS__) || defined(MSDOS)
#ifndef AARU_FSTESTER_SETTER_DOSOS2_H
#define AARU_FSTESTER_SETTER_DOSOS2_H
const char *archivedAttributeText = "This file has the archived attribute set.\n";
const char *systemAttributeText = "This file has the system attribute set.\n";
const char *hiddenAttributeText = "This file has the hidden attribute set.\n";
const char *readonlyAttributeText = "This file has the read-only attribute set.\n";
const char *noAttributeText = "This file has no attribute set.\n";
#endif
#endif

View File

@@ -40,7 +40,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include "os2_16.h"
#include "dosos2.h"
#include "include/consts.h"
#include "include/defs.h"

View File

@@ -242,6 +242,12 @@ unsigned char IconEA[3516] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00};
const char *archivedAttributeText = "This file has the archived attribute set.\n";
const char *systemAttributeText = "This file has the system attribute set.\n";
const char *hiddenAttributeText = "This file has the hidden attribute set.\n";
const char *readonlyAttributeText = "This file has the read-only attribute set.\n";
const char *noAttributeText = "This file has no attribute set.\n";
#endif
#endif

View File

@@ -38,7 +38,6 @@ Copyright (C) 2011-2021 Natalia Portillo
#include <stdlib.h>
#include <string.h>
#include "dosos2.h"
#include "include/consts.h"
#include "include/defs.h"
#include "os2_16.h"