1 // Volume.h 2 3 #ifndef NET_FS_VOLUME_H 4 #define NET_FS_VOLUME_H 5 6 #include <fsproto.h> 7 8 #include <HashString.h> 9 10 #include "FSObject.h" 11 #include "Locker.h" 12 13 class Node; 14 class QueryIterator; 15 class VolumeEvent; 16 class VolumeManager; 17 18 class Volume : public FSObject { 19 public: 20 Volume(VolumeManager* volumeManager); 21 ~Volume(); 22 23 VolumeManager* GetVolumeManager() const; 24 25 void SetParentVolume(Volume* parent); 26 Volume* GetParentVolume() const; 27 // TODO: Add the parent node ID and maybe get rid of parent volume. 28 29 void PutVolume(); 30 31 status_t Init(const char* name); 32 void Uninit(); 33 34 const char* GetName() const; 35 36 vnode_id GetRootID() const; 37 virtual Node* GetRootNode() const = 0; 38 39 void SetUnmounting(bool unmounting); 40 bool IsUnmounting() const; 41 42 virtual void PrepareToUnmount(); 43 44 virtual void RemoveChildVolume(Volume* volume) = 0; 45 46 virtual void HandleEvent(VolumeEvent* event); 47 48 // client methods 49 status_t GetVNode(vnode_id vnid, Node** node); 50 status_t PutVNode(vnode_id vnid); 51 status_t NewVNode(vnode_id vnid, Node* node); 52 status_t RemoveVNode(vnode_id vnid); 53 status_t UnremoveVNode(vnode_id vnid); 54 int IsVNodeRemoved(vnode_id vnid); 55 56 int SendNotification(port_id port, int32 token, 57 uint32 what, int32 op, nspace_id nsida, 58 nspace_id nsidb, vnode_id vnida, 59 vnode_id vnidb, vnode_id vnidc, 60 const char *name); 61 int NotifyListener(int32 opcode, nspace_id nsid, 62 vnode_id vnida, vnode_id vnidb, 63 vnode_id vnidc, const char *name); 64 65 // FS 66 virtual status_t Unmount(); 67 virtual status_t Sync(); 68 virtual status_t ReadFSStat(fs_info* info); 69 virtual status_t WriteFSStat(struct fs_info* info, int32 mask); 70 71 // vnodes 72 virtual status_t ReadVNode(vnode_id vnid, char reenter, 73 Node** node); 74 virtual status_t WriteVNode(Node* node, char reenter); 75 virtual status_t RemoveVNode(Node* node, char reenter); 76 77 // nodes 78 virtual status_t FSync(Node* node); 79 virtual status_t ReadStat(Node* node, struct stat* st); 80 virtual status_t WriteStat(Node* node, struct stat *st, 81 uint32 mask); 82 virtual status_t Access(Node* node, int mode); 83 84 // files 85 virtual status_t Create(Node* dir, const char* name, 86 int openMode, int mode, vnode_id* vnid, 87 void** cookie); 88 virtual status_t Open(Node* node, int openMode, 89 void** cookie); 90 virtual status_t Close(Node* node, void* cookie); 91 virtual status_t FreeCookie(Node* node, void* cookie); 92 virtual status_t Read(Node* node, void* cookie, off_t pos, 93 void* buffer, size_t bufferSize, 94 size_t* bytesRead); 95 virtual status_t Write(Node* node, void* cookie, off_t pos, 96 const void* buffer, size_t bufferSize, 97 size_t* bytesWritten); 98 virtual status_t IOCtl(Node* node, void* cookie, int cmd, 99 void* buffer, size_t bufferSize); 100 virtual status_t SetFlags(Node* node, void* cookie, 101 int flags); 102 103 // hard links / symlinks 104 virtual status_t Link(Node* dir, const char* name, 105 Node* node); 106 virtual status_t Unlink(Node* dir, const char* name); 107 virtual status_t Symlink(Node* dir, const char* name, 108 const char* target); 109 virtual status_t ReadLink(Node* node, char* buffer, 110 size_t bufferSize, size_t* bytesRead); 111 virtual status_t Rename(Node* oldDir, const char* oldName, 112 Node* newDir, const char* newName); 113 114 // directories 115 virtual status_t MkDir(Node* dir, const char* name, 116 int mode); 117 virtual status_t RmDir(Node* dir, const char* name); 118 virtual status_t OpenDir(Node* node, void** cookie); 119 virtual status_t CloseDir(Node* node, void* cookie); 120 virtual status_t FreeDirCookie(Node* node, void* cookie); 121 virtual status_t ReadDir(Node* node, void* cookie, 122 struct dirent* buffer, size_t bufferSize, 123 int32 count, int32* countRead); 124 virtual status_t RewindDir(Node* node, void* cookie); 125 virtual status_t Walk(Node* dir, const char* entryName, 126 char** resolvedPath, vnode_id* vnid); 127 128 // attributes 129 virtual status_t OpenAttrDir(Node* node, void** cookie); 130 virtual status_t CloseAttrDir(Node* node, void* cookie); 131 virtual status_t FreeAttrDirCookie(Node* node, 132 void* cookie); 133 virtual status_t ReadAttrDir(Node* node, void* cookie, 134 struct dirent* buffer, size_t bufferSize, 135 int32 count, int32* countRead); 136 virtual status_t RewindAttrDir(Node* node, void* cookie); 137 virtual status_t ReadAttr(Node* node, const char* name, 138 int type, off_t pos, void* buffer, 139 size_t bufferSize, size_t* bytesRead); 140 virtual status_t WriteAttr(Node* node, const char* name, 141 int type, off_t pos, const void* buffer, 142 size_t bufferSize, size_t* bytesWritten); 143 virtual status_t RemoveAttr(Node* node, const char* name); 144 virtual status_t RenameAttr(Node* node, 145 const char* oldName, const char* newName); 146 virtual status_t StatAttr(Node* node, const char* name, 147 struct attr_info* attrInfo); 148 149 // queries 150 virtual status_t OpenQuery(const char* queryString, 151 uint32 flags, port_id port, int32 token, 152 QueryIterator** iterator); 153 virtual void FreeQueryIterator(QueryIterator* iterator); 154 virtual status_t ReadQuery(QueryIterator* iterator, 155 struct dirent* buffer, size_t bufferSize, 156 int32 count, int32* countRead); 157 158 protected: 159 Locker fLock; 160 VolumeManager* fVolumeManager; 161 Volume* fParentVolume; 162 HashString fName; 163 bool fUnmounting; 164 }; 165 166 #endif // NET_FS_VOLUME_H 167