xref: /haiku/headers/os/storage/Entry.h (revision a1163de83ea633463a79de234b8742ee106531b2)
1 /*
2  * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT 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 
18 #ifdef USE_OPENBEOS_NAMESPACE
19 namespace OpenBeOS {
20 #endif
21 
22 class	BDirectory;
23 class	BPath;
24 
25 struct entry_ref {
26 	entry_ref();
27   	entry_ref(dev_t dev, ino_t dir, const char *name);
28 	entry_ref(const entry_ref &ref);
29 	~entry_ref();
30 
31   	status_t set_name(const char *name);
32 
33 	bool operator==(const entry_ref &ref) const;
34 	bool operator!=(const entry_ref &ref) const;
35 	entry_ref &operator=(const entry_ref &ref);
36 
37 	dev_t	device;
38 	ino_t	directory;
39 	char	*name;
40 };
41 
42 class BEntry : public BStatable {
43 public:
44 	BEntry();
45 	BEntry(const BDirectory *dir, const char *path, bool traverse = false);
46 	BEntry(const entry_ref *ref, bool traverse = false);
47 	BEntry(const char *path, bool traverse = false);
48 	BEntry(const BEntry &entry);
49 	virtual ~BEntry();
50 
51 	status_t InitCheck() const;
52 	bool Exists() const;
53 
54 	virtual status_t GetStat(struct stat *st) const;
55 
56 	status_t SetTo(const BDirectory *dir, const char *path,
57 				   bool traverse = false);
58 	status_t SetTo(const entry_ref *ref, bool traverse = false);
59 	status_t SetTo(const char *path, bool traverse = false);
60 	void Unset();
61 
62 	status_t GetRef(entry_ref *ref) const;
63 	status_t GetPath(BPath *path) const;
64 	status_t GetParent(BEntry *entry) const;
65 	status_t GetParent(BDirectory *dir) const;
66 	status_t GetName(char *buffer) const;
67 
68 	status_t Rename(const char *path, bool clobber = false);
69 	status_t MoveTo(BDirectory *dir, const char *path = NULL,
70 					bool clobber = false);
71 	status_t Remove();
72 
73 	bool operator==(const BEntry &item) const;
74 	bool operator!=(const BEntry &item) const;
75 
76 	BEntry &operator=(const BEntry &item);
77 
78 private:
79 	friend class BDirectory;
80 	friend class BFile;
81 	friend class BNode;
82 	friend class BSymLink;
83 
84 	virtual	void _PennyEntry1();
85 	virtual	void _PennyEntry2();
86 	virtual	void _PennyEntry3();
87 	virtual	void _PennyEntry4();
88 	virtual	void _PennyEntry5();
89 	virtual	void _PennyEntry6();
90 
91 	/*! BEntry implementation of BStatable::set_stat() */
92 	virtual	status_t set_stat(struct stat &st, uint32 what);
93 
94 	status_t set(int dir, const char *path, bool traverse);
95 
96 	status_t set_name(const char *name);
97 
98 	status_t _Rename(BEntry& target, bool clobber);
99 
100 	void Dump(const char *name = NULL);
101 
102 	status_t _GetStat(struct stat *st) const;
103 	virtual status_t _GetStat(struct stat_beos *st) const;
104 
105 private:
106 	/*! Currently unused. */
107 	uint32 _pennyData[4];
108 
109 	/*! File descriptor for the entry's parent directory. */
110 	int fDirFd;
111 
112 	/*! Leaf name of the entry. */
113 	char *fName;
114 
115 	/*! The object's initialization status. */
116 	status_t fCStatus;
117 };
118 
119 // C functions
120 
121 status_t get_ref_for_path(const char *path, entry_ref *ref);
122 bool operator<(const entry_ref &a, const entry_ref &b);
123 
124 
125 #ifdef USE_OPENBEOS_NAMESPACE
126 };		// namespace OpenBeOS
127 #endif
128 
129 #endif	// _ENTRY_H
130