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