File globals.h changed (mode: 100644) (index 8bbc0d3..e33a5e2) |
... |
... |
extern k_u8 *g_dprintf_buf; |
12 |
12 |
#define DPRINTF_BUF_SZ 1024 |
#define DPRINTF_BUF_SZ 1024 |
13 |
13 |
#define OUT(f,...) u_a_dprintf(g_console,g_dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ |
#define OUT(f,...) u_a_dprintf(g_console,g_dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ |
14 |
14 |
__VA_ARGS__) |
__VA_ARGS__) |
15 |
|
//FIXME: deal with -K_EINTR and -K_EAGAIN |
|
16 |
15 |
#define OUTC(s) sysc(write,3,g_console,s,sizeof(s)) |
#define OUTC(s) sysc(write,3,g_console,s,sizeof(s)) |
17 |
16 |
#else |
#else |
18 |
17 |
#define PRE |
#define PRE |
File init.c changed (mode: 100644) (index bf22a45..d5de9ab) |
7 |
7 |
#include <ulinux/sysc.h> |
#include <ulinux/sysc.h> |
8 |
8 |
#include <ulinux/types.h> |
#include <ulinux/types.h> |
9 |
9 |
#include <ulinux/error.h> |
#include <ulinux/error.h> |
|
10 |
|
#include <ulinux/fs.h> |
10 |
11 |
#include <ulinux/socket/socket.h> |
#include <ulinux/socket/socket.h> |
11 |
12 |
#include <ulinux/socket/netlink.h> |
#include <ulinux/socket/netlink.h> |
12 |
13 |
#ifdef DEBUG |
#ifdef DEBUG |
|
... |
... |
static void sigs_setup(void) |
40 |
41 |
OUTC("done\n"); |
OUTC("done\n"); |
41 |
42 |
} |
} |
42 |
43 |
|
|
|
44 |
|
static void proc_mount(void) |
|
45 |
|
{ |
|
46 |
|
OUTC(PRE "mounting proc..."); |
|
47 |
|
k_l r=sysc(mount,5,"proc","/proc","proc",K_MS_NOSUID|K_MS_NODEV|K_MS_NOEXEC, |
|
48 |
|
0); |
|
49 |
|
if(K_ISERR(r)){ |
|
50 |
|
OUT("ERROR:%ld\n",r); |
|
51 |
|
sysc(exit_group,1,-1); |
|
52 |
|
} |
|
53 |
|
OUTC("done\n"); |
|
54 |
|
} |
|
55 |
|
|
|
56 |
|
static void root_remount_rw(void) |
|
57 |
|
{ |
|
58 |
|
OUTC(PRE "remounting / as RW..."); |
|
59 |
|
k_l r=sysc(mount,5,0,"/",0,K_MS_REMOUNT,0); |
|
60 |
|
if(K_ISERR(r)){ |
|
61 |
|
OUT("ERROR:%ld\n",r); |
|
62 |
|
sysc(exit_group,1,-1); |
|
63 |
|
} |
|
64 |
|
OUTC("done\n"); |
|
65 |
|
} |
|
66 |
|
|
|
67 |
|
static void sysfs_mount(void) |
|
68 |
|
{ |
|
69 |
|
OUTC(PRE "mounting sysfs..."); |
|
70 |
|
k_l r=sysc(mount,5,"sysfs","/sys","sysfs",K_MS_NOSUID|K_MS_NODEV|K_MS_NOEXEC, |
|
71 |
|
0); |
|
72 |
|
if(K_ISERR(r)){ |
|
73 |
|
OUT("ERROR:%ld\n",r); |
|
74 |
|
sysc(exit_group,1,-1); |
|
75 |
|
} |
|
76 |
|
OUTC("done\n"); |
|
77 |
|
} |
|
78 |
|
|
43 |
79 |
void _start(void) |
void _start(void) |
44 |
80 |
{ |
{ |
45 |
81 |
# ifdef DEBUG |
# ifdef DEBUG |
|
... |
... |
void _start(void) |
52 |
88 |
# endif |
# endif |
53 |
89 |
sigs_setup(); |
sigs_setup(); |
54 |
90 |
proc_mount(); |
proc_mount(); |
55 |
|
sys_mount(); |
|
56 |
|
sigs_setup(); |
|
|
91 |
|
root_remount_rw(); |
|
92 |
|
sysfs_mount(); |
57 |
93 |
uevent_setup(); |
uevent_setup(); |
58 |
|
uevent_recv_thread_start(); |
|
59 |
94 |
modules_load(); |
modules_load(); |
60 |
|
while(1); |
|
|
95 |
|
uevent_recv(); |
61 |
96 |
sysc(exit_group,1,0); |
sysc(exit_group,1,0); |
62 |
97 |
} |
} |
File uevent.c changed (mode: 100644) (index ef452f3..4306e6f) |
... |
... |
void uevent_setup(void) |
79 |
79 |
OUTC("done\n"); |
OUTC("done\n"); |
80 |
80 |
} |
} |
81 |
81 |
|
|
82 |
|
static void uevent_rcv(k_i s) |
|
|
82 |
|
static void uevent_msg(k_i s) |
83 |
83 |
{ |
{ |
84 |
84 |
k_u8 buf[8192]; |
k_u8 buf[8192]; |
85 |
85 |
u_memset(buf,0,sizeof(buf)); |
u_memset(buf,0,sizeof(buf)); |
|
... |
... |
static void uevent_rcv(k_i s) |
116 |
116 |
OUTC("\n"); |
OUTC("\n"); |
117 |
117 |
} |
} |
118 |
118 |
|
|
119 |
|
static void uevent_recv(void) |
|
|
119 |
|
void uevent_recv(void) |
120 |
120 |
{ |
{ |
121 |
121 |
OUTC(PRE "receiving uevent...\n"); |
OUTC(PRE "receiving uevent...\n"); |
122 |
122 |
while(1){ |
while(1){ |
|
... |
... |
static void uevent_recv(void) |
134 |
134 |
while(i<r){ |
while(i<r){ |
135 |
135 |
if(evts[i].data.fd==s){ |
if(evts[i].data.fd==s){ |
136 |
136 |
if(evts[i].events&K_EPOLLIN){ |
if(evts[i].events&K_EPOLLIN){ |
137 |
|
uevent_rcv(s); |
|
|
137 |
|
uevent_msg(s); |
138 |
138 |
}else{ |
}else{ |
139 |
139 |
OUT(PRE "ERROR:unmanaged epolling event on uevent netlink socket" |
OUT(PRE "ERROR:unmanaged epolling event on uevent netlink socket" |
140 |
140 |
" n=%ld events=%u\n", i,evts[i].events); |
" n=%ld events=%u\n", i,evts[i].events); |
|
... |
... |
static void uevent_recv(void) |
145 |
145 |
} |
} |
146 |
146 |
} |
} |
147 |
147 |
} |
} |
148 |
|
|
|
149 |
|
void uevent_recv_thread_start(void) |
|
150 |
|
{ |
|
151 |
|
k_l r=sysc(clone,5,K_,0,NULL,NULL,NULL); |
|
152 |
|
if(K_ISERR(r)){ |
|
153 |
|
PERR("FATAL:error precloning process slot %d with error %ld\n",slot,r); |
|
154 |
|
return -1; |
|
155 |
|
} |
|
156 |
|
if(r==0) goto preclone_entry_setup; |
|
157 |
|
|
|
158 |
|
_preclones[slot].s=s[1]; |
|
159 |
|
sysc(close,1,s[0]); |
|
160 |
|
_preclones[slot].pid=(k_i)r; |
|
161 |
|
return 0; |
|
162 |
|
|
|
163 |
|
preclone_entry_setup: |
|
164 |
|
_slot=slot; |
|
165 |
|
sysc(close,1,s[1]);//close parent unix socket |
|
166 |
|
_parent_sock=s[0]; |
|
167 |
|
|
|
168 |
|
sysc(close,1,0);//for the connexion socket |
|
169 |
|
sysc(close,1,1);//for the connexion socket |
|
170 |
|
//keep stderr |
|
171 |
|
|
|
172 |
|
sysc(close,1,_sigs_fd);//don't care of parent signal |
|
173 |
|
sysc(close,1,_epfd);//don't use parent epoll |
|
174 |
|
|
|
175 |
|
_preclone_entry(); |
|
176 |
|
return -1; |
|
177 |
|
} |
|
File uevent_monitor.c changed (mode: 100644) (index 75cce0f..18603bc) |
10 |
10 |
#include <ulinux/file.h> |
#include <ulinux/file.h> |
11 |
11 |
#include <ulinux/stat.h> |
#include <ulinux/stat.h> |
12 |
12 |
#include <ulinux/mmap.h> |
#include <ulinux/mmap.h> |
|
13 |
|
#include <ulinux/time.h> |
13 |
14 |
#include <ulinux/signal/signal.h> |
#include <ulinux/signal/signal.h> |
14 |
15 |
#include <ulinux/socket/socket.h> |
#include <ulinux/socket/socket.h> |
15 |
16 |
#include <ulinux/socket/msg.h> |
#include <ulinux/socket/msg.h> |
|
... |
... |
void _start(void) |
113 |
114 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
114 |
115 |
} |
} |
115 |
116 |
|
|
|
117 |
|
//---------------------------------------------------------------------------- |
|
118 |
|
|
|
119 |
|
struct timespec wanted={20,0}; |
|
120 |
|
struct timespec rem={0,0}; |
|
121 |
|
ERRC("Sleeping 20 sec (buffering)...\n"); |
|
122 |
|
r=sysc(nanosleep,2,&wanted,&rem); |
|
123 |
|
if(r==-K_EINTR){ |
|
124 |
|
ERR("WARNING:sleep was interruped. Remainder %ld sec/%ld nsec\n",rem.sec, |
|
125 |
|
rem.nsec); |
|
126 |
|
}else if(K_ISERR(r)){ |
|
127 |
|
ERR("ERROR:sleeping:%ld\n",r); |
|
128 |
|
sysc(exit_group,1,-1); |
|
129 |
|
} |
|
130 |
|
ERRC("done\n"); |
|
131 |
|
|
116 |
132 |
//---------------------------------------------------------------------------- |
//---------------------------------------------------------------------------- |
117 |
133 |
|
|
118 |
134 |
struct k_epoll_event ep_evt; |
struct k_epoll_event ep_evt; |
File ulinux/dirent.h copied from file ulinux/time.h (similarity 71%) (mode: 100644) (index 37b6383..1fdb28f) |
1 |
|
#ifndef ULINUX_TIME_H |
|
2 |
|
#define ULINUX_TIME_H |
|
|
1 |
|
#ifndef ULINUX_DIRENT_H |
|
2 |
|
#define ULINUX_DIRENT_H |
3 |
3 |
//****************************************************************************** |
//****************************************************************************** |
4 |
4 |
//*this code is protected by the GNU affero GPLv3 |
//*this code is protected by the GNU affero GPLv3 |
5 |
5 |
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
6 |
6 |
//* <digital.ragnarok AT gmail dot com> |
//* <digital.ragnarok AT gmail dot com> |
7 |
7 |
//****************************************************************************** |
//****************************************************************************** |
8 |
|
struct timespec{ |
|
9 |
|
long sec;//seconds |
|
10 |
|
long nsec;//nanoseconds |
|
|
8 |
|
struct k_dirent64{ |
|
9 |
|
k_u64 ino; |
|
10 |
|
k_s64 off; |
|
11 |
|
k_us rec_len; |
|
12 |
|
k_u8 type; |
|
13 |
|
k_u8 name[0]; |
11 |
14 |
}; |
}; |
12 |
15 |
#endif |
#endif |
File ulinux/patterns/dir_parse/dir_parse.c added (mode: 100644) (index 0000000..1b22dfd) |
|
1 |
|
#include <stdarg.h> |
|
2 |
|
#include <ulinux/compiler_types.h> |
|
3 |
|
#include <ulinux/sysc.h> |
|
4 |
|
#include <ulinux/types.h> |
|
5 |
|
#include <ulinux/error.h> |
|
6 |
|
#include <ulinux/args.h> |
|
7 |
|
#include <ulinux/file.h> |
|
8 |
|
#include <ulinux/fs.h> |
|
9 |
|
#include <ulinux/dirent.h> |
|
10 |
|
|
|
11 |
|
#include <ulinux/utils/ascii/string/vsprintf.h> |
|
12 |
|
|
|
13 |
|
#define DPRINTF_BUF_SZ 1024 |
|
14 |
|
static k_u8 *dprintf_buf; |
|
15 |
|
|
|
16 |
|
#define PERRC(s) {k_l rl;do{rl=sysc(write,3,2,s,sizeof(s));}\ |
|
17 |
|
while(rl==-K_EINTR||rl==-K_EAGAIN);} |
|
18 |
|
#define PERR(f,...) u_a_dprintf(2,dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ |
|
19 |
|
##__VA_ARGS__) |
|
20 |
|
#define POUT(f,...) u_a_dprintf(1,dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ |
|
21 |
|
__VA_ARGS__) |
|
22 |
|
#define POUTC(s) {k_l rl;do{rl=sysc(write,3,1,s,sizeof(s));}\ |
|
23 |
|
while(rl==-K_EINTR||rl==-K_EAGAIN);} |
|
24 |
|
|
|
25 |
|
static k_ut is_current(k_u8 *n) |
|
26 |
|
{ |
|
27 |
|
if(n[0]=='.'&&n[1]==0) return 1; |
|
28 |
|
return 0; |
|
29 |
|
} |
|
30 |
|
|
|
31 |
|
static k_ut is_parent(k_u8 *n) |
|
32 |
|
{ |
|
33 |
|
if(n[0]=='.'&&n[1]=='.'&&n[2]==0) return 1; |
|
34 |
|
return 0; |
|
35 |
|
} |
|
36 |
|
|
|
37 |
|
static k_u depth=-1; |
|
38 |
|
|
|
39 |
|
static void dout(struct k_dirent64 *d) |
|
40 |
|
{ |
|
41 |
|
POUT("%20lu %20ld %2u ",d->ino,d->off,d->type,d->name); |
|
42 |
|
k_u i=depth; |
|
43 |
|
while(i--) POUTC(" "); |
|
44 |
|
POUT("%s\n",d->name);//XXX:ugly-->we already have the string size |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
#define DIRENTS_BUF_SZ 8192 |
|
48 |
|
//XXX:carefull, the dentry type is not supported by all fs |
|
49 |
|
static void dir_parse(k_i parent_fd) |
|
50 |
|
{ |
|
51 |
|
++depth; |
|
52 |
|
k_u8 dirents[DIRENTS_BUF_SZ]; |
|
53 |
|
while(1){ |
|
54 |
|
k_l r=sysc(getdents64,3,parent_fd,dirents,DIRENTS_BUF_SZ); |
|
55 |
|
if(K_ISERR(r)){ |
|
56 |
|
PERR("ERROR(%ld):getdents error\n",r); |
|
57 |
|
sysc(exit_group,1,-1); |
|
58 |
|
} |
|
59 |
|
if(!r) break; |
|
60 |
|
k_l i=0; |
|
61 |
|
while(i<r){ |
|
62 |
|
struct k_dirent64 *d=(struct k_dirent64*)(dirents+i); |
|
63 |
|
|
|
64 |
|
dout(d); |
|
65 |
|
|
|
66 |
|
if(d->type==K_DT_DIR&&!is_current(d->name)&&!is_parent(d->name)){ |
|
67 |
|
k_i dir_fd; |
|
68 |
|
do |
|
69 |
|
dir_fd=(k_i)sysc(openat,4,parent_fd,d->name,K_O_RDONLY|K_O_NONBLOCK, |
|
70 |
|
0); |
|
71 |
|
while(dir_fd==-K_EINTR); |
|
72 |
|
if(K_ISERR(dir_fd)) |
|
73 |
|
PERR("ERROR(%d):unable to open subdir:%s\n",dir_fd,d->name); |
|
74 |
|
else{ |
|
75 |
|
dir_parse(dir_fd); |
|
76 |
|
sysc(close,1,dir_fd); |
|
77 |
|
} |
|
78 |
|
} |
|
79 |
|
i+=d->rec_len; |
|
80 |
|
} |
|
81 |
|
} |
|
82 |
|
depth--; |
|
83 |
|
} |
|
84 |
|
|
|
85 |
|
void start(k_i argc,k_u8 **argv) |
|
86 |
|
{ |
|
87 |
|
k_u8 _dprintf_buf[DPRINTF_BUF_SZ]; |
|
88 |
|
dprintf_buf=&_dprintf_buf[0]; |
|
89 |
|
|
|
90 |
|
if(argc!=2){ |
|
91 |
|
PERR("ERROR:wrong number of command arguments(%d)\n",argc); |
|
92 |
|
sysc(exit_group,1,-1); |
|
93 |
|
} |
|
94 |
|
|
|
95 |
|
//root fd |
|
96 |
|
k_i root_fd; |
|
97 |
|
do |
|
98 |
|
root_fd=(k_i)sysc(open,3,argv[1],K_O_RDONLY|K_O_NONBLOCK,0); |
|
99 |
|
while(root_fd==-K_EINTR); |
|
100 |
|
if(K_ISERR(root_fd)){ |
|
101 |
|
PERR("ERROR(%d):unable to open root dir:%s\n",root_fd,argv[1]); |
|
102 |
|
sysc(exit_group,1,-1); |
|
103 |
|
} |
|
104 |
|
|
|
105 |
|
dir_parse(root_fd); |
|
106 |
|
sysc(exit_group,1,0); |
|
107 |
|
} |
File ulinux/patterns/dir_parse/makefile copied from file ulinux/patterns/args/makefile (similarity 72%) (mode: 100644) (index 09250c7..4210853) |
2 |
2 |
|
|
3 |
3 |
ARCH?=$(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/) |
ARCH?=$(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/) |
4 |
4 |
|
|
5 |
|
args:args.c ../../../ulinux/arch |
|
|
5 |
|
dir_parse:dir_parse.c ../../../ulinux/arch |
6 |
6 |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
7 |
7 |
../../arch/utils/mem.c -o mem.s |
../../arch/utils/mem.c -o mem.s |
8 |
8 |
as mem.s -o mem.o |
as mem.s -o mem.o |
|
... |
... |
args:args.c ../../../ulinux/arch |
12 |
12 |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
13 |
13 |
../../utils/ascii/string/string.c -o string.s |
../../utils/ascii/string/string.c -o string.s |
14 |
14 |
as string.s -o string.o |
as string.s -o string.o |
15 |
|
as ../../arch/args.s -o arch_args.o |
|
|
15 |
|
as ../../arch/args.s -o args.o |
16 |
16 |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
gcc -Wall -Wextra -std=gnu99 -O3 -march=native -fverbose-asm -I../../.. -S \ |
17 |
|
args.c -o args.s |
|
18 |
|
as args.s -o args.o |
|
19 |
|
ld -O -nostdlib -Bstatic --strip-all args.o arch_args.o string.o mem.o vsprintf.o --output args |
|
|
17 |
|
dir_parse.c -o dir_parse.s |
|
18 |
|
as dir_parse.s -o dir_parse.o |
|
19 |
|
ld -O -nostdlib -Bstatic --strip-all dir_parse.o args.o string.o mem.o vsprintf.o --output dir_parse |
20 |
20 |
|
|
21 |
21 |
../../../ulinux/arch: |
../../../ulinux/arch: |
22 |
22 |
ln -s archs/$(ARCH) ../../../ulinux/arch |
ln -s archs/$(ARCH) ../../../ulinux/arch |
23 |
23 |
|
|
24 |
24 |
clean: |
clean: |
25 |
|
-rm -f ../../../ulinux/arch args.s args.o args \ |
|
|
25 |
|
-rm -f ../../../ulinux/arch dir_parse.s dir_parse.o dir_parse \ |
26 |
26 |
mem.s mem.o \ |
mem.s mem.o \ |
27 |
27 |
string.s string.o \ |
string.s string.o \ |
28 |
28 |
vsprintf.s vsprintf.o \ |
vsprintf.s vsprintf.o \ |
29 |
|
arch_args.o |
|
|
29 |
|
args.o |
File ulinux/utils/ascii/string/vsprintf.c changed (mode: 100644) (index ca45280..84c5a66) |
... |
... |
static k_u8 *_number(k_u8 *buf,k_u8 *end,k_ull num,struct printf_spec spec) |
272 |
272 |
|
|
273 |
273 |
static k_u8 *_string(k_u8 *buf,k_u8 *end,k_u8 *s,struct printf_spec spec) |
static k_u8 *_string(k_u8 *buf,k_u8 *end,k_u8 *s,struct printf_spec spec) |
274 |
274 |
{ |
{ |
275 |
|
if((k_ul)s<K_PAGE_SIZE) s=(k_u8*)"(null)";//XXX:why excluding first page *here*?? |
|
|
275 |
|
if((k_ul)s<K_PAGE_SZ) s=(k_u8*)"(null)";//XXX:why excluding first page *here*?? |
276 |
276 |
|
|
277 |
277 |
k_ul len; |
k_ul len; |
278 |
278 |
if(!u_a_strnlen(&len,s,spec.precision)) len=spec.precision; |
if(!u_a_strnlen(&len,s,spec.precision)) len=spec.precision; |