xavier.montagne ha scritto:
> OK, it is an idea !
> Do you know how to rmmod and insmod a driver from an application ?
>
You can do it with a system.
If useful attached the piece of code that I use.

regards,
daniele
> Cordialement,
> Xavier MONTAGNE
> Pragmatec
> 06.98.06.21.55
>
>     ----- Original Message -----
>     *From:* Daniele Ziglioli <mailto:[EMAIL PROTECTED]>
>     *To:* uClinux development list <mailto:[email protected]>
>     *Sent:* Tuesday, September 11, 2007 4:56 PM
>     *Subject:* Re: [uClinux-dev] USB and /dev/sdx interface
>
>     xavier.montagne ha scritto:
>>     Hi,
>>     Everytime I insert a new USB key to my SL811 controler, the
>>     kernel detects properly the key and affect a new interface :
>>     /dev/sda1
>>     /dev/sdb1
>>     /dev/sdc1
>>     If I reuse the same key Linux succeeds to see it and affect the
>>     same previous interface (/dev/sdb for instance).
>>     But how to use everytime the same interface /dev/sda, even if I
>>     remove the key and insert a different one into the same slot ?
>>     Is it a standard Linux behavior to lock a /dev/sdx interface for
>>     a dedicated peripheral once detected ?
>>
>>     Cordialement,
>>     Xavier MONTAGNE
>>     Pragmatec
>>     06.98.06.21.55
>>     ------------------------------------------------------------------------
>>
>>     _______________________________________________
>>     uClinux-dev mailing list
>>     [email protected]
>>     http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
>>     This message was resent by [email protected]
>>     To unsubscribe see:
>>     http://mailman.uclinux.org/mailman/options/uclinux-dev
>     If applicable, I do rmmod/insmod of the usb storage kernel module,
>     every time insert a usbkey, to avoid this.
>
>     -- 
>     Daniele Ziglioli
>     Signal S.r.l.
>
>     ------------------------------------------------------------------------
>     _______________________________________________
>     uClinux-dev mailing list
>     [email protected]
>     http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
>     This message was resent by [email protected]
>     To unsubscribe see:
>     http://mailman.uclinux.org/mailman/options/uclinux-dev
>
>     ------------------------------------------------------------------------
>     No virus found in this incoming message.
>     Checked by AVG Free Edition.
>     Version: 7.5.485 / Virus Database: 269.13.14/999 - Release Date:
>     10/09/2007 17:43
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> uClinux-dev mailing list
> [email protected]
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by [email protected]
> To unsubscribe see:
> http://mailman.uclinux.org/mailman/options/uclinux-dev

-- 
Daniele Ziglioli
Signal S.r.l.



/*///////////////////////////////////////////////////////////////////////////
//
// This file is released under the GPL license.
// 
//
// Module: usbmount
//
// Description:
//      automatic usb disk mount/umount 
//
// History :
// 01.00 04/01/03 DZ    prima versione
// 01.01 31/08/07 DZ    sleep a 3
//
///////////////////////////////////////////////////////////////////////////*/

#define TRACE   printf
//#define TRACE         //

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <termios.h>

#include <math.h>
#include <sys/stat.h>
#include <sys/times.h>

static void usage(int rc)
{
        printf("usbmount:  automatic usb disk mount/umount \n");
        printf("(C) Signal s.r.l.  (DZ)    Ver 1.01   %s %s \n", __DATE__, 
__TIME__);
        printf("usage : usbmount mount_dir [umount]\n");
        printf("  mount_dir     : where to mount usb disk\n");
        printf("  umount        : to unmount a previous mounted dir\n");
        exit(rc);
}



#define MAX_BUFF        512
#ifdef __NO_SBB__
int main(int argc,char **argv)
#else
int main_usbmount(int argc,char **argv)
#endif
{
    int ret, tmp;
        FILE *fp;
        FILE *fp_part;
        char buff[MAX_BUFF], *p;
        char strApp[MAX_BUFF];
        char strApp2[MAX_BUFF];
        int found=0;

        if(argc < 2) {
                usage(1);
        }

        if(argc == 3) {
                if(strcmp(argv[2], "umount")==0) {
                        sprintf(strApp2, "umount %s", argv[1]);
                        system(strApp2);
                        system("rmmod usb-storage");
                        system("rmmod hc_sl811");
                        exit(0);
                }
        }

        if((fp_part = fopen("/proc/partitions", "r")) == NULL)
                return 0;

        sprintf(strApp2, "umount %s", argv[1]);
        system(strApp2);
        system("rmmod usb-storage");
        system("rmmod hc_sl811");
        sleep(1);

//      system("rmmod usb-storage");
        system("insmod hc_sl811");
        system("insmod usb-storage");
        sleep(3);



        // cerca solo partizoni con finale numero tipo sda[1-9]
        while(fgets(buff, MAX_BUFF, fp_part) && !found) {
                TRACE(buff);

                if(p=strstr(buff, "sd")) {
                        sscanf(p, "%s", strApp);
                        tmp = strlen(strApp)-1;
                        if(strApp[tmp] < '1' || strApp[tmp] > '9')
                                continue;
                        printf("TRY:  mount -t vfat /dev/%s %s\n", strApp, 
argv[1]);
                        sprintf(strApp2, "mount -t vfat /dev/%s %s", strApp, 
argv[1]);
                        if(system(strApp2) == 0) {
                                TRACE("%s\n", strApp2);
                                found=1;
                                goto _ex1;
                        }
                }
        }

        // riprova per tutte
        printf("RETRY\n");
        fseek(fp_part, 0, SEEK_SET);
        while(fgets(buff, MAX_BUFF, fp_part) && !found) {
                TRACE(buff);

                if(p=strstr(buff, "sd")) {
                        sscanf(p, "%s", strApp);
                        printf("TRY:  mount -t vfat /dev/%s %s\n", strApp, 
argv[1]);
                        sprintf(strApp2, "mount -t vfat /dev/%s %s", strApp, 
argv[1]);
                        if(system(strApp2) == 0) {
                                TRACE("%s\n", strApp2);
                                found=1;
                                goto _ex1;
                        }
                }
        }


        _ex1:
        fclose(fp_part);

        if(found)
                exit(0);

        exit(1);
        return 0;
}
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

Reply via email to