xref: /haiku/headers/os/storage/Entry.h (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
1 /*
2  * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ENTRY_H
6 #define _ENTRY_H
7 
8 
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <SupportDefs.h>
12 
13 #include <Statable.h>
14 
15 
16 class BDirectory;
17 class BPath;
18 
19 
20 struct entry_ref {
21 								entry_ref();
22 								entry_ref(dev_t dev, ino_t dir,
23 									const char* name);
24 								entry_ref(const entry_ref& ref);
25 								~entry_ref();
26 
27 			status_t			set_name(const char* name);
28 
29 			bool				operator==(const entry_ref& ref) const;
30 			bool				operator!=(const entry_ref& ref) const;
31 			entry_ref&			operator=(const entry_ref& ref);
32 
33 			dev_t				device;
34 			ino_t				directory;
35 			char*				name;
36 };
37 
38 
39 class BEntry : public BStatable {
40 public:
41 								BEntry();
42 								BEntry(const BDirectory* dir, const char* path,
43 									bool traverse = false);
44 								BEntry(const entry_ref* ref,
45 									bool traverse = false);
46 								BEntry(const char* path, bool traverse = false);
47 								BEntry(const BEntry& entry);
48 	virtual						~BEntry();
49 
50 			status_t			InitCheck() const;
51 			bool				Exists() const;
52 
53 	virtual status_t			GetStat(struct stat* stat) const;
54 
55 			status_t			SetTo(const BDirectory* dir, const char* path,
56 								   bool traverse = false);
57 			status_t			SetTo(const entry_ref* ref,
58 									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& stat, uint32 what);
93 			status_t			_SetTo(int dir, const char* path,
94 									bool traverse);
95 			status_t			_SetName(const char* name);
96 
97 			status_t			_Rename(BEntry& target, bool clobber);
98 
99 			void				_Dump(const char* name = NULL);
100 
101 			status_t			_GetStat(struct stat* stat) const;
102 	virtual status_t			_GetStat(struct stat_beos* stat) const;
103 
104 private:
105 			int					fDirFd;
106 			char*				fName;
107 			status_t			fCStatus;
108 
109 			uint32				_reserved[4];
110 };
111 
112 
113 status_t get_ref_for_path(const char* path, entry_ref* ref);
114 bool operator<(const entry_ref& a, const entry_ref& b);
115 
116 
117 #endif	// _ENTRY_H
118