1/*
2 * Copyright 2019, Bharathi Ramana Joshi, joshibharathiramana@gmail.com.
3 * Copyright 2017, Ch��� V�� Gia Hy, cvghy116@gmail.com.
4 * Copyright 2010-2011, J��r��me Duval, korli@users.berlios.de.
5 * Copyright 2004-2008, Axel D��rfler, axeld@pinc-software.de.
6 * This file may be used under the terms of the MIT License.
7 */
8#ifndef ATTRIBUTE_H
9#define ATTRIBUTE_H
10
11
12#include "CachedBlock.h"
13#include "Inode.h"
14
15
16struct attr_cookie {
17	char	name[B_ATTR_NAME_LENGTH];
18	uint32	type;
19	int		open_mode;
20	bool	create;
21};
22
23
24/** Attributes in btrfs use the same on-disk format as directories, in the
25 * XATTR_ITEM of the inode. Each attribute appears as a "file" there.
26 *
27 * Additionally, this class provides access to the non-extended attributes
28 * through the Stat method. These are stored dorectly in the base inode of
29 * the file.
30 */
31class Attribute {
32public:
33			//! Constructs an Attribute object for the file inode
34								Attribute(Inode* inode);
35								Attribute(Inode* inode, attr_cookie* cookie);
36								~Attribute();
37
38			//! Tests if operations specified by openMode can be performed on file *name
39			status_t			CheckAccess(const char* name, int openMode);
40
41			status_t			Create(const char* name, type_code type,
42									int openMode, attr_cookie** _cookie);
43			//! Loads file attributes into cookie
44			status_t			Open(const char* name, int openMode,
45									attr_cookie** _cookie);
46
47			//! Get the stat from the attribute
48			status_t			Stat(struct stat& stat);
49
50			//! Loads extended attributes of file into buffer
51			status_t			Read(attr_cookie* cookie, off_t pos,
52									uint8* buffer, size_t* _length);
53private:
54			//! Searches through the filesystem tree for the entry named *name
55			status_t			_Lookup(const char* name, size_t nameLength,
56									btrfs_dir_entry** entries = NULL,
57									uint32* length = NULL);
58			//! Searches through the entry array for the entry named *name
59			status_t			_FindEntry(btrfs_dir_entry* entries,
60									size_t length, const char* name,
61									size_t nameLength,
62									btrfs_dir_entry** _entry);
63
64			::Volume*			fVolume;
65			Inode*				fInode;
66			const char*			fName;
67};
68
69#endif	// ATTRIBUTE_H
70
71