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);
28 if( !(h->Mode & VFS_OPENFLAG_READ) ) {
32 if( (h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
33 LOG("Reading directory");
37 if(!h->Node->Type || !h->Node->Type->Read) {
38 LOG("No read method");
42 ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer);
43 if(ret == -1) LEAVE_RET('i', -1);
51 * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
52 * \brief Read data from a given offset (atomic)
54 Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
59 h = VFS_GetHandle(FD);
62 if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1;
63 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
65 if( !h->Node->Type || !h->Node->Type->Read) {
66 Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node);
69 ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer);
70 if(ret == -1) return -1;
75 * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
76 * \brief Read data from a node (file)
78 Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
83 h = VFS_GetHandle(FD);
86 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
87 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
89 if( !h->Node->Type || !h->Node->Type->Write ) return 0;
91 ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer);
92 if(ret == -1) return -1;
99 * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
100 * \brief Write data to a file at a given offset
102 Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
107 h = VFS_GetHandle(FD);
110 if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1;
111 if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
113 if(!h->Node->Type || !h->Node->Type->Write) return 0;
114 ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer);
116 if(ret == -1) return -1;
121 * \fn Uint64 VFS_Tell(int FD)
122 * \brief Returns the current file position
124 Uint64 VFS_Tell(int FD)
128 h = VFS_GetHandle(FD);
135 * \fn int VFS_Seek(int FD, Sint64 Offset, int Whence)
136 * \brief Seek to a new location
137 * \param FD File descriptor
138 * \param Offset Where to go
139 * \param Whence From where
141 int VFS_Seek(int FD, Sint64 Offset, int Whence)
145 h = VFS_GetHandle(FD);
148 //Log_Debug("VFS", "VFS_Seek: (fd=0x%x, Offset=0x%llx, Whence=%i)",
149 // FD, Offset, Whence);
151 // Set relative to current position
153 h->Position += Offset;
157 // Set relative to end of file
159 if( h->Node->Size == -1 ) return -1;
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->Type || !h->Node->Type->IOCtl) return -1;
182 return h->Node->Type->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);
199 Dest->mount = h->Mount->Identifier;
202 Dest->inode = h->Node->Inode;
203 Dest->uid = h->Node->UID;
204 Dest->gid = h->Node->GID;
205 Dest->size = h->Node->Size;
206 Dest->atime = h->Node->ATime;
207 Dest->ctime = h->Node->MTime;
208 Dest->mtime = h->Node->CTime;
209 Dest->numacls = h->Node->NumACLs;
212 if(h->Node->Flags & VFS_FFLAG_DIRECTORY) Dest->flags |= 0x10;
213 if(h->Node->Flags & VFS_FFLAG_SYMLINK) Dest->flags |= 0x20;
215 max = (MaxACLs < h->Node->NumACLs) ? MaxACLs : h->Node->NumACLs;
216 memcpy(&Dest->acls, h->Node->ACLs, max*sizeof(tVFS_ACL));