IBNOS
filesystem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_FILESYSTEM_
29 #define _H_FILESYSTEM_
30 
31 #ifdef __KERNEL__
32 
33  struct directory;
34  struct file;
35  struct openedFile;
36 
37  #include <stdint.h>
38  #include <stdbool.h>
39 
40  #include <process/object.h>
41  #include <util/list.h>
42 
43  struct directory
44  {
45  struct object obj;
46  struct directory *parent;
47  char *name;
48 
50 
51  struct linkedList files;
53  };
54 
55  struct file
56  {
57  struct object obj;
58  struct directory *parent;
59  char *name;
60 
61  struct linkedList openedFiles;
62 
63  bool isHeap;
64  uint8_t *buffer;
65  uint32_t size;
66  };
67 
69  {
70  struct object obj;
72 
73  struct object *pos;
74  };
75 
76  struct openedFile
77  {
78  struct object obj;
79  struct file *file;
80 
81  uint32_t pos;
82  };
83 
84  struct tarHeader
85  {
86  char name[100];
87  char mode[8];
88  char uid[8];
89  char gid[8];
90  char size[12];
91  char mtime[12];
92  char checksum[8];
93  char typeflag;
94  char linkname[100];
95  char magic[6];
96  char version[2];
97  char uname[32];
98  char gname[32];
99  char devmajor[8];
100  char devminor[8];
101  char prefix[155];
102  char pad[12];
103  } __attribute__((packed));
104 
105  #define TAR_TYPE_FILE '0'
106  #define TAR_TYPE_HARDLINK '1'
107  #define TAR_TYPE_SYMLINK '2'
108  #define TAR_TYPE_DEVICE '3'
109  #define TAR_TYPE_BLOCKDEV '4'
110  #define TAR_TYPE_DIRECTORY '5'
111  #define TAR_TYPE_NAMEDPIPE '6'
112 
113  struct directory *directoryCreate(struct directory *parent, char *name, uint32_t nameLength);
114  struct file *fileCreate(struct directory *parent, char *name, uint32_t nameLength, uint8_t *staticBuffer, uint32_t staticSize);
115 
116  struct openedFile *fileOpen(struct file *file);
118 
119  void fileSystemInit(void *addr, uint32_t length);
120 
121  struct directory *fileSystemIsValidDirectory(struct object *obj);
122  struct file *fileSystemIsValidFile(struct object *obj);
123 
124  struct directory *fileSystemGetRoot();
125 
126  struct directory *fileSystemSearchDirectory(struct directory *directory, char *path, uint32_t pathLength, bool create);
127  struct file *fileSystemSearchFile(struct directory *directory, char *path, uint32_t pathLength, bool create);
128 
129 #endif
130 
131 #endif /* _H_FILESYSTEM_ */
struct file * fileCreate(struct directory *parent, char *name, uint32_t nameLength, uint8_t *staticBuffer, uint32_t staticSize)
Creates a new kernel file object.
Definition: filesystem.c:333
struct directory * fileSystemIsValidDirectory(struct object *obj)
Checks if a given object is of the type directory and casts it if possible.
Definition: filesystem.c:934
struct tarHeader __attribute__((packed))
char devminor[8]
Definition: filesystem.h:78
struct openedDirectory * directoryOpen(struct directory *directory)
Creates a new kernel openedDirectory object.
Definition: filesystem.c:699
struct openedFile * fileOpen(struct file *file)
Creates a new kernel openedFile object.
Definition: filesystem.c:513
char gid[8]
Definition: filesystem.h:67
char uid[8]
Definition: filesystem.h:66
struct file * fileSystemIsValidFile(struct object *obj)
Checks if a given object is of the type file and casts it if possible.
Definition: filesystem.c:960
uint32_t pos
Definition: filesystem.h:81
char prefix[155]
Definition: filesystem.h:79
char size[12]
Definition: filesystem.h:68
struct directory * parent
Definition: filesystem.h:46
char * name
Definition: filesystem.h:59
Definition: object.h:69
char version[2]
Definition: filesystem.h:74
char checksum[8]
Definition: filesystem.h:70
struct linkedList directories
Definition: filesystem.h:52
char uname[32]
Definition: filesystem.h:75
char pad[12]
Definition: filesystem.h:80
char gname[32]
Definition: filesystem.h:76
char * name
Definition: filesystem.h:47
void fileSystemInit(void *addr, uint32_t length)
Initializes the root file system.
Definition: filesystem.c:858
struct directory * fileSystemSearchDirectory(struct directory *directory, char *path, uint32_t pathLength, bool create)
Opens or creates a directory.
Definition: filesystem.c:1004
char magic[6]
Definition: filesystem.h:73
char linkname[100]
Definition: filesystem.h:72
struct linkedList openedDirectories
Definition: filesystem.h:49
char mtime[12]
Definition: filesystem.h:69
struct directory * directoryCreate(struct directory *parent, char *name, uint32_t nameLength)
Creates a new kernel directory object.
Definition: filesystem.c:174
struct linkedList files
Definition: filesystem.h:51
char devmajor[8]
Definition: filesystem.h:77
struct directory * parent
Definition: filesystem.h:58
struct directory * fileSystemGetRoot()
Returns a reference to the root node of the file system.
Definition: filesystem.c:985
bool isHeap
Definition: filesystem.h:63
struct object obj
Definition: filesystem.h:45
struct file * fileSystemSearchFile(struct directory *directory, char *path, uint32_t pathLength, bool create)
Opens or creates a file.
Definition: filesystem.c:1092
char mode[8]
Definition: filesystem.h:65
char typeflag
Definition: filesystem.h:93