James Molloy File System and Function Prototypes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
redoyk20
Posts: 4
Joined: Sun Apr 05, 2020 3:14 pm
Location: GNU/LINUX

James Molloy File System and Function Prototypes

Post by redoyk20 »

Hi,

I’m currently reading the James Molloy OS Development series and working on implementing file I/O functions. In the documentation, James defines the following function prototypes for file operations:

Code: Select all

typedef u32int (*read_type_t)(struct fs_node*, u32int, u32int, u8int*);
typedef u32int (*write_type_t)(struct fs_node*, u32int, u32int, u8int*);
typedef void (*open_type_t)(struct fs_node*);
typedef void (*close_type_t)(struct fs_node*);
typedef struct dirent* (*readdir_type_t)(struct fs_node*, u32int);
typedef struct fs_node* (*finddir_type_t)(struct fs_node*, char *name);

struct dirent { 
    char name[128];  // Filename
    u32int ino;      // Inode number (required by POSIX)
};
These function prototypes are supposed to be used for interacting with a custom file system in the OS. However, the actual implementations for these prototypes are not clearly explained or provided in the series.

I have a couple of questions:

Where are the actual implementations for these prototypes?
Specifically, where in the James Molloy OS codebase do the read, write, open, close, readdir, and finddir functions get implemented and how are they used?

POSIX read/write vs. James Molloy’s implementation:
I looked at the POSIX documentation for the read function:

Code: Select all

ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
ssize_t read(int fildes, void *buf, size_t nbyte);
But the function signature and the way it's used in James Molloy’s OS examples don’t exactly match the POSIX definitions.

Thanks in advance for any help!
Octocontrabass
Member
Member
Posts: 5623
Joined: Mon Mar 25, 2013 7:01 pm

Re: James Molloy File System and Function Prototypes

Post by Octocontrabass »

redoyk20 wrote: Tue Dec 31, 2024 12:38 amWhere are the actual implementations for these prototypes?
Each filesystem needs its own implementation of these functions. For the tutorial's initrd filesystem, look at initrd.c.
redoyk20 wrote: Tue Dec 31, 2024 12:38 amPOSIX read/write vs. James Molloy’s implementation:
The tutorial doesn't implement the POSIX API. The tutorial's VFS API was intended to be close to POSIX so you could implement the POSIX API on top of the VFS API, but the tutorial doesn't actually implement the POSIX API.
Post Reply