UbixOS V2 2.0

file.h
Go to the documentation of this file.
1 /*-
2 * Copyright (c) 2002-2018 The UbixOS Project.
3 * All rights reserved.
4 *
5 * This was developed by Christopher W. Olsen for the UbixOS Project.
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright notice, this list of
11 * conditions, the following disclaimer and the list of authors.
12 * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions, the following disclaimer and the list of authors in the documentation and/or
14 * other materials provided with the distribution.
15 * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _VFS_FILE_H_
30 #define _VFS_FILE_H_ 1
31
32 #include <sys/types.h>
33
34 #include <ubixfs/dirCache.h>
35 #include <sys/thread.h>
36 #include <vfs/inode.h>
37 #include <vfs/mount.h>
38 #include <ufs/ufs.h>
39
40 /* HACK */
41 int getchar();
42
43 #define SEEK_SET 0
44 #define SEEK_CUR 1
45 #define SEEK_END 2
46
47 #define VBLKSHIFT 12
48 #define VBLKSIZE (1 << VBLKSHIFT)
49 #define SBLOCKSIZE 8192
50 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
51 #define DEV_BSIZE (1<<DEV_BSHIFT)
52
53 #define MAX_OFILES 256
54
55 struct dmadat {
56 char blkbuf[VBLKSIZE]; /* filesystem blocks */
57 char indbuf[VBLKSIZE]; /* indir blocks */
58 char sbbuf[SBLOCKSIZE]; /* superblock */
59 char secbuf[DEV_BSIZE]; /* for MBR/disklabel */
60 };
61
62 typedef struct fileDescriptor {
63 struct fileDescriptor *prev;
64 struct fileDescriptor *next;
65 struct vfs_mountPoint *mp;
66 uint32_t ino;
67 uint16_t status;
68 uint16_t mode;
69 off_t offset;
70 uint32_t size;
71 uint16_t length;
72 uint32_t start;
73 char fileName[512];
74 char *buffer;
75 struct cacheNode *cacheNode;
76 uint32_t perms;
77 struct dmadat *dmadat;
78 int dsk_meta;
79 uint32_t resid;
80 struct inode inode;
81 int fd_type;
82 void *res;
83 int dup;
84 } fileDescriptor_t;
85
86 typedef struct userFileDescriptorStruct {
87 struct fileDescriptor *fd;
88 uint32_t fdSize;
89 } userFileDescriptor;
90
91 extern fileDescriptor_t *fdTable;
92
93 fileDescriptor_t *fopen(const char *, const char *);
94 int fclose(fileDescriptor_t *);
95
96 /* UBU */
97 struct sys_fwrite_args {
98 void *buf;
99 size_t nbytes;
100 size_t nmemb;
101 userFileDescriptor *fd;
102 };
103
104 int unlink(const char *path);
105 int feof(fileDescriptor_t *fd);
106 int fgetc(fileDescriptor_t *fd);
107 size_t fread(void *ptr, size_t size, size_t nmemb, fileDescriptor_t *fd);
108 size_t fwrite(void *ptr, int size, int nmemb, fileDescriptor_t *fd);
109 int fseek(fileDescriptor_t *, long, int);
110
111 int sysFseek(userFileDescriptor *, long, int);
112
113 //Good
114 //int sysChDir(const char *path);
115 //void chDir(const char *path);
116 char *verifyDir(const char *path);
117
118 /* New Syscall */
119 int sys_fwrite(struct thread *, struct sys_fwrite_args *);
120
121 #endif
fileDescriptor::cacheNode
struct cacheNode * cacheNode
Definition: file.h:75
fileDescriptor_t
struct fileDescriptor fileDescriptor_t
fileDescriptor::buffer
char * buffer
Definition: file.h:74
fileDescriptor::dup
int dup
Definition: file.h:83
fileDescriptor::start
uint32_t start
Definition: file.h:72
fread
size_t fread(void *ptr, size_t size, size_t nmemb, fileDescriptor_t *fd)
Definition: file.c:291
userFileDescriptorStruct::fdSize
uint32_t fdSize
Definition: file.h:88
fileDescriptor::res
void * res
Definition: file.h:82
sys_fwrite_args::nmemb
size_t nmemb
Definition: file.h:100
fileDescriptor::dmadat
struct dmadat * dmadat
Definition: file.h:77
userFileDescriptorStruct
Definition: file.h:86
dmadat::sbbuf
char sbbuf[8192]
Definition: file.h:58
fileDescriptor::offset
off_t offset
Definition: file.h:69
fileDescriptor::mode
uint16_t mode
Definition: file.h:68
fileDescriptor
Definition: file.h:62
userFileDescriptorStruct::fd
struct fileDescriptor * fd
Definition: file.h:87
thread
Definition: thread.h:40
DEV_BSIZE
#define DEV_BSIZE
Definition: file.h:51
dirCache.h
sys_fwrite
int sys_fwrite(struct thread *, struct sys_fwrite_args *)
Definition: file.c:47
fileDescriptor::dsk_meta
int dsk_meta
Definition: file.h:78
fseek
int fseek(fileDescriptor_t *, long, int)
Definition: file.c:326
sys_fwrite_args
Definition: file.h:97
types.h
fileDescriptor::fd_type
int fd_type
Definition: file.h:81
sys_fwrite_args::buf
void * buf
Definition: file.h:98
dmadat::blkbuf
char blkbuf[(1<< 12)]
Definition: file.h:56
fileDescriptor::mp
struct vfs_mountPoint * mp
Definition: file.h:65
vfs_mountPoint
Definition: mount.h:66
uint16_t
__uint16_t uint16_t
Definition: types.h:45
sys_fwrite_args::nbytes
size_t nbytes
Definition: file.h:99
fileDescriptor::resid
uint32_t resid
Definition: file.h:79
inode
Definition: inode.h:39
sys_fwrite_args::fd
userFileDescriptor * fd
Definition: file.h:101
fwrite
size_t fwrite(void *ptr, int size, int nmemb, fileDescriptor_t *fd)
Definition: file.c:311
fdTable
fileDescriptor_t * fdTable
Definition: file.c:43
fileDescriptor::length
uint16_t length
Definition: file.h:71
uint32_t
__uint32_t uint32_t
Definition: types.h:46
VBLKSIZE
#define VBLKSIZE
Definition: file.h:48
fileDescriptor::ino
uint32_t ino
Definition: file.h:66
dmadat::secbuf
char secbuf[(1<< 9)]
Definition: file.h:59
verifyDir
char * verifyDir(const char *path)
fopen
fileDescriptor_t * fopen(const char *, const char *)
Definition: file.c:388
fileDescriptor::perms
uint32_t perms
Definition: file.h:76
fileDescriptor::fileName
char fileName[512]
Definition: file.h:73
ufs.h
SBLOCKSIZE
#define SBLOCKSIZE
Definition: file.h:49
dmadat::indbuf
char indbuf[(1<< 12)]
Definition: file.h:57
dmadat
Definition: file.h:55
mount.h
off_t
__int64_t off_t
Definition: types.h:119
fileDescriptor::status
uint16_t status
Definition: file.h:67
unlink
int unlink(const char *path)
Definition: file.c:618
getchar
int getchar()
Definition: atkbd.c:346
sysFseek
int sysFseek(userFileDescriptor *, long, int)
fileDescriptor::size
uint32_t size
Definition: file.h:70
thread.h
fclose
int fclose(fileDescriptor_t *)
Definition: file.c:526
userFileDescriptor
struct userFileDescriptorStruct userFileDescriptor
feof
int feof(fileDescriptor_t *fd)
Definition: file.c:337
fileDescriptor::prev
struct fileDescriptor * prev
Definition: file.h:63
fgetc
int fgetc(fileDescriptor_t *fd)
Definition: file.c:366
cacheNode
Definition: dirCache.h:35
fileDescriptor::next
struct fileDescriptor * next
Definition: file.h:64
inode.h