# mount.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2004 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: mount_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <vfs/mount.h>
    00031 #include <ubixos/vitals.h>
    00032 #include <ubixos/kpanic.h>
    00033 #include <lib/kmalloc.h>
    00034 #include <lib/kprintf.h>
    00035 #include <lib/string.h>
    00036 #include <sys/device.h>
    00037
    00038 /************************************************************************
    00039
    00040 Function: mount(int driveId,int partition,int fsType,char *mountPoint,char *perms)
    00041
    00042 Description: mount adds a mount point and returns 0 if successful 1 if it fails
    00043
    00044 Notes:
    00045
    00046 ************************************************************************/
    00047 int vfs_mount(int major,int minor,int partition,int vfsType,char *mountPoint,char *perms) {
    00048   struct vfs_mountPoint *mp     = 0x0;
    00049   struct device_node  *device = 0x0;
    00050
    00051   /* Allocate Memory For Mount Point */
    00052   if ((mp = (struct vfs_mountPoint *)kmalloc(sizeof(struct vfs_mountPoint))) == NULL)
    00053     kprintf("vfs_mount: failed to allocate mp\n");
    00054
    00055   /* Copy Mount Point Into Buffer */
    00056   sprintf(mp->mountPoint,mountPoint);
    00057
    00058   /* Set Pointer To Physical Drive */
    00059   device = device_find(major,minor);
    00060
    00061   /* Set Up Mp Defaults */
    00062   mp->device    = device;
    00063   mp->fs        = vfsFindFS(vfsType);
    00064   mp->partition = partition;
    00065   mp->perms     = *perms;
    00066
    00067   if (mp->fs == 0x0) {
    00068     /* sysErr(systemErr,"File System Type: %i Not Found\n",fsType); */
    00069     kprintf("File System Type: %i Not Found\n",vfsType);
    00070     return(0x1);
    00071     }
    00072   /*What is this for? 10/6/2006 */
    00073 /*
    00074   if (device != 0x0) {
    00075     mp->diskLabel = (struct ubixDiskLabel *)kmalloc(512);
    00076     mp->device->devInfo->read(mp->device->devInfo->info,mp->diskLabel,1,1);
    00077     kprintf("READING SECTOR");
    00078     }
    00079 */
    00080
    00081   /* Add Mountpoint If It Fails Free And Return */
    00082   if (vfs_addMount(mp) != 0x0) {
    00083     kfree(mp);
    00084     return(0x1);
    00085     }
    00086
    00087   /* Initialize The File System If It Fails Return */
    00088   if (mp->fs->vfsInitFS(mp) == 0x0) {
    00089     kfree(mp);
    00090     return(0x1);
    00091     }
    00092   /* Return */
    00093   return(0x0);
    00094   }
    00095
    00096 /************************************************************************
    00097
    00098 Function: vfs_addMount(struct vfs_mountPoint *mp)
    00099
    00100 Description: This function adds a mount point to the system
    00101
    00102 Notes:
    00103
    00104 ************************************************************************/
    00105 int vfs_addMount(struct vfs_mountPoint  *mp) {
    00106
    00107   /* If There Are No Existing Mounts Make It The First */
    00108   if (systemVitals->mountPoints == 0x0) {
    00109     mp->prev               = 0x0;
    00110     mp->next               = 0x0;
    00111     systemVitals->mountPoints = mp;
    00112     }
    00113   else {
    00114     mp->next                        = systemVitals->mountPoints;
    00115     systemVitals->mountPoints->prev = mp;
    00116     mp->prev                        = 0x0;
    00117     systemVitals->mountPoints       = mp;
    00118     }
    00119   /* Return */
    00120   return(0x0);
    00121   }
    00122
    00123 /************************************************************************
    00124
    00125 Function: vfs_findMount(char *mountPoint)
    00126
    00127 Description: This function finds a particular mount point
    00128
    00129 Notes:
    00130
    00131 ************************************************************************/
    00132 struct vfs_mountPoint *vfs_findMount(char *mountPoint) {
    00133   struct vfs_mountPoint *tmpMp = 0x0;
    00134
    00135   for (tmpMp=systemVitals->mountPoints;tmpMp;tmpMp=tmpMp->next) {
    00136     if (strcmp(tmpMp->mountPoint,mountPoint) == 0x0) {
    00137       return(tmpMp);
    00138       }
    00139     }
    00140   /* Return NULL If Mount Point Not Found */
    00141   return NULL;
    00142   }
    00143
    00144 /***
    00145  END
    00146  ***/
    00147