FreeNOS
FileDescriptor.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 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#include "FileDescriptor.h"
19
21 : m_array(ZERO)
22{
23}
24
26{
27 count = m_count;
28 return m_array;
29}
30
32 const Size count)
33{
34 m_array = array;
35 m_count = count;
36}
37
39 const ProcessID filesystem,
40 Size & index)
41{
42 // Insert into file descriptor table
43 for (index = 0; index < m_count; index++)
44 {
45 if (!m_array[index].open)
46 {
47 m_array[index].open = true;
48 m_array[index].position = 0;
49 m_array[index].inode = inode;
50 m_array[index].pid = filesystem;
52 }
53 }
54
56}
57
59{
60 if (index >= m_count)
61 {
62 return ZERO;
63 }
64
65 return &m_array[index];
66}
67
69{
70 if (index >= m_count)
71 {
73 }
74
75 m_array[index].open = false;
77}
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.
C int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
Definition open.cpp:26
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
#define ZERO
Zero value.
Definition Macros.h:43
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