xref: /haiku/src/add-ons/kernel/file_systems/ext2/Attribute.h (revision db1b905e370e63d8f5abf215351765fb08c4758a)
1 /*
2  * Copyright 2010, Jérôme Duval, korli@users.berlios.de.
3  * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
4  * This file may be used under the terms of the MIT License.
5  */
6 #ifndef ATTRIBUTE_H
7 #define ATTRIBUTE_H
8 
9 
10 #include "CachedBlock.h"
11 #include "Inode.h"
12 
13 
14 struct attr_cookie {
15 	char	name[B_ATTR_NAME_LENGTH];
16 	uint32	type;
17 	int		open_mode;
18 	bool	create;
19 };
20 
21 
22 class Attribute {
23 public:
24 							Attribute(Inode* inode);
25 							Attribute(Inode* inode, attr_cookie* cookie);
26 							~Attribute();
27 
28 			status_t		InitCheck();
29 			status_t		CheckAccess(const char* name, int openMode);
30 
31 			status_t		Find(const char* name);
32 			status_t		Find(int32 index);
33 			status_t		GetName(char* name, size_t* _nameLength);
34 			void			Put();
35 
36 			status_t		Create(const char* name, type_code type,
37 								int openMode, attr_cookie** _cookie);
38 			status_t		Open(const char* name, int openMode,
39 								attr_cookie** _cookie);
40 
41 			status_t		Stat(struct stat& stat);
42 
43 			status_t		Read(attr_cookie* cookie, off_t pos, uint8* buffer,
44 								size_t* _length);
45 			status_t		Write(Transaction& transaction, attr_cookie* cookie,
46 								off_t pos, const uint8* buffer,
47 								size_t* _length, bool* _created);
48 
49 private:
50 			status_t		_Truncate();
51 			status_t		_Find(const char* name, int32 index);
52 			status_t		_FindAttributeBody(const uint8* start, const uint8* end,
53 								const char* name, int32 index, int32 *count,
54 								ext2_xattr_entry** entry);
55 			status_t		_FindAttributeBlock(const uint8* start, const uint8* end,
56 								const char* name, int32 index, int32 *count,
57 								ext2_xattr_entry** entry);
58 			status_t 		_FindAttribute(const uint8* start, const uint8* end,
59 								const char* name, int32 index, int32 *count,
60 								ext2_xattr_entry** entry);
61 			status_t		_PrefixedName(ext2_xattr_entry* entry, char* _name,
62 								size_t* _nameLength);
63 
64 			::Volume*		fVolume;
65 			CachedBlock		fBlock;
66 			Inode*			fInode;
67 			ext2_xattr_entry* fBodyEntry;
68 			ext2_xattr_entry* fBlockEntry;
69 			const char*		fName;
70 };
71 
72 #endif	// ATTRIBUTE_H
73