ATF_TC_BODY(cam_open_device_negative_test_unprivileged, tc) { const char *cam_test_device; cam_test_device = get_cam_test_device(tc); cam_clear_error(); ATF_CHECK(cam_open_device(cam_test_device, O_RDONLY) == NULL); ATF_REQUIRE(cam_has_error()); cam_clear_error(); ATF_CHECK(cam_open_device(cam_test_device, O_RDWR) == NULL); ATF_REQUIRE(cam_has_error()); }
ATF_TC_BODY(cam_open_device_negative_test_nonexistent, tc) { cam_clear_error(); ATF_REQUIRE(cam_open_device("/nonexistent", O_RDWR) == NULL); ATF_REQUIRE(cam_has_error()); }
static HFPCDROM * hfp_cdrom_new_real (boolean has_fd, int fd, const char *path, const char *parent) { HFPCDROM *cdrom = NULL; struct cam_device *cam; assert(path != NULL); assert(parent != NULL); /* cam_open_device() fails unless we use O_RDWR */ cam = cam_open_device(path, O_RDWR); if (cam) { cdrom = hfp_new0(HFPCDROM, 1); cdrom->cam = cam; cdrom->fd = -1; } else { #ifndef IOCATAREQUEST fd = open("/dev/ata", O_RDONLY); #else if (! has_fd) fd = open(path, O_RDONLY); #endif if (fd >= 0) { cdrom = hfp_new0(HFPCDROM, 1); cdrom->fd = fd; #ifndef IOCATAREQUEST cdrom->fd_owned = TRUE; cdrom->channel = libhal_device_get_property_int(hfp_ctx, parent, "ide.host", &hfp_error); dbus_error_free(&hfp_error); cdrom->device = libhal_device_get_property_int(hfp_ctx, parent, "ide.channel", &hfp_error); dbus_error_free(&hfp_error); #else cdrom->fd_owned = ! has_fd; cdrom->channel = -1; cdrom->device = -1; #endif } } return cdrom; }
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); }
int scsi_open(const char *name, int flag, int mode, void **extra_data) { #if (defined(OS_freebsd)) && (__FreeBSD__ >= 2) struct cam_device *cam_dev; cam_dev = cam_open_device(name, O_RDWR); *extra_data = (void *) cam_dev; if (cam_dev) return cam_dev->fd; else return -1; #else return open(name, O_RDONLY | O_LARGEFILE | O_BINARY #ifdef O_NDELAY | O_NDELAY #endif /* O_RDONLY | dev->mode*/); #endif }
int sg_grab(struct burn_drive *d) { struct cam_device *cam; char path_string[80]; if (mmc_function_spy(d, "sg_grab") <= 0) return 0; if (burn_drive_is_open(d)) { d->released = 0; return 1; } cam = cam_open_device(d->devname, O_RDWR); if (cam == NULL) { libdax_msgs_submit(libdax_messenger, d->global_index, 0x00020003, LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH, "Could not grab drive", errno, 0); return 0; } d->cam = cam; if (burn_sg_open_o_excl & 63) if (sg_lock(d, 0) <= 0) return 0; fcntl(cam->fd, F_SETOWN, getpid()); cam_path_string(d->cam, path_string, sizeof(path_string)); #ifdef Libburn_ahci_verbouS fprintf(stderr, "libburn_EXPERIMENTAL: CAM path = %s\n", path_string); #endif if (strstr(path_string, ":ahcich") != NULL) d->is_ahci = 1; else d->is_ahci = -1; d->released = 0; return 1; }
/** Opens the drive for SCSI commands and - if burn activities are prone to external interference on your system - obtains an exclusive access lock on the drive. (Note: this is not physical tray locking.) A drive that has been opened with sg_grab() will eventually be handed over to sg_release() for closing and unreserving. */ int sg_grab(struct burn_drive *d) { struct cam_device *cam; if(d->cam != NULL) { d->released = 0; return 1; } cam = cam_open_device(d->devname, O_RDWR); if (cam == NULL) { libdax_msgs_submit(libdax_messenger, d->global_index, 0x00020003, LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH, "Could not grab drive", 0/*os_errno*/, 0); return 0; } d->cam = cam; fcntl(cam->fd, F_SETOWN, getpid()); d->released = 0; return 1; }