2016-07-21 17:36:51 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Xattr.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-07-21 17:36:51 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Component : Apple Lisa filesystem plugin.
|
2016-07-21 17:36:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Methods to handle Apple Lisa extended attributes (label, tags, serial,
|
|
|
|
|
|
// etc).
|
2016-07-21 17:36:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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
|
2016-07-21 17:36:51 +01:00
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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.
|
2016-07-21 17:36:51 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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/>.
|
2016-07-21 17:36:51 +01:00
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Copyright © 2011-2016 Natalia Portillo
|
2016-07-21 17:36:51 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
|
2016-07-21 17:36:51 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-07-22 02:18:53 +01:00
|
|
|
|
using System.Text;
|
2016-07-21 17:36:51 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems.LisaFS
|
|
|
|
|
|
{
|
|
|
|
|
|
partial class LisaFS : Filesystem
|
|
|
|
|
|
{
|
|
|
|
|
|
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
short fileId;
|
2016-07-22 02:18:53 +01:00
|
|
|
|
Errno error = LookupFileId(path, out fileId);
|
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
|
|
|
|
return ListXAttr(fileId, ref xattrs);
|
2016-07-21 17:36:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
short fileId;
|
2016-07-22 02:18:53 +01:00
|
|
|
|
Errno error = LookupFileId(path, out fileId);
|
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
|
|
|
|
return GetXattr(fileId, xattr, out buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
Errno ListXAttr(short fileId, ref List<string> xattrs)
|
2016-07-22 02:18:53 +01:00
|
|
|
|
{
|
|
|
|
|
|
xattrs = null;
|
|
|
|
|
|
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
if(fileId < 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!debug || fileId == 0)
|
|
|
|
|
|
return Errno.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
|
|
xattrs = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
if(fileId == FILEID_MDDF)
|
2016-07-27 02:41:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] buf = Encoding.ASCII.GetBytes(mddf.password);
|
|
|
|
|
|
if(buf.Length > 0)
|
|
|
|
|
|
xattrs.Add("com.apple.lisa.password");
|
|
|
|
|
|
}
|
2016-07-22 02:18:53 +01:00
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
ExtentFile file;
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
Errno error = ReadExtentsFile(fileId, out file);
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
xattrs = new List<string>();
|
|
|
|
|
|
if(file.password_valid > 0)
|
|
|
|
|
|
xattrs.Add("com.apple.lisa.password");
|
2016-07-28 13:45:57 +01:00
|
|
|
|
|
|
|
|
|
|
if(file.serial > 0)
|
|
|
|
|
|
xattrs.Add("com.apple.lisa.serial");
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo))
|
|
|
|
|
|
xattrs.Add("com.apple.lisa.label");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(debug)
|
|
|
|
|
|
xattrs.Add("com.apple.lisa.tags");
|
|
|
|
|
|
|
|
|
|
|
|
xattrs.Sort();
|
2016-07-22 02:18:53 +01:00
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
|
Errno GetXattr(short fileId, string xattr, out byte[] buf)
|
2016-07-22 02:18:53 +01:00
|
|
|
|
{
|
|
|
|
|
|
buf = null;
|
|
|
|
|
|
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
if(fileId < 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!debug || fileId == 0)
|
|
|
|
|
|
return Errno.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
|
|
if(fileId == FILEID_MDDF)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(xattr == "com.apple.lisa.password")
|
|
|
|
|
|
{
|
|
|
|
|
|
buf = Encoding.ASCII.GetBytes(mddf.password);
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
if(debug && xattr == "com.apple.lisa.tags")
|
|
|
|
|
|
return ReadSystemFile(fileId, out buf, true);
|
|
|
|
|
|
|
2016-07-22 02:18:53 +01:00
|
|
|
|
return Errno.NoSuchExtendedAttribute;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExtentFile file;
|
|
|
|
|
|
|
|
|
|
|
|
Errno error = ReadExtentsFile(fileId, out file);
|
|
|
|
|
|
|
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
if(xattr == "com.apple.lisa.password" && file.password_valid > 0)
|
2016-07-22 02:18:53 +01:00
|
|
|
|
{
|
|
|
|
|
|
buf = new byte[8];
|
|
|
|
|
|
Array.Copy(file.password, 0, buf, 0, 8);
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-28 13:45:57 +01:00
|
|
|
|
if(xattr == "com.apple.lisa.serial" && file.serial > 0)
|
2016-07-22 02:18:53 +01:00
|
|
|
|
{
|
2016-07-27 02:35:29 +01:00
|
|
|
|
buf = Encoding.ASCII.GetBytes(file.serial.ToString());
|
2016-07-22 02:18:53 +01:00
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo) && xattr == "com.apple.lisa.label")
|
|
|
|
|
|
{
|
|
|
|
|
|
buf = new byte[128];
|
|
|
|
|
|
Array.Copy(file.LisaInfo, 0, buf, 0, 128);
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
|
if(debug && xattr == "com.apple.lisa.tags")
|
|
|
|
|
|
return ReadFile(fileId, out buf, true);
|
|
|
|
|
|
|
2016-07-22 02:18:53 +01:00
|
|
|
|
return Errno.NoSuchExtendedAttribute;
|
2016-07-21 17:36:51 +01:00
|
|
|
|
}
|
2016-07-27 22:13:47 +01:00
|
|
|
|
|
|
|
|
|
|
Errno DecodeTag(byte[] tag, out Tag decoded)
|
|
|
|
|
|
{
|
|
|
|
|
|
decoded = new Tag();
|
|
|
|
|
|
|
|
|
|
|
|
if(tag.Length == 12)
|
|
|
|
|
|
{
|
|
|
|
|
|
decoded.version = BigEndianBitConverter.ToUInt16(tag, 0x00);
|
|
|
|
|
|
decoded.unknown = BigEndianBitConverter.ToUInt16(tag, 0x02);
|
|
|
|
|
|
decoded.fileID = BigEndianBitConverter.ToInt16(tag, 0x04);
|
|
|
|
|
|
decoded.relBlock = BigEndianBitConverter.ToUInt16(tag, 0x06);
|
|
|
|
|
|
decoded.nextBlock = BigEndianBitConverter.ToUInt16(tag, 0x08);
|
|
|
|
|
|
decoded.nextBlock &= 0x7FF;
|
|
|
|
|
|
decoded.prevBlock = BigEndianBitConverter.ToUInt16(tag, 0x0A);
|
|
|
|
|
|
decoded.prevBlock &= 0x7FF;
|
|
|
|
|
|
|
|
|
|
|
|
if(decoded.nextBlock == 0x7FF)
|
|
|
|
|
|
decoded.isLast = true;
|
|
|
|
|
|
if(decoded.prevBlock == 0x7FF)
|
|
|
|
|
|
decoded.isFirst = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
decoded.version = BigEndianBitConverter.ToUInt16(tag, 0x00);
|
|
|
|
|
|
decoded.unknown = BigEndianBitConverter.ToUInt16(tag, 0x02);
|
|
|
|
|
|
decoded.fileID = BigEndianBitConverter.ToInt16(tag, 0x04);
|
|
|
|
|
|
decoded.usedBytes = BigEndianBitConverter.ToUInt16(tag, 0x06);
|
|
|
|
|
|
decoded.absoluteBlock = BigEndianBitConverter.ToUInt32(tag, 0x07);
|
|
|
|
|
|
decoded.absoluteBlock &= 0xFFFFFF;
|
|
|
|
|
|
decoded.checksum = tag[0x0B];
|
|
|
|
|
|
decoded.relBlock = BigEndianBitConverter.ToUInt16(tag, 0x0C);
|
|
|
|
|
|
decoded.nextBlock = BigEndianBitConverter.ToUInt32(tag, 0x0D);
|
|
|
|
|
|
decoded.nextBlock &= 0xFFFFFF;
|
|
|
|
|
|
decoded.prevBlock = BigEndianBitConverter.ToUInt32(tag, 0x10);
|
|
|
|
|
|
decoded.prevBlock &= 0xFFFFFF;
|
|
|
|
|
|
|
|
|
|
|
|
if(decoded.nextBlock == 0xFFFFFF)
|
|
|
|
|
|
decoded.isLast = true;
|
|
|
|
|
|
if(decoded.prevBlock == 0xFFFFFF)
|
|
|
|
|
|
decoded.isFirst = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
2016-07-21 17:36:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|