about summary refs log tree commit diff stats
path: root/tools/iso/kernel.soso/spinlock.h
blob: fb7b820b0f7dcaaa192844c8a6615c2e45c3b17f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef SPINLOCK_H
#define SPINLOCK_H

#include "common.h"

typedef int32 Spinlock;

void Spinlock_Init(Spinlock* spinlock);
void Spinlock_Lock(Spinlock* spinlock);
void Spinlock_Unlock(Spinlock* spinlock);

#endif // SPINLOCK_H
.no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef FS_H
#define FS_H

#include "common.h"

typedef enum FileType {
    FT_File               = 1,
    FT_CharacterDevice    = 2,
    FT_BlockDevice        = 3,
    FT_Pipe               = 4,
    FT_SymbolicLink       = 5,
    FT_Directory          = 128,
    FT_MountPoint         = 256
} FileType;

typedef enum IoctlCommand {
    IC_GetSectorSizeInBytes,
    IC_GetSectorCount,
} IoctlCommand;

typedef struct FileSystem FileSystem;
typedef struct FileSystemNode FileSystemNode;
typedef struct FileSystemDirent FileSystemDirent;
typedef struct Process Process;
typedef struct Thread Thread;
typedef struct File File;

struct stat;

typedef int32 (*ReadWriteFunction)(File* file, uint32 size, uint8* buffer);
typedef int32 (*ReadWriteBlockFunction)(FileSystemNode* node, uint32 blockNumber, uint32 count, uint8* buffer);
typedef BOOL (*OpenFunction)(File* file, uint32 flags);
typedef void (*CloseFunction)(File* file);
typedef int32 (*IoctlFunction)(File *file, int32 request, void * argp);
typedef int32 (*LseekFunction)(File *file, int32 offset, int32 whence);
typedef int32 (*FtruncateFunction)(File *file, int32 length);
typedef int32 (*StatFunction)(FileSystemNode *node, struct stat *buf);
typedef FileSystemDirent * (*ReadDirFunction)(FileSystemNode*,uint32);
typedef FileSystemNode * (*FindDirFunction)(FileSystemNode*,char *name);
typedef BOOL (*MkDirFunction)(FileSystemNode* node, const char *name, uint32 flags);
typedef void* (*MmapFunction)(File* file, uint32 size, uint32 offset, uint32 flags);
typedef BOOL (*MunmapFunction)(File* file, void* address, uint32 size);

typedef BOOL (*MountFunction)(const char* sourcePath, const char* targetPath, uint32 flags, void *data);

typedef struct FileSystem {
    char name[32];
    MountFunction checkMount;
    MountFunction mount;
} FileSystem;

typedef struct FileSystemNode {
    char name[128];
    uint32 mask;
    uint32 userId;
    uint32 groupId;
    uint32 nodeType;
    uint32 inode;
    uint32 length;
    ReadWriteBlockFunction readBlock;
    ReadWriteBlockFunction writeBlock;
    ReadWriteFunction read;
    ReadWriteFunction write;
    OpenFunction open;
    CloseFunction close;
    IoctlFunction ioctl;
    LseekFunction lseek;
    FtruncateFunction ftruncate;
    StatFunction stat;
    ReadDirFunction readdir;
    FindDirFunction finddir;
    MkDirFunction mkdir;
    MmapFunction mmap;
    MunmapFunction munmap;
    FileSystemNode *firstChild;
    FileSystemNode *nextSibling;
    FileSystemNode *parent;
    FileSystemNode *mountPoint;//only used in mounts
    FileSystemNode *mountSource;//only used in mounts
    void* privateNodeData;
} FileSystemNode;

typedef struct FileSystemDirent {
    char name[128];
    FileType fileType;
    uint32 inode;
} FileSystemDirent;

//Per open
typedef struct File {
    FileSystemNode* node;
    Process* process;
    Thread* thread;
    int32 fd;
    int32 offset;
    void* privateData;
} File;

struct stat {
    uint16/*dev_t      */ st_dev;     /* ID of device containing file */
    uint16/*ino_t      */ st_ino;     /* inode number */
    uint32/*mode_t     */ st_mode;    /* protection */
    uint16/*nlink_t    */ st_nlink;   /* number of hard links */
    uint16/*uid_t      */ st_uid;     /* user ID of owner */
    uint16/*gid_t      */ st_gid;     /* group ID of owner */
    uint16/*dev_t      */ st_rdev;    /* device ID (if special file) */
    uint32/*off_t      */ st_size;    /* total size, in bytes */

    uint32/*time_t     */ st_atime;
    uint32/*long       */ st_spare1;
    uint32/*time_t     */ st_mtime;
    uint32/*long       */ st_spare2;
    uint32/*time_t     */ st_ctime;
    uint32/*long       */ st_spare3;
    uint32/*blksize_t  */ st_blksize;
    uint32/*blkcnt_t   */ st_blocks;
    uint32/*long       */ st_spare4[2];
};


uint32 read_fs(File* file, uint32 size, uint8* buffer);
uint32 write_fs(File* file, uint32 size, uint8* buffer);
File* open_fs(FileSystemNode* node, uint32 flags);
File* open_fs_forProcess(Thread* thread, FileSystemNode* node, uint32 flags);
void close_fs(File* file);
int32 ioctl_fs(File* file, int32 request, void* argp);
int32 lseek_fs(File* file, int32 offset, int32 whence);
int32 ftruncate_fs(File* file, int32 length);
int32 stat_fs(FileSystemNode *node, struct stat *buf);
FileSystemDirent* readdir_fs(FileSystemNode* node, uint32 index);
FileSystemNode* finddir_fs(FileSystemNode* node, char* name);
BOOL mkdir_fs(FileSystemNode *node, const char* name, uint32 flags);
void* mmap_fs(File* file, uint32 size, uint32 offset, uint32 flags);
BOOL munmap_fs(File* file, void* address, uint32 size);
int getFileSystemNodePath(FileSystemNode* node, char* buffer, uint32 bufferSize);
BOOL resolvePath(const char* path, char* buffer, int bufferSize);

void initializeVFS();
FileSystemNode* getFileSystemRootNode();
FileSystemNode* getFileSystemNode(const char* path);
FileSystemNode* getFileSystemNodeAbsoluteOrRelative(const char* path, Process* process);
void copyFileDescriptors(Process* fromProcess, Process* toProcess);

BOOL registerFileSystem(FileSystem* fs);
BOOL mountFileSystem(const char *source, const char *target, const char *fsType, uint32 flags, void *data);
BOOL checkMountFileSystem(const char *source, const char *target, const char *fsType, uint32 flags, void *data);

#endif