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
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 //Log_Debug("VFS", "VFS_Seek: (fd=0x%x, Offset=0x%llx, Whence=%i)",
154 // FD, Offset, Whence);
156 // Set relative to current position
158 h->Position += Offset;
162 // Set relative to end of file
164 h->Position = h->Node->Size - Offset;
168 // Set relative to start of file
169 h->Position = Offset;
174 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
175 * \brief Call an IO Control on a file
177 int VFS_IOCtl(int FD, int ID, void *Buffer)
181 h = VFS_GetHandle(FD);
184 if(!h->Node->IOCtl) return -1;
185 return h->Node->IOCtl(h->Node, ID, Buffer);
189 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
190 * \brief Retrieve file information
191 * \return Number of ACLs stored
193 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
198 h = VFS_GetHandle(FD);
201 Dest->uid = h->Node->UID;
202 Dest->gid = h->Node->GID;
203 Dest->size = h->Node->Size;
204 Dest->atime = h->Node->ATime;
205 Dest->ctime = h->Node->MTime;
206 Dest->mtime = h->Node->CTime;
207 Dest->numacls = h->Node->NumACLs;
210 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
211 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
213 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
214 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));