# Nikon D50 USB mass-storage...[SOLVED]

## slackline

Hi,

Until recently I'd been mounting my Nikon D50 is USB Mass Storage mode via the built in USB port with a custom udev rule.

```

 # grep -i nikon /etc/udev/rules.d/10-local.rules

## Nikon D50

bus=="usb", KERNEL=="sd*", SYSFS{manufacturer}=="NIKON", SYSFS{product}=="NIKON DSC D50", SYMLINK+="nikon"

```

Recently this has stopped working and I can't mount the camera.  This isn't a problem with the card as I've not done anything to it, its been sat in the camera taking pictures and then uploading them to the computer.  To check I tried a second card (same as the first a Toshiba 2Gb SD) and a third (some 64Mb card I have lying around).  None of these work when in the Nikon D50, but are read fine when placed in the SD card reader of my networked printer (HP6310).

I've not upgraded the kernel at all, although recently I did add USB audio support in ALSA.

Some (hopefully) useful information...

```

# uname -a

Linux fisher 2.6.20-gentoo-r6 #10 SMP Fri Jul 13 13:40:56 BST 2007 i686 AMD Athlon(tm) XP 2600+ AuthenticAMD GNU/Linux

# lsusb 

Bus 004 Device 001: ID 0000:0000  

Bus 004 Device 002: ID 10df:0100 In-Win Development, Inc. 

Bus 003 Device 003: ID 045e:00db Microsoft Corp. 

Bus 003 Device 002: ID 046d:c016 Logitech, Inc. M-UV69a Optical Wheel Mouse

Bus 003 Device 001: ID 0000:0000  

Bus 002 Device 001: ID 0000:0000  

Bus 001 Device 007: ID 04b0:0409 Nikon Corp. 

Bus 001 Device 001: ID 0000:0000  

# dmesg | tail -n70

usb 1-1: USB disconnect, address 6

usb 1-1: new high speed USB device using ehci_hcd and address 7

usb 1-1: configuration #1 chosen from 1 choice

scsi2 : SCSI emulation for USB Mass Storage devices

usb-storage: device found at 7

usb-storage: waiting for device to settle before scanning

scsi 2:0:0:0: Direct-Access     NIKON    D50              1.00 PQ: 0 ANSI: 2

SCSI device sdb: 4022273 512-byte hdwr sectors (2059 MB)

sdb: Write Protect is off

sdb: Mode Sense: 0f 00 00 00

sdb: assuming drive cache: write through

SCSI device sdb: 4022273 512-byte hdwr sectors (2059 MB)

sdb: Write Protect is off

sdb: Mode Sense: 0f 00 00 00

sdb: assuming drive cache: write through

 sdb: sdb1

sd 2:0:0:0: Attached scsi removable disk sdb

sd 2:0:0:0: Attached scsi generic sg1 type 0

usb-storage: device scan complete

end_request: I/O error, dev sdb, sector 4022272

printk: 277 messages suppressed.

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 4022272

Buffer I/O error on device sdb, logical block 4022272

end_request: I/O error, dev sdb, sector 40

Buffer I/O error on device sdb, logical block 40

Buffer I/O error on device sdb, logical block 41

Buffer I/O error on device sdb, logical block 42

end_request: I/O error, dev sdb, sector 40

end_request: I/O error, dev sdb, sector 40

end_request: I/O error, dev sdb, sector 40

end_request: I/O error, dev sdb, sector 40

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

end_request: I/O error, dev sdb, sector 243

```

So the camera is being detected to an extent but not read correctly.

I initially thought part of the problem might be that I had a set of headphones plugged into the adjacent USB port which according to this thread there can be conflicts if you have USB1 and USB2 devices on the same hub.  However, I've unplugged the headset and rebooted and the problem persists.  Also the problem occurs on my laptop as well, which doesn't have the headphones plugged in.

