2019-07-31 20:10:27 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2019-07-31 20:10:27 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : File.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : ISO9660 filesystem plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Handles file and extents.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library 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
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2019-07-31 20:19:22 +01:00
|
|
|
// In the loving memory of Facunda "Tata" Suárez Domínguez, R.I.P. 2019/07/24
|
2019-07-31 20:10:27 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2019-07-19 12:14:30 +01:00
|
|
|
using System;
|
2019-07-19 16:34:43 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
2019-07-20 00:38:59 +01:00
|
|
|
using System.IO;
|
2019-07-19 16:34:43 +01:00
|
|
|
using System.Linq;
|
2020-03-10 19:31:34 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
2020-06-21 21:40:15 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Structs;
|
2020-03-10 19:31:34 +00:00
|
|
|
using Aaru.Console;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Helpers;
|
|
|
|
|
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
|
2019-07-19 12:14:30 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class ISO9660
|
2019-07-19 12:14:30 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber MapBlock(string path, long fileBlock, out long deviceBlock)
|
2019-07-19 12:14:30 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
deviceBlock = 0;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2019-07-19 21:37:02 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
|
2019-07-19 21:37:02 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Directory) &&
|
|
|
|
|
!_debug)
|
|
|
|
|
return ErrorNumber.IsDirectory;
|
2019-07-19 21:37:02 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// TODO: Multi-extents
|
|
|
|
|
if(entry.Extents.Count > 1)
|
|
|
|
|
return ErrorNumber.NotImplemented;
|
2019-07-31 19:39:55 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
deviceBlock = entry.Extents[0].extent + fileBlock;
|
2019-07-19 21:37:02 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-07-19 12:14:30 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetAttributes(string path, out FileAttributes attributes)
|
|
|
|
|
{
|
|
|
|
|
attributes = new FileAttributes();
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2019-07-19 16:35:27 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber err = Stat(path, out FileEntryInfo stat);
|
2019-07-19 16:35:27 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
2019-07-19 16:35:27 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
attributes = stat.Attributes;
|
2019-07-19 16:35:27 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-07-19 12:14:30 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// TODO: Resolve symbolic link
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
{
|
|
|
|
|
buf = null;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2019-07-20 00:38:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
|
2019-07-20 00:38:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Directory) &&
|
|
|
|
|
!_debug)
|
|
|
|
|
return ErrorNumber.IsDirectory;
|
2019-07-20 00:38:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Extents is null)
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2019-07-31 19:39:55 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Size == 0)
|
|
|
|
|
{
|
|
|
|
|
buf = Array.Empty<byte>();
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-07-20 00:38:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(offset >= (long)entry.Size)
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2019-07-29 04:43:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(size + offset >= (long)entry.Size)
|
|
|
|
|
size = (long)entry.Size - offset;
|
2019-07-31 04:33:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
offset += entry.XattrLength * _blockSize;
|
2019-07-29 04:43:49 +01:00
|
|
|
|
2022-11-13 21:14:18 +00:00
|
|
|
if(entry.CdiSystemArea?.attributes.HasFlag(CdiAttributes.DigitalAudio) != true ||
|
|
|
|
|
entry.Extents.Count != 1)
|
|
|
|
|
return ReadWithExtents(offset, size, entry.Extents,
|
|
|
|
|
entry.XA?.signature == XA_MAGIC &&
|
|
|
|
|
entry.XA?.attributes.HasFlag(XaAttributes.Interleaved) == true,
|
|
|
|
|
entry.XA?.filenumber ?? 0, out buf);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
long firstSector = offset / 2352;
|
|
|
|
|
long offsetInSector = offset % 2352;
|
|
|
|
|
long sizeInSectors = (size + offsetInSector) / 2352;
|
|
|
|
|
|
|
|
|
|
if((size + offsetInSector) % 2352 > 0)
|
|
|
|
|
sizeInSectors++;
|
|
|
|
|
|
|
|
|
|
ErrorNumber errno = _image.ReadSectorsLong((ulong)(entry.Extents[0].extent + firstSector),
|
|
|
|
|
(uint)sizeInSectors, out byte[] buffer);
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
|
|
buf = new byte[size];
|
|
|
|
|
Array.Copy(buffer, offsetInSector, buf, 0, size);
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
AaruConsole.DebugWriteLine("ISO9660 plugin", Localization.Exception_reading_CD_i_audio_file);
|
2022-11-13 21:14:18 +00:00
|
|
|
AaruConsole.DebugWriteLine("ISO9660 plugin", "{0}", e);
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.UnexpectedException;
|
|
|
|
|
}
|
2020-03-10 19:31:34 +00:00
|
|
|
|
2022-05-21 18:52:42 +01:00
|
|
|
return ReadWithExtents(offset, size, entry.Extents,
|
|
|
|
|
entry.XA?.signature == XA_MAGIC &&
|
|
|
|
|
entry.XA?.attributes.HasFlag(XaAttributes.Interleaved) == true,
|
|
|
|
|
entry.XA?.filenumber ?? 0, out buf);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2019-07-19 12:14:30 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Stat(string path, out FileEntryInfo stat)
|
|
|
|
|
{
|
|
|
|
|
stat = null;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat = new FileEntryInfo
|
|
|
|
|
{
|
|
|
|
|
Attributes = new FileAttributes(),
|
|
|
|
|
Blocks = (long)(entry.Size / 2048), // TODO: XA
|
|
|
|
|
BlockSize = 2048,
|
|
|
|
|
Length = (long)entry.Size,
|
|
|
|
|
Links = 1,
|
|
|
|
|
LastWriteTimeUtc = entry.Timestamp
|
|
|
|
|
};
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Extents?.Count > 0)
|
|
|
|
|
stat.Inode = entry.Extents[0].extent;
|
2020-04-18 20:49:46 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Size % 2048 > 0)
|
|
|
|
|
stat.Blocks++;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Directory))
|
|
|
|
|
stat.Attributes |= FileAttributes.Directory;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.Flags.HasFlag(FileFlags.Hidden))
|
|
|
|
|
stat.Attributes |= FileAttributes.Hidden;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsAlias) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.Alias;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsInvisible) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.Hidden;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBeenInited) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.HasBeenInited;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasCustomIcon) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.HasCustomIcon;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasNoINITs) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.HasNoINITs;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsOnDesk) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.IsOnDesk;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsShared) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.Shared;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsStationery) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.Stationery;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.FinderInfo?.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBundle) == true)
|
|
|
|
|
stat.Attributes |= FileAttributes.Bundle;
|
2019-07-28 13:41:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AppleIcon != null)
|
|
|
|
|
stat.Attributes |= FileAttributes.HasCustomIcon;
|
2019-07-28 13:41:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA != null)
|
|
|
|
|
{
|
|
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.GroupExecute))
|
|
|
|
|
stat.Mode |= 8;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.GroupRead))
|
|
|
|
|
stat.Mode |= 32;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.OwnerExecute))
|
|
|
|
|
stat.Mode |= 64;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.OwnerRead))
|
|
|
|
|
stat.Mode |= 256;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.SystemExecute))
|
|
|
|
|
stat.Mode |= 1;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XA.Value.attributes.HasFlag(XaAttributes.SystemRead))
|
|
|
|
|
stat.Mode |= 4;
|
2019-07-28 16:48:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.UID = entry.XA.Value.user;
|
|
|
|
|
stat.GID = entry.XA.Value.group;
|
|
|
|
|
stat.Inode = entry.XA.Value.filenumber;
|
|
|
|
|
}
|
2019-07-28 16:48:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes != null)
|
|
|
|
|
{
|
|
|
|
|
stat.Mode = (uint?)entry.PosixAttributes.Value.st_mode & 0x0FFF;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes.Value.st_mode.HasFlag(PosixMode.Block))
|
|
|
|
|
stat.Attributes |= FileAttributes.BlockDevice;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes.Value.st_mode.HasFlag(PosixMode.Character))
|
|
|
|
|
stat.Attributes |= FileAttributes.CharDevice;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes.Value.st_mode.HasFlag(PosixMode.Pipe))
|
|
|
|
|
stat.Attributes |= FileAttributes.Pipe;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes.Value.st_mode.HasFlag(PosixMode.Socket))
|
|
|
|
|
stat.Attributes |= FileAttributes.Socket;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributes.Value.st_mode.HasFlag(PosixMode.Symlink))
|
|
|
|
|
stat.Attributes |= FileAttributes.Symlink;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.Links = entry.PosixAttributes.Value.st_nlink;
|
|
|
|
|
stat.UID = entry.PosixAttributes.Value.st_uid;
|
|
|
|
|
stat.GID = entry.PosixAttributes.Value.st_gid;
|
|
|
|
|
stat.Inode = entry.PosixAttributes.Value.st_ino;
|
|
|
|
|
}
|
|
|
|
|
else if(entry.PosixAttributesOld != null)
|
|
|
|
|
{
|
|
|
|
|
stat.Mode = (uint?)entry.PosixAttributesOld.Value.st_mode & 0x0FFF;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributesOld.Value.st_mode.HasFlag(PosixMode.Block))
|
|
|
|
|
stat.Attributes |= FileAttributes.BlockDevice;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributesOld.Value.st_mode.HasFlag(PosixMode.Character))
|
|
|
|
|
stat.Attributes |= FileAttributes.CharDevice;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributesOld.Value.st_mode.HasFlag(PosixMode.Pipe))
|
|
|
|
|
stat.Attributes |= FileAttributes.Pipe;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributesOld.Value.st_mode.HasFlag(PosixMode.Socket))
|
|
|
|
|
stat.Attributes |= FileAttributes.Socket;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixAttributesOld.Value.st_mode.HasFlag(PosixMode.Symlink))
|
|
|
|
|
stat.Attributes |= FileAttributes.Symlink;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.Links = entry.PosixAttributesOld.Value.st_nlink;
|
|
|
|
|
stat.UID = entry.PosixAttributesOld.Value.st_uid;
|
|
|
|
|
stat.GID = entry.PosixAttributesOld.Value.st_gid;
|
|
|
|
|
}
|
2019-07-28 17:46:09 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection != null)
|
|
|
|
|
{
|
|
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupExec))
|
|
|
|
|
stat.Mode |= 8;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupRead))
|
|
|
|
|
stat.Mode |= 32;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupWrite))
|
|
|
|
|
stat.Mode |= 16;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherExec))
|
|
|
|
|
stat.Mode |= 1;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherRead))
|
|
|
|
|
stat.Mode |= 4;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherWrite))
|
|
|
|
|
stat.Mode |= 2;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerExec))
|
|
|
|
|
stat.Mode |= 64;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerRead))
|
|
|
|
|
stat.Mode |= 256;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerWrite))
|
|
|
|
|
stat.Mode |= 128;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.Archive))
|
|
|
|
|
stat.Attributes |= FileAttributes.Archive;
|
|
|
|
|
}
|
2019-07-28 17:29:45 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.PosixDeviceNumber != null)
|
|
|
|
|
stat.DeviceNo = ((ulong)entry.PosixDeviceNumber.Value.dev_t_high << 32) +
|
|
|
|
|
entry.PosixDeviceNumber.Value.dev_t_low;
|
2019-07-28 17:54:40 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.RripModify != null)
|
|
|
|
|
stat.LastWriteTimeUtc = DecodeIsoDateTime(entry.RripModify);
|
2019-07-28 18:32:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.RripAccess != null)
|
|
|
|
|
stat.AccessTimeUtc = DecodeIsoDateTime(entry.RripAccess);
|
2019-07-28 18:32:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.RripAttributeChange != null)
|
|
|
|
|
stat.StatusChangeTimeUtc = DecodeIsoDateTime(entry.RripAttributeChange);
|
2019-07-28 18:32:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.RripBackup != null)
|
|
|
|
|
stat.BackupTimeUtc = DecodeIsoDateTime(entry.RripBackup);
|
2019-07-28 18:32:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.SymbolicLink != null)
|
|
|
|
|
stat.Attributes |= FileAttributes.Symlink;
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.XattrLength == 0 ||
|
|
|
|
|
_cdi ||
|
|
|
|
|
_highSierra)
|
|
|
|
|
return ErrorNumber.NoError;
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea != null)
|
|
|
|
|
{
|
|
|
|
|
stat.UID = entry.CdiSystemArea.Value.owner;
|
|
|
|
|
stat.GID = entry.CdiSystemArea.Value.group;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.GroupExecute))
|
|
|
|
|
stat.Mode |= 8;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.GroupRead))
|
|
|
|
|
stat.Mode |= 32;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.OtherExecute))
|
|
|
|
|
stat.Mode |= 1;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.OtherRead))
|
|
|
|
|
stat.Mode |= 4;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.OwnerExecute))
|
|
|
|
|
stat.Mode |= 64;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.OwnerRead))
|
|
|
|
|
stat.Mode |= 256;
|
|
|
|
|
}
|
2019-07-31 17:44:51 +01:00
|
|
|
|
2022-05-21 18:52:42 +01:00
|
|
|
ErrorNumber errno = ReadSingleExtent(entry.XattrLength * _blockSize, entry.Extents[0].extent, out byte[] ea);
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
return ErrorNumber.NoError;
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ExtendedAttributeRecord ear = Marshal.ByteArrayToStructureLittleEndian<ExtendedAttributeRecord>(ea);
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.UID = ear.owner;
|
|
|
|
|
stat.GID = ear.group;
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.Mode = 0;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.GroupExecute))
|
|
|
|
|
stat.Mode |= 8;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.GroupRead))
|
|
|
|
|
stat.Mode |= 32;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.OwnerExecute))
|
|
|
|
|
stat.Mode |= 64;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.OwnerRead))
|
|
|
|
|
stat.Mode |= 256;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.OtherExecute))
|
|
|
|
|
stat.Mode |= 1;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ear.permissions.HasFlag(Permissions.OtherRead))
|
|
|
|
|
stat.Mode |= 4;
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.CreationTimeUtc = DateHandlers.Iso9660ToDateTime(ear.creation_date);
|
|
|
|
|
stat.LastWriteTimeUtc = DateHandlers.Iso9660ToDateTime(ear.modification_date);
|
2019-07-22 01:53:12 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber ReadLink(string path, out string dest)
|
|
|
|
|
{
|
|
|
|
|
dest = null;
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(entry.SymbolicLink is null)
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
dest = entry.SymbolicLink;
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-07-28 21:33:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ErrorNumber GetFileEntry(string path, out DecodedDirectoryEntry entry)
|
|
|
|
|
{
|
|
|
|
|
entry = null;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
|
2022-11-14 01:15:06 +00:00
|
|
|
? path[1..].ToLower(CultureInfo.CurrentUICulture)
|
2022-03-06 13:29:38 +00:00
|
|
|
: path.ToLower(CultureInfo.CurrentUICulture);
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string[] pieces = cutPath.Split(new[]
|
|
|
|
|
{
|
|
|
|
|
'/'
|
|
|
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(pieces.Length == 0)
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
string parentPath = string.Join("/", pieces, 0, pieces.Length - 1);
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_directoryCache.TryGetValue(parentPath, out _))
|
|
|
|
|
{
|
|
|
|
|
ErrorNumber err = ReadDir(parentPath, out _);
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(err != ErrorNumber.NoError)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Dictionary<string, DecodedDirectoryEntry> parent;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(pieces.Length == 1)
|
|
|
|
|
parent = _rootDirectoryCache;
|
|
|
|
|
else if(!_directoryCache.TryGetValue(parentPath, out parent))
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
KeyValuePair<string, DecodedDirectoryEntry> dirent =
|
|
|
|
|
parent.FirstOrDefault(t => t.Key.ToLower(CultureInfo.CurrentUICulture) == pieces[^1]);
|
2019-07-19 16:34:43 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(string.IsNullOrEmpty(dirent.Key))
|
|
|
|
|
{
|
|
|
|
|
if(!_joliet &&
|
|
|
|
|
!pieces[^1].EndsWith(";1", StringComparison.Ordinal))
|
2019-07-24 05:28:48 +01:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
dirent = parent.FirstOrDefault(t => t.Key.ToLower(CultureInfo.CurrentUICulture) == pieces[^1] + ";1");
|
2019-07-24 05:28:48 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(string.IsNullOrEmpty(dirent.Key))
|
2021-09-16 04:42:14 +01:00
|
|
|
return ErrorNumber.NoSuchFile;
|
2019-07-24 05:28:48 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
else
|
|
|
|
|
return ErrorNumber.NoSuchFile;
|
2019-07-19 16:34:43 +01:00
|
|
|
}
|
2019-07-31 19:39:55 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
entry = dirent.Value;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2020-11-07 01:17:06 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2022-05-21 18:52:42 +01:00
|
|
|
ErrorNumber ReadSingleExtent(long size, uint startingSector, out byte[] buffer, bool interleaved = false,
|
|
|
|
|
byte fileNumber = 0) => ReadWithExtents(0, size, new List<(uint extent, uint size)>
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
(startingSector, (uint)size)
|
2022-05-21 18:52:42 +01:00
|
|
|
}, interleaved, fileNumber, out buffer);
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
ErrorNumber ReadSingleExtent(long offset, long size, uint startingSector, out byte[] buffer,
|
|
|
|
|
bool interleaved = false, byte fileNumber = 0) => ReadWithExtents(offset, size,
|
|
|
|
|
new List<(uint extent, uint size)>
|
|
|
|
|
{
|
|
|
|
|
(startingSector, (uint)size)
|
|
|
|
|
}, interleaved, fileNumber, out buffer);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
// Cannot think how to make this faster, as we don't know the mode sector until it is read, but we have size in bytes
|
2022-05-21 18:52:42 +01:00
|
|
|
ErrorNumber ReadWithExtents(long offset, long size, List<(uint extent, uint size)> extents, bool interleaved,
|
|
|
|
|
byte fileNumber, out byte[] buffer)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
var ms = new MemoryStream();
|
|
|
|
|
long currentFilePos = 0;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
for(int i = 0; i < extents.Count; i++)
|
2019-07-31 19:39:55 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(offset - currentFilePos >= extents[i].size)
|
|
|
|
|
{
|
|
|
|
|
currentFilePos += extents[i].size;
|
2019-07-31 19:39:55 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long leftExtentSize = extents[i].size;
|
|
|
|
|
uint currentExtentSector = 0;
|
|
|
|
|
|
|
|
|
|
while(leftExtentSize > 0)
|
2019-07-31 19:39:55 +01:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
ErrorNumber errno = ReadSector(extents[i].extent + currentExtentSector, out byte[] sector, interleaved,
|
|
|
|
|
fileNumber);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-05-21 18:52:42 +01:00
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
{
|
|
|
|
|
buffer = ms.ToArray();
|
|
|
|
|
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(sector is null)
|
2019-07-31 19:39:55 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
currentExtentSector++;
|
2022-05-21 18:52:42 +01:00
|
|
|
leftExtentSize -= 2048;
|
|
|
|
|
currentFilePos += 2048;
|
2020-02-19 01:20:23 +00:00
|
|
|
|
2019-07-31 19:39:55 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(offset - currentFilePos > sector.Length)
|
2019-07-31 19:39:55 +01:00
|
|
|
{
|
|
|
|
|
currentExtentSector++;
|
|
|
|
|
leftExtentSize -= sector.Length;
|
|
|
|
|
currentFilePos += sector.Length;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
2019-07-31 19:39:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(offset - currentFilePos > 0)
|
2022-03-07 07:36:44 +00:00
|
|
|
ms.Write(sector, (int)(offset - currentFilePos), (int)(sector.Length - (offset - currentFilePos)));
|
2022-03-06 13:29:38 +00:00
|
|
|
else
|
|
|
|
|
ms.Write(sector, 0, sector.Length);
|
|
|
|
|
|
|
|
|
|
currentExtentSector++;
|
|
|
|
|
leftExtentSize -= sector.Length;
|
|
|
|
|
currentFilePos += sector.Length;
|
|
|
|
|
|
2020-02-19 01:20:23 +00:00
|
|
|
if(ms.Length >= size)
|
|
|
|
|
break;
|
2019-07-31 19:39:55 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-19 01:20:23 +00:00
|
|
|
if(ms.Length >= size)
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2019-07-31 19:39:55 +01:00
|
|
|
}
|
2020-06-21 21:40:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ms.Length >= size)
|
|
|
|
|
ms.SetLength(size);
|
|
|
|
|
|
2022-05-21 18:52:42 +01:00
|
|
|
buffer = ms.ToArray();
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] ReadSubheaderWithExtents(List<(uint extent, uint size)> extents, bool copy)
|
|
|
|
|
{
|
|
|
|
|
var ms = new MemoryStream();
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
for(int i = 0; i < extents.Count; i++)
|
2020-06-21 21:40:15 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
long leftExtentSize = extents[i].size;
|
|
|
|
|
uint currentExtentSector = 0;
|
2020-06-21 21:40:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
while(leftExtentSize > 0)
|
2020-06-21 21:40:15 +01:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
ErrorNumber errno = _image.ReadSectorTag((extents[i].extent + currentExtentSector) * _blockSize / 2048,
|
|
|
|
|
SectorTagType.CdSectorSubHeader, out byte[] fullSector);
|
2020-06-21 21:40:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
return null;
|
2021-09-20 20:52:18 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ms.Write(fullSector, copy ? 0 : 4, 4);
|
2020-06-21 21:40:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
currentExtentSector++;
|
|
|
|
|
leftExtentSize -= 2048;
|
2020-06-21 21:40:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return ms.ToArray();
|
2019-07-19 12:14:30 +01:00
|
|
|
}
|
|
|
|
|
}
|