Subversion Repositories HelenOS

Rev

Rev 2386 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2404 konopa 1
/*
2
 * Copyright (c) 1987,1997, Prentice Hall
3
 * All rights reserved.
4
 *
5
 * Redistribution and use of the MINIX operating system in source and
6
 * binary forms, with or without modification, are permitted provided
7
 * that the following conditions are met:
8
 
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 
12
 * - Redistributions in binary form must reproduce the above
13
 *   copyright notice, this list of conditions and the following
14
 *   disclaimer in the documentation and/or other materials provided
15
 *   with the distribution.
16
 
17
 * - Neither the name of Prentice Hall nor the names of the software
18
 *   authors or contributors may be used to endorse or promote
19
 *   products derived from this software without specific prior
20
 *   written permission.
21
 
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
23
 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26
 * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
27
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 */
35
 
36
 
2386 konopa 37
/* This file contains a few general purpose utility routines. */
38
 
39
/* Methods:
40
 * fetch_name:  go get a path name from user space
41
 * no_sys:      reject a system call that FS does not handle
42
 * conv2:       does byte swapping on a 16-bit int
43
 * conv4:       does byte swapping on a 32-bit long
44
 * fs_strncmp:  same like strncmp
45
 */
46
 
47
 
48
#include <unistd.h>
49
#include "fs.h"
50
#include "block.h"
51
#include "file.h"
52
#include "fproc.h"
53
#include "inode.h"
54
 
55
 
56
int fetch_name(char* path, int len)
57
{
58
 
59
    /* Go get path and put it in 'user_path' */
60
 
61
    register char *rpu, *rpm;
62
 
63
    /* Check name length for validity */
64
    if (len <= 0) {
65
        err_code = FS_EINVAL;
66
        return FS_EGENERIC;
67
    }
68
 
69
    if (len > PATH_MAX) {
70
        err_code = FS_ENAMETOOLONG;
71
        return FS_EGENERIC;
72
    }
73
 
74
    rpu = &user_path[0];
75
    rpm = path;
76
    do { *rpu++ = *rpm++;
77
        } while (--len);
78
 
79
    return OK;
80
}
81
 
82
int no_sys()
83
{
84
 
85
    /* Somebody has used an illegal system call number */
86
 
87
    print_console("FS_NOSYS called, illegal system call number!\n");
88
 
89
    return FS_EINVAL;
90
}
91
 
92
unsigned conv2(int norm, int w)
93
{
94
 
95
    /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
96
 
97
    if (norm)   /* TRUE if no swap, FALSE for byte swap */
98
        return((unsigned) w & 0xFFFF);
99
 
100
    return(((w&BYTE) << 8) | ( (w>>8) & BYTE));
101
}
102
 
103
long conv4(int norm, long x)
104
{
105
 
106
    /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
107
 
108
    unsigned lo, hi;
109
    long l;
110
 
111
    if (norm)       /* byte order was already ok */
112
        return(x);
113
 
114
    lo = conv2(FALSE, (int) x & 0xFFFF);        /* low-order half, byte swapped */
115
    hi = conv2(FALSE, (int) (x>>16) & 0xFFFF);  /* high-order half, swapped */
116
    l = ((long) lo <<16) | hi;
117
 
118
    return l;
119
}
120
 
121
int fs_strncmp(const char *src, const char *dst, size_t len)
122
{
123
 
124
    int i, src_len, dst_len;
125
 
126
    if (src == NULL) {
127
        if (dst == NULL)
128
            return 0;
129
        return -1; 
130
    }
131
 
132
    if (dst == NULL)
133
        return 1;
134
 
135
    src_len = strlen(src);
136
    dst_len = strlen(dst);
137
 
138
    for (i = 0; i < len && i < src_len && i < dst_len; i++) {
139
        if (src[i] > dst[i])
140
            return 1;
141
        if (src[i] < dst[i])
142
            return -1;
143
    }
144
 
145
    return 0;
146
}