UbixOS  2.0
vfs.c
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 #include <vfs/vfs.h>
30 #include <ubixos/vitals.h>
31 #include <lib/kmalloc.h>
32 #include <lib/kprintf.h>
33 #include <string.h>
34 #include <sys/descrip.h>
35 
36 /************************************************************************
37 
38 Function: void vfs_init();
39 
40 Description: This Function Initializes The VFS Layer
41 
42 Notes:
43 
44 02/20/2004 - Approved for quality
45 
46 ************************************************************************/
47 int vfs_init() {
48  /* Set up default fileSystems list */
50 
51  /* Print information */
52  kprintf("vfs0: loaded at address: [0x%X]\n",systemVitals->fileSystems);
53 
54  /* Return so we know things went well */
55  return(0x0);
56  }
57 
58 struct fileSystem *vfsFindFS(int vfsType) {
59  struct fileSystem *tmp = 0x0;
60 
61  /* Search For File System */
62  for (tmp=systemVitals->fileSystems;tmp;tmp=tmp->next) {
63  /* If Found Return File System */
64  if (tmp->vfsType == vfsType) {
65  return(tmp);
66  }
67  }
68 
69  /* If FS Not Found Return NULL */
70  return(0x0);
71  }
72 
80 int vfsRegisterFS(struct fileSystem newFS) {
81 /*
82 int vfsType,
83 void *vfsInitFS,
84 void *vfsRead,
85 void *vfsWrite,
86 void *vfsOpenFile,
87 void *vfsUnlink,
88 void *vfsMakeDir,
89 void *vfsRemDir,
90 void *vfsSync) {
91  */
92  struct fileSystem *tmpFs = 0x0;
93 
94  if (vfsFindFS(newFS.vfsType) != 0x0) {
95  kprintf("FS Is already Registered\n");
96  return(0x1);
97  }
98 
99  /* Allocate Memory */
100  tmpFs = (struct fileSystem *)kmalloc(sizeof(struct fileSystem));
101  if (tmpFs == NULL) {
102  kprintf("vfsRegisterFS: memory allocation failed\n");
103  /* Memory Allocation Failed */
104  return(0x1);
105  }
106 
107  /* Set Up FS Defaults */
108 
109 /* 2004 7-16-2004 mji
110  * Old method:
111  * tmpFs->vfsType = newFS.vfsType;
112  * tmpFs->vfsInitFS = newFS.vfsInitFS;
113  * tmpFs->vfsRead = newFS.vfsRead;
114  * tmpFs->vfsWrite = newFS.vfsWrite;
115  * tmpFs->vfsOpenFile = newFS.vfsOpenFile;
116  * tmpFs->vfsUnlink = newFS.vfsUnlink;
117  * tmpFs->vfsMakeDir = newFS.vfsMakeDir;
118  * tmpFs->vfsRemDir = newFS.vfsRemDir;
119  * tmpFs->vfsSync = newFS.vfsSync;
120  */
121  /* new method: */
122 
123  memcpy(tmpFs, &newFS, sizeof(struct fileSystem));
124  if (!systemVitals->fileSystems) {
125  tmpFs->prev = 0x0;
126  tmpFs->next = 0x0;
127  systemVitals->fileSystems = tmpFs;
128  }
129  else {
130  tmpFs->prev = 0x0;
131  tmpFs->next = systemVitals->fileSystems;
132  systemVitals->fileSystems->prev = tmpFs;
133  systemVitals->fileSystems = tmpFs;
134  }
135 
136  return(0x0);
137  }
vitalsStruct::fileSystems
struct fileSystem * fileSystems
Definition: vitals.h:44
fileSystem::next
struct fileSystem * next
Definition: vfs.h:61
vfs.h
vfsFindFS
struct fileSystem * vfsFindFS(int vfsType)
Definition: vfs.c:57
string.h
fileSystem
filesSystem Structure
Definition: vfs.h:59
memcpy
void * memcpy(const void *dst, const void *src, size_t length)
vfsRegisterFS
int vfsRegisterFS(struct fileSystem newFS)
register a file system
Definition: vfs.c:79
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
kprintf.h
vitals.h
fileSystem::prev
struct fileSystem * prev
Definition: vfs.h:60
fileSystem::vfsType
int vfsType
Definition: vfs.h:70
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
descrip.h
vfs_init
int vfs_init()
Definition: vfs.c:46
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
kmalloc.h
NULL
#define NULL
Definition: fat_string.h:17