As i have told u before in previous posts, at the first time i have written a small C program for device detection using mount API of linux.
I am giving here that. Please look once.
void main()
{
Char Buffer[256];
FILE *fp1;
system ("ls /dev/sd* > NodeList");
fp1 = fopen (NodeList, "r");
if(fp1 == NULL)
{
printf("IN CM FIle Open Fail\n");
}
pthread_create(&threadID , NULL, (void*)detect, NULL);
}
void detect(void)
{
int i;
FILE *fp;
char Node[256];
while (1)
{
fp = fopen(NodeList, “r”);
if(!fp)
{
Printf(“File open unsuccessful\n”);
continue;
}
while(!feof(fP))
{
fgets(Node, BYTES_TO_READ,pp_fd);
i = mount(Node,"/mnt/DEVICE","vfat",0,0);
if(i == 0 )
{
printf("Mounted %s\n”, DeviceNode);
}
fgets(Node, 256, fp);
}
fclose (fp);
system ("ls /dev/sd* > NodeList");
Continue;
}
}
Mount API of Linux returns zero when mounting is successful. Hence i am checking here the return value of mount API.
It was working fine when it was not integrated with our other modules. But when we integrated, this was not working sometimes. I dont know why it was inconsistent in our project. Hence i have implemented my other idea using shell scripting and signals. I have posted the same in previous posts.
But it could give problem at sometimes when some hard disk or more devices are connected to the system. Also, in some embedded linux, USB device detection itself will take more time. For example, our current linux Freescale linux is taking near by 8 secaonds to create a node in /dev/ directory. Hence our application (my shell script) also will take more time.
If anybody finds a different and easy ways for device detection, please fell free to write to me at pramoda.ma@gmail.com.
Wish u best of luck...
No comments:
Post a Comment