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
36class FileDescriptor : public StrictSingleton<FileDescriptor>
37{
38 public:
39
41 static const Size MaximumFiles = 1024;
42
53
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 */
Abstracts files which are opened by a user process.
static const Size MaximumFiles
Default maximum number of files which can be opened.
Entry * getEntry(const Size index)
Retrieve a file descriptor Entry.
Entry * getArray(Size &count)
Get entry table.
void setArray(Entry *array, const Size count)
Assign entry table.
Result openEntry(const u32 inode, const ProcessID filesystem, Size &index)
Add new file descriptor entry.
Size m_count
Number of entries in the array.
Result
Result code.
Result closeEntry(const Size index)
Remove file descriptor entry.
FileDescriptor()
Constructor.
Entry * m_array
Pointer to array of entries.
Singleton design pattern: only one instance is allowed.
Definition Singleton.h:40
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Describes a single file opened by a user process.
ProcessID pid
< Inode number of the file
bool open
< Current position indicator.
Size position
< Process identifier of the filesystem