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", h->Node->Type, h->Node, h->Node->Type->TypeName,
49 LOG("Position=%llx", h->Position);
50 ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer);
51 if(ret == (size_t)-1) LEAVE_RET('i', -1);
59 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
60 * \brief Read data from a given offset (atomic)
62 size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer)
67 h = VFS_GetHandle(FD);
70 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
71 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
73 if( !h->Node->Type || !h->Node->Type->Read) {
74 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
78 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
79 Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
84 ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer);
85 if(ret == (size_t)-1) return -1;
90 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
91 * \brief Read data from a node (file)
93 size_t VFS_Write(int FD, size_t Length, const void *Buffer)
98 h = VFS_GetHandle(FD);
101 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
102 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
104 if( !h->Node->Type || !h->Node->Type->Write ) return 0;
106 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
107 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
108 h->Node->Type->Write);
112 ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer);
113 if(ret == (size_t)-1) return -1;
120 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
121 * \brief Write data to a file at a given offset
123 size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer)
128 h = VFS_GetHandle(FD);
131 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
132 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
134 if(!h->Node->Type || !h->Node->Type->Write) return 0;
136 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
137 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
138 h->Node->Type->Write);
141 ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer);
142 if(ret == (size_t)-1) return -1;
147 * \fn Uint64 VFS_Tell(int FD)
148 * \brief Returns the current file position
150 Uint64 VFS_Tell(int FD)
154 h = VFS_GetHandle(FD);
161 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
162 * \brief Seek to a new location
163 * \param FD File descriptor
164 * \param Offset Where to go
165 * \param Whence From where
167 int VFS_Seek(int FD, Sint64 Offset, int Whence)
171 h = VFS_GetHandle(FD);
174 // Set relative to current position
176 LOG("(FD%x)->Position += %lli", FD, Offset);
177 h->Position += Offset;
181 // Set relative to end of file
183 if( h->Node->Size == (Uint64)-1 ) return -1;
185 LOG("(FD%x)->Position = %llx - %llx", FD, h->Node->Size, Offset);
186 h->Position = h->Node->Size - Offset;
190 // Set relative to start of file
191 LOG("(FD%x)->Position = %llx", FD, Offset);
192 h->Position = Offset;
197 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
198 * \brief Call an IO Control on a file
200 int VFS_IOCtl(int FD, int ID, void *Buffer)
204 h = VFS_GetHandle(FD);
207 if(!h->Node->Type || !h->Node->Type->IOCtl) return -1;
208 return h->Node->Type->IOCtl(h->Node, ID, Buffer);
212 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
213 * \brief Retrieve file information
214 * \return Number of ACLs stored
216 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
221 h = VFS_GetHandle(FD);
225 Dest->mount = h->Mount->Identifier;
228 Dest->inode = h->Node->Inode;
229 Dest->uid = h->Node->UID;
230 Dest->gid = h->Node->GID;
231 Dest->size = h->Node->Size;
232 Dest->atime = h->Node->ATime;
233 Dest->ctime = h->Node->MTime;
234 Dest->mtime = h->Node->CTime;
235 Dest->numacls = h->Node->NumACLs;
238 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
239 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
241 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
242 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));