xref: /haiku/headers/os/storage/Entry.h (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 /*!
6 	\file Entry.h
7 	BEntry and entry_ref interface declarations.
8 */
9 #ifndef _ENTRY_H
10 #define _ENTRY_H
11 
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <SupportDefs.h>
15 
16 #include <Statable.h>
17 #include <StorageDefs.Private.h>
18 
19 #ifdef USE_OPENBEOS_NAMESPACE
20 namespace OpenBeOS {
21 #endif
22 
23 class	BDirectory;
24 class	BPath;
25 
26 struct entry_ref {
27 	entry_ref();
28   	entry_ref(dev_t dev, ino_t dir, const char *name);
29 	entry_ref(const entry_ref &ref);
30 	~entry_ref();
31 
32   	status_t set_name(const char *name);
33 
34 	bool operator==(const entry_ref &ref) const;
35 	bool operator!=(const entry_ref &ref) const;
36 	entry_ref &operator=(const entry_ref &ref);
37 
38 	dev_t	device;
39 	ino_t	directory;
40 	char	*name;
41 };
42 
43 class BEntry : public BStatable {
44 public:
45 	BEntry();
46 	BEntry(const BDirectory *dir, const char *path, bool traverse = false);
47 	BEntry(const entry_ref *ref, bool traverse = false);
48 	BEntry(const char *path, bool traverse = false);
49 	BEntry(const BEntry &entry);
50 	virtual ~BEntry();
51 
52 	status_t InitCheck() const;
53 	bool Exists() const;
54 
55 	virtual status_t GetStat(struct stat *st) const;
56 
57 	status_t SetTo(const BDirectory *dir, const char *path,
58 				   bool traverse = false);
59 	status_t SetTo(const entry_ref *ref, bool traverse = false);
60 	status_t SetTo(const char *path, bool traverse = false);
61 	void Unset();
62 
63 	status_t GetRef(entry_ref *ref) const;
64 	status_t GetPath(BPath *path) const;
65 	status_t GetParent(BEntry *entry) const;
66 	status_t GetParent(BDirectory *dir) const;
67 	status_t GetName(char *buffer) const;
68 
69 	status_t Rename(const char *path, bool clobber = false);
70 	status_t MoveTo(BDirectory *dir, const char *path = NULL,
71 					bool clobber = false);
72 	status_t Remove();
73 
74 	bool operator==(const BEntry &item) const;
75 	bool operator!=(const BEntry &item) const;
76 
77 	BEntry &operator=(const BEntry &item);
78 
79 private:
80 	virtual	void _PennyEntry1();
81 	virtual	void _PennyEntry2();
82 	virtual	void _PennyEntry3();
83 	virtual	void _PennyEntry4();
84 	virtual	void _PennyEntry5();
85 	virtual	void _PennyEntry6();
86 
87 	/*! Currently unused. */
88 	uint32 _pennyData[4];
89 
90 	/*! BEntry implementation of BStatable::set_stat() */
91 	virtual	status_t set_stat(struct stat &st, uint32 what);
92 
93 	status_t set(BPrivate::Storage::FileDescriptor dir, const char *path,
94 				 bool traverse);
95 
96 	/*! File descriptor for the entry's parent directory. */
97 	BPrivate::Storage::FileDescriptor fDirFd;
98 
99 	/*! Leaf name of the entry. */
100 	char *fName;
101 
102 	/*! The object's initialization status. */
103 	status_t fCStatus;
104 
105 	status_t set_name(const char *name);
106 
107 	void Dump(const char *name = NULL);
108 };
109 
110 // C functions
111 
112 status_t get_ref_for_path(const char *path, entry_ref *ref);
113 bool operator<(const entry_ref &a, const entry_ref &b);
114 
115 
116 #ifdef USE_OPENBEOS_NAMESPACE
117 };		// namespace OpenBeOS
118 #endif
119 
120 #endif	// _ENTRY_H
121 
122 
123 
124 
125