xref: /haiku/src/add-ons/kernel/file_systems/xfs/ShortAttribute.h (revision 9f3bdf3d039430b5172c424def20ce5d9f7367d4)
1 /*
2  * Copyright 2022, Raghav Sharma, raghavself28@gmail.com
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef SHORT_ATTRIBUTE_H
6 #define SHORT_ATTRIBUTE_H
7 
8 
9 #include "Attribute.h"
10 #include "Inode.h"
11 
12 
13 class ShortAttribute : public Attribute {
14 public:
15 			struct AShortFormEntry {
16 			public:
17 				uint8				namelen;
18 				uint8				valuelen;
19 				uint8				flags;
20 				uint8				nameval[];
21 			};
22 
23 			struct AShortFormHeader {
24 				uint16				totsize;
25 				uint8				count;
26 				uint8				padding;
27 			};
28 								ShortAttribute(Inode* inode);
29 								~ShortAttribute();
30 
31 			status_t			Stat(attr_cookie* cookie, struct stat& stat);
32 
33 			status_t			Read(attr_cookie* cookie, off_t pos,
34 									uint8* buffer, size_t* length);
35 
36 			status_t			Open(const char* name, int openMode, attr_cookie** _cookie);
37 
38 			status_t			GetNext(char* name, size_t* nameLength);
39 
40 			status_t			Lookup(const char* name, size_t* nameLength);
41 private:
42 			void				SwapEndian();
43 private:
44 			uint32				_DataLength(AShortFormEntry* entry);
45 
46 			AShortFormEntry*	_FirstEntry();
47 
48 			Inode*				fInode;
49 			const char*			fName;
50 			AShortFormHeader*	fHeader;
51 			AShortFormEntry*	fEntry;
52 			uint16				fLastEntryOffset;
53 };
54 
55 #endif