usb_find_busses iterates through the /proc/bus/usb/ directory to generate the list of busses and accordingly initialized the usb_busses list.usb_find_devices then iterates through the directories corresponding to
the busses on the system, and creates a usb_device entry on the bus for each file(device)
inside the directory.
As mentioned earlier, each device on the
bus is represented as a file in the usb filesystem (at /proc/bus/usb/001 directory). The contents of the file represent
the device descriptor for the associated device. The descriptor may be read from the file to initialize a pointer of type dev, to point to the device as follows:
ret = read(fd, (void *)&dev->descriptor, sizeof(dev->descriptor));
fd is a file descriptor corresponding to the device file inside the usb filesystem.
After calling the two functions (usb_find_busses() and usb_find_devices()), the devices list in the appropriate bus may be iterated along to get access to each of the devices. On reaching the desired device, a handle to the device may be obtained by calling the usb_open() method, passing a pointer to the usb_device structure as a parameter. The handle may then be used to read to, write from and configure the device.
The range of functions broadly classify into two classes: