2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
9 #include <SupportDefs.h>
10 #include <ByteOrder.h>
15 /** The base class for all FFS blocks */
19 BaseBlock() : fData(NULL
) {}
20 BaseBlock(void *data
, int32 blockSize
) { SetTo(data
, blockSize
); }
21 BaseBlock(int32 blockSize
) { fSize
= blockSize
>> 2; }
23 void SetTo(void *data
, int32 blockSize
) { fData
= (int32
*)data
; fSize
= blockSize
>> 2; }
24 void SetTo(void *data
) { fData
= (int32
*)data
; }
26 int32
*BlockData() const { return fData
; }
27 int32
BlockSize() const { return fSize
<< 2; }
28 int32
LongWords() const { return fSize
; }
30 int32
PrimaryType() const { return Offset(0); }
31 int32
SecondaryType() const { return BackOffset(1); }
32 int32
CheckSum() const { return Offset(5); }
34 inline bool IsRootBlock() const;
35 inline bool IsDirectory() const;
36 inline bool IsFile() const;
37 inline bool IsExtensionBlock() const;
38 inline bool IsDirectoryLink() const;
39 inline bool IsFileLink() const;
40 inline bool IsSymbolicLink() const;
42 status_t
ValidateCheckSum() const;
45 int32
Offset(int16 i
) const { return B_BENDIAN_TO_HOST_INT32(fData
[i
]); }
46 int32
BackOffset(int16 i
) const { return B_BENDIAN_TO_HOST_INT32(fData
[fSize
- i
]); }
48 status_t
GetNameBackOffset(int32 offset
, char *name
, size_t size
) const;
56 /** The base class for all blocks that represent files and directories
57 * (all blocks that are accessible to the user)
60 class NodeBlock
: public BaseBlock
{
63 NodeBlock(int32 blockSize
) : BaseBlock(blockSize
) {}
64 NodeBlock(void *data
, int32 blockSize
) : BaseBlock(data
, blockSize
) {}
66 int32
HeaderKey() const { return Offset(1); }
67 int32
Protection() const { return BackOffset(48); }
69 int32
Days() const { return BackOffset(23); }
70 int32
Minute() const { return BackOffset(22); }
71 int32
Ticks() const { return BackOffset(21); }
73 status_t
GetName(char *name
, size_t size
) const { return GetNameBackOffset(20, name
, size
); }
75 int32
LinkChain() const { return BackOffset(10); }
76 int32
HashChain() const { return BackOffset(4); }
78 int32
Parent() const { return BackOffset(3); }
82 /** A standard user directory block */
84 class DirectoryBlock
: public NodeBlock
{
86 DirectoryBlock() : NodeBlock() {}
87 DirectoryBlock(int32 blockSize
) : NodeBlock(blockSize
) {}
88 DirectoryBlock(void *data
, int32 blockSize
) : NodeBlock(data
, blockSize
) {}
90 char ToUpperChar(int32 type
, char c
) const;
91 int32
HashIndexFor(int32 type
, const char *name
) const;
93 int32
HashValueAt(int32 index
) const;
94 int32
NextHashValue(int32
&index
) const;
95 int32
FirstHashValue(int32
&index
) const;
98 int32
*HashTable() const { return BlockData() + 6; }
99 int32
HashSize() const { return LongWords() - 56; }
103 /** The root block of the device and at the same time the root directory */
105 class RootBlock
: public DirectoryBlock
{
107 RootBlock() : DirectoryBlock() {}
108 RootBlock(int32 blockSize
) : DirectoryBlock(blockSize
) {}
109 RootBlock(void *data
, int32 blockSize
) : DirectoryBlock(data
, blockSize
) {}
111 int32
BitmapFlag() const { return BackOffset(50); }
112 int32
BitmapExtension() const { return BackOffset(24); }
114 int32
VolumeDays() const { return BackOffset(10); }
115 int32
VolumeMinutes() const { return BackOffset(9); }
116 int32
VolumeTicks() const { return BackOffset(8); }
118 int32
CreationDays() const { return BackOffset(7); }
119 int32
CreationMinutes() const { return BackOffset(6); }
120 int32
CreationTicks() const { return BackOffset(5); }
124 /** A standard user file block */
126 class FileBlock
: public NodeBlock
{
128 FileBlock() : NodeBlock() {}
129 FileBlock(int32 blockSize
) : NodeBlock(blockSize
) {}
130 FileBlock(void *data
, int32 blockSize
) : NodeBlock(data
, blockSize
) {}
132 int32
BlockCount() const { return Offset(2); }
133 int32
FirstData() const { return Offset(4); }
134 int32
Size() const { return BackOffset(47); }
135 int32
NextExtension() const { return BackOffset(2); }
136 // The extension block is handled by this class as well
138 int32
DataBlock(int32 index
) const { return BackOffset(51 + index
); }
139 int32
NumDataBlocks() const { return LongWords() - 56; }
144 HashIterator(int32 device
, DirectoryBlock
&node
);
147 status_t
InitCheck();
148 void Goto(int32 index
);
149 NodeBlock
*GetNext(int32
&block
);
153 DirectoryBlock
&fDirectory
;
167 enum secondary_types
{
171 ST_DIRECTORY_LINK
= 4,
177 DT_AMIGA_OFS
= 'DOS\0',
178 DT_AMIGA_FFS
= 'DOS\1',
179 DT_AMIGA_FFS_INTL
= 'DOS\2',
180 DT_AMIGA_FFS_DCACHE
= 'DOS\3',
183 enum protection_flags
{
184 FILE_IS_DELETABLE
= 1,
185 FILE_IS_EXECUTABLE
= 2,
186 FILE_IS_READABLE
= 4,
187 FILE_IS_WRITABLE
= 8,
188 FILE_IS_ARCHIVED
= 16,
195 FFS_NAME_LENGTH
= 30,
199 status_t
get_root_block(int fDevice
, char *buffer
, int32 blockSize
, off_t partitionSize
);
204 BaseBlock::IsRootBlock() const
206 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_ROOT
;
211 BaseBlock::IsDirectory() const
213 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_DIRECTORY
;
218 BaseBlock::IsFile() const
220 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_FILE
;
225 BaseBlock::IsExtensionBlock() const
227 return PrimaryType() == PT_LIST
&& SecondaryType() == ST_FILE
;
232 BaseBlock::IsDirectoryLink() const
234 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_DIRECTORY_LINK
;
239 BaseBlock::IsFileLink() const
241 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_FILE_LINK
;
246 BaseBlock::IsSymbolicLink() const
248 return PrimaryType() == PT_SHORT
&& SecondaryType() == ST_SOFT_LINK
;
253 #endif /* AMIGA_FFS_H */