FreeNOS
FileDescriptor.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_FILEDESCRIPTOR_H
19 #define __LIB_LIBFS_FILEDESCRIPTOR_H
20 
21 #include <Types.h>
22 #include <Singleton.h>
23 #include "FileSystemPath.h"
24 
36 class FileDescriptor : public StrictSingleton<FileDescriptor>
37 {
38  public:
39 
41  static const Size MaximumFiles = 1024;
42 
46  struct Entry
47  {
51  bool open;
52  };
53 
57  enum Result
58  {
62  };
63 
64  public:
65 
70 
78  Entry * getArray(Size & count);
79 
86  void setArray(Entry *array,
87  const Size count);
88 
98  Result openEntry(const u32 inode,
99  const ProcessID filesystem,
100  Size & index);
101 
109  Entry * getEntry(const Size index);
110 
118  Result closeEntry(const Size index);
119 
120  private:
121 
124 
127 };
128 
134 #endif /* __LIB_LIBFS_FILEDESCRIPTOR_H */
FileDescriptor::setArray
void setArray(Entry *array, const Size count)
Assign entry table.
Definition: FileDescriptor.cpp:31
FileDescriptor::Entry::position
Size position
< Process identifier of the filesystem
Definition: FileDescriptor.h:50
FileSystemPath.h
StrictSingleton
Singleton design pattern: only one instance is allowed.
Definition: Singleton.h:39
FileDescriptor::getArray
Entry * getArray(Size &count)
Get entry table.
Definition: FileDescriptor.cpp:25
Types.h
FileDescriptor::MaximumFiles
static const Size MaximumFiles
Default maximum number of files which can be opened.
Definition: FileDescriptor.h:41
FileDescriptor::Entry::open
bool open
< Current position indicator.
Definition: FileDescriptor.h:51
FileDescriptor::m_count
Size m_count
Number of entries in the array.
Definition: FileDescriptor.h:126
FileDescriptor::InvalidArgument
@ InvalidArgument
Definition: FileDescriptor.h:60
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
FileDescriptor
Abstracts files which are opened by a user process.
Definition: FileDescriptor.h:36
FileDescriptor::getEntry
Entry * getEntry(const Size index)
Retrieve a file descriptor Entry.
Definition: FileDescriptor.cpp:58
FileDescriptor::Entry::inode
u32 inode
Definition: FileDescriptor.h:48
FileDescriptor::Entry
Describes a single file opened by a user process.
Definition: FileDescriptor.h:46
FileDescriptor::Result
Result
Result code.
Definition: FileDescriptor.h:57
FileDescriptor::closeEntry
Result closeEntry(const Size index)
Remove file descriptor entry.
Definition: FileDescriptor.cpp:68
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
FileDescriptor::FileDescriptor
FileDescriptor()
Constructor.
Definition: FileDescriptor.cpp:20
FileDescriptor::Success
@ Success
Definition: FileDescriptor.h:59
FileDescriptor::openEntry
Result openEntry(const u32 inode, const ProcessID filesystem, Size &index)
Add new file descriptor entry.
Definition: FileDescriptor.cpp:38
Singleton.h
FileDescriptor::OutOfFiles
@ OutOfFiles
Definition: FileDescriptor.h:61
FileDescriptor::Entry::pid
ProcessID pid
< Inode number of the file
Definition: FileDescriptor.h:49
FileDescriptor::m_array
Entry * m_array
Pointer to array of entries.
Definition: FileDescriptor.h:123