MP3 1.0
This is the Doxygen document for ECE391 MP3.
Loading...
Searching...
No Matches
file_descriptor.h
Go to the documentation of this file.
1
10#ifndef FILE_DESCRIPTOR_H
11#define FILE_DESCRIPTOR_H
12
13#include "types.h"
14#include "terminal.h"
15#include "rtc.h"
16#include "filesystem.h"
17
18#define STDIN_FD (0) // File descriptor index for stdin (keyboard)
19#define STDOUT_FD (1) // File descriptor index for stdout (terminal)
20#define FILE_DESCRIPTOR_IN_USE (1)
21#define FILE_DESCRIPTOR_NOT_IN_USE (0)
22
34typedef struct fileOpStruct
35{
36 // Seems like you can't have arg names in function pointers. I list the names here for reference
37 //int32_t (*read) (int32_t fd, void* buf, int32_t nybytes);
38 //int32_t (*write) (int32_t fd, void* buf, int32_t nybytes);
39 //int32_t (*open) (const uint8_t* filename);
40 //int32_t (*close) (int32_t fd);
41
42 int32_t (*read) (int32_t , void* , int32_t);
43 int32_t (*write) (int32_t , const void* , int32_t);
44 int32_t (*open) (const uint8_t*);
47
49{
50 fileOp_t fileOpPtr; // Points to open, read, write, and close actions specific to this file type
51 int32_t inode; // Only valid for data files (0 for directories and RTC file)
52 int32_t filePosition; // Keeps track of where user is currently reading from file. read sys calls update this
53 uint32_t flags; // Used to mark descriptor as "in-use" and other ambigous things not answered directly by doc
55
56/********** Start of unique file ops pointers **********/
57// Individual fileOp structs for each unique driver
58// Initializing struct reference https://stackoverflow.com/questions/330793/how-to-initialize-a-struct-in-accordance-with-c-programming-language-standards
59
60extern fileOp_t rtcFileOps;
65
66// For a null file op pointer where all functions just return -1
67inline int32_t dummyRead() ;
68inline int32_t dummyWrite();
69inline int32_t dummyOpen() ;
70inline int32_t dummyClose();
72/********** End of unique file ops pointers **********/
73
81void createBlankFileDescriptor(fd_t* fileDescriptor);
82
88void initFileDescriptor(fd_t* fileDescriptor);
89
95void destroyFileDescriptor(fd_t* fileDescriptor);
96
97#endif // FILE_DESCRIPTOR_H
int32_t dummyClose()
Definition: file_descriptor.c:16
int32_t dummyWrite()
Definition: file_descriptor.c:14
void createBlankFileDescriptor(fd_t *fileDescriptor)
Create a Blank File Descriptor.
Definition: file_descriptor.c:72
fileOp_t stdoutFileOps
Definition: file_descriptor.c:34
void destroyFileDescriptor(fd_t *fileDescriptor)
Destroy a file descriptor.
Definition: file_descriptor.c:120
fileOp_t dummyFileOp
Definition: file_descriptor.c:57
fileOp_t rtcFileOps
Definition: file_descriptor.c:18
struct fileDescriptorStruct fd_t
struct fileOpStruct fileOp_t
File descriptor array to represent open files.
void initFileDescriptor(fd_t *fileDescriptor)
Initializes the fileDescriptor given by setting stdin and stdout files.
Definition: file_descriptor.c:88
int32_t dummyOpen()
Definition: file_descriptor.c:15
fileOp_t directoryFileOps
Definition: file_descriptor.c:49
int32_t dummyRead()
Definition: file_descriptor.c:13
fileOp_t stdinFileOps
Definition: file_descriptor.c:26
fileOp_t dataFileOps
Definition: file_descriptor.c:42
Header file for filesystem.c.
Header function for rtc.c.
Definition: file_descriptor.h:49
int32_t inode
Definition: file_descriptor.h:51
uint32_t flags
Definition: file_descriptor.h:53
fileOp_t fileOpPtr
Definition: file_descriptor.h:50
int32_t filePosition
Definition: file_descriptor.h:52
File descriptor array to represent open files.
Definition: file_descriptor.h:35
int32_t(* write)(int32_t, const void *, int32_t)
Definition: file_descriptor.h:43
int32_t(* close)(int32_t)
Definition: file_descriptor.h:45
int32_t(* read)(int32_t, void *, int32_t)
Definition: file_descriptor.h:42
int32_t(* open)(const uint8_t *)
Definition: file_descriptor.h:44
Header files for terminal.c.
Defines to use the familiar explicitly-sized types in this OS.
int int32_t
Definition: types.h:18
unsigned int uint32_t
Definition: types.h:19
unsigned char uint8_t
Definition: types.h:25