btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / bfs_tools / lib / Inode.h
blob0d11199798bc74bb05293d7deafb2817ffa15950
1 /*
2 * Copyright 2001-2008, pinc Software. All Rights Reserved.
3 * Released under the terms of the MIT license.
4 */
5 #ifndef INODE_H
6 #define INODE_H
9 #include <SupportDefs.h>
11 #include "Disk.h"
13 class BPlusTree;
14 class Directory;
17 class Inode {
18 public:
19 Inode(Disk* disk, bfs_inode* inode, bool ownBuffer = true);
20 Inode(const Inode &inode);
21 virtual ~Inode();
23 status_t SetTo(bfs_inode *inode);
24 virtual status_t InitCheck() const;
26 bool IsFile() const { return S_ISREG(fInode->mode); }
27 bool IsDirectory() const { return S_ISDIR(fInode->mode); }
28 bool IsSymlink() const { return S_ISLNK(fInode->mode); }
29 bool IsIndex() const { return S_ISINDEX(fInode->mode); }
30 bool IsAttribute() const
31 { return (fInode->mode & S_ATTR) != 0; }
32 bool IsAttributeDirectory() const
33 { return (fInode->mode & S_ATTR_DIR) != 0; }
34 bool IsRoot() const { return BlockRun() == fDisk->Root(); }
36 int32 Mode() const { return fInode->mode; }
37 int32 Flags() const { return fInode->flags; }
38 off_t Size() const { return fInode->data.size; }
40 off_t Offset() const
41 { return fDisk->ToOffset(BlockRun()); }
42 off_t Block() const { return fDisk->ToBlock(BlockRun()); }
43 const block_run& BlockRun() const { return fBlockRun; }
44 block_run Parent() const { return fInode->parent; }
45 block_run Attributes() const { return fInode->attributes; }
47 const bfs_inode* InodeBuffer() const { return fInode; }
48 status_t CopyBuffer();
50 void ReleaseBuffer();
51 status_t AcquireBuffer();
52 void BufferClobbered();
54 void SetParent(const block_run& run);
55 void SetBlockRun(const block_run& run);
56 void SetMode(uint32 mode);
58 status_t SetName(const char* name);
59 const char* Name() const;
60 status_t GetNextSmallData(small_data** smallData);
62 status_t RewindAttributes();
63 status_t GetNextAttribute(char* name, uint32* type, void** data,
64 size_t* length);
66 class Source;
67 const char* Path(Inode::Source* source = NULL);
68 virtual status_t CopyTo(const char* path, bool fullPath = true,
69 Inode::Source* source = NULL);
70 status_t CopyAttributesTo(BNode* node);
72 static Inode* Factory(Disk* disk, bfs_inode* inode,
73 bool ownBuffer = true);
74 static Inode* Factory(Disk* disk, block_run run);
75 static Inode* Factory(Disk* disk, Inode* inode,
76 bool copyBuffer = true);
78 static Inode* EmptyInode(Disk* disk,const char* name, int32 mode);
80 class Source {
81 public:
82 virtual Inode *InodeAt(block_run run) = 0;
85 protected:
86 static bool _LowMemory();
87 void _Unset();
88 status_t _FindPath(Inode::Source *source = NULL);
90 Disk *fDisk;
91 bfs_inode *fInode;
92 bool fOwnBuffer;
93 char *fPath;
94 block_run fBlockRun;
95 int32 fRefCount;
97 small_data *fCurrentSmallData;
98 Directory *fAttributes;
99 void *fAttributeBuffer;
103 class DataStream : public Inode, public BPositionIO {
104 public:
105 DataStream(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
106 DataStream(const Inode &inode);
107 ~DataStream();
109 status_t FindBlockRun(off_t pos);
111 virtual ssize_t ReadAt(off_t pos, void *buffer, size_t size);
112 virtual ssize_t WriteAt(off_t pos, const void *buffer, size_t size);
114 virtual off_t Seek(off_t position, uint32 seek_mode);
115 virtual off_t Position() const;
117 virtual status_t SetSize(off_t size);
119 private:
120 int32 fCurrent;
121 int32 fLevel;
122 block_run fRun;
123 off_t fRunFileOffset;
124 off_t fRunBlockEnd;
125 off_t fPosition;
129 class File : public DataStream {
130 public:
131 File(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
132 File(const Inode &inode);
133 ~File();
135 virtual status_t InitCheck() const;
136 virtual status_t CopyTo(const char *path, bool fullPath = true,
137 Inode::Source *source = NULL);
141 class Attribute : public File {
142 public:
143 Attribute(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
144 Attribute(const Inode &inode);
145 ~Attribute();
147 virtual status_t InitCheck() const;
148 virtual status_t CopyTo(const char *path, bool fullPath = true,
149 Inode::Source *source = NULL);
151 uint32 Type() const { return fInode->type; }
155 class Directory : public DataStream {
156 public:
157 Directory(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
158 Directory(const Inode &inode);
159 ~Directory();
161 virtual status_t InitCheck() const;
162 virtual status_t CopyTo(const char *path, bool fullPath = true,
163 Inode::Source *source = NULL);
165 virtual status_t Rewind();
166 virtual status_t GetNextEntry(char *name, block_run *run);
167 virtual status_t GetNextEntry(block_run *run);
169 virtual status_t Contains(const block_run *run);
170 virtual status_t Contains(const Inode *inode);
171 virtual status_t FindEntry(const char *name, block_run *run);
173 virtual status_t AddEntry(Inode *inode);
175 status_t GetTree(BPlusTree **tree);
177 private:
178 virtual status_t CreateTree();
180 BPlusTree *fTree;
184 class Symlink : public Inode {
185 public:
186 Symlink(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
187 Symlink(const Inode &inode);
188 ~Symlink();
190 virtual status_t InitCheck() const;
191 virtual status_t CopyTo(const char *path, bool fullPath = true,
192 Inode::Source *source = NULL);
194 status_t LinksTo(char *to, size_t maxLength);
196 private:
197 char *fTo;
200 #endif /* INODE_H */