Пример #1
0
ndmp9_error
ndmos_scsi_open (struct ndm_session *sess, char *name)
{
	struct ndm_robot_agent *	robot = sess->robot_acb;
	struct cam_device *		camdev = robot->camdev;

	/* redundant test */
	if (camdev) {
		return NDMP9_DEVICE_OPENED_ERR;
	}

	camdev = cam_open_pass(name, 2, 0);
	if (!camdev) {
		/* could sniff errno */
		switch (errno) {
		default:
		case ENOENT:
			return NDMP9_NO_DEVICE_ERR;

		case EACCES:
		case EPERM:
			return NDMP9_PERMISSION_ERR;

		case EBUSY:
			return NDMP9_DEVICE_BUSY_ERR;
		}
	}

	robot->camdev = camdev;
	ndmos_scsi_sync_state (sess);

	return NDMP9_NO_ERR;
}
Пример #2
0
bool
init_freebsd_cam (_img_private_t *p_env)
{
  char pass[100];
  
  p_env->cam=NULL;
  memset (&p_env->ccb, 0, sizeof(p_env->ccb));
  p_env->ccb.ccb_h.func_code = XPT_GDEVLIST;

  if (-1 == p_env->gen.fd) 
    p_env->gen.fd = open (p_env->device, O_RDONLY, 0);

  if (p_env->gen.fd < 0)
    {
      cdio_warn ("open (%s): %s", p_env->device, strerror (errno));
      return false;
    }

  (void)ioctl(p_env->gen.fd, CDIOCALLOW);

  if (ioctl (p_env->gen.fd, CAMGETPASSTHRU, &p_env->ccb) < 0)
    {
      cdio_warn ("open: %s", strerror (errno));
      return false;
    }
  sprintf (pass,"/dev/%.15s%u",
	   p_env->ccb.cgdl.periph_name,
	   p_env->ccb.cgdl.unit_number);
  p_env->cam = cam_open_pass (pass,O_RDWR,NULL);
  if (!p_env->cam) return false;
  
  p_env->gen.init   = true;
  p_env->b_cam_init = true;
  return true;
}
Пример #3
0
/*---------------------------------------------------------------------------
 *
 *--------------------------------------------------------------------------*/
int 
scsi_init(char *devname) 
{
  char *inq_buf;

#ifdef DIXTRAC_LINUX_SG

#ifdef SG_NONBLOCKING
  int ictl_val;
#endif

#ifdef SG_NONBLOCKING
  int fd = open(devname, O_RDWR | O_NONBLOCK);
#else
  int fd = open(devname, O_RDWR);
#endif

  if (fd < 0) {
    error_handler("Device %s not defined or no R/W permmissions.\n",devname);
  }
#ifdef SG_NONBLOCKING
  ictl_val = 1;
  if ( 0 > ioctl(fd,SG_SET_COMMAND_Q,&ictl_val)) {
    if (errno == ENOTTY)
      ictl_val = 0;
    else
      error_handler("Problems with ioctl on device %s \n",devname);
  }
/*  #ifndef SILENT */
#if 0
  printf("Command queueing%s allowed.\n",(ictl_val == 1 ? "" : " not"));
#endif
  ictl_val = 0;
/*  if ( 0 > ioctl(fd,SG_SET_FORCE_PACK_ID,&ictl_val)) {
    error_handler("Could not set FORCE_PACK_ID  on device %s \n",devname);
  } */
  ictl_val = BIG_BUF_SIZE;
  if ( 0 > ioctl(fd,SG_SET_RESERVED_SIZE,&ictl_val)) {
    error_handler("Problems with ioctl on device %s!\n",devname);
  }
  ioctl(fd,SG_GET_RESERVED_SIZE,&ictl_val);
/*  #ifndef SILENT */
#if 0
  fprintf(stderr, "*** The size of the RESERVED kernel buffer: %d\n",ictl_val);
  /*  ioctl(fd,SG_GET_SG_TABLESIZE,&ictl_val); */
  /*  printf("TABLESIZE: %d\n",ictl_val); */
#endif

#endif

#ifdef STATE_THREADS
  if (st_init()) {
    error_handler("Problems with st_init!\n");
  }
  
  if (!(scsidev_fd = st_netfd_open(fd))) {
    error_handler("Opening sthread fd failed\n", devname);
  }
#else
  scsidev_fd = fd;
#endif

/* DIXTRAC_LINUX_SG */
#endif

#ifdef DIXTRAC_FREEBSD_CAM
  if (cam_open_pass(devname, O_RDWR, &cam_device) == NULL) {
    error_handler("Opening pass device (%s) failed\n", devname);
  }
#endif

  inq_buf = scsi_alloc_buffer();
  /* get_scsi_version */
  send_scsi_command(inq_buf, SCSI_inq_command(),0);
  recv_scsi_command(inq_buf);
  scsi_version = ((u_int8_t) inq_buf[2]);

  /* get the device block size (not all disks use 512-byte sector) */
  exec_scsi_command(inq_buf,SCSI_read_capacity(0,0));
  /* this is a global that is accessed through te SECT_SIZE macro */
  blksize = _4btol((u_int8_t *) &inq_buf[4]);
  return(0);

}