1/*
2 * Copyright 2022, Raghav Sharma, raghavself28@gmail.com
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef XFS_SYMLINK_H
6#define XFS_SYMLINK_H
7
8
9#include "Inode.h"
10
11
12#define SYMLINK_MAGIC 0x58534c4d
13
14
15// Used only on Version 5
16struct SymlinkHeader {
17public:
18
19			uint32				Magic()
20								{ return B_BENDIAN_TO_HOST_INT32(sl_magic); }
21
22			uint64				Blockno()
23								{ return B_BENDIAN_TO_HOST_INT64(sl_blkno); }
24
25			const uuid_t&		Uuid()
26								{ return sl_uuid; }
27
28			uint64				Owner()
29								{ return B_BENDIAN_TO_HOST_INT64(sl_owner); }
30
31	static	uint32				ExpectedMagic(int8 whichDirectory, Inode* inode)
32								{ return SYMLINK_MAGIC; }
33
34	static	uint32				CRCOffset()
35								{ return offsetof(SymlinkHeader, sl_crc); }
36
37private:
38			uint32				sl_magic;
39			uint32				sl_offset;
40			uint32				sl_bytes;
41			uint32				sl_crc;
42			uuid_t				sl_uuid;
43			uint64				sl_owner;
44			uint64				sl_blkno;
45			uint64				sl_lsn;
46};
47
48
49// This class will handle all formats of Symlinks in xfs
50class Symlink {
51public:
52								Symlink(Inode* inode);
53								~Symlink();
54			status_t			ReadLink(off_t pos, char* buffer, size_t* _length);
55private:
56			status_t			_FillMapEntry();
57			status_t			_FillBuffer();
58			status_t			_ReadLocalLink(off_t pos, char* buffer, size_t* _length);
59			status_t			_ReadExtentLink(off_t pos, char* buffer, size_t* _length);
60
61			Inode*				fInode;
62			ExtentMapEntry		fMap;
63			char*				fSymlinkBuffer;
64};
65
66#endif
67