A bit of googling threw a few things up on the linux kernel dev mailing list, but nothing was particularly clear to me as some were saying things worked fine, other were saying the patch was needed (see here).  Personally I don't think the patch should be needed as I'd been using the camera in USB Mass Storage mode fine since I got the camera and have transferred some ~10-12000 pictures to my laptop/desktop in this time.

Any thoughts or suggestions would be more than welcome.

Cheers

slack[/url]Last edited by slackline on Thu Aug 23, 2007 12:37 pm; edited 1 time in total

----------

## Naib

I to have a D50 (nice camera) and I two have also had this for a couple of kernel versions now. from what I can google & understand it, usbstorage got a little bit borked when they went to libata and SCSI was used for less. 

guess gotta wait for a patch, hopefully soon.

----------

## slackline

hmm, thats a bit of an arse!

Do you have any thoughts on the kernel patch detailed in this thread on the linux kernel mailing list?

If anyone knows a work around in the mean time it would be very much appreciated.

slack

----------

## Jorgo

I have the same problem with Nikon D200 and cardreader.

Are you using udev-113 ? I solved the problem by downgrading to

udev-112-r1.

----------

## slackline

Yep, currently using udev-113-r2...

```

# eix sys-fs/udev

[I] sys-fs/udev

     Available versions:  104-r12 (~)111 (~)111-r1 (~)111-r3 (~)112 (~)112-r1 (~)113 (~)113-r1 (~)113-r2 {selinux}

     Installed versions:  113-r2(08:13:19 07/16/07)(-selinux)

     Homepage:            http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html

     Description:         Linux dynamic and persistent device naming support (aka userspace devfs)

```

But if its a problem with udev, then its not kernel related as Naib suggests?

If it is a udev problem would it not be possible to write a local rule to override the problem?

----------

## Jorgo

I dont think its kernel related because the problem persists with gentoo-sources-2.6.21 

and gentoo-sources-2.6.22. I tried udev-113 + r builds on both kernels.

----------

## slackline

Well the udev rules on my system are...

```

# grep -i nikon /etc/udev/rules.d/*

10-local.rules:## Nikon D50

10-local.rules:bus=="usb", KERNEL=="sd*", SYSFS{manufacturer}=="NIKON", SYSFS{product}=="NIKON DSC D50", SYMLINK+="nikon"

60-camera.rules:#Nikon D50 USB mass storage device

60-camera.rules:#SYSFS{model}=="D50             ", SYSFS{vendor}=="NIKON   ", MODE="0660", GROUP="plugdev", ENV{camera}="Nikon_D50", ENV{type}="mass_storage", SYMLINK+="/mnt/nikon", RUN+="/usr/local/bin/download_camera"

60-camera.rules:SYSFS{model}=="D50

```

As you can see most of the /etc/udev/rules.d/60-camera.rules are commented out, whilst the local rule I wrote myself worked fine, no problem, when the camera plugged in a node was created at /dev/nikon, but not anymore.

Now the problem perhaps is that given the local.rules is preceeded by a lower number it rules are read first, so the last rule defined in 60-camera.rules is over-riding my custom rule.  But thats irrelevant, as it should still allow me to do something like mount -t vfat /dev/sda1 /mnt/nikon as root, but I can't as the USB device fails to be detected correctly (see original dmesg output).

I'm inclined to think that this is a kernel problem, but will have a go at downgrading udev later.

----------

## KMS

I am having the exact same errors as reported in the first post of the thread and I will share my investigation so far.

My first step was to downgrade my kernel from 2.6.20-gentoo-r8 to the older kernel 2.6.17-gentoo-r6. No change.

I changed back to the 2.6.20 kernel and loaded vmware. Vmware Win2K loaded the camera as USB mass storage without problems! At this point I ruled out the kernel as the problem.

I then downgraded hal. This also did not change anything.

I changed the camera to use PTP instead of USB Mass Storage and digikam could download the pictures off the camera!

I then downgraded udev from 113-r2 to 104-r12 and bingo, the camera as USB mass storage automounted without problems. 

