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("iFD 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 ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer);
50 if(ret == (size_t)-1) LEAVE_RET('i', -1);
58 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
59 * \brief Read data from a given offset (atomic)
61 size_t VFS_ReadAt(int FD, Uint64 Offset, size_t 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;
72 if( !h->Node->Type || !h->Node->Type->Read) {
73 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
77 if( !MM_GetPhysAddr(h->Node->Type->Read) ) {
78 Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
83 ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer);
84 if(ret == (size_t)-1) return -1;
89 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
90 * \brief Read data from a node (file)
92 size_t VFS_Write(int FD, size_t Length, const void *Buffer)
97 h = VFS_GetHandle(FD);
100 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
101 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
103 if( !h->Node->Type || !h->Node->Type->Write ) return 0;
105 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
106 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
107 h->Node->Type->Write);
111 ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer);
112 if(ret == (size_t)-1) return -1;
119 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
120 * \brief Write data to a file at a given offset
122 size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer)
127 h = VFS_GetHandle(FD);
130 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
131 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
133 if(!h->Node->Type || !h->Node->Type->Write) return 0;
135 if( !MM_GetPhysAddr(h->Node->Type->Write) ) {
136 Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName,
137 h->Node->Type->Write);
140 ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer);
141 if(ret == (size_t)-1) return -1;
146 * \fn Uint64 VFS_Tell(int FD)
147 * \brief Returns the current file position
149 Uint64 VFS_Tell(int FD)
153 h = VFS_GetHandle(FD);
160 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
161 * \brief Seek to a new location
162 * \param FD File descriptor
163 * \param Offset Where to go
164 * \param Whence From where
166 int VFS_Seek(int FD, Sint64 Offset, int Whence)
170 h = VFS_GetHandle(FD);
173 //Log_Debug("VFS", "VFS_Seek: (fd=0x%x, Offset=0x%llx, Whence=%i)",
174 // FD, Offset, Whence);
176 // Set relative to current position
178 h->Position += Offset;
182 // Set relative to end of file
184 if( h->Node->Size == (Uint64)-1 ) return -1;
186 h->Position = h->Node->Size - Offset;
190 // Set relative to start of file
191 h->Position = Offset;
196 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
197 * \brief Call an IO Control on a file
199 int VFS_IOCtl(int FD, int ID, void *Buffer)
203 h = VFS_GetHandle(FD);
206 if(!h->Node->Type || !h->Node->Type->IOCtl) return -1;
207 return h->Node->Type->IOCtl(h->Node, ID, Buffer);
211 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
212 * \brief Retrieve file information
213 * \return Number of ACLs stored
215 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
220 h = VFS_GetHandle(FD);
224 Dest->mount = h->Mount->Identifier;
227 Dest->inode = h->Node->Inode;
228 Dest->uid = h->Node->UID;
229 Dest->gid = h->Node->GID;
230 Dest->size = h->Node->Size;
231 Dest->atime = h->Node->ATime;
232 Dest->ctime = h->Node->MTime;
233 Dest->mtime = h->Node->CTime;
234 Dest->numacls = h->Node->NumACLs;
237 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
238 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
240 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
241 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));