Exemplo n.º 1
0
ATF_TC_BODY(cam_close_device_negative_test_NULL, tc)
{

	cam_clear_error();
	cam_close_device(NULL);
	ATF_REQUIRE(!cam_has_error());
}
Exemplo n.º 2
0
static int sg_close_drive(struct burn_drive * d)
{
	if (d->cam != NULL) {
		cam_close_device(d->cam);
		d->cam = NULL;
	}
	return 0;
}
Exemplo n.º 3
0
int sg_close_drive(struct burn_drive * d)
{
	if (d->cam != NULL) {
		cam_close_device(d->cam);
		d->cam = NULL;
	}
	if (d->lock_fd > 0) {
		close(d->lock_fd);
		d->lock_fd = -1;
	}
	return 0;
}
Exemplo n.º 4
0
void
hfp_cdrom_free (HFPCDROM *cdrom)
{
  assert(cdrom != NULL);

  if (cdrom->cam)
    cam_close_device(cdrom->cam);
  if (cdrom->fd_owned && cdrom->fd >= 0)
    close(cdrom->fd);

  hfp_free(cdrom);
}
Exemplo n.º 5
0
Arquivo: fsm.c Projeto: 2asoft/freebsd
static int
doCAM(isess_t *sess)
{
     char	pathstr[1024];
     union ccb	*ccb;
     int	i, n;

     if(ioctl(sess->fd, ISCSIGETCAM, &sess->cam) != 0) {
	  syslog(LOG_WARNING, "ISCSIGETCAM failed: %d", errno);
	  return 0;
     }
     debug(1, "nluns=%d", sess->cam.target_nluns);
     /*
      | for now will do this for each lun ...
      */
     for(n = i = 0; i < sess->cam.target_nluns; i++) {
	  debug(2, "CAM path_id=%d target_id=%d",
		sess->cam.path_id, sess->cam.target_id);

	  sess->camdev = cam_open_btl(sess->cam.path_id, sess->cam.target_id,
				      i, O_RDWR, NULL);
	  if(sess->camdev == NULL) {
	       //syslog(LOG_WARNING, "%s", cam_errbuf);
	       debug(3, "%s", cam_errbuf);
	       continue;
	  }

	  cam_path_string(sess->camdev, pathstr, sizeof(pathstr));
	  debug(2, "pathstr=%s", pathstr);

	  ccb = cam_getccb(sess->camdev);
	  CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->crs);
	  ccb->ccb_h.func_code = XPT_REL_SIMQ;
	  ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
	  ccb->crs.openings = sess->op->tags;
	  if(cam_send_ccb(sess->camdev, ccb) < 0)
	       debug(2, "%s", cam_errbuf);
	  else
	  if((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
	       syslog(LOG_WARNING, "XPT_REL_SIMQ CCB failed");
	       // cam_error_print(sess->camdev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr);
	  }
	  else {
	       n++;
	       syslog(LOG_INFO, "%s tagged openings now %d\n", pathstr, ccb->crs.openings);
	  }
	  cam_freeccb(ccb);
	  cam_close_device(sess->camdev);
     }
     return n;
}
Exemplo n.º 6
0
ATF_TC_BODY(cam_open_device_positive_test, tc)
{
	struct cam_device *cam_dev;
	const char *cam_test_device;

	cam_test_device = get_cam_test_device(tc);

	cam_clear_error();
	cam_dev = cam_open_device(cam_test_device, O_RDWR);
	ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
	    cam_errbuf);
	ATF_REQUIRE(!cam_has_error());
	cam_close_device(cam_dev);
}
Exemplo n.º 7
0
void
free_freebsd_cam (void *user_data)
{
  _img_private_t *p_env = user_data;

  if (NULL == p_env) return;

  if (p_env->gen.fd > 0)
    close (p_env->gen.fd);
  p_env->gen.fd = -1;

  if(p_env->cam)
    cam_close_device(p_env->cam);

  free (p_env);
}
Exemplo n.º 8
0
ndmp9_error
ndmos_scsi_close (struct ndm_session *sess)
{
	struct ndm_robot_agent *	robot = sess->robot_acb;
	struct cam_device *		camdev = robot->camdev;

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

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

	cam_close_device (camdev);

	return NDMP9_NO_ERR;
}
Exemplo n.º 9
0
int
smp_initiator_close(struct smp_target_obj * tobj)
{
    struct tobj_cam_t * tcp;

    if ((NULL == tobj) || (0 == tobj->opened)) {
        fprintf(stderr, "smp_initiator_close: nothing open??\n");
        return -1;
    }
    if (tobj->vp) {
        tcp = (struct tobj_cam_t *)tobj->vp;
        cam_close_device(tcp->cam_dev);
        free(tobj->vp);
        tobj->vp = NULL;
    }
    tobj->opened = 0;
    return 0;
}
Exemplo n.º 10
0
/* close ata device and free memory, set pointer to NULL */
void ata_close(ATA **ataptr) {
	if (ataptr != NULL) {
		ATA *ata = *ataptr;
		if (ata != NULL) {
			switch (ata->access_mode) {
			case ACCESS_MODE_ATA:
				if (ata->devhandle.fd > 0)
					close(ata->devhandle.fd);
				ata->devhandle.fd = -1;
				break;
			case ACCESS_MODE_SAT:
				if (ata->devhandle.camdev != NULL)
					cam_close_device(ata->devhandle.camdev);
				ata->devhandle.camdev = NULL;
				break;
			}
			free(ata);
		}
		*ataptr = NULL;
	}
}
Exemplo n.º 11
0
/* Returns 0 if successful. If error in Unix returns negated errno. */
int
scsi_pt_close_device(int device_fd)
{
    struct freebsd_dev_channel *fdchan;
    int fd = device_fd - FREEBSD_FDOFFSET;

    if ((fd < 0) || (fd >= FREEBSD_MAXDEV)) {
        errno = ENODEV;
        return -1;
    }
    fdchan = devicetable[fd];
    if (NULL == fdchan) {
        errno = ENODEV;
        return -1;
    }
    if (fdchan->devname)
        free(fdchan->devname);
    if (fdchan->cam_dev)
        cam_close_device(fdchan->cam_dev);
    free(fdchan);
    devicetable[fd] = NULL;
    return 0;
}
Exemplo n.º 12
0
/*
 * Core interface function to lowlevel SCSI interface.
 */
