本文整理汇总了C++中dev_close函数的典型用法代码示例。如果您正苦于以下问题:C++ dev_close函数的具体用法?C++ dev_close怎么用?C++ dev_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dev_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _dev_read_ahead_dev
static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
{
long read_ahead_long;
if (dev->read_ahead != -1) {
*read_ahead = (uint32_t) dev->read_ahead;
return 1;
}
if (!dev_open(dev))
return_0;
if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) {
log_sys_error("ioctl BLKRAGET", dev_name(dev));
if (!dev_close(dev))
stack;
return 0;
}
if (!dev_close(dev))
stack;
*read_ahead = (uint32_t) read_ahead_long;
dev->read_ahead = read_ahead_long;
log_very_verbose("%s: read_ahead is %u sectors",
dev_name(dev), *read_ahead);
return 1;
}
示例2: _dev_discard_blocks
static int _dev_discard_blocks(struct device *dev, uint64_t offset_bytes, uint64_t size_bytes)
{
uint64_t discard_range[2];
if (!dev_open(dev))
return_0;
discard_range[0] = offset_bytes;
discard_range[1] = size_bytes;
log_debug_devs("Discarding %" PRIu64 " bytes offset %" PRIu64 " bytes on %s.",
size_bytes, offset_bytes, dev_name(dev));
if (ioctl(dev->fd, BLKDISCARD, &discard_range) < 0) {
log_error("%s: BLKDISCARD ioctl at offset %" PRIu64 " size %" PRIu64 " failed: %s.",
dev_name(dev), offset_bytes, size_bytes, strerror(errno));
if (!dev_close(dev))
stack;
/* It doesn't matter if discard failed, so return success. */
return 1;
}
if (!dev_close(dev))
stack;
return 1;
}
示例3: start
void start(void)
{
uint16_t count;
uint8_t index;
buffer = (char *)mos_mem_alloc((uint16_t)BUFFER_SIZE);
memset(buffer, 'X', BUFFER_SIZE);
/* For safety, erase entire FLASH */
dev_ioctl(DEV_TELOS_FLASH, TELOS_FLASH_BULK_ERASE);
/* Turn on the FLASH */
dev_mode(DEV_TELOS_FLASH, DEV_MODE_ON);
/* Acquire lock on FLASH and preliminarly
* write 64 bits of data */
dev_open(DEV_TELOS_FLASH);
count = dev_write(DEV_TELOS_FLASH, "abcdefgh", 8);
printf("%d bytes of data have been written to FLASH memory\n", count);
dev_close(DEV_TELOS_FLASH);
/* Perform experiments over R/W pointer to FLASH */
/* Experiment#1 - flash is on, lock is free; aquire lock and read
* without using any SEEK function */
dev_open(DEV_TELOS_FLASH);
count = dev_read(DEV_TELOS_FLASH, buffer, 1);
printf("#1 : %c has been read from FLASH memory\n", buffer[0]);
dev_close(DEV_TELOS_FLASH);
/* Move pointer */
dev_open(DEV_TELOS_FLASH);
dev_ioctl(DEV_TELOS_FLASH, DEV_SEEK, 3);
dev_close(DEV_TELOS_FLASH);
/* Experiment#2 - flash is on, lock is free; aquire lock, read single data,
* write single data and read multiple data from it */
dev_open(DEV_TELOS_FLASH);
dev_read(DEV_TELOS_FLASH, buffer, 1);
printf("#2 : %c has been read\n"
" : FLASH memory written\n", buffer[0]);
dev_write(DEV_TELOS_FLASH, "l", 1);
count = dev_read(DEV_TELOS_FLASH, buffer, 1);
printf(" : %d bytes have been read from FLASH memory: ", count);
for(index = 0; index < count; index++)
{
printf("%c ", buffer[index]);
}
printf("\n");
dev_close(DEV_TELOS_FLASH);
/* Release lock and free resources */
dev_close(DEV_TELOS_FLASH);
dev_mode(DEV_TELOS_FLASH, DEV_MODE_OFF);
mos_mem_free(buffer);
return;
}
示例4: dev_clear
/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */
static int dev_clear(void)
{
GSList *l;
struct sr_dev_inst *sdi;
struct drv_context *drvc;
struct dev_context *devc;
int ret = SR_OK;
if (!(drvc = di->priv))
return SR_OK;
/* Properly close and free all devices. */
for (l = drvc->instances; l; l = l->next) {
if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
sr_err("%s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
if (!(devc = sdi->priv)) {
/* Log error, but continue cleaning up the rest. */
sr_err("%s: sdi->priv was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
dev_close(sdi);
sr_serial_dev_inst_free(devc->serial);
sr_dev_inst_free(sdi);
}
g_slist_free(drvc->instances);
drvc->instances = NULL;
return ret;
}
示例5: config_file_read
int config_file_read(struct dm_config_tree *cft)
{
const char *filename = NULL;
struct config_file *cf = dm_config_get_custom(cft);
struct stat info;
int r;
if (!config_file_check(cft, &filename, &info))
return_0;
/* Nothing to do. E.g. empty file. */
if (!filename)
return 1;
if (!cf->dev) {
if (!(cf->dev = dev_create_file(filename, NULL, NULL, 1)))
return_0;
if (!dev_open_readonly_buffered(cf->dev))
return_0;
}
r = config_file_read_fd(cft, cf->dev, 0, (size_t) info.st_size, 0, 0,
(checksum_fn_t) NULL, 0);
if (!cf->keep_open) {
if (!dev_close(cf->dev))
stack;
cf->dev = NULL;
}
return r;
}
示例6: __adf_net_dev_close
a_status_t
__adf_net_dev_close(adf_net_handle_t hdl)
{
dev_close(hdl_to_netdev(hdl));
return A_STATUS_OK;
}
示例7: label_read
/* FIXME Avoid repeated re-reading if cache lock held */
int label_read(struct device *dev, struct label **result,
uint64_t scan_sector)
{
#pragma pack(8)
char buf[LABEL_SIZE]; //__attribute((aligned(8)));
#pragma pack()
struct labeller *l;
uint64_t sector;
struct lvmcache_info *info;
int r = 0;
if (!dev_open(dev)) {
stack;
if ((info = info_from_pvid(dev->pvid)))
lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
0, NULL);
return r;
}
if (!(l = _find_labeller(dev, buf, §or, scan_sector)))
goto_out;
if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
(*result)->sector = sector;
out:
if (!dev_close(dev))
stack;
return r;
}
示例8: _native_check_pv_min_size
static int _native_check_pv_min_size(struct device *dev)
{
uint64_t size;
int ret = 0;
/* Check it's accessible */
if (!dev_open_readonly_quiet(dev)) {
log_debug_devs("%s: Skipping: open failed", dev_name(dev));
return 0;
}
/* Check it's not too small */
if (!dev_get_size(dev, &size)) {
log_debug_devs("%s: Skipping: dev_get_size failed", dev_name(dev));
goto out;
}
if (size < pv_min_size()) {
log_debug_devs("%s: Skipping: %s", dev_name(dev),
_too_small_to_hold_pv_msg);
goto out;
}
ret = 1;
out:
if (!dev_close(dev))
stack;
return ret;
}
示例9: cmd_model_new_end
static void cmd_model_new_end(char *file)
{
//printf("reached cmd_model_new_end\n");
//fflush(stdout);
//hmm_print_3d(&hmm);
//printf("state len: %d\n", hmm.state_len);
//printf("wrote HMM\n");
//fflush(stdout);
hmm_write_3d(&hmm, file);
printf("Done.\n");
fflush(stdout);
if (g_mode == graphical) {
percentage += 0.2;
update_gui("Done creating gesture", percentage);
}
if (g_mode == graphical) {
dev_close(g_dev);
//pthread_exit(0); /* don't exit, as we probably going to train the gesture */
} else {
kill(getpid(), SIGTERM);
}
gauss_mix_delete_3d(&endpoint.each[0]);
gauss_mix_delete_3d(&endpoint.each[1]);
hmm_delete_3d(&hmm);
seq.index = 0;
detected = 0;
seq.till_end = FRAME_AFTER;
seq.begin = 0;
seq.end = 0;
}
示例10: cmd_model_train_end
static void cmd_model_train_end(char *file)
{
//printf("reached cmd_model_train_end\n");
//fflush(stdout);
hmm_write_3d(&hmm, file);
printf("Done.\n");
fflush(stdout);
if (g_mode == graphical) {
percentage += 0.2;
update_gui("Done training gesture", percentage);
}
if (g_mode == graphical) {
dev_close(g_dev);
//pthread_exit(0);
} else {
kill(getpid(), SIGTERM);
}
gauss_mix_delete_3d(&endpoint.each[0]);
gauss_mix_delete_3d(&endpoint.each[1]);
hmm_delete_3d(&hmm);
seq.index = 0;
detected = 0;
seq.till_end = FRAME_AFTER;
seq.begin = 0;
seq.end = 0;
}
示例11: dev_open
int DeviceV4L2Base::open_dev(int color_model)
{
v4l2_lock->lock("DeviceV4L2Base::open_dev");
int result = 0;
if( !opened )
{
result = dev_open();
if( !result )
result = v4l2_open(color_model);
if( !result )
result = start_dev();
if( !result )
{
qbfrs_lock->reset();
video_lock->reset();
getq = new DeviceV4L2BufferQ(total_buffers+1);
put_thread = new DeviceV4L2Put(this);
put_thread->start();
done = 0;
Thread::start();
}
else
printf("DeviceV4L2Base::open_dev failed\n");
}
if( result )
{
printf("DeviceV4L2Base::open_dev: adaptor open failed\n");
stop_dev();
dev_close();
}
else
opened = 1;
v4l2_lock->unlock();
return result;
}
示例12: ipmr_del_tunnel
static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v)
{
struct net *net = dev_net(dev);
dev_close(dev);
dev = __dev_get_by_name(net, "tunl0");
if (dev) {
const struct net_device_ops *ops = dev->netdev_ops;
struct ifreq ifr;
struct ip_tunnel_parm p;
memset(&p, 0, sizeof(p));
p.iph.daddr = v->vifc_rmt_addr.s_addr;
p.iph.saddr = v->vifc_lcl_addr.s_addr;
p.iph.version = 4;
p.iph.ihl = 5;
p.iph.protocol = IPPROTO_IPIP;
sprintf(p.name, "dvmrp%d", v->vifc_vifi);
ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
if (ops->ndo_do_ioctl) {
mm_segment_t oldfs = get_fs();
set_fs(KERNEL_DS);
ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL);
set_fs(oldfs);
}
}
}
示例13: install_drivers
void install_drivers() {
dev_t console;
// Register /proc/units
register_proc_inode("units", units_proc, NULL);
register_proc_inode("devices", devices_proc, NULL);
register_proc_inode("devstat", devstat_proc, NULL);
// Parse driver binding database
parse_bindings();
// Match bindings to units
bind_units();
// Install legacy drivers
install_legacy_drivers();
// Make sure we have a console device
console = dev_open("console");
if (console == NODEV) {
initialize_driver(NULL, "krnl.dll!console");
} else {
dev_close(console);
}
}
示例14: label_verify
/* Unused */
int label_verify(struct device *dev)
{
#pragma pack(8)
char buf[LABEL_SIZE];
#pragma pack()
struct labeller *l;
//char buf[LABEL_SIZE] __attribute((aligned(8)));
uint64_t sector;
struct lvmcache_info *info;
int r = 0;
if (!dev_open(dev)) {
if ((info = info_from_pvid(dev->pvid)))
lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
0, NULL);
return_0;
}
if (!(l = _find_labeller(dev, buf, §or, UINT64_C(0))))
goto_out;
r = l->ops->verify ? l->ops->verify(l, buf, sector) : 1;
out:
if (!dev_close(dev))
stack;
return r;
}
示例15: trivfs_goaway
error_t
trivfs_goaway (struct trivfs_control *fsys, int flags)
{
struct dev *const device = fsys->hook;
error_t err;
int force = (flags & FSYS_GOAWAY_FORCE);
int nosync = (flags & FSYS_GOAWAY_NOSYNC);
struct port_class *root_port_class = fsys->protid_class;
mutex_lock (&device->lock);
if (device->store == NULL)
/* The device is not actually open.
XXX note that exitting here nukes non-io users, like someone
in the middle of a stat who will get SIGLOST or something. */
exit (0);
/* Wait until all pending rpcs are done. */
err = ports_inhibit_class_rpcs (root_port_class);
if (err == EINTR || (err && !force))
{
mutex_unlock (&device->lock);
return err;
}
if (force && nosync)
/* Exit with extreme prejudice. */
exit (0);
if (!force && ports_count_class (root_port_class) > 0)
/* Still users, so don't exit. */
goto busy;
if (! nosync)
/* Sync the device here, if necessary, so that closing it won't result in
any I/O (which could get hung up trying to use one of our pagers). */
dev_sync (device, 1);
/* devpager_shutdown may sync the pagers as side-effect (if NOSYNC is 0),
so we put that first in this test. */
if (dev_stop_paging (device, nosync) || force)
/* Bye-bye. */
{
if (! nosync)
/* If NOSYNC is true, we don't close DEV, as that could cause data to
be written back. */
dev_close (device);
exit (0);
}
busy:
/* Allow normal operations to proceed. */
ports_enable_class (root_port_class);
ports_resume_class_rpcs (root_port_class);
mutex_unlock (&device->lock);
/* Complain that there are still users. */
return EBUSY;
}