Alan, 

I fixed the problem. It was my logical mistake. One can access
bus/device number _only_ when device is connected hence I need to do
something like

If(us->pusb_dev) {
        /* show device topology field */
        SPRINTF("          Bus: %d\n",us->pusb_dev->bus->busnum);
        SPRINTF("          Dev: %d\n",us->pusb_dev->devnum);
}

Thanks for all your help.

Brijesh
-----Original Message-----
From: Singh, Brijeshkumar 
Sent: Wednesday, August 24, 2005 3:17 PM
To: Singh, Brijeshkumar; Alan Stern
Cc: linux-usb-devel@lists.sourceforge.net
Subject: RE: [linux-usb-devel] RE: how to distinguish two device if they
does not provide serial number!

Alan: 
I mean occasionally I get kernel oops. The proc_info () looks as below

static int proc_info (char *buffer, char **start, off_t offset, int
length,
                int hostno, int inout)
{
        struct us_data *us;
        char *pos = buffer;

        /* if someone is sending us data, just throw it away */
        if (inout)
                return length;

        /* lock the data structures */
        down(&us_list_semaphore);

        /* find our data from hostno */
        us = us_list;
        while (us) {
                if (us->host_no == hostno)
                        break;
                us = us->next;
        }

        /* release our lock on the data structures */
        up(&us_list_semaphore);

        /* if we couldn't find it, we return an error */
        if (!us) {
                return -ESRCH;
        }

        /* print the controller name */
        SPRINTF("   Host scsi%d: usb-storage\n", hostno);

        /* print product, vendor, and serial number strings */
        SPRINTF("       Vendor: %s\n", us->vendor);
        SPRINTF("      Product: %s\n", us->product);
        SPRINTF("Serial Number: %s\n", us->serial);

        /* show the protocol and transport */
        SPRINTF("     Protocol: %s\n", us->protocol_name);
        SPRINTF("    Transport: %s\n", us->transport_name);

        SPRINTF("     Attached: %s\n", us->pusb_dev ? "Yes" : "No");

        /* show device topology field */
        SPRINTF("          Bus: %d\n",us->pusb_dev->bus->busnum);
        SPRINTF("          Dev: %d\n",us->pusb_dev->devnum);


        /*
         * Calculate start of next buffer, and return value.
         */
        *start = buffer + offset;

        if ((pos - buffer) < offset)
                return (0);
        else if ((pos - buffer - offset) < length)
                return (pos - buffer - offset);
        else
                return (length);
}
 
Thanks for all your help.


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Singh,
Brijeshkumar
Sent: Wednesday, August 24, 2005 3:11 PM
To: Alan Stern
Cc: linux-usb-devel@lists.sourceforge.net
Subject: RE: [linux-usb-devel] RE: how to distinguish two device if they
does not provide serial number!

Alan, thanks for input.

I made the respective changes in scsiglue.c for displaying bus and
device number.

driver/usb/storage/scsiglue.c as follows:
static int proc_info (char *buffer, char **start, off_t offset, int
length,int hostno, int inout)
{
        ............ 
        SPRINTF("    Bus: %d\n",us->pusb_dev->bus->busnum);
        SPRINTF("    prnt: %d\n",us->pusb_dev->devnum);
        ............
}

It works good. But something I get kernel oops while accessing
/proc/scsi/usb-storage-A/B. Did I missed any steps?

I am new to the kernel programming so please excuse for silly questions.

Thanks.
Brijesh

-----Original Message-----
From: Alan Stern [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 24, 2005 11:06 AM
To: Singh, Brijeshkumar
Cc: linux-usb-devel@lists.sourceforge.net
Subject: RE: [linux-usb-devel] RE: how to distinguish two device if they
does not provide serial number!

On Wed, 24 Aug 2005, Singh, Brijeshkumar wrote:

> Alan thanks for quick response.
> 
> By index I mean local "index" variable in drive/usb/device.c [function
> usb_device_dump]. As if I understand, the below snippet from
> drive/usb/device.c writes topology;
> 
> static ssize_t usb_device_dump(char **buffer, size_t *nbytes, loff_t
> *skip_bytes, loff_t *file_offset, struct usb_device *usbdev, struct
> usb_bus *bus, int level, int index, int count)
> {
> .................
> .................
> data_end = pages_start + sprintf(pages_start, format_topo,
>                         bus->busnum, level, parent_devnum,
>                         index, count, usbdev->devnum,
>                         speed, usbdev->maxchild);
> .........
> }
> 
> I can access busnum,parent_devnum,devnum,maxchild,speed in
> driver/usb/storage/scsiglue.c as follows:
> static int proc_info (char *buffer, char **start, off_t offset, int
> length,int hostno, int inout)
> > {
> > ............
> > /* ADDING bus & prnt */
> >         SPRINTF("    Bus: %d\n",us->pusb_dev->bus->busnum);
> >       SPRINTF("    prnt: %d\n",us->pusb_dev->parent->devnum);
> >       SPRINTF("    prnt: %d\n",us->pusb_dev->devnum);
> >       SPRINTF("    prnt: %d\n",us->pusb_dev->maxchild);
> > /*ADDITION ENDS */ 
> .........
> }
> But I'm not able to access "level" "index" and "count" variable in
> proc_info function as they are local variables.
> 
> I have observed that first four fields (busno,lev,prnt,port) are
always
> unique to each connected device. Please correct me if I'm wrong.

You are right.  However the bus number and device number are also
unique.  
So you can use just those two and stop worrying about the level, parent,

index, and count.

Alan Stern




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing &
QA
Security * Process Improvement & Measurement *
http://www.sqe.com/bsce5sf
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to