1 /* 2 * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _NODE_H 6 #define _NODE_H 7 8 9 #include <Statable.h> 10 11 class BDirectory; 12 13 //! Reference structure to a particular vnode on a particular device 14 /*! <b>node_ref</b> - A node reference. 15 16 @author <a href="mailto:tylerdauwalder@users.sf.net">Tyler Dauwalder</a> 17 @author Be Inc. 18 @version 0.0.0 19 */ 20 struct node_ref { 21 node_ref(); 22 node_ref(const node_ref &ref); 23 24 bool operator==(const node_ref &ref) const; 25 bool operator!=(const node_ref &ref) const; 26 node_ref& operator=(const node_ref &ref); 27 28 dev_t device; 29 ino_t node; 30 }; 31 32 33 //! A BNode represents a chunk of data in the filesystem. 34 /*! The BNode class provides an interface for manipulating the data and attributes 35 belonging to filesystem entries. The BNode is unaware of the name that refers 36 to it in the filesystem (i.e. its entry); a BNode is solely concerned with 37 the entry's data and attributes. 38 39 40 @author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a> 41 @version 0.0.0 42 43 */ 44 class BNode : public BStatable { 45 public: 46 BNode(); 47 BNode(const entry_ref *ref); 48 BNode(const BEntry *entry); 49 BNode(const char *path); 50 BNode(const BDirectory *dir, const char *path); 51 BNode(const BNode &node); 52 virtual ~BNode(); 53 54 status_t InitCheck() const; 55 56 virtual status_t GetStat(struct stat *st) const; 57 58 status_t SetTo(const entry_ref *ref); 59 status_t SetTo(const BEntry *entry); 60 status_t SetTo(const char *path); 61 status_t SetTo(const BDirectory *dir, const char *path); 62 void Unset(); 63 64 status_t Lock(); 65 status_t Unlock(); 66 67 status_t Sync(); 68 69 ssize_t WriteAttr(const char *name, type_code type, off_t offset, 70 const void *buffer, size_t len); 71 ssize_t ReadAttr(const char *name, type_code type, off_t offset, 72 void *buffer, size_t len) const; 73 status_t RemoveAttr(const char *name); 74 status_t RenameAttr(const char *oldname, const char *newname); 75 status_t GetAttrInfo(const char *name, struct attr_info *info) const; 76 status_t GetNextAttrName(char *buffer); 77 status_t RewindAttrs(); 78 status_t WriteAttrString(const char *name, const BString *data); 79 status_t ReadAttrString(const char *name, BString *result) const; 80 81 BNode& operator=(const BNode &node); 82 bool operator==(const BNode &node) const; 83 bool operator!=(const BNode &node) const; 84 85 int Dup(); // This should be "const" but R5's is not... Ugggh. 86 87 private: 88 friend class BFile; 89 friend class BDirectory; 90 friend class BSymLink; 91 92 virtual void _RudeNode1(); 93 virtual void _RudeNode2(); 94 virtual void _RudeNode3(); 95 virtual void _RudeNode4(); 96 virtual void _RudeNode5(); 97 virtual void _RudeNode6(); 98 99 uint32 rudeData[4]; 100 101 private: 102 status_t set_fd(int fd); 103 virtual void close_fd(); 104 void set_status(status_t newStatus); 105 106 status_t _SetTo(int fd, const char *path, bool traverse); 107 status_t _SetTo(const entry_ref *ref, bool traverse); 108 109 virtual status_t set_stat(struct stat &st, uint32 what); 110 111 int fFd; 112 int fAttrFd; 113 status_t fCStatus; 114 115 status_t InitAttrDir(); 116 }; 117 118 #endif // _NODE_H 119