199071c0cSMashijams /* 299071c0cSMashijams * Copyright 2022, Raghav Sharma, raghavself28@gmail.com 399071c0cSMashijams * Distributed under the terms of the MIT License. 499071c0cSMashijams */ 599071c0cSMashijams #ifndef XFS_SYMLINK_H 699071c0cSMashijams #define XFS_SYMLINK_H 799071c0cSMashijams 899071c0cSMashijams 999071c0cSMashijams #include "Inode.h" 1099071c0cSMashijams 1199071c0cSMashijams 1299071c0cSMashijams #define SYMLINK_MAGIC 0x58534c4d 1399071c0cSMashijams 1499071c0cSMashijams 1599071c0cSMashijams // Used only on Version 5 1699071c0cSMashijams struct SymlinkHeader { 1799071c0cSMashijams public: 1899071c0cSMashijams MagicSymlinkHeader1999071c0cSMashijams uint32 Magic() 2099071c0cSMashijams { return B_BENDIAN_TO_HOST_INT32(sl_magic); } 2199071c0cSMashijams BlocknoSymlinkHeader2299071c0cSMashijams uint64 Blockno() 2399071c0cSMashijams { return B_BENDIAN_TO_HOST_INT64(sl_blkno); } 2499071c0cSMashijams UuidSymlinkHeader25*0849c914SAdrien Destugues const uuid_t& Uuid() 26*0849c914SAdrien Destugues { return sl_uuid; } 2799071c0cSMashijams OwnerSymlinkHeader2899071c0cSMashijams uint64 Owner() 2999071c0cSMashijams { return B_BENDIAN_TO_HOST_INT64(sl_owner); } 3099071c0cSMashijams ExpectedMagicSymlinkHeader3199071c0cSMashijams static uint32 ExpectedMagic(int8 whichDirectory, Inode* inode) 3299071c0cSMashijams { return SYMLINK_MAGIC; } 3399071c0cSMashijams CRCOffsetSymlinkHeader3499071c0cSMashijams static uint32 CRCOffset() 3599071c0cSMashijams { return offsetof(SymlinkHeader, sl_crc); } 3699071c0cSMashijams 3799071c0cSMashijams private: 3899071c0cSMashijams uint32 sl_magic; 3999071c0cSMashijams uint32 sl_offset; 4099071c0cSMashijams uint32 sl_bytes; 4199071c0cSMashijams uint32 sl_crc; 4299071c0cSMashijams uuid_t sl_uuid; 4399071c0cSMashijams uint64 sl_owner; 4499071c0cSMashijams uint64 sl_blkno; 4599071c0cSMashijams uint64 sl_lsn; 4699071c0cSMashijams }; 4799071c0cSMashijams 4899071c0cSMashijams 4999071c0cSMashijams // This class will handle all formats of Symlinks in xfs 5099071c0cSMashijams class Symlink { 5199071c0cSMashijams public: 5299071c0cSMashijams Symlink(Inode* inode); 5399071c0cSMashijams ~Symlink(); 5499071c0cSMashijams status_t ReadLink(off_t pos, char* buffer, size_t* _length); 5599071c0cSMashijams private: 5699071c0cSMashijams status_t _FillMapEntry(); 5799071c0cSMashijams status_t _FillBuffer(); 5899071c0cSMashijams status_t _ReadLocalLink(off_t pos, char* buffer, size_t* _length); 5999071c0cSMashijams status_t _ReadExtentLink(off_t pos, char* buffer, size_t* _length); 6099071c0cSMashijams 6199071c0cSMashijams Inode* fInode; 6299071c0cSMashijams ExtentMapEntry fMap; 6399071c0cSMashijams char* fSymlinkBuffer; 6499071c0cSMashijams }; 6599071c0cSMashijams 6699071c0cSMashijams #endif 67