xref: /haiku/src/add-ons/kernel/file_systems/xfs/ShortAttribute.h (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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 // xfs_attr_sf_hdr
14 struct AShortFormHeader {
15 			uint16				totsize;
16 			uint8				count;
17 			uint8				padding;
18 };
19 
20 
21 // xfs_attr_sf_entry
22 struct AShortFormEntry {
23 			uint8				namelen;
24 			uint8				valuelen;
25 			uint8				flags;
26 			uint8				nameval[];
27 };
28 
29 
30 class ShortAttribute : public Attribute {
31 public:
32 								ShortAttribute(Inode* inode);
33 								~ShortAttribute();
34 
35 			status_t			Stat(attr_cookie* cookie, struct stat& stat);
36 
37 			status_t			Read(attr_cookie* cookie, off_t pos,
38 									uint8* buffer, size_t* length);
39 
40 			status_t			Open(const char* name, int openMode, attr_cookie** _cookie);
41 
42 			status_t			GetNext(char* name, size_t* nameLength);
43 
44 			status_t			Lookup(const char* name, size_t* nameLength);
45 private:
46 			uint32				_DataLength(AShortFormEntry* entry);
47 
48 			AShortFormEntry*	_FirstEntry();
49 
50 			Inode*				fInode;
51 			const char*			fName;
52 			AShortFormHeader*	fHeader;
53 			AShortFormEntry*	fEntry;
54 			uint16				fLastEntryOffset;
55 };
56 
57 #endif