1956f541dSJérôme Duval /* 2*5bfbdf0dSbrjhaiku * Copyright 2019, Bharathi Ramana Joshi, joshibharathiramana@gmail.com. 399768086Shyche * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com. 4956f541dSJérôme Duval * Copyright 2010-2011, Jérôme Duval, korli@users.berlios.de. 5956f541dSJérôme Duval * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. 6956f541dSJérôme Duval * This file may be used under the terms of the MIT License. 7956f541dSJérôme Duval */ 8956f541dSJérôme Duval #ifndef ATTRIBUTE_H 9956f541dSJérôme Duval #define ATTRIBUTE_H 10956f541dSJérôme Duval 11956f541dSJérôme Duval 12956f541dSJérôme Duval #include "CachedBlock.h" 13956f541dSJérôme Duval #include "Inode.h" 14956f541dSJérôme Duval 15956f541dSJérôme Duval 16956f541dSJérôme Duval struct attr_cookie { 17956f541dSJérôme Duval char name[B_ATTR_NAME_LENGTH]; 18956f541dSJérôme Duval uint32 type; 19956f541dSJérôme Duval int open_mode; 20956f541dSJérôme Duval bool create; 21956f541dSJérôme Duval }; 22956f541dSJérôme Duval 23956f541dSJérôme Duval 24*5bfbdf0dSbrjhaiku /** Attributes in btrfs use the same on-disk format as directories, in the 25*5bfbdf0dSbrjhaiku * XATTR_ITEM of the inode. Each attribute appears as a "file" there. 26*5bfbdf0dSbrjhaiku * 27*5bfbdf0dSbrjhaiku * Additionally, this class provides access to the non-extended attributes 28*5bfbdf0dSbrjhaiku * through the Stat method. These are stored dorectly in the base inode of 29*5bfbdf0dSbrjhaiku * the file. 30*5bfbdf0dSbrjhaiku */ 31956f541dSJérôme Duval class Attribute { 32956f541dSJérôme Duval public: 33*5bfbdf0dSbrjhaiku //! Constructs an Attribute object for the file inode 34956f541dSJérôme Duval Attribute(Inode* inode); 35956f541dSJérôme Duval Attribute(Inode* inode, attr_cookie* cookie); 36956f541dSJérôme Duval ~Attribute(); 37956f541dSJérôme Duval 38*5bfbdf0dSbrjhaiku //! Tests if operations specified by openMode can be performed on file *name 39956f541dSJérôme Duval status_t CheckAccess(const char* name, int openMode); 40956f541dSJérôme Duval 41956f541dSJérôme Duval status_t Create(const char* name, type_code type, 42956f541dSJérôme Duval int openMode, attr_cookie** _cookie); 43*5bfbdf0dSbrjhaiku //! Loads file attributes into cookie 44956f541dSJérôme Duval status_t Open(const char* name, int openMode, 45956f541dSJérôme Duval attr_cookie** _cookie); 46956f541dSJérôme Duval 47*5bfbdf0dSbrjhaiku //! Get the stat from the attribute 48956f541dSJérôme Duval status_t Stat(struct stat& stat); 49956f541dSJérôme Duval 50*5bfbdf0dSbrjhaiku //! Loads extended attributes of file into buffer 51956f541dSJérôme Duval status_t Read(attr_cookie* cookie, off_t pos, 52956f541dSJérôme Duval uint8* buffer, size_t* _length); 53956f541dSJérôme Duval private: 54*5bfbdf0dSbrjhaiku //! Searches through the filesystem tree for the entry named *name 55956f541dSJérôme Duval status_t _Lookup(const char* name, size_t nameLength, 56956f541dSJérôme Duval btrfs_dir_entry** entries = NULL, 5716de9db5Shyche uint32* length = NULL); 58*5bfbdf0dSbrjhaiku //! Searches through the entry array for the entry named *name 59956f541dSJérôme Duval status_t _FindEntry(btrfs_dir_entry* entries, 60956f541dSJérôme Duval size_t length, const char* name, 61956f541dSJérôme Duval size_t nameLength, 62956f541dSJérôme Duval btrfs_dir_entry** _entry); 63956f541dSJérôme Duval 64956f541dSJérôme Duval ::Volume* fVolume; 65956f541dSJérôme Duval Inode* fInode; 66956f541dSJérôme Duval const char* fName; 67956f541dSJérôme Duval }; 68956f541dSJérôme Duval 69956f541dSJérôme Duval #endif // ATTRIBUTE_H 70956f541dSJérôme Duval 71