-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CBMFS] Implement full support for mounting, reading and extracting C…
…ommodore 1540/1541/1571/1581 filesystems.
- Loading branch information
Showing
9 changed files
with
750 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// /*************************************************************************** | ||
// Aaru Data Preservation Suite | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// Filename : CBM.cs | ||
// Author(s) : Natalia Portillo <claunia@claunia.com> | ||
// | ||
// Component : Commodore file system plugin. | ||
// | ||
// --[ 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/>. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// Copyright © 2011-2023 Natalia Portillo | ||
// ****************************************************************************/ | ||
|
||
using System; | ||
using System.Linq; | ||
using Aaru.CommonTypes.Enums; | ||
using Aaru.CommonTypes.Interfaces; | ||
|
||
namespace Aaru.Filesystems; | ||
|
||
/// <inheritdoc /> | ||
/// <summary>Implements detection of the filesystem used in 8-bit Commodore microcomputers</summary> | ||
public sealed partial class CBM | ||
{ | ||
#region IReadOnlyFilesystem Members | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber OpenDir(string path, out IDirNode node) | ||
{ | ||
node = null; | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0) | ||
return ErrorNumber.NotSupported; | ||
|
||
var contents = _cache.Keys.ToList(); | ||
|
||
contents.Sort(); | ||
|
||
node = new CbmDirNode | ||
{ | ||
Path = path, Position = 0, Contents = contents.ToArray() | ||
}; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber CloseDir(IDirNode node) | ||
{ | ||
if(node is not CbmDirNode mynode) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
mynode.Position = -1; | ||
mynode.Contents = null; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber ReadDir(IDirNode node, out string filename) | ||
{ | ||
filename = null; | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
if(node is not CbmDirNode mynode) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
if(mynode.Position < 0) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
if(mynode.Position >= mynode.Contents.Length) | ||
return ErrorNumber.NoError; | ||
|
||
filename = mynode.Contents[mynode.Position++]; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// /*************************************************************************** | ||
// Aaru Data Preservation Suite | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// Filename : CBM.cs | ||
// Author(s) : Natalia Portillo <claunia@claunia.com> | ||
// | ||
// Component : Commodore file system plugin. | ||
// | ||
// --[ 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/>. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// Copyright © 2011-2023 Natalia Portillo | ||
// ****************************************************************************/ | ||
|
||
using System; | ||
using Aaru.CommonTypes.Enums; | ||
using Aaru.CommonTypes.Interfaces; | ||
using Aaru.CommonTypes.Structs; | ||
|
||
namespace Aaru.Filesystems; | ||
|
||
/// <inheritdoc /> | ||
/// <summary>Implements detection of the filesystem used in 8-bit Commodore microcomputers</summary> | ||
public sealed partial class CBM | ||
{ | ||
#region IReadOnlyFilesystem Members | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber GetAttributes(string path, out FileAttributes attributes) | ||
{ | ||
attributes = new FileAttributes(); | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
string[] pathElements = path.Split(new[] | ||
{ | ||
'/' | ||
}, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
if(pathElements.Length != 1) | ||
return ErrorNumber.NotSupported; | ||
|
||
string filename = pathElements[0].ToUpperInvariant(); | ||
|
||
if(!_cache.TryGetValue(filename, out CachedFile file)) | ||
return ErrorNumber.NoSuchFile; | ||
|
||
attributes = file.attributes; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber Stat(string path, out FileEntryInfo stat) | ||
{ | ||
stat = null; | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
string[] pathElements = path.Split(new[] | ||
{ | ||
'/' | ||
}, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
if(pathElements.Length != 1) | ||
return ErrorNumber.NotSupported; | ||
|
||
string filename = pathElements[0].ToUpperInvariant(); | ||
|
||
if(filename.Length > 14) | ||
return ErrorNumber.NameTooLong; | ||
|
||
if(!_cache.TryGetValue(filename, out CachedFile file)) | ||
return ErrorNumber.NoSuchFile; | ||
|
||
stat = new FileEntryInfo | ||
{ | ||
Attributes = file.attributes, | ||
BlockSize = 256, | ||
Length = (long)file.length, | ||
Blocks = file.blocks, | ||
Inode = file.id, | ||
Links = 1 | ||
}; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber OpenFile(string path, out IFileNode node) | ||
{ | ||
node = null; | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
string[] pathElements = path.Split(new[] | ||
{ | ||
'/' | ||
}, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
if(pathElements.Length != 1) | ||
return ErrorNumber.NotSupported; | ||
|
||
string filename = pathElements[0].ToUpperInvariant(); | ||
|
||
if(filename.Length > 14) | ||
return ErrorNumber.NameTooLong; | ||
|
||
if(!_cache.TryGetValue(filename, out CachedFile file)) | ||
return ErrorNumber.NoSuchFile; | ||
|
||
node = new CbmFileNode | ||
{ | ||
Path = path, Length = (long)file.length, Offset = 0, Cache = file.data | ||
}; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber CloseFile(IFileNode node) | ||
{ | ||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
if(node is not CbmFileNode mynode) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
mynode.Cache = null; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ErrorNumber ReadFile(IFileNode node, long length, byte[] buffer, out long read) | ||
{ | ||
read = 0; | ||
|
||
if(!_mounted) | ||
return ErrorNumber.AccessDenied; | ||
|
||
if(buffer is null || buffer.Length < length) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
if(node is not CbmFileNode mynode) | ||
return ErrorNumber.InvalidArgument; | ||
|
||
read = length; | ||
|
||
if(length + mynode.Offset >= mynode.Length) | ||
read = mynode.Length - mynode.Offset; | ||
|
||
Array.Copy(mynode.Cache, mynode.Offset, buffer, 0, read); | ||
|
||
mynode.Offset += read; | ||
|
||
return ErrorNumber.NoError; | ||
} | ||
|
||
#endregion | ||
} |
Oops, something went wrong.