13 * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer)
14 * \brief Read data from a node (file)
16 size_t VFS_Read(int FD, size_t Length, void *Buffer)
21 ENTER("xFD xLength pBuffer", FD, Length, Buffer);
23 h = VFS_GetHandle(FD);
29 if( !(h->Mode & VFS_OPENFLAG_READ) ) {
33 if( (h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
34 LOG("Reading directory");
38 if(!h->Node->Type || !h->Node->Type->Read) {
39 LOG("No read method");
43 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
44 Log_Error("VFS", "Node type %p(%s) read method is junk %p",
45 h->Node->Type, h->Node, h->Node->Type->TypeName,
50 LOG("Position=%llx", h->Position);
51 ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer);
52 if(ret == (size_t)-1) LEAVE_RET('i', -1);
60 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
61 * \brief Read data from a given offset (atomic)
63 size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer)
68 h = VFS_GetHandle(FD);
71 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
72 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
74 if( !h->Node->Type || !h->Node->Type->Read) {
75 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
79 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
80 Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
85 ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer);
86 if(ret == (size_t)-1) return -1;
91 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
92 * \brief Read data from a node (file)
94 size_t VFS_Write(int FD, size_t Length, const void *Buffer)
99 h = VFS_GetHandle(FD);
102 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) {
103 LOG("FD%i not opened for writing", FD);
106 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) {
107 LOG("FD%i is a director", FD);
111 if( !h->Node->Type || !h->Node->Type->Write ) {
112 LOG("FD%i has no write method", FD);
116 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
117 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
118 h->Node->Type->Write);
122 ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer);
123 if(ret == (size_t)-1) return -1;
130 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
131 * \brief Write data to a file at a given offset
133 size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer)
138 h = VFS_GetHandle(FD);
141 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
142 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
144 if(!h->Node->Type || !h->Node->Type->Write) return 0;
146 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
147 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
148 h->Node->Type->Write);
151 ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer);
152 if(ret == (size_t)-1) return -1;
157 * \fn Uint64 VFS_Tell(int FD)
158 * \brief Returns the current file position
160 Uint64 VFS_Tell(int FD)
164 h = VFS_GetHandle(FD);
171 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
172 * \brief Seek to a new location
173 * \param FD File descriptor
174 * \param Offset Where to go
175 * \param Whence From where
177 int VFS_Seek(int FD, Sint64 Offset, int Whence)
181 h = VFS_GetHandle(FD);
184 // Set relative to current position
186 LOG("(FD%x)->Position += %lli", FD, Offset);
187 h->Position += Offset;
191 // Set relative to end of file
193 if( h->Node->Size == (Uint64)-1 ) return -1;
195 LOG("(FD%x)->Position = %llx - %llx", FD, h->Node->Size, Offset);
196 h->Position = h->Node->Size - Offset;
200 // Set relative to start of file
201 LOG("(FD%x)->Position = %llx", FD, Offset);
202 h->Position = Offset;
207 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
208 * \brief Call an IO Control on a file
210 int VFS_IOCtl(int FD, int ID, void *Buffer)
214 h = VFS_GetHandle(FD);
217 if(!h->Node->Type || !h->Node->Type->IOCtl) return -1;
218 return h->Node->Type->IOCtl(h->Node, ID, Buffer);
222 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
223 * \brief Retrieve file information
224 * \return Number of ACLs stored
226 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
231 h = VFS_GetHandle(FD);
235 Dest->mount = h->Mount->Identifier;
238 Dest->inode = h->Node->Inode;
239 Dest->uid = h->Node->UID;
240 Dest->gid = h->Node->GID;
241 Dest->size = h->Node->Size;
242 Dest->atime = h->Node->ATime;
243 Dest->ctime = h->Node->MTime;
244 Dest->mtime = h->Node->CTime;
245 Dest->numacls = h->Node->NumACLs;
248 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
249 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
251 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
252 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));