12 * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer)
13 * \brief Read data from a node (file)
15 Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer)
20 ENTER("iFD XLength pBuffer", FD, Length, Buffer);
22 h = VFS_GetHandle(FD);
28 if( !(h->Mode & VFS_OPENFLAG_READ) ) {
32 if( (h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
33 LOG("Reading directory");
37 if(!h->Node->Type || !h->Node->Type->Read) {
38 LOG("No read method");
42 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
43 Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
48 ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer);
49 if(ret == -1) LEAVE_RET('i', -1);
57 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
58 * \brief Read data from a given offset (atomic)
60 Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
65 h = VFS_GetHandle(FD);
68 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
69 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
71 if( !h->Node->Type || !h->Node->Type->Read) {
72 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
76 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
77 Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
82 ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer);
83 if(ret == -1) return -1;
88 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
89 * \brief Read data from a node (file)
91 Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
96 h = VFS_GetHandle(FD);
99 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
100 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
102 if( !h->Node->Type || !h->Node->Type->Write ) return 0;
104 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
105 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
106 h->Node->Type->Write);
110 ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer);
111 if(ret == -1) return -1;
118 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
119 * \brief Write data to a file at a given offset
121 Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
126 h = VFS_GetHandle(FD);
129 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
130 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
132 if(!h->Node->Type || !h->Node->Type->Write) return 0;
134 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
135 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
136 h->Node->Type->Write);
139 ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer);
140 if(ret == -1) return -1;
145 * \fn Uint64 VFS_Tell(int FD)
146 * \brief Returns the current file position
148 Uint64 VFS_Tell(int FD)
152 h = VFS_GetHandle(FD);
159 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
160 * \brief Seek to a new location
161 * \param FD File descriptor
162 * \param Offset Where to go
163 * \param Whence From where
165 int VFS_Seek(int FD, Sint64 Offset, int Whence)
169 h = VFS_GetHandle(FD);
172 //Log_Debug("VFS", "VFS_Seek: (fd=0x%x, Offset=0x%llx, Whence=%i)",
173 // FD, Offset, Whence);
175 // Set relative to current position
177 h->Position += Offset;
181 // Set relative to end of file
183 if( h->Node->Size == -1 ) return -1;
185 h->Position = h->Node->Size - Offset;
189 // Set relative to start of file
190 h->Position = Offset;
195 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
196 * \brief Call an IO Control on a file
198 int VFS_IOCtl(int FD, int ID, void *Buffer)
202 h = VFS_GetHandle(FD);
205 if(!h->Node->Type || !h->Node->Type->IOCtl) return -1;
206 return h->Node->Type->IOCtl(h->Node, ID, Buffer);
210 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
211 * \brief Retrieve file information
212 * \return Number of ACLs stored
214 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
219 h = VFS_GetHandle(FD);
223 Dest->mount = h->Mount->Identifier;
226 Dest->inode = h->Node->Inode;
227 Dest->uid = h->Node->UID;
228 Dest->gid = h->Node->GID;
229 Dest->size = h->Node->Size;
230 Dest->atime = h->Node->ATime;
231 Dest->ctime = h->Node->MTime;
232 Dest->mtime = h->Node->CTime;
233 Dest->numacls = h->Node->NumACLs;
236 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
237 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
239 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
240 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));