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);
23 if(!h) LEAVE_RET('i', -1);
25 if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY )
28 if(!h->Node->Read) LEAVE_RET('i', 0);
30 ret = h->Node->Read(h->Node, h->Position, Length, Buffer);
31 if(ret == -1) LEAVE_RET('i', -1);
39 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
40 * \brief Read data from a given offset (atomic)
42 Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
47 h = VFS_GetHandle(FD);
50 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
51 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
54 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
57 ret = h->Node->Read(h->Node, Offset, Length, Buffer);
58 if(ret == -1) return -1;
63 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
64 * \brief Read data from a node (file)
66 Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
71 h = VFS_GetHandle(FD);
74 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
75 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
77 if(!h->Node->Write) return 0;
79 // TODO: This is a hack, I need to change VFS_Node to have "const void*"
80 ret = h->Node->Write(h->Node, h->Position, Length, (void*)Buffer);
81 if(ret == -1) return -1;
87 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
88 * \brief Write data to a file at a given offset
90 Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
95 h = VFS_GetHandle(FD);
98 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
99 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
101 if(!h->Node->Write) return 0;
102 // TODO: This is a hack, I need to change VFS_Node to have "const void*"
103 ret = h->Node->Write(h->Node, Offset, Length, (void*)Buffer);
104 if(ret == -1) return -1;
109 * \fn Uint64 VFS_Tell(int FD)
110 * \brief Returns the current file position
112 Uint64 VFS_Tell(int FD)
116 h = VFS_GetHandle(FD);
123 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
124 * \brief Seek to a new location
125 * \param FD File descriptor
126 * \param Offset Where to go
127 * \param Whence From where
129 int VFS_Seek(int FD, Sint64 Offset, int Whence)
133 h = VFS_GetHandle(FD);
136 //Log_Debug("VFS", "VFS_Seek: (fd=0x%x, Offset=0x%llx, Whence=%i)",
137 // FD, Offset, Whence);
139 // Set relative to current position
141 h->Position += Offset;
145 // Set relative to end of file
147 if( h->Node->Size == -1 ) return -1;
149 h->Position = h->Node->Size - Offset;
153 // Set relative to start of file
154 h->Position = Offset;
159 * \fn int VFS_IOCtl(int FD, int ID, void *Buffer)
160 * \brief Call an IO Control on a file
162 int VFS_IOCtl(int FD, int ID, void *Buffer)
166 h = VFS_GetHandle(FD);
169 if(!h->Node->IOCtl) return -1;
170 return h->Node->IOCtl(h->Node, ID, Buffer);
174 * \fn int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
175 * \brief Retrieve file information
176 * \return Number of ACLs stored
178 int VFS_FInfo(int FD, tFInfo *Dest, int MaxACLs)
183 h = VFS_GetHandle(FD);
187 Dest->mount = h->Mount->Identifier;
190 Dest->inode = h->Node->Inode;
191 Dest->uid = h->Node->UID;
192 Dest->gid = h->Node->GID;
193 Dest->size = h->Node->Size;
194 Dest->atime = h->Node->ATime;
195 Dest->ctime = h->Node->MTime;
196 Dest->mtime = h->Node->CTime;
197 Dest->numacls = h->Node->NumACLs;
200 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
201 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
203 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
204 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));