23 * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer)
24 * \brief Read data from a node (file)
26 Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer)
31 ENTER("iFD XLength pBuffer", FD, Length, Buffer);
33 h = VFS_GetHandle(FD);
36 if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) {
46 ret = h->Node->Read(h->Node, h->Position, Length, Buffer);
58 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
59 * \brief Read data from a given offset (atomic)
61 Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
66 h = VFS_GetHandle(FD);
69 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
70 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
73 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
76 ret = h->Node->Read(h->Node, Offset, Length, Buffer);
77 if(ret == -1) return -1;
82 * \fn Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer)
83 * \brief Read data from a node (file)
85 Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer)
90 h = VFS_GetHandle(FD);
93 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
94 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
96 if(!h->Node->Write) return 0;
98 ret = h->Node->Write(h->Node, h->Position, Length, Buffer);
99 if(ret == -1) return -1;
105 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
106 * \brief Write data to a file at a given offset (atomic)
108 Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
113 h = VFS_GetHandle(FD);
116 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
117 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
119 if(!h->Node->Write) return 0;
120 ret = h->Node->Write(h->Node, Offset, Length, Buffer);
121 if(ret == -1) return -1;
126 * \fn Uint64 VFS_Tell(int FD)
127 * \brief Returns the current file position
129 Uint64 VFS_Tell(int FD)
133 h = VFS_GetHandle(FD);
140 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
141 * \brief Seek to a new location
142 * \param FD File descriptor
143 * \param Offset Where to go
144 * \param Whence From where
146 int VFS_Seek(int FD, Sint64 Offset, int Whence)
150 h = VFS_GetHandle(FD);
153 // Set relative to current position
155 h->Position += Offset;
159 // Set relative to end of file
161 h->Position = h->Node->Size - Offset;
165 // Set relative to start of file
166 h->Position = Offset;
171 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
172 * \brief Call an IO Control on a file
174 int VFS_IOCtl(int FD, int ID, void *Buffer)
178 h = VFS_GetHandle(FD);
181 if(!h->Node->IOCtl) return -1;
182 return h->Node->IOCtl(h->Node, ID, Buffer);
186 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
187 * \brief Retrieve file information
188 * \return Number of ACLs stored
190 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
195 h = VFS_GetHandle(FD);
198 Dest->uid = h->Node->UID;
199 Dest->gid = h->Node->GID;
200 Dest->size = h->Node->Size;
201 Dest->atime = h->Node->ATime;
202 Dest->ctime = h->Node->MTime;
203 Dest->mtime = h->Node->CTime;
204 Dest->numacls = h->Node->NumACLs;
207 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
208 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
210 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
211 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));