/*
* Copyright (c) 1987,1997, Prentice Hall
* All rights reserved.
*
* Redistribution and use of the MINIX operating system 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 and the following disclaimer.
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* - Neither the name of Prentice Hall nor the names of the software
* authors or 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, AUTHORS, 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 PRENTICE HALL OR ANY AUTHORS 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.
*/
/** @addtogroup FileSystemImpl
* @{
*/
/**
* @file utility.c
* @brief This is the master header for fs. It includes some other files
* and defines the principal constants.
*/
/* This file contains a few general purpose utility routines. */
#include <unistd.h>
#include "fs.h"
#include "block.h"
#include "file.h"
#include "fproc.h"
#include "inode.h"
/**
* Go get a path name from user space
*/
int fetch_name(char* path, int len)
{
/* Go get path and put it in 'user_path' */
register char *rpu, *rpm;
/* Check name length for validity */
if (len <= 0) {
err_code = FS_EINVAL;
return FS_EGENERIC;
}
if (len > PATH_MAX) {
err_code = FS_ENAMETOOLONG;
return FS_EGENERIC;
}
rpu = &user_path[0];
rpm = path;
do { *rpu++ = *rpm++;
} while (--len);
return OK;
}
/**
* Reject a system call that FS does not handle
*/
int no_sys()
{
/* Somebody has used an illegal system call number */
print_console("FS_NOSYS called, illegal system call number!\n");
re\turn FS_EINVAL;
}
/**
* Does byte swapping on a 16-bit int
*/
unsigned conv2(int norm, int w)
{
/* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
if (norm) /* TRUE if no swap, FALSE for byte swap */
return((unsigned) w & 0xFFFF);
return(((w&BYTE) << 8) | ( (w>>8) & BYTE));
}
/**
* Does byte swapping on a 32-bit long
*/
long conv4(int norm, long x)
{
/* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
unsigned lo, hi;
long l;
if (norm) /* byte order was already ok */
return(x);
lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */
hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */
l = ((long) lo <<16) | hi;
return l;
}
/**
* Same like strncmp
*/
int fs_strncmp(const char *src, const char *dst, size_t len)
{
int i, src_len, dst_len;
if (src == NULL) {
if (dst == NULL)
return 0;
return -1;
}
if (dst == NULL)
return 1;
for (i = 0; i < len && i < src_len && i < dst_len; i++) {
if (src[i] > dst[i])
return 1;
if (src[i] < dst[i])
return -1;
}
return 0;
}
/**
* }
*/