MentOS  0.8.0
The Mentoring Operating System
vfs_types.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "sys/list_head.h"
9 #include "sys/dirent.h"
10 #include "bits/stat.h"
11 #include "stdint.h"
12 
13 #define PATH_SEPARATOR '/'
14 #define PATH_SEPARATOR_STRING "/"
15 #define PATH_UP ".."
16 #define PATH_DOT "."
17 
19 typedef struct vfs_file_t vfs_file_t;
20 
22 struct iattr;
23 
25 typedef int (*vfs_mkdir_callback)(const char *, mode_t);
27 typedef int (*vfs_rmdir_callback)(const char *);
29 typedef vfs_file_t *(*vfs_creat_callback)(const char *, mode_t);
33 typedef vfs_file_t *(*vfs_open_callback)(const char *, int, mode_t);
35 typedef int (*vfs_unlink_callback)(const char *);
37 typedef int (*vfs_close_callback)(vfs_file_t *);
41 typedef ssize_t (*vfs_write_callback)(vfs_file_t *, const void *, off_t, size_t);
45 typedef int (*vfs_stat_callback)(const char *, stat_t *);
47 typedef int (*vfs_fstat_callback)(vfs_file_t *, stat_t *);
49 typedef int (*vfs_ioctl_callback)(vfs_file_t *, int, void *);
51 typedef int (*vfs_symlink_callback)(const char *, const char *);
53 typedef ssize_t (*vfs_readlink_callback)(const char *, char *, size_t);
55 typedef int (*vfs_setattr_callback)(const char *, struct iattr *);
57 typedef int (*vfs_fsetattr_callback)(vfs_file_t *, struct iattr *);
58 
60 typedef struct file_system_type {
62  const char *name;
64  int fs_flags;
66  vfs_file_t *(*mount)(const char *, const char *);
68 
70 typedef struct vfs_sys_operations_t {
84 
86 typedef struct vfs_file_operations_t {
110 
112 struct vfs_file_t {
114  char name[NAME_MAX];
116  void *device;
134  int count;
146  size_t f_pos;
150  list_head siblings;
153 };
154 
156 typedef struct super_block_t {
158  char name[NAME_MAX];
160  char path[PATH_MAX];
166  list_head mounts;
168 
170 typedef struct vfs_file_descriptor_t {
176 
178 struct iattr {
180  unsigned int ia_valid;
193 };
194 
195 #define ATTR_MODE (1 << 0)
196 #define ATTR_UID (1 << 1)
197 #define ATTR_GID (1 << 2)
198 #define ATTR_ATIME (1 << 3)
199 #define ATTR_MTIME (1 << 4)
200 #define ATTR_CTIME (1 << 5)
201 
203 #define IATTR_CHOWN(user, group) \
204  { \
205  .ia_valid = ATTR_UID | ATTR_GID, \
206  .ia_uid = (user), \
207  .ia_gid = (group) \
208  }
209 
211 #define IATTR_CHMOD(mode) \
212  { \
213  .ia_valid = ATTR_MODE, \
214  .ia_mode = (mode) \
215  }
Defines the structure used by the functiosn fstat(), lstat(), and stat().
Functions used to manage directories.
#define NAME_MAX
Maximum number of characters in a file name.
Definition: limits.h:51
#define PATH_MAX
Maximum number of characters in a path name.
Definition: limits.h:54
int gid_t
The type of group-id.
Definition: stddef.h:43
long ssize_t
Define the generic signed size type.
Definition: stddef.h:31
long int off_t
The type of offset.
Definition: stddef.h:46
unsigned long size_t
Define the generic size type.
Definition: stddef.h:28
unsigned int mode_t
The type of mode.
Definition: stddef.h:49
int uid_t
The type of user-id.
Definition: stddef.h:40
Standard integer data-types.
int int32_t
Define the signed 32-bit integer.
Definition: stdint.h:15
unsigned int uint32_t
Define the unsigned 32-bit integer.
Definition: stdint.h:18
Directory entry.
Definition: dirent.h:44
Filesystem information.
Definition: vfs_types.h:60
const char * name
Name of the filesystem.
Definition: vfs_types.h:62
int fs_flags
Flags of the filesystem.
Definition: vfs_types.h:64
Data structure containing attributes of a file.
Definition: vfs_types.h:178
gid_t ia_gid
Owner gid.
Definition: vfs_types.h:186
unsigned int ia_valid
Validity check on iattr struct.
Definition: vfs_types.h:180
uint32_t ia_atime
Time of last access.
Definition: vfs_types.h:188
uint32_t ia_mtime
Time of last data modification.
Definition: vfs_types.h:190
uid_t ia_uid
Owner uid.
Definition: vfs_types.h:184
mode_t ia_mode
Access mode.
Definition: vfs_types.h:182
uint32_t ia_ctime
Time of last status change.
Definition: vfs_types.h:192
Data structure which contains information about a file.
Definition: stat.h:16
A structure that represents an instance of a filesystem, i.e., a mounted filesystem.
Definition: vfs_types.h:156
list_head mounts
List to hold all active mounting points.
Definition: vfs_types.h:166
vfs_file_t * root
Pointer to the root file of the given filesystem.
Definition: vfs_types.h:162
file_system_type * type
Pointer to the information regarding the filesystem.
Definition: vfs_types.h:164
char name[NAME_MAX]
Name of the superblock.
Definition: vfs_types.h:158
char path[PATH_MAX]
Path of the superblock.
Definition: vfs_types.h:160
Data structure containing information about an open file.
Definition: vfs_types.h:170
vfs_file_t * file_struct
the underlying file structure
Definition: vfs_types.h:172
int flags_mask
Flags for file opening modes.
Definition: vfs_types.h:174
Set of functions used to perform operations on files.
Definition: vfs_types.h:86
vfs_lseek_callback lseek_f
Reposition the file offset inside a file.
Definition: vfs_types.h:98
vfs_write_callback write_f
Write inside a file.
Definition: vfs_types.h:96
vfs_getdents_callback getdents_f
Read entries inside the directory.
Definition: vfs_types.h:104
vfs_ioctl_callback ioctl_f
Perform ioctl on file.
Definition: vfs_types.h:102
vfs_fstat_callback stat_f
Stat the file.
Definition: vfs_types.h:100
vfs_unlink_callback unlink_f
Remove a file.
Definition: vfs_types.h:90
vfs_close_callback close_f
Close a file.
Definition: vfs_types.h:92
vfs_open_callback open_f
Open a file.
Definition: vfs_types.h:88
vfs_readlink_callback readlink_f
Reads the symbolik link data.
Definition: vfs_types.h:106
vfs_fsetattr_callback setattr_f
Modifies the attributes of a file.
Definition: vfs_types.h:108
vfs_read_callback read_f
Read from a file.
Definition: vfs_types.h:94
Data structure that contains information about the mounted filesystems.
Definition: vfs_types.h:112
uint32_t uid
The owning user.
Definition: vfs_types.h:120
uint32_t open_flags
Flags passed to open (read/write/append, etc.)
Definition: vfs_types.h:132
size_t f_pos
Offset for read operations.
Definition: vfs_types.h:146
uint32_t gid
The owning group.
Definition: vfs_types.h:122
vfs_file_operations_t * fs_operations
Files operations.
Definition: vfs_types.h:144
int count
Number of file descriptors associated with this file.
Definition: vfs_types.h:134
uint32_t length
Size of the file, in byte.
Definition: vfs_types.h:128
uint32_t ino
Inode number.
Definition: vfs_types.h:126
uint32_t atime
Accessed (time).
Definition: vfs_types.h:136
uint32_t ctime
Created (time).
Definition: vfs_types.h:140
int32_t refcount
TODO: Comment.
Definition: vfs_types.h:152
vfs_sys_operations_t * sys_operations
Generic system operations.
Definition: vfs_types.h:142
uint32_t nlink
The number of links.
Definition: vfs_types.h:148
uint32_t mask
The permissions mask.
Definition: vfs_types.h:118
uint32_t flags
Flags (node type, etc).
Definition: vfs_types.h:124
uint32_t impl
Used to keep track which fs it belongs to.
Definition: vfs_types.h:130
list_head siblings
List to hold all active files associated with a specific entry in a filesystem.
Definition: vfs_types.h:150
void * device
Device object (optional).
Definition: vfs_types.h:116
uint32_t mtime
Modified (time).
Definition: vfs_types.h:138
char name[NAME_MAX]
The filename.
Definition: vfs_types.h:114
Set of functions used to perform operations on filesystem.
Definition: vfs_types.h:70
vfs_rmdir_callback rmdir_f
Removes a directory.
Definition: vfs_types.h:74
vfs_setattr_callback setattr_f
Modifies the attributes of a file.
Definition: vfs_types.h:82
vfs_symlink_callback symlink_f
Symbolic link creation function.
Definition: vfs_types.h:80
vfs_mkdir_callback mkdir_f
Creates a directory.
Definition: vfs_types.h:72
vfs_stat_callback stat_f
Stat function.
Definition: vfs_types.h:76
vfs_creat_callback creat_f
File creation function.
Definition: vfs_types.h:78
off_t(* vfs_lseek_callback)(vfs_file_t *, off_t, int)
Function used to reposition the file offset inside a file.
Definition: vfs_types.h:43
ssize_t(* vfs_readlink_callback)(const char *, char *, size_t)
Function that reads the symbolic link data associated with a file.
Definition: vfs_types.h:53
ssize_t(* vfs_read_callback)(vfs_file_t *, char *, off_t, size_t)
Function used to read from a file.
Definition: vfs_types.h:39
int(* vfs_mkdir_callback)(const char *, mode_t)
Function used to create a directory.
Definition: vfs_types.h:25
struct super_block_t super_block_t
A structure that represents an instance of a filesystem, i.e., a mounted filesystem.
int(* vfs_stat_callback)(const char *, stat_t *)
Function used to stat fs entries.
Definition: vfs_types.h:45
int(* vfs_ioctl_callback)(vfs_file_t *, int, void *)
Function used to perform ioctl on files.
Definition: vfs_types.h:49
struct file_system_type file_system_type
Filesystem information.
struct vfs_file_descriptor_t vfs_file_descriptor_t
Data structure containing information about an open file.
struct vfs_file_operations_t vfs_file_operations_t
Set of functions used to perform operations on files.
vfs_file_t *(* vfs_open_callback)(const char *, int, mode_t)
Function used to open a file (or directory).
Definition: vfs_types.h:33
int(* vfs_unlink_callback)(const char *)
Function used to remove a file.
Definition: vfs_types.h:35
int(* vfs_symlink_callback)(const char *, const char *)
Function for creating symbolic links.
Definition: vfs_types.h:51
struct vfs_sys_operations_t vfs_sys_operations_t
Set of functions used to perform operations on filesystem.
int(* vfs_rmdir_callback)(const char *)
Function used to remove a directory.
Definition: vfs_types.h:27
int(* vfs_fsetattr_callback)(vfs_file_t *, struct iattr *)
Function used to modify the attributes of a file.
Definition: vfs_types.h:57
vfs_file_t *(* vfs_creat_callback)(const char *, mode_t)
Function used to open a file (or directory).
Definition: vfs_types.h:29
int(* vfs_fstat_callback)(vfs_file_t *, stat_t *)
Function used to stat files.
Definition: vfs_types.h:47
ssize_t(* vfs_write_callback)(vfs_file_t *, const void *, off_t, size_t)
Function used to write inside a file.
Definition: vfs_types.h:41
ssize_t(* vfs_getdents_callback)(vfs_file_t *, dirent_t *, off_t, size_t)
Function used to read the entries of a directory.
Definition: vfs_types.h:31
int(* vfs_close_callback)(vfs_file_t *)
Function used to close a file.
Definition: vfs_types.h:37
int(* vfs_setattr_callback)(const char *, struct iattr *)
Function used to modify the attributes of an fs entry.
Definition: vfs_types.h:55