Consolidate error number enumerations.

This commit is contained in:
2021-09-16 04:42:14 +01:00
parent a615cde12e
commit 12a72a45e4
78 changed files with 945 additions and 906 deletions

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
@@ -42,24 +43,24 @@ namespace Aaru.Filesystems
public sealed partial class AppleDOS
{
/// <inheritdoc />
public Errno ReadLink(string path, out string dest)
public ErrorNumber ReadLink(string path, out string dest)
{
dest = null;
return !_mounted ? Errno.AccessDenied : Errno.NotSupported;
return !_mounted ? ErrorNumber.AccessDenied : ErrorNumber.NotSupported;
}
/// <inheritdoc />
public Errno ReadDir(string path, out List<string> contents)
public ErrorNumber ReadDir(string path, out List<string> contents)
{
contents = null;
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
if(!string.IsNullOrEmpty(path) &&
string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
contents = _catalogCache.Keys.ToList();
@@ -72,10 +73,10 @@ namespace Aaru.Filesystems
contents.Sort();
return Errno.NoError;
return ErrorNumber.NoError;
}
Errno ReadCatalog()
ErrorNumber ReadCatalog()
{
var catalogMs = new MemoryStream();
ulong lba = (ulong)((_vtoc.catalogTrack * _sectorsPerTrack) + _vtoc.catalogSector);
@@ -87,7 +88,7 @@ namespace Aaru.Filesystems
if(lba == 0 ||
lba > _device.Info.Sectors)
return Errno.InvalidArgument;
return ErrorNumber.InvalidArgument;
while(lba != 0)
{
@@ -138,7 +139,7 @@ namespace Aaru.Filesystems
if(_debug)
_catalogBlocks = catalogMs.ToArray();
return Errno.NoError;
return ErrorNumber.NoError;
}
}
}

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
@@ -43,12 +44,12 @@ namespace Aaru.Filesystems
public sealed partial class AppleDOS
{
/// <inheritdoc />
public Errno GetAttributes(string path, out FileAttributes attributes)
public ErrorNumber GetAttributes(string path, out FileAttributes attributes)
{
attributes = new FileAttributes();
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
@@ -56,12 +57,12 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
string filename = pathElements[0].ToUpperInvariant();
if(!_fileCache.ContainsKey(filename))
return Errno.NoSuchFile;
return ErrorNumber.NoSuchFile;
attributes = FileAttributes.Extents;
attributes |= FileAttributes.File;
@@ -74,14 +75,14 @@ namespace Aaru.Filesystems
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
attributes |= FileAttributes.System;
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno Read(string path, long offset, long size, ref byte[] buf)
public ErrorNumber Read(string path, long offset, long size, ref byte[] buf)
{
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
@@ -89,13 +90,13 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
byte[] file;
string filename = pathElements[0].ToUpperInvariant();
if(filename.Length > 30)
return Errno.NameTooLong;
return ErrorNumber.NameTooLong;
if(_debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
@@ -110,18 +111,18 @@ namespace Aaru.Filesystems
{
if(!_fileCache.TryGetValue(filename, out file))
{
Errno error = CacheFile(filename);
ErrorNumber error = CacheFile(filename);
if(error != Errno.NoError)
if(error != ErrorNumber.NoError)
return error;
if(!_fileCache.TryGetValue(filename, out file))
return Errno.InvalidArgument;
return ErrorNumber.InvalidArgument;
}
}
if(offset >= file.Length)
return Errno.InvalidArgument;
return ErrorNumber.InvalidArgument;
if(size + offset >= file.Length)
size = file.Length - offset;
@@ -130,16 +131,16 @@ namespace Aaru.Filesystems
Array.Copy(file, offset, buf, 0, size);
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno Stat(string path, out FileEntryInfo stat)
public ErrorNumber Stat(string path, out FileEntryInfo stat)
{
stat = null;
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
@@ -147,15 +148,15 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
string filename = pathElements[0].ToUpperInvariant();
if(filename.Length > 30)
return Errno.NameTooLong;
return ErrorNumber.NameTooLong;
if(!_fileCache.ContainsKey(filename))
return Errno.NoSuchFile;
return ErrorNumber.NoSuchFile;
stat = new FileEntryInfo();
@@ -185,19 +186,19 @@ namespace Aaru.Filesystems
stat.BlockSize = _vtoc.bytesPerSector;
stat.Links = 1;
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno MapBlock(string path, long fileBlock, out long deviceBlock)
public ErrorNumber MapBlock(string path, long fileBlock, out long deviceBlock)
{
deviceBlock = 0;
// TODO: Not really important.
return !_mounted ? Errno.AccessDenied : Errno.NotImplemented;
return !_mounted ? ErrorNumber.AccessDenied : ErrorNumber.NotImplemented;
}
Errno CacheFile(string path)
ErrorNumber CacheFile(string path)
{
string[] pathElements = path.Split(new[]
{
@@ -205,15 +206,15 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
string filename = pathElements[0].ToUpperInvariant();
if(filename.Length > 30)
return Errno.NameTooLong;
return ErrorNumber.NameTooLong;
if(!_catalogCache.TryGetValue(filename, out ushort ts))
return Errno.NoSuchFile;
return ErrorNumber.NoSuchFile;
ulong lba = (ulong)((((ts & 0xFF00) >> 8) * _sectorsPerTrack) + (ts & 0xFF));
var fileMs = new MemoryStream();
@@ -266,15 +267,16 @@ namespace Aaru.Filesystems
_fileCache.Add(filename, fileMs.ToArray());
_extentCache.Add(filename, tsListMs.ToArray());
return Errno.NoError;
return ErrorNumber.NoError;
}
Errno CacheAllFiles()
ErrorNumber CacheAllFiles()
{
_fileCache = new Dictionary<string, byte[]>();
_extentCache = new Dictionary<string, byte[]>();
foreach(Errno error in _catalogCache.Keys.Select(CacheFile).Where(error => error != Errno.NoError))
foreach(ErrorNumber error in _catalogCache.Keys.Select(CacheFile).
Where(error => error != ErrorNumber.NoError))
return error;
uint tracksOnBoot = 1;
@@ -288,7 +290,7 @@ namespace Aaru.Filesystems
_bootBlocks = _device.ReadSectors(0, (uint)(tracksOnBoot * _sectorsPerTrack));
_usedSectors += (uint)(_bootBlocks.Length / _vtoc.bytesPerSector);
return Errno.NoError;
return ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Console;
@@ -45,8 +46,8 @@ namespace Aaru.Filesystems
public sealed partial class AppleDOS
{
/// <inheritdoc />
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
Dictionary<string, string> options, string @namespace)
public ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
Dictionary<string, string> options, string @namespace)
{
_device = imagePlugin;
_start = partition.Start;
@@ -57,21 +58,21 @@ namespace Aaru.Filesystems
{
AaruConsole.DebugWriteLine("Apple DOS plugin", "Incorrect device size.");
return Errno.InOutError;
return ErrorNumber.InOutError;
}
if(_start > 0)
{
AaruConsole.DebugWriteLine("Apple DOS plugin", "Partitions are not supported.");
return Errno.InOutError;
return ErrorNumber.InOutError;
}
if(_device.Info.SectorSize != 256)
{
AaruConsole.DebugWriteLine("Apple DOS plugin", "Incorrect sector size.");
return Errno.InOutError;
return ErrorNumber.InOutError;
}
_sectorsPerTrack = _device.Info.Sectors == 455 ? 13 : 16;
@@ -84,9 +85,9 @@ namespace Aaru.Filesystems
_track2UsedByFiles = false;
_usedSectors = 1;
Errno error = ReadCatalog();
ErrorNumber error = ReadCatalog();
if(error != Errno.NoError)
if(error != ErrorNumber.NoError)
{
AaruConsole.DebugWriteLine("Apple DOS plugin", "Unable to read catalog.");
@@ -95,7 +96,7 @@ namespace Aaru.Filesystems
error = CacheAllFiles();
if(error != Errno.NoError)
if(error != ErrorNumber.NoError)
{
AaruConsole.DebugWriteLine("Apple DOS plugin", "Unable cache all files.");
@@ -123,11 +124,11 @@ namespace Aaru.Filesystems
_mounted = true;
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno Unmount()
public ErrorNumber Unmount()
{
_mounted = false;
_extentCache = null;
@@ -135,11 +136,11 @@ namespace Aaru.Filesystems
_catalogCache = null;
_fileSizeCache = null;
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno StatFs(out FileSystemInfo stat)
public ErrorNumber StatFs(out FileSystemInfo stat)
{
stat = new FileSystemInfo
{
@@ -153,7 +154,7 @@ namespace Aaru.Filesystems
stat.FreeFiles = _totalFileEntries - stat.Files;
stat.FreeBlocks = stat.Blocks - _usedSectors;
return Errno.NoError;
return ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs;
namespace Aaru.Filesystems
@@ -39,12 +40,12 @@ namespace Aaru.Filesystems
public sealed partial class AppleDOS
{
/// <inheritdoc />
public Errno ListXAttr(string path, out List<string> xattrs)
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
{
xattrs = null;
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
@@ -52,12 +53,12 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
string filename = pathElements[0].ToUpperInvariant();
if(filename.Length > 30)
return Errno.NameTooLong;
return ErrorNumber.NameTooLong;
xattrs = new List<string>();
@@ -67,7 +68,7 @@ namespace Aaru.Filesystems
else
{
if(!_catalogCache.ContainsKey(filename))
return Errno.NoSuchFile;
return ErrorNumber.NoSuchFile;
xattrs.Add("com.apple.dos.type");
@@ -75,14 +76,14 @@ namespace Aaru.Filesystems
xattrs.Add("com.apple.dos.tracksectorlist");
}
return Errno.NoError;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public Errno GetXattr(string path, string xattr, ref byte[] buf)
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
{
if(!_mounted)
return Errno.AccessDenied;
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
@@ -90,43 +91,43 @@ namespace Aaru.Filesystems
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
return ErrorNumber.NotSupported;
string filename = pathElements[0].ToUpperInvariant();
if(filename.Length > 30)
return Errno.NameTooLong;
return ErrorNumber.NameTooLong;
if(_debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
return Errno.NoSuchExtendedAttribute;
return ErrorNumber.NoSuchExtendedAttribute;
if(!_catalogCache.ContainsKey(filename))
return Errno.NoSuchFile;
return ErrorNumber.NoSuchFile;
if(string.Compare(xattr, "com.apple.dos.type", StringComparison.InvariantCulture) == 0)
{
if(!_fileTypeCache.TryGetValue(filename, out byte type))
return Errno.InvalidArgument;
return ErrorNumber.InvalidArgument;
buf = new byte[1];
buf[0] = type;
return Errno.NoError;
return ErrorNumber.NoError;
}
if(string.Compare(xattr, "com.apple.dos.tracksectorlist", StringComparison.InvariantCulture) != 0 ||
!_debug)
return Errno.NoSuchExtendedAttribute;
return ErrorNumber.NoSuchExtendedAttribute;
if(!_extentCache.TryGetValue(filename, out byte[] ts))
return Errno.InvalidArgument;
return ErrorNumber.InvalidArgument;
buf = new byte[ts.Length];
Array.Copy(ts, 0, buf, 0, buf.Length);
return Errno.NoError;
return ErrorNumber.NoError;
}
}
}