xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Attribute.h (revision b31cb92f29fe89eaca84d173d0f70d38bf0c6a3d)
1 /*
2  * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com.
3  * Copyright 2010-2011, Jérôme Duval, korli@users.berlios.de.
4  * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
5  * This file may be used under the terms of the MIT License.
6  */
7 #ifndef ATTRIBUTE_H
8 #define ATTRIBUTE_H
9 
10 
11 #include "CachedBlock.h"
12 #include "Inode.h"
13 
14 
15 struct attr_cookie {
16 	char	name[B_ATTR_NAME_LENGTH];
17 	uint32	type;
18 	int		open_mode;
19 	bool	create;
20 };
21 
22 
23 class Attribute {
24 public:
25 								Attribute(Inode* inode);
26 								Attribute(Inode* inode, attr_cookie* cookie);
27 								~Attribute();
28 
29 			status_t			CheckAccess(const char* name, int openMode);
30 
31 			status_t			Create(const char* name, type_code type,
32 									int openMode, attr_cookie** _cookie);
33 			status_t			Open(const char* name, int openMode,
34 									attr_cookie** _cookie);
35 
36 			status_t			Stat(struct stat& stat);
37 
38 			status_t			Read(attr_cookie* cookie, off_t pos,
39 									uint8* buffer, size_t* _length);
40 private:
41 			status_t			_Lookup(const char* name, size_t nameLength,
42 									btrfs_dir_entry** entries = NULL,
43 									uint32* length = NULL);
44 			status_t			_FindEntry(btrfs_dir_entry* entries,
45 									size_t length, const char* name,
46 									size_t nameLength,
47 									btrfs_dir_entry** _entry);
48 
49 			::Volume*			fVolume;
50 			Inode*				fInode;
51 			const char*			fName;
52 };
53 
54 #endif	// ATTRIBUTE_H
55 
56