Everything points to udev as the problem. I do not have any custom rules for the camera and used the default automount of /media/disk. Also interesting is that my USB key (Sandisk Cruzer) automounts without any problem when used with udev 113-r2.

Then I ran out of time. The next step would be to upgrade udev to find out exactly when this was broken and report the bug to the udev group.

I hope this information helps someone. Thanks.

----------

## dsd

its not a udev bug. udev's involvement is very little: udev chooses names for device nodes and doesn't do a whole lot more.

it's definitely a kernel bug: errors are appearing in the kernel logs.

the kernel patch linked to in this thread is what you want.

note the sector count:

 *Quote:*   

> SCSI device sdb: 4022273 512-byte hdwr sectors (2059 MB) 

 

so, the first sector is sector 0, and the last sector is sector 4022272.

now look at the first error message:

 *Quote:*   

> end_request: I/O error, dev sdb, sector 4022272

 

thats the last sector!

now add the fact that many devices are broken in that they report one sector too many (hence the US_FL_FIX_CAPACITY flag), many nikon devices do exactly this, plus there is an upstream report of exactly the same condition.

the reason you may not have seen this before is that before, probably nothing accessed the final sector, but now something is doing so.

please file this as a bug report at https://bugs.gentoo.org and we will go from there

----------

## slackline

I opened a bug as advised and the patch I linked above was added to it.

Applying the patch to kernel 2.6.22-gentoo-r2 resolves the problem.

Grab the patch from here (includes an example of how to apply the patch for others like me who have never patched their kernels before   :Smile:  )

----------

## KMS

The kernel patch does not solve my problem because I have a D80, but I looked at what the patch was doing and was pleasantly surprised to find the Nikon D80 already handled in the 2.6.22-gentoo-r2 kernel. But I was still getting I/O errors. 

The problem was that I had upgraded the firmware of my camera and the max revision parameter of the device definition in drivers/usb/storage/unusual_devs.h was 0x0100. Changing the max revision to 0x0101 solved the problem.

I filed a bug to record my finding and the simple patch. 

A kernel patch for each firmware revision is not an ideal situation. The proper fix would be get Nikon to report the size properly. I suspect the chance of that happening is low.   :Sad: 

----------

## saber850

This patch worked for me w/ a Nikon D50 and vanilla kernel 2.6.22.3.

Thank you.

----------

## slackline

This has now been resolved upstream in the kernel sources and in gentoo sources (see comments in bug 186236).

----------

## Gadger

I have the Nikon D200 and had been battling with this exact issue for a while before I thought to look here [  :Idea:  ]. I have a kernel including the patches associated with bug 186236 but they don't do it for the Nikon D200.

```
uname -sr

Linux 2.6.22-gentoo-r5

```

Here's my /proc/bus/usb/devices entry

```
T:  Bus=01 Lev=01 Prnt=01 Port=04 Cnt=01 Dev#=  9 Spd=480 MxCh= 0

D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1

P:  Vendor=04b0 ProdID=040f Rev= 2.00

S:  Manufacturer=NIKON

S:  Product=NIKON DSC D200

S:  SerialNumber=0000000

C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  2mA

I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage

E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms

E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms

```

and here's the additional entry I put in unusual_devs.h to get it to work

```
UNUSUAL_DEV(  0x04b0, 0x040f, 0x0200, 0x0200,

        "NIKON",

        "NIKON DSC D200",

        US_SC_DEVICE, US_PR_DEVICE, NULL,

        US_FL_FIX_CAPACITY),

```

This is the latest firmware for the D200 so should cover it for the moment.

This is my first post here so, someone please let me know if I should raise another bug or post somewhere else to get this resolved upstream.

----------

## mpagano

Gadger,

Will you submit a patch upstream or would you like the Gentoo Kernel team to submit it on your behalf?

-Mike

----------

## Gadger

I'm happy for the Kernel team to do it.

----------

## mpagano

ok, thanks, I'll take care of it.

----------

