1f9d99406SAxel Dörfler /* 2b9216114SAxel Dörfler * Copyright 2002-2008, Haiku, Inc. All Rights Reserved. 3f9d99406SAxel Dörfler * Distributed under the terms of the MIT License. 4338b8dc3SIngo Weinhold */ 5338b8dc3SIngo Weinhold #ifndef _NODE_H 6338b8dc3SIngo Weinhold #define _NODE_H 7338b8dc3SIngo Weinhold 8f9d99406SAxel Dörfler 9338b8dc3SIngo Weinhold #include <Statable.h> 10338b8dc3SIngo Weinhold 11f9d99406SAxel Dörfler class BDirectory; 12a1f8d8a1SIngo Weinhold class BEntry; 13a1f8d8a1SIngo Weinhold class BString; 14a1f8d8a1SIngo Weinhold struct entry_ref; 15338b8dc3SIngo Weinhold 16338b8dc3SIngo Weinhold //! Reference structure to a particular vnode on a particular device 17338b8dc3SIngo Weinhold /*! <b>node_ref</b> - A node reference. 18338b8dc3SIngo Weinhold 19338b8dc3SIngo Weinhold @author <a href="mailto:tylerdauwalder@users.sf.net">Tyler Dauwalder</a> 20338b8dc3SIngo Weinhold @author Be Inc. 21338b8dc3SIngo Weinhold @version 0.0.0 22338b8dc3SIngo Weinhold */ 23338b8dc3SIngo Weinhold struct node_ref { 24338b8dc3SIngo Weinhold node_ref(); 25338b8dc3SIngo Weinhold node_ref(const node_ref &ref); 26338b8dc3SIngo Weinhold 27338b8dc3SIngo Weinhold bool operator==(const node_ref &ref) const; 28338b8dc3SIngo Weinhold bool operator!=(const node_ref &ref) const; 29338b8dc3SIngo Weinhold node_ref& operator=(const node_ref &ref); 30338b8dc3SIngo Weinhold 31*28c8a16aSAugustin Cavalier bool operator<(const node_ref &ref) const; 32338b8dc3SIngo Weinhold 33338b8dc3SIngo Weinhold dev_t device; 34338b8dc3SIngo Weinhold ino_t node; 35338b8dc3SIngo Weinhold }; 36338b8dc3SIngo Weinhold 37338b8dc3SIngo Weinhold 38338b8dc3SIngo Weinhold //! A BNode represents a chunk of data in the filesystem. 39338b8dc3SIngo Weinhold /*! The BNode class provides an interface for manipulating the data and attributes 40338b8dc3SIngo Weinhold belonging to filesystem entries. The BNode is unaware of the name that refers 41338b8dc3SIngo Weinhold to it in the filesystem (i.e. its entry); a BNode is solely concerned with 42338b8dc3SIngo Weinhold the entry's data and attributes. 43338b8dc3SIngo Weinhold 44338b8dc3SIngo Weinhold 45338b8dc3SIngo Weinhold @author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a> 46338b8dc3SIngo Weinhold @version 0.0.0 47338b8dc3SIngo Weinhold 48338b8dc3SIngo Weinhold */ 49338b8dc3SIngo Weinhold class BNode : public BStatable { 50338b8dc3SIngo Weinhold public: 51338b8dc3SIngo Weinhold BNode(); 52338b8dc3SIngo Weinhold BNode(const entry_ref *ref); 53338b8dc3SIngo Weinhold BNode(const BEntry *entry); 54338b8dc3SIngo Weinhold BNode(const char *path); 55338b8dc3SIngo Weinhold BNode(const BDirectory *dir, const char *path); 56338b8dc3SIngo Weinhold BNode(const BNode &node); 57338b8dc3SIngo Weinhold virtual ~BNode(); 58338b8dc3SIngo Weinhold 59338b8dc3SIngo Weinhold status_t InitCheck() const; 60338b8dc3SIngo Weinhold 61338b8dc3SIngo Weinhold virtual status_t GetStat(struct stat *st) const; 62338b8dc3SIngo Weinhold 63338b8dc3SIngo Weinhold status_t SetTo(const entry_ref *ref); 64338b8dc3SIngo Weinhold status_t SetTo(const BEntry *entry); 65338b8dc3SIngo Weinhold status_t SetTo(const char *path); 66338b8dc3SIngo Weinhold status_t SetTo(const BDirectory *dir, const char *path); 67338b8dc3SIngo Weinhold void Unset(); 68338b8dc3SIngo Weinhold 69338b8dc3SIngo Weinhold status_t Lock(); 70338b8dc3SIngo Weinhold status_t Unlock(); 71338b8dc3SIngo Weinhold 72338b8dc3SIngo Weinhold status_t Sync(); 73338b8dc3SIngo Weinhold 74338b8dc3SIngo Weinhold ssize_t WriteAttr(const char *name, type_code type, off_t offset, 75338b8dc3SIngo Weinhold const void *buffer, size_t len); 76338b8dc3SIngo Weinhold ssize_t ReadAttr(const char *name, type_code type, off_t offset, 77338b8dc3SIngo Weinhold void *buffer, size_t len) const; 78338b8dc3SIngo Weinhold status_t RemoveAttr(const char *name); 79338b8dc3SIngo Weinhold status_t RenameAttr(const char *oldname, const char *newname); 80338b8dc3SIngo Weinhold status_t GetAttrInfo(const char *name, struct attr_info *info) const; 81338b8dc3SIngo Weinhold status_t GetNextAttrName(char *buffer); 82338b8dc3SIngo Weinhold status_t RewindAttrs(); 83338b8dc3SIngo Weinhold status_t WriteAttrString(const char *name, const BString *data); 84338b8dc3SIngo Weinhold status_t ReadAttrString(const char *name, BString *result) const; 85338b8dc3SIngo Weinhold 86338b8dc3SIngo Weinhold BNode& operator=(const BNode &node); 87338b8dc3SIngo Weinhold bool operator==(const BNode &node) const; 88338b8dc3SIngo Weinhold bool operator!=(const BNode &node) const; 89338b8dc3SIngo Weinhold 90338b8dc3SIngo Weinhold int Dup(); // This should be "const" but R5's is not... Ugggh. 91338b8dc3SIngo Weinhold 92338b8dc3SIngo Weinhold private: 93338b8dc3SIngo Weinhold friend class BFile; 94338b8dc3SIngo Weinhold friend class BDirectory; 95338b8dc3SIngo Weinhold friend class BSymLink; 96338b8dc3SIngo Weinhold 97338b8dc3SIngo Weinhold virtual void _RudeNode1(); 98338b8dc3SIngo Weinhold virtual void _RudeNode2(); 99338b8dc3SIngo Weinhold virtual void _RudeNode3(); 100338b8dc3SIngo Weinhold virtual void _RudeNode4(); 101338b8dc3SIngo Weinhold virtual void _RudeNode5(); 102338b8dc3SIngo Weinhold virtual void _RudeNode6(); 103338b8dc3SIngo Weinhold 104338b8dc3SIngo Weinhold uint32 rudeData[4]; 105338b8dc3SIngo Weinhold 106338b8dc3SIngo Weinhold private: 107338b8dc3SIngo Weinhold status_t set_fd(int fd); 108338b8dc3SIngo Weinhold virtual void close_fd(); 109338b8dc3SIngo Weinhold void set_status(status_t newStatus); 110338b8dc3SIngo Weinhold 111338b8dc3SIngo Weinhold status_t _SetTo(int fd, const char *path, bool traverse); 112338b8dc3SIngo Weinhold status_t _SetTo(const entry_ref *ref, bool traverse); 113338b8dc3SIngo Weinhold 114338b8dc3SIngo Weinhold virtual status_t set_stat(struct stat &st, uint32 what); 115338b8dc3SIngo Weinhold 116338b8dc3SIngo Weinhold int fFd; 117338b8dc3SIngo Weinhold int fAttrFd; 118338b8dc3SIngo Weinhold status_t fCStatus; 119338b8dc3SIngo Weinhold 120338b8dc3SIngo Weinhold status_t InitAttrDir(); 121338b8dc3SIngo Weinhold }; 122338b8dc3SIngo Weinhold 123338b8dc3SIngo Weinhold #endif // _NODE_H 124