1 /* 2 * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef USERLAND_FS_VOLUME_H 6 #define USERLAND_FS_VOLUME_H 7 8 #include <fs_interface.h> 9 #include <SupportDefs.h> 10 11 #include <kernel/util/DoublyLinkedList.h> 12 13 #include "FSCapabilities.h" 14 15 16 namespace UserlandFS { 17 18 class FileSystem; 19 class IORequestInfo; 20 21 using UserlandFSUtil::FSVolumeCapabilities; 22 23 class Volume : public DoublyLinkedListLinkImpl<Volume> { 24 public: 25 Volume(FileSystem* fileSystem, dev_t id); 26 virtual ~Volume(); 27 28 FileSystem* GetFileSystem() const; 29 dev_t GetID() const; 30 31 void GetCapabilities( 32 FSVolumeCapabilities& capabilities) const 33 { capabilities = fCapabilities; } 34 35 // FS 36 virtual status_t Mount(const char* device, uint32 flags, 37 const char* parameters, ino_t* rootID); 38 virtual status_t Unmount(); 39 virtual status_t Sync(); 40 virtual status_t ReadFSInfo(fs_info* info); 41 virtual status_t WriteFSInfo(const struct fs_info* info, 42 uint32 mask); 43 44 // vnodes 45 virtual status_t Lookup(void* dir, const char* entryName, 46 ino_t* vnid); 47 virtual status_t GetVNodeType(void* node, int* type); 48 // Only needs to be implemented when 49 // the three parameters publish_vnode() is 50 // used. 51 virtual status_t GetVNodeName(void* node, char* buffer, 52 size_t bufferSize); 53 virtual status_t ReadVNode(ino_t vnid, bool reenter, 54 void** node, int* type, uint32* flags, 55 FSVNodeCapabilities* _capabilities); 56 virtual status_t WriteVNode(void* node, bool reenter); 57 virtual status_t RemoveVNode(void* node, bool reenter); 58 59 // asynchronous I/O 60 virtual status_t DoIO(void* node, void* cookie, 61 const IORequestInfo& requestInfo); 62 virtual status_t CancelIO(void* node, void* cookie, 63 int32 ioRequestID); 64 virtual status_t IterativeIOGetVecs(void* cookie, 65 int32 requestID, off_t offset, size_t size, 66 struct file_io_vec* vecs, size_t* _count); 67 virtual status_t IterativeIOFinished(void* cookie, 68 int32 requestID, status_t status, 69 bool partialTransfer, 70 size_t bytesTransferred); 71 72 // nodes 73 virtual status_t IOCtl(void* node, void* cookie, 74 uint32 command, void* buffer, size_t size); 75 virtual status_t SetFlags(void* node, void* cookie, 76 int flags); 77 virtual status_t Select(void* node, void* cookie, 78 uint8 event, selectsync* sync); 79 virtual status_t Deselect(void* node, void* cookie, 80 uint8 event, selectsync* sync); 81 82 virtual status_t FSync(void* node); 83 84 virtual status_t ReadSymlink(void* node, char* buffer, 85 size_t bufferSize, size_t* bytesRead); 86 virtual status_t CreateSymlink(void* dir, const char* name, 87 const char* target, int mode); 88 89 virtual status_t Link(void* dir, const char* name, 90 void* node); 91 virtual status_t Unlink(void* dir, const char* name); 92 virtual status_t Rename(void* oldDir, const char* oldName, 93 void* newDir, const char* newName); 94 95 virtual status_t Access(void* node, int mode); 96 virtual status_t ReadStat(void* node, struct stat* st); 97 virtual status_t WriteStat(void* node, const struct stat *st, 98 uint32 mask); 99 100 // files 101 virtual status_t Create(void* dir, const char* name, 102 int openMode, int mode, void** cookie, 103 ino_t* vnid); 104 virtual status_t Open(void* node, int openMode, 105 void** cookie); 106 virtual status_t Close(void* node, void* cookie); 107 virtual status_t FreeCookie(void* node, void* cookie); 108 virtual status_t Read(void* node, void* cookie, off_t pos, 109 void* buffer, size_t bufferSize, 110 size_t* bytesRead); 111 virtual status_t Write(void* node, void* cookie, 112 off_t pos, const void* buffer, 113 size_t bufferSize, size_t* bytesWritten); 114 115 // directories 116 virtual status_t CreateDir(void* dir, const char* name, 117 int mode); 118 virtual status_t RemoveDir(void* dir, const char* name); 119 virtual status_t OpenDir(void* node, void** cookie); 120 virtual status_t CloseDir(void* node, void* cookie); 121 virtual status_t FreeDirCookie(void* node, void* cookie); 122 virtual status_t ReadDir(void* node, void* cookie, 123 void* buffer, size_t bufferSize, 124 uint32 count, uint32* countRead); 125 virtual status_t RewindDir(void* node, void* cookie); 126 127 // attribute directories 128 virtual status_t OpenAttrDir(void* node, void** cookie); 129 virtual status_t CloseAttrDir(void* node, void* cookie); 130 virtual status_t FreeAttrDirCookie(void* node, 131 void* cookie); 132 virtual status_t ReadAttrDir(void* node, void* cookie, 133 void* buffer, size_t bufferSize, 134 uint32 count, uint32* countRead); 135 virtual status_t RewindAttrDir(void* node, void* cookie); 136 137 // attributes 138 virtual status_t CreateAttr(void* node, const char* name, 139 uint32 type, int openMode, 140 void** cookie); 141 virtual status_t OpenAttr(void* node, const char* name, 142 int openMode, void** cookie); 143 virtual status_t CloseAttr(void* node, void* cookie); 144 virtual status_t FreeAttrCookie(void* node, void* cookie); 145 virtual status_t ReadAttr(void* node, void* cookie, 146 off_t pos, void* buffer, size_t bufferSize, 147 size_t* bytesRead); 148 virtual status_t WriteAttr(void* node, void* cookie, 149 off_t pos, const void* buffer, 150 size_t bufferSize, size_t* bytesWritten); 151 virtual status_t ReadAttrStat(void* node, void* cookie, 152 struct stat* st); 153 virtual status_t WriteAttrStat(void* node, void* cookie, 154 const struct stat* st, int statMask); 155 virtual status_t RenameAttr(void* oldNode, 156 const char* oldName, void* newNode, 157 const char* newName); 158 virtual status_t RemoveAttr(void* node, const char* name); 159 160 // indices 161 virtual status_t OpenIndexDir(void** cookie); 162 virtual status_t CloseIndexDir(void* cookie); 163 virtual status_t FreeIndexDirCookie(void* cookie); 164 virtual status_t ReadIndexDir(void* cookie, void* buffer, 165 size_t bufferSize, uint32 count, 166 uint32* countRead); 167 virtual status_t RewindIndexDir(void* cookie); 168 virtual status_t CreateIndex(const char* name, uint32 type, 169 uint32 flags); 170 virtual status_t RemoveIndex(const char* name); 171 virtual status_t ReadIndexStat(const char *name, 172 struct stat *st); 173 174 // queries 175 virtual status_t OpenQuery(const char* queryString, 176 uint32 flags, port_id port, uint32 token, 177 void** cookie); 178 virtual status_t CloseQuery(void* cookie); 179 virtual status_t FreeQueryCookie(void* cookie); 180 virtual status_t ReadQuery(void* cookie, void* buffer, 181 size_t bufferSize, uint32 count, 182 uint32* countRead); 183 virtual status_t RewindQuery(void* cookie); 184 185 protected: 186 FileSystem* fFileSystem; 187 dev_t fID; 188 FSVolumeCapabilities fCapabilities; 189 }; 190 191 } // namespace UserlandFS 192 193 using UserlandFS::Volume; 194 195 #endif // USERLAND_FS_VOLUME_H 196