Subject: Re: external USB cases for ATA drives
To: Denis Lagno <dlagno@smtp.ru>
From: Florian Stoehr <netbsd@wolfnode.de>
List: netbsd-users
Date: 12/31/2004 21:00:59
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-874324355-1104523258=:548
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Fri, 31 Dec 2004, Denis Lagno wrote:

> Hi,
>
> I use USB drives sometimes.  Flashes work fine.
> But recently I've got external USB case for hard drive.
> It turns on the drive only after plugging USB cable in.
> And 2-3 seconds are needed to spin the drive on.
> And it often happens that kernel recognizes only umass and
> scsibus at umass, but not sd itself.
> So I need to plug it off and on again in hope of finding
> myself more fortunate.
> Can it be because of some too restrictive timeouts in the kernel?
>
> --
> Denis Lagno,
> PGP key fingerprint: F94F F38F 1895 E673 4374 9D63 2B9E FAB3 8E83 584C
>

Maybe this is related to the "buffer space" USB bug?

I wrote a little program some time ago to bypass this. It will allocate,=20
use and free a given amount of RAM.

Since it sets data size to 1G, run this only as root.

compile with "c++ -o neb-umassbug neb-umassbug.cc"

Try with 100 MB first (depends on your system), then see if your device=20
works. Increase in 100 MB steps.

Works for me. Success not guaranteed, as always.

-Florian

/*
 =09NetBSD "No buffer space" workaround
 =09Will allocate and access RAM to
 =09free buffer space for umass-devices.

 =09Calls setrlimit() to set the data size to "unlimited"
 =09-> Must be called by root (or suid root).

 =09Version: $Id: neb-umassbug.cc,v 1.2 2004/12/04 15:38:26 cvs Exp $

 =09(C) St=F6hr, 2004
*/

#include <stdlib.h>
#include <iostream>
#include <sys/resource.h>

static const char* const GetRevision()
{
 =09static char ss[1024];
 =09static char st[1024];

 =09strcpy(ss, "$Revision: 1.2 $");

 =09// Strip out the "$Revision: 1.2 $"
 =09const int numc =3D strlen(ss)-13;
 =09memcpy(st, ss+11, numc);
 =09st[numc] =3D 0x00;

 =09return st;
}

int main(int argc, const char** argv)
{
 =09// Print header
 =09std::cout << "*** neb-umassbug Version " << GetRevision() << " (C)=20
St=F6hr, 2004 ***\n";

 =09// If no amount of RAM given, exit with usage message
 =09if (argc < 2)
 =09{
 =09=09std::cout << "*** Usage: neb-umassbug <RAM to allocate in=20
MEGABYTES>\n\n";
 =09=09return 1;
 =09}

 =09uint numb =3D atoi(argv[1]);

 =09// Must not go beyond 1 GB
 =09if ((!numb) || (numb > 1024))
 =09{
 =09=09std::cout << "*** ERROR: Sorry, setrlimit() only allows up=20
to 1 GB :-(\n\n";
 =09=09return 1;
 =09}

 =09// OK, now get an unlimited data size
 =09rlimit RL;
 =09RL.rlim_cur =3D RLIM_INFINITY;
 =09RL.rlim_max =3D RLIM_INFINITY;

 =09if (setrlimit(RLIMIT_DATA, &RL))
 =09{
 =09=09std::cout << "*** ERROR: Cannot call setrlimit() -=20
Remember, only root want to run me!\n\n";
 =09=09return 1;
 =09}

 =09// RAM operation
 =09std::cout << "*** Accessing RAM. Please wait.\n";

 =09char* la =3D new char[numb * 1024 * 1024];

 =09for (uint i=3D0; i<(numb * 1024); ++i)
 =09=09*(la+(i*1024)) =3D 42;

 =09delete[] la;

 =09std::cout << "*** FINISHED. Now plug in your USB device. If the=20
umass still\n"
 =09=09"    failes, try to call me with a higher RAM value (TIP:=20
Call with the\n"
 =09=09"    total amount of PHYSICAL RAM max).\n\n";

 =09return 0;
}

--0-874324355-1104523258=:548--