Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
static void usb_hpna_disconnect( struct usb_device *dev, void *ptr )
{
//	struct net_device	*net_dev = ptr;
	struct device	*net_dev = ptr;
	struct usb_hpna		*hpna = net_dev->priv;


	if ( net_dev->flags & IFF_UP )
		dev_close(net_dev);
	
	unregister_netdev( net_dev );

	if ( !hpna ) /* should never happen */
		return;
		
	usb_unlink_urb( &hpna->rx_urb );
	usb_unlink_urb( &hpna->tx_urb );
/*	usb_unlink_urb( &hpna->intr_urb );*/
	kfree_s(hpna->rx_buff, MAX_MTU);
	kfree_s(hpna->tx_buff, MAX_MTU);

	hpna->usb_dev = NULL;
	hpna->present = 0;

	printk("USB HPNA disconnected\n");
}
Ejemplo n.º 5
0
/* 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;
}
Ejemplo n.º 6
0
static int bcm_enet_set_ringparam(struct net_device *dev,
				  struct ethtool_ringparam *ering)
{
	struct bcm_enet_priv *priv;
	int was_running;

	priv = netdev_priv(dev);

	was_running = 0;
	if (netif_running(dev)) {
		bcm_enet_stop(dev);
		was_running = 1;
	}

	priv->rx_ring_size = ering->rx_pending;
	priv->tx_ring_size = ering->tx_pending;

	if (was_running) {
		int err;

		err = bcm_enet_open(dev);
		if (err)
			dev_close(dev);
		else
			bcm_enet_set_multicast_list(dev);
	}
	return 0;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
a_status_t
__adf_net_dev_close(adf_net_handle_t hdl)
{
    dev_close(hdl_to_netdev(hdl));
    
    return A_STATUS_OK;
}
Ejemplo n.º 9
0
/* 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, &sector, 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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
static int tun_chr_close(struct inode *inode, struct file *file)
{
	struct tun_struct *tun = (struct tun_struct *)file->private_data;

	if (!tun)
		return 0;

	DBG(KERN_INFO "%s: tun_chr_close\n", tun->name);

	tun_chr_fasync(-1, file, 0);

	rtnl_lock();

	/* Detach from net device */
	file->private_data = NULL;
	tun->attached = 0;

	/* Drop read queue */
	skb_queue_purge(&tun->readq);

	if (!(tun->flags & TUN_PERSIST)) {
		dev_close(&tun->dev);
		unregister_netdevice(&tun->dev);
		kfree(tun);
		MOD_DEC_USE_COUNT;
	}

	rtnl_unlock();
	return 0;
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
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);
		}
	}
}
Ejemplo n.º 16
0
Archivo: dev.c Proyecto: HarryR/sanos
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);
  }
}
Ejemplo n.º 17
0
/* 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, &sector, UINT64_C(0))))
                goto_out;

        r = l->ops->verify ? l->ops->verify(l, buf, sector) : 1;

      out:
        if (!dev_close(dev))
                stack;

        return r;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
void get_rssi()
{
   uint16_t rssi_val;
   dev_open(DEV_AVR_RSSI);
   dev_read(DEV_AVR_RSSI, &rssi_val, sizeof(rssi_val));
   dev_close(DEV_AVR_RSSI);
   printf("rssi %d\n",rssi_val);
}
Ejemplo n.º 20
0
Archivo: siofile.c Proyecto: t6/sndio
void
dev_sio_timeout(void *arg)
{
	struct dev *d = arg;

	dev_log(d);
	log_puts(": watchdog timeout\n");
	dev_close(d);
}
Ejemplo n.º 21
0
void destroy_config_tree(struct config_tree *cft)
{
	struct cs *c = (struct cs *) cft;

	if (c->dev)
		dev_close(c->dev);

	dm_pool_destroy(c->mem);
}
Ejemplo n.º 22
0
static void fjes_force_close_task(struct work_struct *work)
{
	struct fjes_adapter *adapter = container_of(work,
			struct fjes_adapter, force_close_task);
	struct net_device *netdev = adapter->netdev;

	rtnl_lock();
	dev_close(netdev);
	rtnl_unlock();
}
Ejemplo n.º 23
0
void config_file_destroy(struct dm_config_tree *cft)
{
	struct config_file *cf = dm_config_get_custom(cft);

	if (cf && cf->dev)
		if (!dev_close(cf->dev))
			stack;

	dm_config_destroy(cft);
}
Ejemplo n.º 24
0
void
quit(			/* clean up and exit */
	int	code
)
{
	if (code)
		exit(code);
	if (odev.v.type)
		dev_close();
	exit(0);
}
Ejemplo n.º 25
0
/**
 * hns_nic_self_test - self test
 * @dev: net device
 * @eth_test: test cmd
 * @data: test result
 */
static void hns_nic_self_test(struct net_device *ndev,
			      struct ethtool_test *eth_test, u64 *data)
{
	struct hns_nic_priv *priv = netdev_priv(ndev);
	bool if_running = netif_running(ndev);
#define SELF_TEST_TPYE_NUM 3
	int st_param[SELF_TEST_TPYE_NUM][2];
	int i;
	int test_index = 0;

