FreeNOS
File.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBFS_FILE_H
19 #define __LIB_LIBFS_FILE_H
20 
21 #include <Types.h>
22 #include "FileSystemMessage.h"
23 #include "FileSystem.h"
24 #include "IOBuffer.h"
25 
39 class File
40 {
41  public:
42 
51  File(const u32 inode,
53  const UserID uid = ZERO,
54  const GroupID gid = ZERO);
55 
59  virtual ~File();
60 
66  u32 getInode() const;
67 
74 
85  virtual FileSystem::Result read(IOBuffer & buffer,
86  Size & size,
87  const Size offset);
88 
99  virtual FileSystem::Result write(IOBuffer & buffer,
100  Size & size,
101  const Size offset);
102 
111 
119  virtual bool canRead() const;
120 
128  virtual bool canWrite() const;
129 
130  protected:
131 
133  const u32 m_inode;
134 
137 
140 
143 
146 
149 };
150 
156 #endif /* __LIB_LIBFS_FILE_H */
File::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the file.
Definition: File.cpp:55
File::canRead
virtual bool canRead() const
Check if the File has data ready for reading.
Definition: File.cpp:74
FileSystem.h
Types.h
File::~File
virtual ~File()
Destructor function.
Definition: File.cpp:34
FileSystem::FileType
FileType
All possible filetypes.
Definition: FileSystem.h:70
GroupID
unsigned short GroupID
Group Identity.
Definition: Types.h:137
File::getType
FileSystem::FileType getType() const
Retrieve our filetype.
Definition: File.cpp:43
IOBuffer.h
File::getInode
u32 getInode() const
Get inode number.
Definition: File.cpp:38
File::m_type
const FileSystem::FileType m_type
Type of this file.
Definition: File.h:136
File
Represents a file present on a FileSystem.
Definition: File.h:39
File::m_access
FileSystem::FileModes m_access
Access permissions.
Definition: File.h:145
File::m_size
Size m_size
Size of the file, in bytes.
Definition: File.h:148
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
File::m_uid
UserID m_uid
Owner of the file.
Definition: File.h:139
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
FileSystem::RegularFile
@ RegularFile
Definition: FileSystem.h:72
FileSystem::FileModes
u16 FileModes
Multiple FileMode values combined.
Definition: FileSystem.h:108
File::status
virtual FileSystem::Result status(FileSystem::FileStat &st)
Retrieve file statistics.
Definition: File.cpp:62
File::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the file.
Definition: File.cpp:48
File::m_inode
const u32 m_inode
Inode number.
Definition: File.h:133
UserID
unsigned short UserID
User Identity.
Definition: Types.h:134
FileSystem::FileStat
Contains file information.
Definition: FileSystem.h:113
File::m_gid
GroupID m_gid
Group of the file.
Definition: File.h:142
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
File::canWrite
virtual bool canWrite() const
Check if the File can be written to.
Definition: File.cpp:79
type
u8 type
Definition: IntelACPI.h:63
File::File
File(const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO)
Constructor function.
Definition: File.cpp:21
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
FileSystemMessage.h