f32f3638f4
- Got rid of dummy proc[0]. Now proc[0] is init. - Added initcode.S to exec /init, so that /init is just a regular binary. - Moved exec out of sysfile to exec.c - Moved code dealing with fs guts (like struct inode) from sysfile.c to fs.c. Code dealing with system call arguments stays in sysfile.c - Refactored directory routines in fs.c; should be simpler. - Changed iget to return *unlocked* inode structure. This solves the lookup-then-use race in namei without introducing deadlocks. It also enabled getting rid of the dummy proc[0].
87 lines
1.1 KiB
C
87 lines
1.1 KiB
C
#include "types.h"
|
|
#include "defs.h"
|
|
|
|
void*
|
|
memset(void *dst, int c, uint n)
|
|
{
|
|
char *d;
|
|
|
|
d = (char*)dst;
|
|
while(n-- > 0)
|
|
*d++ = c;
|
|
|
|
return dst;
|
|
}
|
|
|
|
int
|
|
memcmp(const void *v1, const void *v2, uint n)
|
|
{
|
|
const uchar *s1, *s2;
|
|
|
|
s1 = v1;
|
|
s2 = v2;
|
|
while(n-- > 0) {
|
|
if(*s1 != *s2)
|
|
return *s1 - *s2;
|
|
s1++, s2++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void*
|
|
memmove(void *dst, const void *src, uint n)
|
|
{
|
|
const char *s;
|
|
char *d;
|
|
|
|
s = src;
|
|
d = dst;
|
|
if(s < d && s + n > d) {
|
|
s += n;
|
|
d += n;
|
|
while(n-- > 0)
|
|
*--d = *--s;
|
|
} else
|
|
while(n-- > 0)
|
|
*d++ = *s++;
|
|
|
|
return dst;
|
|
}
|
|
|
|
int
|
|
strncmp(const char *p, const char *q, uint n)
|
|
{
|
|
while(n > 0 && *p && *p == *q)
|
|
n--, p++, q++;
|
|
if(n == 0)
|
|
return 0;
|
|
else
|
|
return (int) ((uchar) *p - (uchar) *q);
|
|
}
|
|
|
|
// Like strncpy but guaranteed to NUL-terminate.
|
|
char*
|
|
safestrcpy(char *s, const char *t, int n)
|
|
{
|
|
char *os;
|
|
|
|
os = s;
|
|
if(n <= 0)
|
|
return os;
|
|
while(--n > 0 && (*s++ = *t++) != 0)
|
|
;
|
|
*s = 0;
|
|
return os;
|
|
}
|
|
|
|
int
|
|
strlen(const char *s)
|
|
{
|
|
int n;
|
|
|
|
for(n = 0; s[n]; n++)
|
|
;
|
|
return n;
|
|
}
|
|
|