	st_param[0][0] = MAC_INTERNALLOOP_MAC; /* XGE not supported lb */
	st_param[0][1] = (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII);
	st_param[1][0] = MAC_INTERNALLOOP_SERDES;
	st_param[1][1] = 1; /*serdes must exist*/
	st_param[2][0] = MAC_INTERNALLOOP_PHY; /* only supporte phy node*/
	st_param[2][1] = ((!!(priv->ae_handle->phy_dev)) &&
		(priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII));

	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
		set_bit(NIC_STATE_TESTING, &priv->state);

		if (if_running)
			dev_close(ndev);

		for (i = 0; i < SELF_TEST_TPYE_NUM; i++) {
			if (!st_param[i][1])
				continue;	/* NEXT testing */

			data[test_index] = __lb_up(ndev,
				(enum hnae_loop)st_param[i][0]);
			if (!data[test_index]) {
				data[test_index] = __lb_run_test(
					ndev, (enum hnae_loop)st_param[i][0]);
				(void)__lb_down(ndev,
						(enum hnae_loop)st_param[i][0]);
			}

			if (data[test_index])
				eth_test->flags |= ETH_TEST_FL_FAILED;

			test_index++;
		}

		hns_nic_net_reset(priv->netdev);

		clear_bit(NIC_STATE_TESTING, &priv->state);

		if (if_running)
			(void)dev_open(ndev, NULL);
	}
	/* Online tests aren't run; pass by default */

	(void)msleep_interruptible(4 * 1000);
}
Ejemplo n.º 26
0
static void fr_cisco_close(hdlc_device *hdlc)
{
	pvc_device *pvc=hdlc->first_pvc;

	del_timer(&hdlc->timer);
  
	while(pvc)		/* NULL in Cisco mode */ {
		dev_close(&pvc->netdev); /* Shutdown all PVCs for this FRAD */
		pvc=pvc->next;
	}
}
Ejemplo n.º 27
0
/*****************************************************************************
 Close communications with GPS device.
 *****************************************************************************/
void coms_close(int fd, const cmdlnopts_t *cmdopt) {
  if (cmdopt->devs != NULL) {
    dev_close(fd);
    if (cmdopt->vflg)
      printf("Closed device %s\n", cmdopt->devs);
  } else {
    bt_close(fd);
    if (cmdopt->vflg)
      printf("Disconnected from %s\n", cmdopt->btas);
  }
}
Ejemplo n.º 28
0
Archivo: siofile.c Proyecto: t6/sndio
void
dev_sio_hup(void *arg)
{
	struct dev *d = arg;

#ifdef DEBUG
	if (log_level >= 2) {
		dev_log(d);
		log_puts(": disconnected\n");
	}
#endif
	dev_close(d);
}
Ejemplo n.º 29
0
/* Caller may need to use label_get_handler to create label struct! */
int label_write(struct device *dev, struct label *label)
{
#pragma pack(8)
        char buf[LABEL_SIZE]; //__attribute((aligned(8)));
#pragma pack()
        struct label_header *lh = (struct label_header *) buf;
        int r = 1;

        if (!label->labeller->ops->write) {
                log_err("Label handler does not support label writes");
                return 0;
        }

        if ((LABEL_SIZE + (label->sector << SECTOR_SHIFT)) > LABEL_SCAN_SIZE) {
                log_error("Label sector %" PRIu64 " beyond range (%ld)",
                          label->sector, LABEL_SCAN_SECTORS);
                return 0;
        }

        memset(buf, 0, LABEL_SIZE);

        strncpy((char *)lh->id, LABEL_ID, sizeof(lh->id));
        lh->sector_xl = xlate64(label->sector);
        lh->offset_xl = xlate32(sizeof(*lh));

        if (!(label->labeller->ops->write)(label, buf)) {
                stack;
                return 0;
        }

        lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE -
                                      ((char *) &lh->offset_xl - (char *) lh)));
                                      //((void *) &lh->offset_xl - (void *) lh)));

        if (!dev_open(dev)) {
                stack;
                return 0;
        }

        log_info("%s: Writing label to sector %" PRIu64, dev_name(dev),
                 label->sector);
        if (!dev_write(dev, label->sector << SECTOR_SHIFT, LABEL_SIZE, buf)) {
                log_debug("Failed to write label to %s", dev_name(dev));
                r = 0;
        }

        if (!dev_close(dev))
                stack;

        return r;
}
Ejemplo n.º 30
0
static void shutdown_netdev()
{
	struct net_device *dev;
	printk("Shutdown network interface\n");
	read_lock(&dev_base_lock);
      	for (dev = dev_base; dev != NULL; dev = dev->next) {
		if (dev->flags&IFF_UP && dev->stop){
			printk("%s:===>\n",dev->name);
			rtnl_lock();
			dev_close(dev);
			rtnl_unlock();
		}
      	}
	read_unlock(&dev_base_lock);
}