Newer
Older
ubixos-pre / src / sys / vfs / mount.c
@reddawg reddawg on 18 Jun 2004 5 KB UbixOS PreRelease
/*****************************************************************************************
 Copyright (c) 2002-2004 The UbixOS Project
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification, are
 permitted provided that the following conditions are met:

 Redistributions of source code must retain the above copyright notice, this list of
 conditions, the following disclaimer and the list of authors.  Redistributions in binary
 form must reproduce the above copyright notice, this list of conditions, the following
 disclaimer and the list of authors in the documentation and/or other materials provided
 with the distribution. Neither the name of the UbixOS Project nor the names of its
 contributors may be used to endorse or promote products derived from this software
 without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 $Id$

*****************************************************************************************/

#include <vfs/mount.h>
#include <ubixos/vitals.h>
#include <lib/kmalloc.h>
#include <lib/kprintf.h>
#include <lib/string.h>
#include <sys/device.h>

/************************************************************************

Function: mount(int driveId,int partition,int fsType,char *mountPoint,char *perms)

Description: mount adds a mount point and returns 0 if successful 1 if it fails

Notes:

************************************************************************/
int mount(int major,int minor,int partition,int vfsType,char *mountPoint,char *perms) {
  struct mountPoints *mp     = 0x0;
  struct deviceNode  *device = 0x0;

  /* Allocate Memory For Mount Point */
  mp = (struct mountPoints *)kmalloc(sizeof(struct mountPoints));

  /* Copy Mount Point Into Buffer */
  sprintf(mp->mountPoint,mountPoint);
  
  /* Set Pointer To Physical Drive */
  device = deviceFind(major,minor);

  /* Set Up Mp Defaults */
  mp->device    = device;
  mp->fs        = vfsFindFS(vfsType);
  mp->partition = partition;
  mp->perms     = *perms;
  if (device != 0x0) {
    mp->diskLabel = (struct ubixDiskLabel *)kmalloc(512);
    mp->device->devInfo->read(mp->device->devInfo->info,mp->diskLabel,1,1);
    kprintf("READING SECTOR");
    }

  if (mp->fs == 0x0) {
    /* sysErr(systemErr,"File System Type: %i Not Found\n",fsType); */
    kprintf("File System Type: %i Not Found\n",vfsType);
    return(0x1);
    }
  /* Add Mountpoint If It Fails Free And Return */
  if (addMount(mp) != 0x0) {
    kfree(mp);
    return(0x1);
    }
  /* Initialize The File System If It Fails Return */
  if (mp->fs->vfsInitFS(mp) == 0x0) {
    kfree(mp);
    return(0x1);
    }
  /* Return */
  return(0x0);
  }

/************************************************************************

Function: addMount(struct mountPoints *mp)

Description: This function adds a mount point to the system

Notes:

************************************************************************/
int addMount(struct mountPoints *mp) {

  /* If There Are No Existing Mounts Make It The First */
  if (systemVitals->mountPoints == 0x0) {
    mp->prev               = 0x0;
    mp->next               = 0x0;
    systemVitals->mountPoints = mp;
    }
  else {
    mp->next                        = systemVitals->mountPoints;
    systemVitals->mountPoints->prev = mp;
    mp->prev                        = 0x0;
    systemVitals->mountPoints       = mp;
    }
  /* Return */
  return(0x0);
  }

/************************************************************************

Function: findMount(char *mountPoint)

Description: This function finds a particular mount point

Notes:

************************************************************************/
struct mountPoints *findMount(char *mountPoint) {
  struct mountPoints *tmpMp = 0x0;

  for (tmpMp=systemVitals->mountPoints;tmpMp;tmpMp=tmpMp->next) {
    if (kstrcmp(tmpMp->mountPoint,mountPoint) == 0x0) {
      return(tmpMp);
      }
    }
  /* Return NULL If Mount Point Not Found */
  return(0x0);
  }

/***
 $Log$
 Revision 1.6  2004/05/19 15:22:50  reddawg
 Fixed reference issues due to changes in driver subsystem

 Revision 1.5  2004/05/19 04:07:43  reddawg
 kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been

 Revision 1.4  2004/04/29 15:45:19  reddawg
 Fixed some bugs so now the automade images will work correctly

 Revision 1.3  2004/04/28 21:10:40  reddawg
 Lots Of changes to make it work with existing os

 Revision 1.2  2004/04/28 02:22:55  reddawg
 This is a fiarly large commit but we are starting to use new driver model
 all around

 Revision 1.1.1.1  2004/04/15 12:06:53  reddawg
 UbixOS v1.0

 Revision 1.4  2004/04/13 16:36:34  reddawg
 Changed our copyright, it is all now under a BSD-Style license

 END
 ***/