xref: /haiku/src/add-ons/kernel/file_systems/reiserfs/Item.h (revision f0bc043b2a91affc1db09f77313f94f96013ff36)
1*f0bc043bSIngo Weinhold // Item.h
2*f0bc043bSIngo Weinhold //
3*f0bc043bSIngo Weinhold // Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de)
4*f0bc043bSIngo Weinhold //
5*f0bc043bSIngo Weinhold // This program is free software; you can redistribute it and/or modify
6*f0bc043bSIngo Weinhold // it under the terms of the GNU General Public License as published by
7*f0bc043bSIngo Weinhold // the Free Software Foundation; either version 2 of the License, or
8*f0bc043bSIngo Weinhold // (at your option) any later version.
9*f0bc043bSIngo Weinhold //
10*f0bc043bSIngo Weinhold // This program is distributed in the hope that it will be useful,
11*f0bc043bSIngo Weinhold // but WITHOUT ANY WARRANTY; without even the implied warranty of
12*f0bc043bSIngo Weinhold // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*f0bc043bSIngo Weinhold // GNU General Public License for more details.
14*f0bc043bSIngo Weinhold //
15*f0bc043bSIngo Weinhold // You should have received a copy of the GNU General Public License
16*f0bc043bSIngo Weinhold // along with this program; if not, write to the Free Software
17*f0bc043bSIngo Weinhold // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18*f0bc043bSIngo Weinhold //
19*f0bc043bSIngo Weinhold // You can alternatively use *this file* under the terms of the the MIT
20*f0bc043bSIngo Weinhold // license included in this package.
21*f0bc043bSIngo Weinhold 
22*f0bc043bSIngo Weinhold #ifndef ITEM_H
23*f0bc043bSIngo Weinhold #define ITEM_H
24*f0bc043bSIngo Weinhold 
25*f0bc043bSIngo Weinhold #include "endianess.h"
26*f0bc043bSIngo Weinhold #include "reiserfs.h"
27*f0bc043bSIngo Weinhold #include "Key.h"
28*f0bc043bSIngo Weinhold 
29*f0bc043bSIngo Weinhold class LeafNode;
30*f0bc043bSIngo Weinhold 
31*f0bc043bSIngo Weinhold // ItemHeader
32*f0bc043bSIngo Weinhold class ItemHeader : private item_head {
33*f0bc043bSIngo Weinhold public:
ItemHeader()34*f0bc043bSIngo Weinhold 	ItemHeader() {}
35*f0bc043bSIngo Weinhold 
GetLen()36*f0bc043bSIngo Weinhold 	uint16 GetLen() const { return le2h(ih_item_len); }
GetLocation()37*f0bc043bSIngo Weinhold 	uint16 GetLocation() const { return le2h(ih_item_location); }
GetVersion()38*f0bc043bSIngo Weinhold 	uint16 GetVersion() const { return le2h(ih_version); }
GetKey()39*f0bc043bSIngo Weinhold 	const Key *GetKey() const { return Key::CastFrom(&ih_key); }
GetKey(VKey * k)40*f0bc043bSIngo Weinhold 	VKey *GetKey(VKey *k) const { k->SetTo(GetKey(), GetVersion()); return k; }
41*f0bc043bSIngo Weinhold 
42*f0bc043bSIngo Weinhold 	// indirect item only
GetFreeSpaceReserved()43*f0bc043bSIngo Weinhold 	uint16 GetFreeSpaceReserved() const
44*f0bc043bSIngo Weinhold 	{
45*f0bc043bSIngo Weinhold 		return (GetVersion() == KEY_FORMAT_3_6
46*f0bc043bSIngo Weinhold 			? 0 : le2h(u.ih_free_space_reserved));
47*f0bc043bSIngo Weinhold 	}
48*f0bc043bSIngo Weinhold 
49*f0bc043bSIngo Weinhold 	// directory item only
GetEntryCount()50*f0bc043bSIngo Weinhold 	uint16 GetEntryCount() const { return le2h(u.ih_entry_count); }
51*f0bc043bSIngo Weinhold 
GetDirID()52*f0bc043bSIngo Weinhold 	uint32 GetDirID() const { return GetKey()->GetDirID(); }
GetObjectID()53*f0bc043bSIngo Weinhold 	uint32 GetObjectID() const { return GetKey()->GetObjectID(); }
GetOffset()54*f0bc043bSIngo Weinhold 	uint64 GetOffset() const { return GetKey()->GetOffset(GetVersion()); }
GetType()55*f0bc043bSIngo Weinhold 	uint16 GetType() const { return GetKey()->GetType(GetVersion()); }
56*f0bc043bSIngo Weinhold } _PACKED;
57*f0bc043bSIngo Weinhold 
58*f0bc043bSIngo Weinhold 
59*f0bc043bSIngo Weinhold // Item
60*f0bc043bSIngo Weinhold class Item {
61*f0bc043bSIngo Weinhold public:
62*f0bc043bSIngo Weinhold 	Item();
63*f0bc043bSIngo Weinhold 	Item(const Item &item);
64*f0bc043bSIngo Weinhold 	Item(LeafNode *node, const ItemHeader *header);
65*f0bc043bSIngo Weinhold 	~Item();
66*f0bc043bSIngo Weinhold 
67*f0bc043bSIngo Weinhold 	status_t SetTo(LeafNode *node, const ItemHeader *header);
68*f0bc043bSIngo Weinhold 	status_t SetTo(LeafNode *node, int32 index);
69*f0bc043bSIngo Weinhold 	void Unset();
70*f0bc043bSIngo Weinhold 
71*f0bc043bSIngo Weinhold 	LeafNode *GetNode() const;
72*f0bc043bSIngo Weinhold 	ItemHeader *GetHeader() const;
73*f0bc043bSIngo Weinhold 	int32 GetIndex() const;
74*f0bc043bSIngo Weinhold 
75*f0bc043bSIngo Weinhold 	void *GetData() const;
76*f0bc043bSIngo Weinhold 	uint16 GetLen() const;
77*f0bc043bSIngo Weinhold 	uint16 GetType() const;
78*f0bc043bSIngo Weinhold 	uint32 GetDirID() const;
79*f0bc043bSIngo Weinhold 	uint32 GetObjectID() const;
80*f0bc043bSIngo Weinhold 	uint64 GetOffset() const;
81*f0bc043bSIngo Weinhold 	const Key *GetKey() const;
82*f0bc043bSIngo Weinhold 	VKey *GetKey(VKey *k) const;
83*f0bc043bSIngo Weinhold 
84*f0bc043bSIngo Weinhold 	uint16 GetEntryCount() const;
85*f0bc043bSIngo Weinhold 
86*f0bc043bSIngo Weinhold 	status_t Check() const;
87*f0bc043bSIngo Weinhold 
88*f0bc043bSIngo Weinhold 	Item &operator=(const Item &item);
89*f0bc043bSIngo Weinhold 
90*f0bc043bSIngo Weinhold protected:
91*f0bc043bSIngo Weinhold 	LeafNode	*fNode;
92*f0bc043bSIngo Weinhold 	ItemHeader	*fHeader;
93*f0bc043bSIngo Weinhold };
94*f0bc043bSIngo Weinhold 
95*f0bc043bSIngo Weinhold #endif	// ITEM_H
96