2009-05-29 08:56:17     Check if USB Device is detected before mounting

Document created by Aaronwu Employee on Aug 15, 2013
Version 1Show Document
  • View in full screen mode

2009-05-29 08:56:17     Check if USB Device is detected before mounting

Narendra Nath (INDIA)

Message: 74759   

 

Dear all

 

    I am Working on USB based application,where in Once the pen drive is detected as Mass storage device , i will be calling mount.But here i am unable to know when the device detection will be completed.

 

temporarily i kept the usleep and after that calling mount.The following is the listing i  am using in my C file

 

main()

 

{

 

int i=999;

    system("modprobe usbcore");

    system("insmod usb-storage.ko");

     system("insmod bfin-isp1761.ko");

     system("insmod hal_pxa.ko");

      system("insmod pehci.ko");

      //system("mkdir mnt");

         while(i--)

     {

         printf("sleeping");

         usleep(10000);

         usleep(10000);

          usleep(10000);

      }

 

/********* Call mount only if dev/sda is there ***********/

      printf("Monuting...");

      system("mount -t vfat /dev/sda /mnt");

}

 

Is there any way we can find if dev/sda is present before calling mount

 

Please support in this regard

 

 

 

Best regards

 

Narendra

QuoteReplyEditDelete

 

 

2009-05-29 08:58:16     Re: Check if USB Device is detected before mounting

Mike Frysinger (UNITED STATES)

Message: 74761   

 

you can either use hotplug, or simply use stat() to check if the device node exists

QuoteReplyEditDelete

 

 

2009-05-29 09:23:04     Re: Check if USB Device is detected before mounting

Narendra Nath (INDIA)

Message: 74763   

 

Hi Mike

 

Thank you  very much i tested with stat () its working

 

 

 

Narendra

Attachments

    Outcomes