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 16 struct SymlinkHeader { 17 public: 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 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 37 private: 38 uint32 sl_magic; 39 uint32 sl_offset; 40 uint32 sl_bytes; 41 public: 42 uint32 sl_crc; 43 private: 44 uuid_t sl_uuid; 45 uint64 sl_owner; 46 uint64 sl_blkno; 47 uint64 sl_lsn; 48 }; 49 50 51 // This class will handle all formats of Symlinks in xfs 52 class Symlink { 53 public: 54 Symlink(Inode* inode); 55 ~Symlink(); 56 status_t ReadLink(off_t pos, char* buffer, size_t* _length); 57 private: 58 status_t _FillMapEntry(); 59 status_t _FillBuffer(); 60 status_t _ReadLocalLink(off_t pos, char* buffer, size_t* _length); 61 status_t _ReadExtentLink(off_t pos, char* buffer, size_t* _length); 62 63 Inode* fInode; 64 ExtentMapEntry fMap; 65 char* fSymlinkBuffer; 66 }; 67 68 #endif