Rev 2404 | 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 | */ |
||
2435 | jelen | 35 | |
36 | /** @addtogroup FileSystemImpl |
||
37 | * @{ |
||
38 | */ |
||
2404 | konopa | 39 | |
2435 | jelen | 40 | /** |
41 | * @file utility.c |
||
42 | * @brief This is the master header for fs. It includes some other files |
||
43 | * and defines the principal constants. |
||
44 | */ |
||
2404 | konopa | 45 | |
2435 | jelen | 46 | |
2386 | konopa | 47 | /* This file contains a few general purpose utility routines. */ |
48 | |||
49 | #include <unistd.h> |
||
50 | #include "fs.h" |
||
51 | #include "block.h" |
||
52 | #include "file.h" |
||
53 | #include "fproc.h" |
||
54 | #include "inode.h" |
||
55 | |||
2435 | jelen | 56 | /** |
57 | * Go get a path name from user space |
||
58 | */ |
||
2386 | konopa | 59 | int fetch_name(char* path, int len) |
60 | { |
||
61 | |||
62 | /* Go get path and put it in 'user_path' */ |
||
63 | |||
64 | register char *rpu, *rpm; |
||
65 | |||
66 | /* Check name length for validity */ |
||
67 | if (len <= 0) { |
||
68 | err_code = FS_EINVAL; |
||
69 | return FS_EGENERIC; |
||
70 | } |
||
71 | |||
72 | if (len > PATH_MAX) { |
||
73 | err_code = FS_ENAMETOOLONG; |
||
74 | return FS_EGENERIC; |
||
75 | } |
||
76 | |||
77 | rpu = &user_path[0]; |
||
78 | rpm = path; |
||
79 | do { *rpu++ = *rpm++; |
||
80 | } while (--len); |
||
81 | |||
82 | return OK; |
||
83 | } |
||
2435 | jelen | 84 | |
85 | /** |
||
86 | * Reject a system call that FS does not handle |
||
87 | */ |
||
2386 | konopa | 88 | int no_sys() |
89 | { |
||
90 | |||
91 | /* Somebody has used an illegal system call number */ |
||
92 | |||
93 | print_console("FS_NOSYS called, illegal system call number!\n"); |
||
94 | |||
2435 | jelen | 95 | re\turn FS_EINVAL; |
2386 | konopa | 96 | } |
2435 | jelen | 97 | |
98 | /** |
||
99 | * Does byte swapping on a 16-bit int |
||
100 | */ |
||
2386 | konopa | 101 | unsigned conv2(int norm, int w) |
102 | { |
||
103 | |||
104 | /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */ |
||
105 | |||
106 | if (norm) /* TRUE if no swap, FALSE for byte swap */ |
||
107 | return((unsigned) w & 0xFFFF); |
||
108 | |||
109 | return(((w&BYTE) << 8) | ( (w>>8) & BYTE)); |
||
110 | } |
||
111 | |||
2435 | jelen | 112 | /** |
113 | * Does byte swapping on a 32-bit long |
||
114 | */ |
||
2386 | konopa | 115 | long conv4(int norm, long x) |
116 | { |
||
117 | |||
118 | /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */ |
||
119 | |||
120 | unsigned lo, hi; |
||
121 | long l; |
||
122 | |||
123 | if (norm) /* byte order was already ok */ |
||
124 | return(x); |
||
125 | |||
126 | lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */ |
||
127 | hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */ |
||
128 | l = ((long) lo <<16) | hi; |
||
129 | |||
130 | return l; |
||
131 | } |
||
132 | |||
2435 | jelen | 133 | /** |
134 | * Same like strncmp |
||
135 | */ |
||
2386 | konopa | 136 | int fs_strncmp(const char *src, const char *dst, size_t len) |
137 | { |
||
138 | |||
139 | int i, src_len, dst_len; |
||
140 | |||
141 | if (src == NULL) { |
||
142 | if (dst == NULL) |
||
143 | return 0; |
||
144 | return -1; |
||
145 | } |
||
146 | |||
147 | if (dst == NULL) |
||
148 | return 1; |
||
149 | |||
150 | src_len = strlen(src); |
||
151 | dst_len = strlen(dst); |
||
152 | |||
153 | for (i = 0; i < len && i < src_len && i < dst_len; i++) { |
||
154 | if (src[i] > dst[i]) |
||
155 | return 1; |
||
156 | if (src[i] < dst[i]) |
||
157 | return -1; |
||
158 | } |
||
159 | |||
160 | return 0; |
||
161 | } |
||
2435 | jelen | 162 | |
163 | /** |
||
164 | * } |
||
165 | */ |
||
166 |