RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / bfs_tools / lib / Inode.h
blob67ff22faa46f3d40d4601e9cf3df3484747ac575
1 /*
2 * Copyright 2001-2008, pinc Software. All Rights Reserved.
3 */
4 #ifndef INODE_H
5 #define INODE_H
8 #include <SupportDefs.h>
10 #include "Disk.h"
12 class BPlusTree;
13 class Directory;
16 class Inode {
17 public:
18 Inode(Disk* disk, bfs_inode* inode, bool ownBuffer = true);
19 Inode(const Inode &inode);
20 virtual ~Inode();
22 status_t SetTo(bfs_inode *inode);
23 virtual status_t InitCheck() const;
25 bool IsFile() const { return S_ISREG(fInode->mode); }
26 bool IsDirectory() const { return S_ISDIR(fInode->mode); }
27 bool IsSymlink() const { return S_ISLNK(fInode->mode); }
28 bool IsIndex() const { return S_ISINDEX(fInode->mode); }
29 bool IsAttribute() const
30 { return (fInode->mode & S_ATTR) != 0; }
31 bool IsAttributeDirectory() const
32 { return (fInode->mode & S_ATTR_DIR) != 0; }
33 bool IsRoot() const { return BlockRun() == fDisk->Root(); }
35 int32 Mode() const { return fInode->mode; }
36 int32 Flags() const { return fInode->flags; }
37 off_t Size() const { return fInode->data.size; }
39 off_t Offset() const
40 { return fDisk->ToOffset(BlockRun()); }
41 off_t Block() const { return fDisk->ToBlock(BlockRun()); }
42 const block_run& BlockRun() const { return fBlockRun; }
43 block_run Parent() const { return fInode->parent; }
44 block_run Attributes() const { return fInode->attributes; }
46 const bfs_inode* InodeBuffer() const { return fInode; }
47 status_t CopyBuffer();
49 void ReleaseBuffer();
50 status_t AcquireBuffer();
51 void BufferClobbered();
53 void SetParent(const block_run& run);
54 void SetBlockRun(const block_run& run);
55 void SetMode(uint32 mode);
57 status_t SetName(const char* name);
58 const char* Name() const;
59 status_t GetNextSmallData(small_data** smallData);
61 status_t RewindAttributes();
62 status_t GetNextAttribute(char* name, uint32* type, void** data,
63 size_t* length);
65 class Source;
66 const char* Path(Inode::Source* source = NULL);
67 virtual status_t CopyTo(const char* path, bool fullPath = true,
68 Inode::Source* source = NULL);
69 status_t CopyAttributesTo(BNode* node);
71 static Inode* Factory(Disk* disk, bfs_inode* inode,
72 bool ownBuffer = true);
73 static Inode* Factory(Disk* disk, block_run run);
74 static Inode* Factory(Disk* disk, Inode* inode,
75 bool copyBuffer = true);
77 static Inode* EmptyInode(Disk* disk,const char* name, int32 mode);
79 class Source {
80 public:
81 virtual Inode *InodeAt(block_run run) = 0;
84 protected:
85 static bool _LowMemory();
86 void _Unset();
87 status_t _FindPath(Inode::Source *source = NULL);
89 Disk *fDisk;
90 bfs_inode *fInode;
91 bool fOwnBuffer;
92 char *fPath;
93 block_run fBlockRun;
94 int32 fRefCount;
96 small_data *fCurrentSmallData;
97 Directory *fAttributes;
98 void *fAttributeBuffer;
102 class DataStream : public Inode, public BPositionIO {
103 public:
104 DataStream(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
105 DataStream(const Inode &inode);
106 ~DataStream();
108 status_t FindBlockRun(off_t pos);
110 virtual ssize_t ReadAt(off_t pos, void *buffer, size_t size);
111 virtual ssize_t WriteAt(off_t pos, const void *buffer, size_t size);
113 virtual off_t Seek(off_t position, uint32 seek_mode);
114 virtual off_t Position() const;
116 virtual status_t SetSize(off_t size);
118 private:
119 int32 fCurrent;
120 int32 fLevel;
121 block_run fRun;
122 off_t fRunFileOffset;
123 off_t fRunBlockEnd;
124 off_t fPosition;
128 class File : public DataStream {
129 public:
130 File(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
131 File(const Inode &inode);
132 ~File();
134 virtual status_t InitCheck() const;
135 virtual status_t CopyTo(const char *path, bool fullPath = true,
136 Inode::Source *source = NULL);
140 class Attribute : public File {
141 public:
142 Attribute(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
143 Attribute(const Inode &inode);
144 ~Attribute();
146 virtual status_t InitCheck() const;
147 virtual status_t CopyTo(const char *path, bool fullPath = true,
148 Inode::Source *source = NULL);
150 uint32 Type() const { return fInode->type; }
154 class Directory : public DataStream {
155 public:
156 Directory(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
157 Directory(const Inode &inode);
158 ~Directory();
160 virtual status_t InitCheck() const;
161 virtual status_t CopyTo(const char *path, bool fullPath = true,
162 Inode::Source *source = NULL);
164 virtual status_t Rewind();
165 virtual status_t GetNextEntry(char *name, block_run *run);
166 virtual status_t GetNextEntry(block_run *run);
168 virtual status_t Contains(const block_run *run);
169 virtual status_t Contains(const Inode *inode);
170 virtual status_t FindEntry(const char *name, block_run *run);
172 virtual status_t AddEntry(Inode *inode);
174 status_t GetTree(BPlusTree **tree);
176 private:
177 virtual status_t CreateTree();
179 BPlusTree *fTree;
183 class Symlink : public Inode {
184 public:
185 Symlink(Disk *disk, bfs_inode *inode, bool ownBuffer = true);
186 Symlink(const Inode &inode);
187 ~Symlink();
189 virtual status_t InitCheck() const;
190 virtual status_t CopyTo(const char *path, bool fullPath = true,
191 Inode::Source *source = NULL);
193 status_t LinksTo(char *to, size_t maxLength);
195 private:
196 char *fTo;
199 #endif /* INODE_H */