UbixOS  2.0
mount.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/mount.h>
30 #include <ubixos/vitals.h>
31 #include <ubixos/kpanic.h>
32 #include <lib/kmalloc.h>
33 #include <lib/kprintf.h>
34 #include <string.h>
35 #include <sys/device.h>
36 
37 /************************************************************************
38 
39  Function: mount(int driveId,int partition,int fsType,char *mountPoint,char *perms)
40 
41  Description: mount adds a mount point and returns 0 if successful 1 if it fails
42 
43  Notes:
44 
45  ************************************************************************/
46 int vfs_mount( int major, int minor, int partition, int vfsType, char *mountPoint, char *perms ) {
47  struct vfs_mountPoint *mp = 0x0;
48  struct device_node *device = 0x0;
49 
50  /* Allocate Memory For Mount Point */
51  if ( (mp = (struct vfs_mountPoint *) kmalloc( sizeof(struct vfs_mountPoint) )) == NULL )
52  kprintf( "vfs_mount: failed to allocate mp\n" );
53 
54  /* Copy Mount Point Into Buffer */
55  sprintf( mp->mountPoint, mountPoint );
56 
57  /* Set Pointer To Physical Drive */
58  device = device_find( major, minor );
59 
60  /* Set Up Mp Defaults */
61  mp->device = device;
62  mp->fs = (struct fileSystem *) vfsFindFS( vfsType );
63  mp->partition = partition;
64  mp->perms = *perms;
65 
66  if ( mp->fs == 0x0 ) {
67  /* sysErr(systemErr,"File System Type: %i Not Found\n",fsType); */
68  kprintf( "File System Type: %i Not Found\n", vfsType );
69  return (0x1);
70  }
71  /*What is this for? 10/6/2006 */
72  /*
73  if (device != 0x0) {
74  mp->diskLabel = (struct ubixDiskLabel *)kmalloc(512);
75  mp->device->devInfo->read(mp->device->devInfo->info,mp->diskLabel,1,1);
76  kprintf("READING SECTOR");
77  }
78  */
79 
80  /* Add Mountpoint If It Fails Free And Return */
81  if ( vfs_addMount( mp ) != 0x0 ) {
82  kfree( mp );
83  return (0x1);
84  }
85 
86  /* Initialize The File System If It Fails Return */
87  if ( mp->fs->vfsInitFS( mp ) == 0x0 ) {
88  kfree( mp );
89  return (0x1);
90  }
91  /* Return */
92  return (0x0);
93 }
94 
95 /************************************************************************
96 
97  Function: vfs_addMount(struct vfs_mountPoint *mp)
98 
99  Description: This function adds a mount point to the system
100 
101  Notes:
102 
103  ************************************************************************/
104 int vfs_addMount( struct vfs_mountPoint *mp ) {
105 
106  /* If There Are No Existing Mounts Make It The First */
107  if ( systemVitals->mountPoints == 0x0 ) {
108  mp->prev = 0x0;
109  mp->next = 0x0;
111  }
112  else {
115  mp->prev = 0x0;
117  }
118  /* Return */
119  return (0x0);
120 }
121 
122 /************************************************************************
123 
124  Function: vfs_findMount(char *mountPoint)
125 
126  Description: This function finds a particular mount point
127 
128  Notes:
129 
130  ************************************************************************/
131 struct vfs_mountPoint *vfs_findMount( char *mountPoint ) {
132  struct vfs_mountPoint *tmpMp = 0x0;
133 
134  for ( tmpMp = systemVitals->mountPoints; tmpMp; tmpMp = tmpMp->next ) {
135  if ( strcmp( tmpMp->mountPoint, mountPoint ) == 0x0 ) {
136  return (tmpMp);
137  }
138  }
139  /* Return NULL If Mount Point Not Found */
140  return NULL;
141 }
142 
143 /***
144  END
145  ***/
146 
vfs_mount
int vfs_mount(int major, int minor, int partition, int vfsType, char *mountPoint, char *perms)
Definition: mount.c:45
vfs_mountPoint::prev
struct vfs_mountPoint * prev
Definition: mount.h:67
vfs_findMount
struct vfs_mountPoint * vfs_findMount(char *mountPoint)
Definition: mount.c:128
vitalsStruct::mountPoints
struct vfs_mountPoint * mountPoints
Definition: vitals.h:45
vfsFindFS
struct fileSystem * vfsFindFS(int vfsType)
Definition: vfs.c:57
string.h
kfree
void kfree(void *baseAddr)
Definition: kmalloc.c:342
strcmp
int strcmp(const char *str1, const char *str2)
device
Definition: device.old.h:34
fileSystem
filesSystem Structure
Definition: vfs.h:59
vfs_mountPoint::next
struct vfs_mountPoint * next
Definition: mount.h:68
sprintf
int sprintf(char *buf, const char *fmt,...)
Definition: kprintf.c:278
device_node::minor
int minor
Definition: device.h:40
vfs_mountPoint
Definition: mount.h:66
kpanic.h
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
kprintf.h
device_node
Definition: device.h:34
vitals.h
vfs_mountPoint::mountPoint
char mountPoint[1024]
Definition: mount.h:74
vfs_mountPoint::fs
struct fileSystem * fs
Definition: mount.h:69
vfs_mountPoint::partition
int partition
Definition: mount.h:73
fileSystem::vfsInitFS
int(* vfsInitFS)(void *)
Definition: vfs.h:62
vfs_mountPoint::perms
char perms
Definition: mount.h:75
device.h
fileSystem::vfsType
int vfsType
Definition: vfs.h:70
device_find
struct device_node * device_find(int major, int minor)
Definition: device.c:82
vfs_mountPoint::device
struct device_node * device
Definition: mount.h:70
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
mount.h
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
kmalloc.h
vfs_addMount
int vfs_addMount(struct vfs_mountPoint *mp)
Definition: mount.c:102
NULL
#define NULL
Definition: fat_string.h:17