static inline bool do_scsi_cmd_page(int fd, const char *device_name,
                                    void *cdb, unsigned int cdb_len,
                                    void *cmd_page, unsigned int cmd_page_len,
                                    int direction)
{
   int unitnum, len;
   union ccb *ccb;
   char errbuf[128];
   char cam_devicename[64];
   struct cam_device *cam_dev;
   SCSI_PAGE_SENSE sense;
   bool retval = false;

   /*
    * See what CAM device to use.
    */
   if (cam_get_device(device_name, cam_devicename, sizeof(cam_devicename), &unitnum) == -1) {
      berrno be;

      Emsg2(M_ERROR, 0, _("Failed to find CAM device for %s: ERR=%s\n"),
            device_name, be.bstrerror());
      Dmsg2(010, "Failed to find CAM device for %s: ERR=%s\n",
            device_name, be.bstrerror());
      return false;
   }

   cam_dev = cam_open_spec_device(cam_devicename, unitnum, O_RDWR, NULL);
   if (!cam_dev) {
      berrno be;

      Emsg2(M_ERROR, 0, _("Failed to open CAM device for %s: ERR=%s\n"),
            device_name, be.bstrerror());
      Dmsg2(010, "Failed to open CAM device for %s: ERR=%s\n",
            device_name, be.bstrerror());
      return false;
   }

   ccb = cam_getccv(cam_dev);
   if (!ccb) {
      Emsg1(M_ERROR, 0, _("Failed to allocate new ccb for %s\n"),
            device_name);
      Dmsg1(0, "Failed to allocate new ccb for %s\n",
            device_name);
      goto bail_out;
   }

   /*
    * Clear out structure, except for header that was filled for us.
    */
   memset(&ccb->ccb_h)[1], 0, sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));

   cam_fill_csio(&ccb->csio,
                 1, /* retries */
                 NULL, /* cbfcnp */
                 direction, /* flags */
                 MSG_SIMPLE_Q_TAG,, /* tagaction */
                 cmd_page, /* dataptr */
                 cmd_page_len, /* datalen */
                 sizeof(sense), /* senselength */
                 cdb_len, /* cdblength  */
                 15000 /* timeout (millisecs) */);
   memcpy(ccb->csio.cdb_io.cdb_bytes, cdb, SPP_SP_CMD_LEN);

   if (cam_send_ccb(cam_dev, ccb) < 0) {
      Emsg2(M_ERROR, 0, _("Failed to send ccb to device %s: %s\n"),
            device_name, cam_error_string(cam_dev, ccb, errbuf, sizeof(errbuf),
                                          CAM_ESF_ALL, CAM_EPF_ALL));
      Dmsg2(010, "Failed to send ccb to device %s: %s\n",
            device_name, cam_error_string(cam_dev, ccb, errbuf, sizeof(errbuf),
                                          CAM_ESF_ALL, CAM_EPF_ALL));
      cam_freeccb(ccb);
      goto bail_out;
   }

   /*
    * Retrieve the SCSI sense data.
    */
   if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) ||
       ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)) {
      if ((SAM_STAT_CHECK_CONDITION == ccb->csio.scsi_status) ||
          (SAM_STAT_COMMAND_TERMINATED == ccb->csio.scsi_status)) {
         len = sizeof(sense) - ccb->csio.sense_resid;
         if (len) {
            memcpy(&sense, &(ccb->csio.sense_data), len);
         }
      }
   }

   retval = true;

bail_out:
   /*
    * Close the CAM device.
    */
   cam_close_device(cam_dev);
   return retval;
}