The Open File Table stores the information about all the files that are open while the OS is running. It consists of MAX_OPENFILE_NUM (= 32 in the present eXpOS version) entries. Thus, there can be at most MAX_OPENFILE_NUM = 32 open files in the system at any time.
The Open system call creates an entry in the Open file table when a process opens a file. If the file is opened again by some other process (or the same process), the Open system call a new entry is created in the open file table. The first field (Inode Index) of the Open file table entry for a file is set to the index of the Inode Table entry for the file.
Each entry is of size 4 words of which last word is left unused.
Every entry of the Open File Table has the following format :
INODE INDEX | OPEN INSTANCE COUNT | LSEEK | Unused |
All invalid entries are set to -1.
An Unused entry is indicated by value of -1 in the INODE INDEX field.
Note: The Open File Table is present in page 56 of the memory (see Memory Organisation), and the SPL constant OPEN_FILE_TABLE points to the starting address of the table.
The File Status Table contains details about lock status and file open count of each file in the inode table. It consists of MAX_FILE_NUM (= 60 in the present eXpOS version) entries.
For each file, the index of its entry in the inode table must match with the index of its entry in the file status table .
Each file lock status table entry is of size 4 words of which two are unused.
LOCKING PID | FILE OPEN COUNT | Unused |
All invalid entries are set to -1
Note: The File Status Table is present in page 57 of the memory (see Memory Organisation), and the SPL constant FILE_STATUS_TABLE points to the starting address of the table.
The Semaphore Table contains details about the semaphores used by all the processes. It consists of MAX_SEM_COUNT (= 32 in the present eXpOS version) entries. Thus, there can be at most MAX_SEM_COUNT = 32 semaphores used in the system at any time. For every semaphore entry in the per-process resource table, there is a corresponding entry in the semaphore table.
A process can acquire a semaphore using the Semget system call, which returns a unique semid for the semaphore. Semid is basically the index of the semaphore table entry for the semaphore.
The Process count field specifies the number of processes which are sharing the semaphore. Semget sets the Process Count to 1. When a process forks, all semaphores acquired by the parent is shared with the child and hence, Process Count is incremented. Semrelease system call decrements the Process Count. Process Count is also decremented when a process exits.
SemLock system call sets the Locking PID field to the PID of the process invoking it. When the semaphore is not locked, Locking PID is -1.
Each semaphore table entry is of size 4 words of which the last two are unused.
LOCKING PID | PROCESS COUNT | Unused |
An unused entry is indicated by 0 in the PROCESS COUNT field.
Note: The Semaphore Table is present in page 56 of the memory (see Memory Organisation), and the SPL constant SEMAPHORE_TABLE points to the starting address of the table.
It is assumed that the machine provides a load instruction to transfer a disk block to a memory page and a store instruction to transfer a memory page to a disk block. The Disk Status Table keeps track of these disk-memory transfers. Every time a disk operation is invoked, the information regarding the operation like the disk block and the memory page involved, the process that invoked the operation and type of disk operation are stored in Disk Status Table by the OS. In the present version of eXpOS, it is assumed that, the disk does not support multiple disk-memory transfers at the same time and is considered busy while a transfer is going on. The state of the disk (busy or free) is also stored in the Disk Status Table.
The size of the table is 8 words of which the last 2 are unused.
STATUS | LOAD/STORE BIT | PAGE NUMBER | BLOCK NUMBER | PID | Unused |
Note: The Disk Staus Table is present in page 56 of the memory (see Memory Organisation), and the SPL constant DISK_STATUS_TABLE points to the starting address of the table.
When a process reads/writes into a file, the relevant disk block is first brought into a memory buffer by the OS and the read/write operation is performed on the buffer. The OS reserves MAX_BUFFER number of memory pages as buffers. The buffer table is a data structure that stores the information regarding the disk block stored in each buffer. The present version of eXpOS sets MAX_BUFFER = 4. Each buffer is identified by its index in the buffer table.
Since all the 4 buffer pages are shared by all the files in the file system, a buffer page may be required to be replaced by another disk block. In this case, write-back is performed only if the page is modified. The dirty bit indicates whether the page has been modified.
When a disk block is required to be brought into the buffer, the buffer to which it must be loaded is identifed by the formula :
Buffer_number = Disk_block_number % MAX_BUFFER
Each entry of the Buffer Table has the following format:
BLOCK NUMBER | DIRTY BIT | LOCKING PID | Unused |
Free entries are represented by -1 in all the fields.
Note: The Buffer Table is present in page 58 of the memory (see Memory Organisation), and the SPL constant BUFFER_TABLE points to the starting address of the table.
It keeps the information about the number of free pages in memory, the number of processes blocked because memory is unavailable, the number of processes in swapped state and, the pid of the process to be scheduled next. The size of the table is 8 words out of which 2 words are unused.
The System Status Table has the following format:
CURRENT_USER_ID | CURRENT_PID | MEM_FREE_COUNT | WAIT_MEM_COUNT | SWAPPED_COUNT | PAGING_STATUS | CURRENT_PID2 | LOGOUT_STATUS |
Initially, when the table is set up by the OS startup code, the MEM_FREE_COUNT is initialized to the number of free pages available in the system, WAIT_MEM_COUNT to 0, SWAPPED_COUNT to 0 and PAGING_STATUS to 0.
Note: The System Status Table is present in page 57 of the memory (see Memory Organisation), and the SPL constant SYSTEM_STATUS_TABLE points to the starting address of the table.
The Terminal Status Table keeps track of the Read/Write operations done on the terminal. Every time a Read or Write system call is invoked on the terminal, the PID of the process that invoked the system call is stored in Terminal Status Table. The table also contains information on the status of the terminal (whether free or busy). The size of the table is 4 words of which the last 2 are unused.
Every entry of the Terminal Status Table has the following format:
STATUS | PID | Unused |
Note: The Terminal Table is present in page 57 of the memory (see Memory Organisation), and the SPL constant TERMINAL_STATUS_TABLE points to the starting address of the table.
The Memory free list is a data structure used for keeping track of used and unused pages in the memory. It consists of MAX_MEM_PAGE entries and each entry is of size one word. Thus, the total size of the free list is MAX_MEM_PAGE words. The number of memory pages available to the OS is architecture dependent. For the version of XSM discussed here, MAX_MEM_PAGE = 128.
Each entry of the free list contains either the value 0 indicating that the corresponding page in the memory is free (not allocated to any process) or contains the number of processes that are sharing the page. Memory free list entries for the pages allocated to the kernel are also set to 1.
Note: Memory copy of the Mem Free List is present in page 57 of the memory (see Memory Organisation), and the SPL constant MEMORY_FREE_LIST points to the starting address of the data structure.
When eXpOS runs on a two-core machine like NEXSM, the OS kernel code executes parallelly on the cores. Hence, to ensure atomicity of the resource acquire functions (of the resource manager module), as well as access/updates of OS data structures, an additional layer of access locking is introduced. The OS maintains an Access Lock Table in memory with the following fields to hold the additional locks.
The Access Lock Table has the following format:
KERN_LOCK | SCHED_LOCK | GLOCK | Unused |
Note: This data structure is used only when eXpOS is running on NEXSM (a two-core extension of XSM) machine.