Go to most recent revision |
Blame |
Last modification |
View Log
| RSS feed
/*
*
*
*
*/
#include <kernel/func.h>
#include <kernel/model.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <semaphore.h>
#include <stdio.h>
#include "common.h"
#define NOSHOW
#undef NOSHOW
#define sem_signal sem_post
int noscroll
=0;
sem_t console
;
#define MPROC ((50<(MAX_PROC-10))?50:MAX_PROC-10)
//#define MWCET 1000l
//#define MPERIOD (MWCET*(MPROC+10))
TASK viewdir
(void *prof
);
sem_t actmutex
,actsync
;
char *globpathname
;
PID globpid
;
int counter
=0,actcounter
=0;
void activate_task
(int prof
, char *pathname
)
{
char tname
[32];
NRT_TASK_MODEL m
;
PID pid
;
REPEAT
:
sem_wait
(&actmutex
);
if (actcounter
>=MPROC
) {
sem_signal
(&actmutex
);
task_delay
(10000);
goto REPEAT
;
}
globpathname
=pathname
;
counter
++;
sprintf(tname
,"tsk%i",counter
);
/*
printd("Û");
sem_wait(&console);
printd("Ü");
cprintf("%03i has called for ##%s##\n",prof,pathname);
sem_signal(&console);
*/
nrt_task_default_model
(m
);
//soft_task_def_met(m,MWCET);
//soft_task_def_wcet(m,MWCET);
//soft_task_def_periodic(m);
nrt_task_def_arg
(m
,(void*)counter
);
//soft_task_def_period(m,MPERIOD);
globpid
=pid
=task_create
(tname
,viewdir
,&m
,NULL
);
if (pid
==-1) {
sem_wait
(&console
);
cprintf
("can't create '%s'\n",tname
);
perror("can't create task");
sem_signal
(&console
);
sys_end
();
return;
}
task_activate
(pid
);
sem_wait
(&actsync
);
actcounter
++;
/*
printd("Û");
sem_wait(&console);
printd("Ü");
if (noscroll) place(0,9);
cprintf("task running: %5i/%5i --- task started: %5i\n",
actcounter,MAX_PROC,counter);
sem_signal(&console);
*/
sem_signal
(&actmutex
);
}
/*
*
*/
int filecounter
=0;
TASK viewdir
(void *pointer
)
{
struct dirent
*den
;
struct stat st
;
char *str
;
DIR
*d
;
int res
;
int x
;
char pathname
[1024];
PID mypid
;
int prof
=(int)pointer
;
strcpy(pathname
,globpathname
);
mypid
=globpid
;
sem_signal
(&actsync
);
//sem_wait(&console);
//cprintf("%03i on <%s>\n",prof,pathname);
//sem_signal(&console);
str
=pathname
+(x
=strlen(pathname
));
d
=opendir
(pathname
);
if (d
==NULL
) {
sem_wait
(&console
);
cprintf
("%03i ERR: can't open dir %s\n",prof
,pathname
);
cprintf
("errno: %i '%s'\n",errno
,strerror(errno
));
sem_signal
(&console
);
sys_end
();
l1_exit
(0);
goto END
;
}
while ((den
=readdir
(d
))!=NULL
) {
if (x
==1&&*pathname
=='/')
strcat(pathname
,den
->d_name
);
else
strcat(strcat(pathname
,"/"),den
->d_name
);
sem_wait
(&console
);
#ifndef NOSHOW
if (noscroll
) {
place
(0,10);
cprintf
(" ");
place
(0,10);
}
//cprintf("%03i(0_%03i) %s\n",prof,(int)mypid,pathname);
cprintf
("t%03i %s\n",prof
,pathname
);
#endif
filecounter
++;
sem_signal
(&console
);
//if (*den->d_name=='.') {
// sem_wait(console,BLOCK);
// cprintf("%03i HAS FOUND <%s>\n",prof,den->d_name);
// sem_signal(console);
//}
if (!strcmp(den
->d_name
,".")) {
//sem_wait(console,BLOCK);
//cprintf("%03i skip for .\n",prof);
//sem_signal(console);
goto SKIP
;
}
if (!strcmp(den
->d_name
,"..")) {
//sem_wait(console,BLOCK);
//cprintf("%03i skip for ..\n",prof);
//sem_signal(console);
goto SKIP
;
}
res
=stat
(pathname
,&st
);
if (res
!=0) {
sem_wait
(&console
);
cprintf
("t%03i can't stat %s\n",prof
,pathname
);
cprintf
("errno: %i '%s'\n",errno
,strerror(errno
));
sem_signal
(&console
);
sys_end
();
l1_exit
(0);
closedir
(d
);
goto END
;
} else {
if (S_ISDIR
(st.
st_mode)) {
sem_wait
(&console
);
//if (den->d_name[0]=='.')
// cprintf("%03i called for <%s>\n",prof,den->d_name);
sem_signal
(&console
);
activate_task
(prof
,pathname
);
}
}
SKIP
:
*str
='\0';
}
closedir
(d
);
END
:
sem_wait
(&actmutex
);
actcounter
--;
sem_signal
(&actmutex
);
return 0;
}
int main
(int argc
,char *argv
[])
{
extern void dump_sem_table
(void);
TIME stime
,etime
;
// int res;
/*
temp_device=bdev_scan_devices(choose_temp_callback);
if (temp_device<0) {
cprintf("can't find a filesystem to mount on /TEMP!!!\n");
return -1;
}
*/
/* mounting 2nd msdos partition on /TEMP */
/*
res=mount(temp_device,FS_MSDOS,"/TEMP",NULL);
if (res!=0) {
cprintf("can't mount XXX on /TEMP\n");
cprintf("errno: %i '%s'\n",errno,strerror(errno));
return -1;
}
*/
/* clear screen */
//clear();
showmessage
("This test show all filenames of a directory of an hardisk\n"
"recursively using a soft task for every directory.\n");
stime
=sys_gettime
(NULL
);
sem_init
(&console
,0,1);
sem_init
(&actmutex
,0,1);
sem_init
(&actsync
,0,0);
//dump_sem_table();
//keyb_getchar();
activate_task
(-1,"/TEMP");
for(;;) {
sem_wait
(&actmutex
);
if (actcounter
==0) break;
sem_signal
(&actmutex
);
}
etime
=sys_gettime
(NULL
);
cprintf
("\nfiles: %i\n",filecounter
);
cprintf
("time : %li\n",etime
-stime
);
waitend
();
return 0;
}