lkml.org 
[lkml]   [1999]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: strange mounting problem


Guest section DW wrote:

> Now that this fails in your case, apparently because it expects
> SCSI-2 behaviour, one may try to force things.
> The ioctl BLKRRPART will do revalidate_scsidisk() which does
> the required invalidate_*().
>
> So, you might try the (of course untested) eject program below.

Built it and as expected 'infinite loop'
Ok I modified the code below. I put the ioctl's before the eject. It
works, but I wonder about the BLKRRPART. Is this necessary? My media has
only one partition.
Is the code change acceptable or do I miss smthg?

With the modification below I get no 'infinite loop'. The Media is spit
out and after a side change I get what I want. :-)


> /*
> * Eject SCSI disk and invalidate buffers - aeb
> */
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <string.h>
> #include <sys/ioctl.h>
> #include <linux/fs.h> /* BLKRRPART */
>
> #define SCSI_IOCTL_SEND_COMMAND 1
> #define PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
> #define START_STOP_UNIT 0x1b
>
> main() {
> char *device = "/dev/sdc";
> int fd;
> int i;
>
> struct {
> int inlen;
> int outlen;
> char cmd[256];
> } scsi_cmd;
>
> fd = open(device, O_RDONLY | O_NONBLOCK);
> if (fd < 0) {
> fprintf(stderr, "cannot open %s\n", device);
> exit(1);
> }
/* Flush chache for this device */

if(ioctl(fd, BLKFLSBUF)) {
perror("BLKRRPART");
exit(1);
}
/* Reread the partition table */

if(ioctl(fd, BLKRRPART)) {
perror("BLKRRPART");
exit(1);
}
>
> memset(&scsi_cmd, 0, sizeof(scsi_cmd));
> scsi_cmd.cmd[0] = PREVENT_ALLOW_MEDIUM_REMOVAL;
> scsi_cmd.cmd[4] = 0; /* Allow */
> i = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd);
> if (i) {
> perror("SCSI_IOCTL_SEND_COMMAND (0)");
> exit(1);
> }
>
> memset(&scsi_cmd, 0, sizeof(scsi_cmd));
> scsi_cmd.cmd[0] = START_STOP_UNIT;
> scsi_cmd.cmd[4] = 2; /* Stop and Eject */
> i = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd);
> if (i) {
> perror("SCSI_IOCTL_SEND_COMMAND (2)");
> exit(1);
> }
>
>
>
> return 0;
> }


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.063 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site