1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
11 /*===========================================================================*
13 *===========================================================================*/
16 /* Somebody has used an illegal system call number */
17 printf("no_sys: invalid call %d\n", req_nr
);
22 /*===========================================================================*
24 *===========================================================================*/
25 unsigned conv2(norm
, w
)
26 int norm
; /* TRUE if no swap, FALSE for byte swap */
27 int w
; /* promotion of 16-bit word to be swapped */
29 /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
30 if (norm
) return( (unsigned) w
& 0xFFFF);
31 return( ((w
&BYTE
) << 8) | ( (w
>>8) & BYTE
));
35 /*===========================================================================*
37 *===========================================================================*/
39 int norm
; /* TRUE if no swap, FALSE for byte swap */
40 long x
; /* 32-bit long to be byte swapped */
42 /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
46 if (norm
) return(x
); /* byte order was already ok */
47 lo
= conv2(FALSE
, (int) x
& 0xFFFF); /* low-order half, byte swapped */
48 hi
= conv2(FALSE
, (int) (x
>>16) & 0xFFFF); /* high-order half, swapped */
49 l
= ( (long) lo
<<16) | hi
;
54 /*===========================================================================*
56 *===========================================================================*/
59 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
60 * astrophysically naive system that assumes the earth rotates at a constant
61 * rate and that such things as leap seconds do not exist.
68 if ( (k
=getuptime2(&uptime
, &boottime
)) != OK
)
69 panic("clock_time: getuptme2 failed: %d", k
);
71 return( (time_t) (boottime
+ (uptime
/sys_hz())));
75 /*===========================================================================*
77 *===========================================================================*/
78 int min(unsigned int l
, unsigned int r
)
86 /*===========================================================================*
88 *===========================================================================*/
89 void mfs_nul_f(char *file
, int line
, char *str
, unsigned int len
,
92 if(len
< maxlen
&& str
[len
-1] != '\0') {
93 printf("ext2 %s:%d string (length %d, maxlen %d) not null-terminated\n",
94 file
, line
, len
, maxlen
);
98 #define MYASSERT(c) if(!(c)) { printf("ext2:%s:%d: sanity check: %s failed\n", \
99 file, line, #c); panic("sanity check " #c " failed: %d", __LINE__); }
102 /*===========================================================================*
104 *===========================================================================*/
105 void sanitycheck(char *file
, int line
)
107 MYASSERT(SELF_E
> 0);
108 if(superblock
->s_dev
!= NO_DEV
) {
109 MYASSERT(superblock
->s_dev
== fs_dev
);
110 MYASSERT(superblock
->s_block_size
== fs_block_size
);
112 MYASSERT(_MIN_BLOCK_SIZE
== fs_block_size
);
116 /*===========================================================================*
118 *===========================================================================*/
119 int ansi_strcmp(register const char* ansi_s
, register const char *s2
,
120 register size_t ansi_s_length
)
122 /* Compare non null-terminated string ansi_s (length=ansi_s_length)
124 * It returns 0 if strings are equal, otherwise -1 is returned.
130 if (*ansi_s
++ != *s2
++)
132 } while (--ansi_s_length
> 0);
143 /*===========================================================================*
145 *===========================================================================*/
146 bit_t
setbit(bitchunk_t
*bitmap
, bit_t max_bits
, unsigned int word
)
148 /* Find free bit in bitmap and set. Return number of the bit,
149 * if failed return -1.
151 bitchunk_t
*wptr
, *wlim
;
154 /* TODO: do we need to add 1? I saw a situation, when it was
155 * required, and since we check bit number with max_bits it
158 wlim
= &bitmap
[FS_BITMAP_CHUNKS(max_bits
>> 3)];
160 /* Iterate over the words in block. */
161 for (wptr
= &bitmap
[word
]; wptr
< wlim
; wptr
++) {
165 /* Does this word contain a free bit? */
166 if (*wptr
== (bitchunk_t
) ~0)
169 /* Find and allocate the free bit. */
171 for (i
= 0; (k
& (1 << i
)) != 0; ++i
) {}
173 /* Bit number from the start of the bit map. */
174 b
= (wptr
- &bitmap
[0]) * FS_BITCHUNK_BITS
+ i
;
176 /* Don't allocate bits beyond the end of the map. */
182 /* Allocate bit number. */
192 /*===========================================================================*
194 *===========================================================================*/
195 bit_t
setbyte(bitchunk_t
*bitmap
, bit_t max_bits
)
197 /* Find free byte in bitmap and set it. Return number of the starting bit,
198 * if failed return -1.
200 unsigned char *wptr
, *wlim
;
203 wptr
= (unsigned char*) &bitmap
[0];
204 /* TODO: do we need to add 1? I saw a situation, when it was
205 * required, and since we check bit number with max_bits it
208 wlim
= &wptr
[(max_bits
>> 3)];
210 /* Iterate over the words in block. */
211 for ( ; wptr
< wlim
; wptr
++) {
212 /* Is it a free byte? */
216 /* Bit number from the start of the bit map. */
217 b
= (wptr
- (unsigned char*) &bitmap
[0]) * CHAR_BIT
;
219 /* Don't allocate bits beyond the end of the map. */
220 if (b
+ CHAR_BIT
>= max_bits
) {
225 /* Allocate byte number. */
226 *wptr
= (unsigned char) ~0;
233 /*===========================================================================*
235 *===========================================================================*/
236 int unsetbit(bitchunk_t
*bitmap
, bit_t bit
)
238 /* Unset specified bit. If requested bit is already free return -1,
239 * otherwise return 0.
241 unsigned int word
; /* bit_returned word in bitmap */
244 word
= bit
/ FS_BITCHUNK_BITS
;
245 bit
= bit
% FS_BITCHUNK_BITS
; /* index in word */
248 k
= (int) bitmap
[word
];
253 bitmap
[word
] = (int) k
;