Operating System - HP-UX
1819870 Members
2357 Online
109607 Solutions
New Discussion юеВ

How to unlock a locked cdrom

 

How to unlock a locked cdrom

Hi all
In a previous thread Stephen Keane, mentioned a firmware lock and a C program to unlock a cdrom whic was complaining of being locked or busy, even when the cdrom was not in use.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=886017

Can someone share this program or sample.
This server can not be rebooted and we'll attempt to unlock the CDROM online.

Thanks in Advance!

David
7 REPLIES 7
Bill Hassell
Honored Contributor

Re: How to unlock a locked cdrom

If you mean that the CDROM cannot be unmounted and therefore, pushing the unload button fails, then you very likely have some user who has cd'ed into the CDROM's mount point (never a good idea). Find that process with fuser and either terminate the process or tell the user to cd someplace else. There may also be a hung process that opened the CDROM filesystem that needs to be terminated.

Whenever the mounted CDROM filesystem is opened, a SCSI lock is sent to the drive to logically lock the drive so the CD cannot be ejected while the filesystem is busy. Actually, the lock just disables the pushbutton and the SCSI command that can eject the CD HP-UX does not have an unload command). Different than PCs, a mounted filesystem is integrated into the root filesystem so pulling out the CD can cause system crashes, thus the lock.

That said, fuser is still very poor at tracking down all the possible ways a CD is being used. For instance, the CD may have been exported as an NFS or CIFS filesystem. So if fuser shows nothing, you'll need lsof to track down the processes. Download lsof from the HP-UX archive:

http://hpux.connect.org.uk/

Once lsof reports no processes associated with the CD's then umount should work and the CD will be released. If not, the drive's firmware may be confused so you can use a paper clip to manually pop open the CD drawer. WARNING: if process(es) are still shown active by lsof (or if you can't use lsof), popping out the CD manually may cause system hangs (typically, logins, the bdf and df commands, etc). If you put in a different CD to stop the hangs, the system will likely crash due to a complete mismatch in the filesystem. When the system is rebooted, the SCSI reset command is sent to all disk (and CDROM) devices which removes the SCSI lock.

By the way, you weren't using PFS were you? This product is deprecated (not recommended) and known to be unstable in some situations. Get the Rock Ridge patches if your HP-UX system is 11.00 or later.


Bill Hassell, sysadmin

Re: How to unlock a locked cdrom

Thanks Bill, the cd drive door can be open but there is another file system mounted on cd0 and there is no cd in the drive. Strange, However, we are going to upgrade to 11i.

David
Juan M Leon
Trusted Contributor

Re: How to unlock a locked cdrom











#include
#include
#include
#include
#include

unsigned char UNLOCK = 0x1E; // Prevent/Allow Media Removal
unsigned char UNLOCK_CMD_LEN = 6; // Bytes
unsigned int SCSI_TIMEOUT = 5000; // Milliseconds

main(argc, argv)
int argc;
char * argv[];
{
int fd, i, rc;
struct sctl_io si;

if (argc != 2)
{
fprintf(stderr, "Usage : %s cd_device\n", argv[0]);
exit(1);
}

fd = open(argv[1], O_RDONLY | O_NDELAY);

if (fd == -1)
{
fprintf(stderr, "Failed to open %s because %s\n",
argv[1], strerror(errno));
exit(1);
}

memset(&si, 0, sizeof(si));

si.flags = 0;
si.cdb_length = UNLOCK_CMD_LEN;
si.cdb[0] = UNLOCK;
si.max_msecs = SCSI_TIMEOUT;

rc = ioctl(fd, SIOC_IO, &si);

if (rc != 0)
{
fprintf(stderr, "ioctl(SIOC_IO) error %s\n", strerror(errno));
(void) close(fd);
exit(1);
}

if (si.cdb_status != S_GOOD)
{
fprintf(stderr, "SCSI error\n");

if (si.sense_xfer != 0)
{
fprintf(stderr, "with sense data ");
for (i = 0; i < (int) si.sense_xfer; i++)
{
fprintf(stderr, "%2.2x ", si.sense[i]);
}
fprintf(stderr, "\n");
}

(void) close(fd);
exit(1);
}

(void) close(fd);

/* success !! */

printf("Drive %s unlocked\n", argv[1]);

exit(0);
}
Juan M Leon
Trusted Contributor

Re: How to unlock a locked cdrom

Someone once gave me this c program and helped me to open the CDrom. Once my CDrom was locked and even I rebooted the server and I was unable to open the cdrom. But this C program helped.

Hope it helps for you









#include
#include
#include
#include
#include

unsigned char UNLOCK = 0x1E; // Prevent/Allow Media Removal
unsigned char UNLOCK_CMD_LEN = 6; // Bytes
unsigned int SCSI_TIMEOUT = 5000; // Milliseconds

main(argc, argv)
int argc;
char * argv[];
{
int fd, i, rc;
struct sctl_io si;

if (argc != 2)
{
fprintf(stderr, "Usage : %s cd_device\n", argv[0]);
exit(1);
}

fd = open(argv[1], O_RDONLY | O_NDELAY);

if (fd == -1)
{
fprintf(stderr, "Failed to open %s because %s\n",
argv[1], strerror(errno));
exit(1);
}

memset(&si, 0, sizeof(si));

si.flags = 0;
si.cdb_length = UNLOCK_CMD_LEN;
si.cdb[0] = UNLOCK;
si.max_msecs = SCSI_TIMEOUT;

rc = ioctl(fd, SIOC_IO, &si);

if (rc != 0)
{
fprintf(stderr, "ioctl(SIOC_IO) error %s\n", strerror(errno));
(void) close(fd);
exit(1);
}

if (si.cdb_status != S_GOOD)
{
fprintf(stderr, "SCSI error\n");

if (si.sense_xfer != 0)
{
fprintf(stderr, "with sense data ");
for (i = 0; i < (int) si.sense_xfer; i++)
{
fprintf(stderr, "%2.2x ", si.sense[i]);
}
fprintf(stderr, "\n");
}

(void) close(fd);
exit(1);
}

(void) close(fd);

/* success !! */

printf("Drive %s unlocked\n", argv[1]);

exit(0);
}
Antonio Cardoso_1
Trusted Contributor

Re: How to unlock a locked cdrom

You can check with
fuser
to get the PID on which mount_point is used.
This sometimes is not enough, and you can try using lsof free software to get this information.
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.76/

Once process is identified, see if you can stop ( or kill) it to free device.
sysadm_1
Valued Contributor

Re: How to unlock a locked cdrom


Hi david,

find all the processes which is using the cdrom using fuser or lsof.

kill all the proceses and try umount cdrom

cheers!!
sysadm
Juan M Leon
Trusted Contributor

Re: How to unlock a locked cdrom

Hello David,

If you planning to use fuser try to use -c
Display the use of a mount point and any file beneath that mount point. I hope it helps