momo zone

调核人的blog

Monthly Archives: 十二月 2010

compiz(&emerald) autostart 设置

试过多种方法,包括最全面的arch wiki 提到的方法,也不是很好。

针对openSuSE kde4 环境下最好的方法是:

菜单->configure desktop->default applications -> window manager -> use a different window manager:

记住 ,选择compiz custom …… ,不要选择compiz 因为这个根本无效。

之后再编辑/usr/bin/compiz-kde-launcher

/usr/bin/compiz –ignore-desktop-hints –replace –indirect-rendering –loose-binding  core decoration move minimize resize ccp&
emerald –replace&
重启后在kde4 的session启动时就会把compiz 作为默认的窗口管理器,而不需要先启动kwin
那么还有emerald , 很简单直接编辑/usr/bin/compiz-decorator 把下面的
USE_EMERALD=”no”
改成
USE_EMERALD=”yes”
就可以了
为什么? 很简单compiz config 中默认设定的就是compiz-decorator –replace
Advertisements

细心的GCC

今天编译netmd driver的时候遇到一个警告:

warning: suggest parentheses around assignment used as truth value

定位的是这句:

if(retval=usb_register_dev(interface,&netmd_class)){…}

 

这个警告的意思是在语句上建议加一个括号,以便判断布尔值。

其实gcc是怕你把 ==  当成了=  ,所以你只要加个括号明确指示这个是赋值语句而非判断语句就好了。

if((retval=usb_register_dev(interface,&netmd_class))){…}



usb 驱动程序简要分析

这是第一个真正的挑战,对于外行人来讲是相当困难,但还是坚持啃下了这500行代码(尽管很短)

这段代码对一个usb 驱动架构进行了一次全局的展示,主要分为这些部分:

1. usb设备事件的处理(probe,disconnect…)

2.usb设备结构构建 (usb_skel),注册等等

3.usb驱动结构构建 (skel_driver),注册等等

4.usb设备操作处理(open,read,write …)

5.usb核心事务 urb的创建,回调定义,提交等等

/*
 * USB Skeleton driver - 2.2
 *
 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation, version 2.
 *
 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
 * but has been rewritten to be easier to read and use.
 *
 */
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kref.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/mutex.h>

/* Define these values to match your devices */
#define USB_SKEL_VENDOR_ID	0xfff0
#define USB_SKEL_PRODUCT_ID	0xfff0

//也许要问这个结构再那里用到,但其实根本就不用担心,因为把usb插上去后由usb core 来处理设备与驱动的匹配,详见ldd p334
/* table of devices that work with this driver */
static const struct usb_device_id skel_table[] = {
	{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
	{ }					/* Terminating entry */
};
//告诉用户空间的热插拔和模块装载,vid和pid对应什么硬件设备。以便执行自动挂载。
MODULE_DEVICE_TABLE(usb, skel_table);

/* Get a minor range for your devices from the usb maintainer */
#define USB_SKEL_MINOR_BASE	192

//不太清楚这样做的目的
/* our private defines. if this grows any larger, use your own .h file */
#define MAX_TRANSFER		(PAGE_SIZE - 512)
/* MAX_TRANSFER is chosen so that the VM is not stressed by
   allocations > PAGE_SIZE and the number of packets in a page
   is an integer 512 is the largest possible packet on EHCI */

//给信号量初始化时设置可以同步访问共享资源的进程数目,L539
#define WRITES_IN_FLIGHT	8
/* arbitrarily chosen */

/* Structure to hold all of our device specific stuff */
struct usb_skel {
	struct usb_device	*udev;			/* the usb device for this device */
	struct usb_interface	*interface;		/* the interface for this device */
	struct semaphore	limit_sem;		/* limiting the number of writes in progress */
	struct usb_anchor	submitted;		/* in case we need to retract our submissions */
	struct urb		*bulk_in_urb;		/* the urb to read data with */
	unsigned char           *bulk_in_buffer;	/* the buffer to receive data */
	size_t			bulk_in_size;		/* the size of the receive buffer */
	size_t			bulk_in_filled;		/* number of bytes in the buffer */
	size_t			bulk_in_copied;		/* already copied to user space */
	__u8			bulk_in_endpointAddr;	/* the address of the bulk in endpoint */
	__u8			bulk_out_endpointAddr;	/* the address of the bulk out endpoint */
	int			errors;			/* the last request tanked */
	int			open_count;		/* count the number of openers */
	bool			ongoing_read;		/* a read is going on */
	bool			processed_urb;		/* indicates we haven't processed the urb */
	spinlock_t		err_lock;		/* lock for errors */
	struct kref		kref;
	struct mutex		io_mutex;		/* synchronize I/O with disconnect */
	struct completion	bulk_in_completion;	/* to wait for an ongoing read */
};
#define to_skel_dev(d) container_of(d, struct usb_skel, kref)

static struct usb_driver skel_driver;
static void skel_draw_down(struct usb_skel *dev);

static void skel_delete(struct kref *kref)
{
	struct usb_skel *dev = to_skel_dev(kref);

	usb_free_urb(dev->bulk_in_urb);
	usb_put_dev(dev->udev);
	kfree(dev->bulk_in_buffer);
	kfree(dev);
}

static int skel_open(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

//通过inode 获得minor 设备号,再根据minor 设备号和驱动找到关联的接口。
	subminor = iminor(inode);
	interface = usb_find_interface(&skel_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
		     __func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

//进一步得到用usb_get_intfdata保存的设备结构
	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	/* increment our usage count for the device */
//增加设备引用计数
	kref_get(&dev->kref);

	/* lock the device to allow correctly handling errors
	 * in resumption */
	mutex_lock(&dev->io_mutex);
//增加open计数
	if (!dev->open_count++) {
//usb interface的电源引用计数加一,只要这个引用计数大于0,这个设备就不允许autosuspend
		retval = usb_autopm_get_interface(interface);
			if (retval) {
				dev->open_count--;
				mutex_unlock(&dev->io_mutex);
				kref_put(&dev->kref, skel_delete);
				goto exit;
			}
	} /* else { //uncomment this block if you want exclusive open
		retval = -EBUSY;
		dev->open_count--;
		mutex_unlock(&dev->io_mutex);
		kref_put(&dev->kref, skel_delete);
		goto exit;
	} */
	/* prevent the device from being autosuspended */

	/* save our object in the file's private structure */
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	return retval;
}

static int skel_release(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;

	dev = file->private_data;
	if (dev == NULL)
		return -ENODEV;

	/* allow the device to be autosuspended */
	mutex_lock(&dev->io_mutex);
	if (!--dev->open_count && dev->interface)
		usb_autopm_put_interface(dev->interface);
	mutex_unlock(&dev->io_mutex);

	/* decrement the count on our device */
	kref_put(&dev->kref, skel_delete);
	return 0;
}

static int skel_flush(struct file *file, fl_owner_t id)
{
	struct usb_skel *dev;
	int res;

	dev = file->private_data;
	if (dev == NULL)
		return -ENODEV;

	/* wait for io to stop */
	mutex_lock(&dev->io_mutex);
	skel_draw_down(dev);

	/* read out errors, leave subsequent opens a clean slate */
	spin_lock_irq(&dev->err_lock);
	res = dev->errors ? (dev->errors == -EPIPE ? -EPIPE : -EIO) : 0;
	dev->errors = 0;
	spin_unlock_irq(&dev->err_lock);

	mutex_unlock(&dev->io_mutex);

	return res;
}

static void skel_read_bulk_callback(struct urb *urb)
{
	struct usb_skel *dev;

	dev = urb->context;

	spin_lock(&dev->err_lock);
	/* sync/async unlink faults aren't errors */
	if (urb->status) {
		if (!(urb->status == -ENOENT ||
		    urb->status == -ECONNRESET ||
		    urb->status == -ESHUTDOWN))
			err("%s - nonzero write bulk status received: %d",
			    __func__, urb->status);

		dev->errors = urb->status;
	} else {
		dev->bulk_in_filled = urb->actual_length;
	}
	dev->ongoing_read = 0;
	spin_unlock(&dev->err_lock);
//通知等待这个消息的代码继续执行,这个程序中只有read 在等待,它正等着把urb提交后传过来的数据copy到用户空间,L281
	complete(&dev->bulk_in_completion);
}

static int skel_do_read_io(struct usb_skel *dev, size_t count)
{
	int rv;

	/* prepare a read */
//这个是设置urb,为submit做准备。usb驱动的核心其实就是这一句了。
	usb_fill_bulk_urb(dev->bulk_in_urb,                //指定要提交的urb
			dev->udev,
			usb_rcvbulkpipe(dev->udev,
				dev->bulk_in_endpointAddr),//输入端点地址
			dev->bulk_in_buffer,               //分配在该驱动程序中的缓存
			min(dev->bulk_in_size, count),     //输入的数据量
			skel_read_bulk_callback,           //urb提交,处理完成后的回调函数
			dev);
	/* tell everybody to leave the URB alone */
	spin_lock_irq(&dev->err_lock);
	dev->ongoing_read = 1;
	spin_unlock_irq(&dev->err_lock);

	/* do it */
//把urb提交给usb core ,接下来等待把数据从usb设备传出来后由回调函数把urb执行结果返回过来
	rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL);
	if (rv < 0) { 		err("%s - failed submitting read urb, error %d", 			__func__, rv); 		dev->bulk_in_filled = 0;
		rv = (rv == -ENOMEM) ? rv : -EIO;
		spin_lock_irq(&dev->err_lock);
		dev->ongoing_read = 0;
		spin_unlock_irq(&dev->err_lock);
	}

	return rv;
}

static ssize_t skel_read(struct file *file, char *buffer, size_t count,
			 loff_t *ppos)
{
	struct usb_skel *dev;
	int rv;
	bool ongoing_io;

	dev = file->private_data;

	/* if we cannot read at all, return EOF */
//这个urb结构应该已在probe时分配了,L565
	if (!dev->bulk_in_urb || !count)
		return 0;

	/* no concurrent readers */
//这个是对mutex而不是对sem操作
	rv = mutex_lock_interruptible(&dev->io_mutex);
	if (rv < 0)
            return rv;
        if (!dev->interface) {		/* disconnect() was called */
		rv = -ENODEV;
		goto exit;
	}

	/* if IO is under way, we must not touch things */
retry:
//见ldd3 p121,这段主要是处理当还有数据没有接收完的情况。
	spin_lock_irq(&dev->err_lock);
	ongoing_io = dev->ongoing_read;
	spin_unlock_irq(&dev->err_lock);

	if (ongoing_io) {
		/* nonblocking IO shall not wait */
//如果设备文件的IO模式是非阻塞模式则直接退出
		if (file->f_flags & O_NONBLOCK) {
			rv = -EAGAIN;
			goto exit;
		}
		/*
		 * IO may take forever
		 * hence wait in an interruptible state
		 */
//见ldd p117, 等待批输入完成。设置完成的代码在urb的回调函数中,L206
		rv = wait_for_completion_interruptible(&dev->bulk_in_completion);
		if (rv < 0)
                   goto exit;
/*
* by waiting we also semiprocessed the urb
* we must finish now
*/
 		dev->bulk_in_copied = 0;
		dev->processed_urb = 1;
	}

//什么情况下会进入这段代码?
	if (!dev->processed_urb) {
		/*
		 * the URB hasn't been processed
		 * do it now
		 */
		wait_for_completion(&dev->bulk_in_completion);
		dev->bulk_in_copied = 0;
		dev->processed_urb = 1;
	}

	/* errors must be reported */
	rv = dev->errors;
	if (rv < 0) { 		/* any error is reported once */ 		dev->errors = 0;
		/* to preserve notifications about reset */
		rv = (rv == -EPIPE) ? rv : -EIO;
		/* no data to deliver */
		dev->bulk_in_filled = 0;
		/* report it */
		goto exit;
	}

	/*
	 * if the buffer is filled we may satisfy the read
	 * else we need to start IO
	 */
//bulk_in_filled 在urb的回调函数中被赋予urb接收的数据长度,见ldd3 p335
	if (dev->bulk_in_filled) {
		/* we had read data */
/*这句很重要,为了搞清楚他的用意,做这样的假设:
(1)第一次执行read,很明x没有数据(copied=0),urb也没有submit 当然也没有任何数据从usb传输到buffer(filled=0)
(2)filled和copied都为非0值,且相等,也就是进入接下来的分支。这种情况说明urb 被sumbit后数据已传到buffer,且buffer的数据
也全部传到了用户空间了。也就是说没有可以被read的数据。那就赶紧去再调用skel_do_read_io去从usb捞数据,然后再copy到用户空间。
(3)filled和copied都为非0,但fiiled>copied ,说明上一次还有urb过来的数据还没有copy到用户空间。ok,很简单直接把他copy到用户
空间吧。
*/
		size_t available = dev->bulk_in_filled - dev->bulk_in_copied;
		size_t chunk = min(available, count);

		if (!available) {
			/*
			 * all data has been used
			 * actual IO needs to be done
			 */
			rv = skel_do_read_io(dev, count);
			if (rv < 0) 				goto exit; 			else 				goto retry; 		} 		/* 		 * data is available 		 * chunk tells us how much shall be copied 		 */ 		if (copy_to_user(buffer, 				 dev->bulk_in_buffer + dev->bulk_in_copied,
				 chunk))
			rv = -EFAULT;
		else
			rv = chunk;

		dev->bulk_in_copied += chunk;

		/*
		 * if we are asked for more than we have,
		 * we start IO but don't wait
		 */
		if (available < count)
			skel_do_read_io(dev, count - chunk);
	} else {
		/* no data in the buffer */
		rv = skel_do_read_io(dev, count);
		if (rv < 0) 			goto exit; 		else if (!(file->f_flags & O_NONBLOCK))
			goto retry;
		rv = -EAGAIN;
	}
exit:
	mutex_unlock(&dev->io_mutex);
	return rv;
}

static void skel_write_bulk_callback(struct urb *urb)
{
	struct usb_skel *dev;

	dev = urb->context;

	/* sync/async unlink faults aren't errors */
	if (urb->status) {
		if (!(urb->status == -ENOENT ||
		    urb->status == -ECONNRESET ||
		    urb->status == -ESHUTDOWN))
			err("%s - nonzero write bulk status received: %d",
			    __func__, urb->status);

		spin_lock(&dev->err_lock);
		dev->errors = urb->status;
		spin_unlock(&dev->err_lock);
	}

	/* free up our allocated buffer */
	usb_free_coherent(urb->dev, urb->transfer_buffer_length,
			  urb->transfer_buffer, urb->transfer_dma);
	up(&dev->limit_sem);
}

static ssize_t skel_write(struct file *file, const char *user_buffer,
			  size_t count, loff_t *ppos)
{
	struct usb_skel *dev;
	int retval = 0;
	struct urb *urb = NULL;
	char *buf = NULL;
	size_t writesize = min(count, (size_t)MAX_TRANSFER);

	dev = file->private_data;

	/* verify that we actually have some data to write */
	if (count == 0)
		goto exit;

	/*
	 * limit the number of URBs in flight to stop a user from using up all
	 * RAM
	 */
	if (!(file->f_flags & O_NONBLOCK)) {
		if (down_interruptible(&dev->limit_sem)) {
			retval = -ERESTARTSYS;
			goto exit;
		}
	} else {
		if (down_trylock(&dev->limit_sem)) {
			retval = -EAGAIN;
			goto exit;
		}
	}

	spin_lock_irq(&dev->err_lock);
	retval = dev->errors;
	if (retval < 0) { 		/* any error is reported once */ 		dev->errors = 0;
		/* to preserve notifications about reset */
		retval = (retval == -EPIPE) ? retval : -EIO;
	}
	spin_unlock_irq(&dev->err_lock);
	if (retval < 0) 		goto error; 	/* create a urb, and a buffer for it, and copy the data to the urb */ 	urb = usb_alloc_urb(0, GFP_KERNEL); 	if (!urb) { 		retval = -ENOMEM; 		goto error; 	} 	buf = usb_alloc_coherent(dev->udev, writesize, GFP_KERNEL,
				 &urb->transfer_dma);
	if (!buf) {
		retval = -ENOMEM;
		goto error;
	}

	if (copy_from_user(buf, user_buffer, writesize)) {
		retval = -EFAULT;
		goto error;
	}

	/* this lock makes sure we don't submit URBs to gone devices */
	mutex_lock(&dev->io_mutex);
	if (!dev->interface) {		/* disconnect() was called */
		mutex_unlock(&dev->io_mutex);
		retval = -ENODEV;
		goto error;
	}

	/* initialize the urb properly */
	usb_fill_bulk_urb(urb, dev->udev,
			  usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
			  buf, writesize, skel_write_bulk_callback, dev);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	usb_anchor_urb(urb, &dev->submitted);

	/* send the data out the bulk port */
	retval = usb_submit_urb(urb, GFP_KERNEL);
	mutex_unlock(&dev->io_mutex);
	if (retval) {
		err("%s - failed submitting write urb, error %d", __func__,
		    retval);
		goto error_unanchor;
	}

	/*
	 * release our reference to this urb, the USB core will eventually free
	 * it entirely
	 */
	usb_free_urb(urb);

	return writesize;

error_unanchor:
	usb_unanchor_urb(urb);
error:
	if (urb) {
		usb_free_coherent(dev->udev, writesize, buf, urb->transfer_dma);
		usb_free_urb(urb);
	}
	up(&dev->limit_sem);

exit:
	return retval;
}

static const struct file_operations skel_fops = {
	.owner =	THIS_MODULE,
	.read =		skel_read,
	.write =	skel_write,
	.open =		skel_open,
	.release =	skel_release,
	.flush =	skel_flush,
};

/*
 * usb class driver info in order to get a minor number from the usb core,
 * and to have the device registered with the driver core
 */
static struct usb_class_driver skel_class = {
	.name =		"skel%d",
	.fops =		&skel_fops,
	.minor_base =	USB_SKEL_MINOR_BASE,
};


//当和驱动匹配的设备被发现后执行探测,这里参数interface的含义详见ldd p328

static int skel_probe(struct usb_interface *interface,
		      const struct usb_device_id *id)
{
	struct usb_skel *dev;
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	size_t buffer_size;
	int i;
	int retval = -ENOMEM;

	/* allocate memory for our device state and initialize it */
	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (!dev) {
		err("Out of memory");
		goto error;
	}
//这段初始化设备结构各成员
	kref_init(&dev->kref);
	sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
	mutex_init(&dev->io_mutex);
	spin_lock_init(&dev->err_lock);
//和urb重提交有关?
	init_usb_anchor(&dev->submitted);

	init_completion(&dev->bulk_in_completion);

/*根据接口获取设备在初始化了一些资源之后,可以看到第一个关键的函数调用——interface_to_usbdev。
他同uo一个usb_interface来得到该接口所在设备的设备描述结构。
本来,要得到一个usb_device只要用interface_to_usbdev就够了,但因为要增加对该usb_device的引用计数,我们应该在做一个usb_get_dev的操作,\
来增加引用计数,并在释放设备时用usb_put_dev来减少引用计数。
这里要解释的是,该引用计数值是对该usb_device的计数,并不是对本模块的计数,本模块的计数要由kref来维护。
所以,probe一开始就有初始化kref。事实上,kref_init操作不单只初始化kref,还将其置设成1。
所以在出错处理代码中有kref_put,它把kref的计数减1,如果kref计数已经为0,那么kref会被释放。
kref_put的第二个参数是一个函数指针,指向一个清理函数。注意,该指针不能为空,或者kfree。该(skel_delete)函数会在最后一个对kref的引用释放时被调用
*/
	dev->udev = usb_get_dev(interface_to_usbdev(interface));
	dev->interface = interface;

	/* set up the endpoint information */
	/* use only the first bulk-in and bulk-out endpoints */
//获得当前配置下的接口描述符
	iface_desc = interface->cur_altsetting;
	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
		endpoint = &iface_desc->endpoint[i].desc;

		if (!dev->bulk_in_endpointAddr &&
		    usb_endpoint_is_bulk_in(endpoint)) {
			/* we found a bulk in endpoint */
//找到批传输端点,这里有个疑问:为什么这个程序只要用批传输端点呢?


			buffer_size = le16_to_cpu(endpoint->wMaxPacketSize)
//不言而喻,将缓冲区设置成该端点一次可以传输的最大字节数

			dev->bulk_in_size = buffer_size;
			dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
			dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
			if (!dev->bulk_in_buffer) {
				err("Could not allocate bulk_in_buffer");
				goto error;
			}
//创建urb,这个是重点哦
			dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
			if (!dev->bulk_in_urb) {
				err("Could not allocate bulk_in_urb");
				goto error;
			}
		}

		if (!dev->bulk_out_endpointAddr &&
		    usb_endpoint_is_bulk_out(endpoint)) {
			/* we found a bulk out endpoint */
			dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
		}
	}
	if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
		err("Could not find both bulk-in and bulk-out endpoints");
		goto error;
	}

	/* save our data pointer in this interface device */
//这个要看ldd p348
	usb_set_intfdata(interface, dev);

	/* we can register the device now, as it is ready */
//同样是重点哦,模块初始化的时候注册的是驱动,这里注册的是设备哦。
/*至于为什么是这两个参数这里讲一下:
interface 要和驱动绑定的(ldd3 p326),这个函数就是干这个的。skel_class定义的usb_class_driver,说明这个驱动是
usb class ,而不是注册给了其他子系统当作其他设备了(比如键盘)。最后实现的功能就是:任何对该skel_class的设备文件操作
都将关联到interface 这个接口上(联系的桥梁是minor 设备号),同时还将分配一个minor备号在usb major设备号之下。
用的时候参考skel_open,L95
*/
	retval = usb_register_dev(interface, &skel_class);
	if (retval) {
		/* something prevented us from registering this driver */
		err("Not able to get a minor for this device.");
		usb_set_intfdata(interface, NULL);
		goto error;
	}

	/* let the user know what node this device is now attached to */
	dev_info(&interface->dev,
		 "USB Skeleton device now attached to USBSkel-%d",
		 interface->minor);
	return 0;

error:
	if (dev)
		/* this frees allocated memory */
		kref_put(&dev->kref, skel_delete);
	return retval;
}

static void skel_disconnect(struct usb_interface *interface)
{
	struct usb_skel *dev;
	int minor = interface->minor;

	dev = usb_get_intfdata(interface);
	usb_set_intfdata(interface, NULL);

	/* give back our minor */
	usb_deregister_dev(interface, &skel_class);

	/* prevent more I/O from starting */
	mutex_lock(&dev->io_mutex);
	dev->interface = NULL;
	mutex_unlock(&dev->io_mutex);

	usb_kill_anchored_urbs(&dev->submitted);

	/* decrement our usage count */
	kref_put(&dev->kref, skel_delete);

	dev_info(&interface->dev, "USB Skeleton #%d now disconnected", minor);
}

static void skel_draw_down(struct usb_skel *dev)
{
	int time;

	time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000);
	if (!time)
		usb_kill_anchored_urbs(&dev->submitted);
	usb_kill_urb(dev->bulk_in_urb);
}

static int skel_suspend(struct usb_interface *intf, pm_message_t message)
{
	struct usb_skel *dev = usb_get_intfdata(intf);

	if (!dev)
		return 0;
	skel_draw_down(dev);
	return 0;
}

static int skel_resume(struct usb_interface *intf)
{
	return 0;
}

static int skel_pre_reset(struct usb_interface *intf)
{
	struct usb_skel *dev = usb_get_intfdata(intf);

	mutex_lock(&dev->io_mutex);
	skel_draw_down(dev);

	return 0;
}

static int skel_post_reset(struct usb_interface *intf)
{
	struct usb_skel *dev = usb_get_intfdata(intf);

	/* we are sure no URBs are active - no locking needed */
	dev->errors = -EPIPE;
	mutex_unlock(&dev->io_mutex);

	return 0;
}

static struct usb_driver skel_driver = {
	.name =		"skeleton",
	.probe =	skel_probe,
	.disconnect =	skel_disconnect,
	.suspend =	skel_suspend,
	.resume =	skel_resume,
	.pre_reset =	skel_pre_reset,
	.post_reset =	skel_post_reset,
	.id_table =	skel_table,
	.supports_autosuspend = 1,
};

static int __init usb_skel_init(void)
{
	int result;
//这里是开始,但真的很简单,因为里面的实际工作都交给usb core 处理了。usb驱动被注册后将会自动匹配设备,然后探测设备,进行初始化。L522
	/* register this driver with the USB subsystem */
	result = usb_register(&skel_driver);
	if (result)
		err("usb_register failed. Error number %d", result);

	return result;
}

static void __exit usb_skel_exit(void)
{
	/* deregister this driver with the USB subsystem */
	usb_deregister(&skel_driver);
}

module_init(usb_skel_init);
module_exit(usb_skel_exit);

支付宝 ,你总算明白了

支付宝  今天发布了linux平台,非ie浏览器的登录插件,接下来就看全国那些傻X 的网银了什么时候么行动了

发布linux插件在当下对支付宝没什么实际的好处,但如果明年chrome os本上市后情况就完全不一样了… 我不多说了大家都明白

安装方法在这里http://help.alipay.com/lab/help_detail.htm?help_id=240951

只介绍了Ubuntu 的安装方法,不过其他发行版也没问题,解压后执行aliedit.sh 就可以了很简单。就一个shell脚本就ok ? 脚本开源? 这还安全?

#!/bin/bash
# __CR__
# Copyright (c) 2008-2010 Alipay Corporation
# All Rights Reserved
#
# This software contains the intellectual property of Alipay Corporation
# or is licensed to Alipay Corporation from third parties.  Use of this
# software and the intellectual property contained therein is expressly
# limited to the terms and conditions of the License Agreement under which
# it is provided by or on behalf of Alipay.
# __CR__
#
# Author: Longda Feng
# Date:   2010/07/29
# Support: If you have any question, please feel free to rais it to
# zhongyan.feng@alipay.com
#
SetStrings()
{
PRE_LANG=$(expr substr $LANG 1 9)
if [ $PRE_LANG = “zh_CN.UTF” ] || [ $PRE_LANG = “zh_CN.utf” ]
then
ALIPAYEDIT=”æ¯ä»å®å®å¨æ§ä»¶”
MK_TEMP_DIR_FAIL=”å›å»ºä¸´æ¶ç›®å½å¤±è´¥ï¼è¯·æå¨å›å»º”
PACKAGE_BAD=”å®è£ååæï¼è¯·éæ°ä¸è½½”
QUIT=”请æä»»æé®é庅”
else
ALIPAYEDIT=”Alipay Security Control”
MK_TEMP_DIR_FAIL=”Failed to create temp directory, please manually delete “
PACKAGE_BAD=”The installation package has been destroyed, please download again”
QUIT=”Press any key to quit…”
fi
return 0
}
ReadChar()
{
#in debug mode, here are some problem
read -n 1 -s $1
#read $1
}
Quit()
{
echo $QUIT
ReadChar val
exit 1
}
Mkdir()
{
ALI_DIR=$HOME/.aliedit
mkdir -p $ALI_DIR > /dev/null
TMP_DIR=$ALI_DIR/install
if [ -d $TMP_DIR ]
then
rm -rf $TMP_DIR
fi
mkdir -p $TMP_DIR > /dev/null
if [ $? -ne 0 ]
then
echo $MK_TEMP_DIR_FAIL $TEMP_DIR
Quit
fi
}
main()
{
SetStrings
Mkdir
ARCHIVE=`awk ‘/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }’ “$0″`
tail -n+$ARCHIVE “$0” | tar xzvm -C $TMP_DIR > /dev/null 2>&1 3>&1
if [ $? -ne 0 ]
then
echo $PACKAGE_BAD
Quit
fi
CUR_DIR=`pwd`
cd $TMP_DIR
./install.sh
#cd “$CUR_DIR”
rm -rf $TMP_DIR
exit 0
}
main
#This line must be the last line of the file
__ARCHIVE_BELOW__

^_<8b>^H^@      ßáL^@^Cì;^?p^\ÕykdS<90><9d>^@-Ó_        éCºb;±¤;I<96>e<93>ÃÈÒÉ=<90>%¡<93><8c><83>^Cë½Ýwwkíí^^»{úaLb^X~ØÄ^N^T0¤@<80><94>^RÓ^Nc^H^NPp^H<93>i^K3MghÓæ<8f>d<9a>̤<95>d<99>¦<93>ÒiKÓ_ô{ï}ûS{²<86>@;<9d>ô`}û½ï÷÷¾÷}ïí­tÓq^UÃhw*Ò<87>öIÃgËæÍ컫;Ó^]þ<86>O’ü×%e2Ý[Ò]<9b>·d¶^@]&Ó<93>IK$ýá<99>^T|êà¿M<88>äRÇ]<8e>î\øÿ£<9f>ÖË;<8a>ºÙQT<9c>Js+<91>åþ1Y<86><9b>~«6këå<8a>K6¨^[Ig:ÝÛÖ<99>ΤI<9f>¡×<94>Y@Û5ËV\Ý2<81>¸Ï0È^X#vÈ^Xu¨=E5^X<85>ÿÇ+ºC^\«äN+6%ªeº<8a>n:Ä­P¢<9b>.5^LªºuÅ 5ÛªQÛ<9d>%V)Y<83>e^S<90>dè*5^]ª^Q×J #%Ûª<82>lÝÖHM±]<9d>:í<84>L8<94>Iu<99>% È7F1µeì@S)§±©n2õt¦fSÇ1fA<8e>¡WuWX¤¸Ô®:\&pj:3Ç^Qj)^Y^RV<93>¾²Mi<95><9a>.©<9b>^ZµÉtEW+Ì&ÝeÒA÷<94>®<81>Èâ,s^Wü)Ò<8a>b<94><82><98>´^G^SÔÜÊÂ^w+<96>½<8d>^LYfYSÈ 5Ë0: ¸t^[!<84>MWGzKGçV^X,Ôk^P&w^[É<97>ȬU’^Ue<8a><85>`<96>Ü\<87>´^Fk7<91><9a>A^U°²D©^A<91>¤<94>¹f+`^X<98>^G· ä@^E^TÍ*f{       4]­^H<9b>T«Ê溹@Ý]<8a>j[^[66ßÒ

原来这个脚本里面嵌入了二进制代码,和NV 的驱动打包一个原理。那么他都是装了什么了? 看这个东西:

~/.aliedit/install.log

Fri Dec 17 19:51:41 CST 2010 : Begin to SetStrings
Fri Dec 17 19:51:41 CST 2010 : Successfully SetStrings
Fri Dec 17 19:51:41 CST 2010 : Begin to CheckOS
Fri Dec 17 19:51:41 CST 2010 : OS– x86
Fri Dec 17 19:51:41 CST 2010 : Current user is root
Fri Dec 17 19:51:41 CST 2010 : Current usr, IS_ROOT:1
Fri Dec 17 19:51:41 CST 2010 : Begin to install binary for Firefox
Fri Dec 17 19:51:41 CST 2010 : install -m 0755 lib/libaliedit32.so /root/.mozilla/plugins, result:0
Opera hasnot been installed in current system

其实那一堆二进制码就是libaliedit32.so 这个库文件, 而且放在/root/.mozilla/plugins ,看来chrome 也是可以调用mozilla的扩展。

ipv6,你爸(ipv4)喊你去推墙

这两天gfw 把appspot.com 全部站点一并封了,屏蔽方式是当本地应用通过google主站获得gae应用的域名时在sync,ack后会被强制rst 。不用怀疑现在gfw 肯定升级了。

不过这也逼我使用终极翻墙术 ipv6+hyk-proxy  。我想就ipv6的应用程度和协议的复杂程度应该不会引起裆的注意吧,估计很长时间应该是自由的。linux下需要miredo来启用teredo ipv6隧道 (teredo 是iana规定的可以分到全球单播地址的接口),win平台下直接就集成了该接口启用方法我这里就不讲了。不过miredo不可用在NAT环境下(win平台的好像可以)。

直接敲miredo 就可以创建一个teredo 接口:

teredo    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet6 addr: 2001:0:53aa:64c:0:478d:8b1f:984e/32 Scope:Global
inet6 addr: fe80::ffff:ffff:ffff/64 Scope:Link
UP POINTOPOINT RUNNING NOARP  MTU:1280  Metric:1
RX packets:29037 errors:0 dropped:0 overruns:0 frame:0
TX packets:22141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:33761119 (32.1 Mb)  TX bytes:3499528 (3.3 Mb)

红色的部分说明分到了一个全球单播地址,这个是让人很兴奋的。因为这个地址相当于现在在用的ipv4 公网ip 。话说现在运营商怎么可能给用户一个ipv4的公网地址呢。ping6 ipv6.google.com 通的话就说明没问题了,把hosts文件加进去gfw就形同虚设了,从此自由。

红色下面的是另外一个地址fe80::ffff:ffff:ffff/64 ,这是一个链路本地地址。相当于不能自动分配ipv4的ip地址时 获得的169.254 开头的地址。

另外还有更方便的是直接在DDwrt上配置ipv6 隧道: http://www.dd-wrt.com/wiki/index.php/IPv6#Enabling_IPv6_Support 有空再研究吧。

bash shell中[[ ]]与[ ]的区别

之前都不太搞懂这两个什么区别,感觉不能在这样蒙下去了,还是搞清楚比较好,翻翻书发觉还是很简单的,说白了其实就是前者是内置的运算符,后者是shell 命令。

与此类似的一个问题是() 和(()) 的区别, 前者是用来调整优先级及block分界,后者就是单纯的表示里面的内容是算数运算。

一,[[用”&&”而不是”-a”表示逻辑”与”,用”||”而不是”-o”表示逻辑”或”:

$ [[ 1 < 2 && b > a ]]&&echo true||echo false
true

$ [[ 1 < 2 -a b > a ]]&&echo true||echo false
bash: syntax error in conditional expression
bash: syntax error near `-a’

$ [ 1 < 2 -a b > a ]&&echo true||echo false
true

$ [ 1 < 2 && b > a ]&&echo true||echo false  #wrong syntax
bash: [: missing `]‘
false

二,[ … ]为shell命令,所以在其中的表达式应是它的命令行参数,所以串比较操作符”>” 与”<”必须转义,否则就变成IO改向操作符了。[[中”<“与”>”不需转义:
$  [ 2 \< 10 ]&&echo true||echo false  #you should use “\<”
false

$  [[ 2 < 10 ]]&&echo true||echo false
false

三,[[ … ]]进行算术扩展,而[ … ]不做。
$ [[ 99+1 -eq 100 ]]&&echo true||echo false
true

$ [ 99+1 -eq 100 ]&&echo true||echo false
bash: [: 99+1: integer expression expected
false

$ [ $((99+1)) -eq 100 ]&&echo true||echo false
true

四,[[]]能用正则,而[]不行

[root@test ccc]# [ “test.php” == *.php ] && echo true || echo false
false

[root@test ccc]# [[ “test.php” == *.php ]] && echo true || echo false
true

[root@test ccc]# [[ “t.php” == [a-z].php ]] && echo true || echo false
true

[root@test ccc]# [ “test.php” == “*.php” ] && echo true || echo false
false

[root@test ccc]# [[ “test.php” == “*.php” ]] && echo true || echo false
false

把键盘LED 变成硬盘 LED

非常实用的程序,把键盘上无用的scroll 灯变成硬盘指示灯,免得每次想看的时候我都要弯腰。代码中可以使用kbd 和 X11提供的两种接口来控制LED。

/*
 * To compile:
 *   Console mode: gcc -Wall -O3 -o hddled hddled.c
 *   X mode:       gcc -Wall -O3 -DX -lX11 -o hddled hddled.c
 *
 * Options:
 * -d, --detach               Detach from terminal
 * -r, --refresh=VALUE        Refresh interval (default: 50 ms)
 *
 * Console options:
 * -C, --console=DEVICE       Console device (default: /dev/console)
 *
 * X options:
 * -D, --display=DISPLAY      X display (default: $DISPLAY)
 */

#define PACKAGE_STRING    "hddled 0.2"
#define PACKAGE_BUGREPORT "hddled@very.puzzling.org"

#define VMSTAT "/proc/vmstat"

#define _GNU_SOURCE

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#ifdef X
# include <X11/X.h>
# include <X11/Xlib.h>
# define SCROLL_LOCK 1

/* X display connection */
typedef Display *data_t;
static char *o_display = NULL;

#else
# include 
# include <linux/kd.h>
# include <sys/ioctl.h>
# define CONSOLE "/dev/console"

/* File descriptor */
typedef int data_t;
static char *o_console = NULL;

#endif

const char *argp_program_version = PACKAGE_STRING;
const char *argp_program_bug_address = "";

static unsigned int o_refresh = 50; /* milliseconds */
static int o_detach = 0;

static volatile sig_atomic_t running = 1;
static char *line = NULL;
static size_t len = 0;

/*
static void sig_hdl(int signo){
	remove("/var/run/hddled.lock");
	printf("killed\n");
	exit(0);
}
*/

/* Reread the vmstat file */
int
activity(FILE *vmstat) {
	static unsigned int prev_pgpgin, prev_pgpgout;
	unsigned int pgpgin, pgpgout;
	int found_pgpgin, found_pgpgout;
	int result;

	/* Reload the vmstat file */
	result = TEMP_FAILURE_RETRY(fseek(vmstat, 0L, SEEK_SET));
	if (result) {
		perror("Could not rewind " VMSTAT);
		return result;
	}

	/* Clear glibc's buffer */
	result = TEMP_FAILURE_RETRY(fflush(vmstat));
	if (result) {
		perror("Could not flush input stream");
		return result;
	}

	/* Extract the I/O stats */
	found_pgpgin = found_pgpgout = 0;
	while (getline(&line, &len, vmstat) != -1 && errno != EINTR) {
		if (sscanf(line, "pgpgin %u", &pgpgin))
			found_pgpgin++;
		else if (sscanf(line, "pgpgout %u", &pgpgout))
			found_pgpgout++;
		if (found_pgpgin && found_pgpgout)
			break;
	}
	if (!found_pgpgin || !found_pgpgout) {
		fprintf(stderr, "Could not find required lines in " VMSTAT);
		return -1;
	}

	/* Anything changed? */
	result =
		(prev_pgpgin  != pgpgin) ||
		(prev_pgpgout != pgpgout);
	prev_pgpgin = pgpgin;
	prev_pgpgout = pgpgout;
	return result;
}

/* Update the keyboard LED */
void
led(data_t data, int on) {
	static int current = 1; /* Ensure the LED turns off on first call */
	if (current == on)
		return;

#ifdef X
	{
		static XKeyboardControl control;
		control.led = SCROLL_LOCK;
		control.led_mode = on ? LedModeOn : LedModeOff;
		XChangeKeyboardControl(data, KBLed | KBLedMode, &control);
		XFlush(data);
	}
#else
	{
		unsigned long state;
		ioctl(data, KDGETLED, &state);
		if (on)
			state |= LED_CAP;
		else
			state &= ~LED_CAP;
//		printf("flash:\n");
		ioctl(data, KDSETLED, state);
	}
#endif

	current = on;
}

/* Signal handler -- break out of the main loop */
void
shutdown(int sig) { running = 0;remove("/var/run/hddled.lock"); }

/* Argp parser function */
error_t
parse_options(int key, char *arg, struct argp_state *state) {
	switch (key) {
	case 'd':
		o_detach = 1;
		break;
	case 'r':
		o_refresh = strtol(arg, NULL, 10);
		if (o_refresh < 10)
			argp_failure(state, EXIT_FAILURE, 0,
				"refresh interval must be at least 10");
		break;
#ifdef X
	case 'D':
		o_display = strdup(arg);
		break;
#else
	case 'C':
		o_console = strdup(arg);
		break;
#endif
	}
	return 0;
}

int
main(int argc, char **argv) {
	struct argp_option options[] = {
		{  "detach", 'd',      NULL, 0, "Detach from terminal" },
		{ "refresh", 'r',   "VALUE", 0, "Refresh interval (default: 50 ms)" },
#ifdef X
		{ "display", 'D', "DISPLAY", 0, "X display (default: $DISPLAY)", 1 },
#else
		{ "console", 'C', "DEVICE",  0, "Console device (default: " CONSOLE ")", 1 },
#endif
		{ 0 },
	};
	struct argp parser = {
		NULL, parse_options, NULL,
		"Show hard disk activity using the Scroll Lock LED.",
		NULL, NULL, NULL
	};
	int status = EXIT_FAILURE;
	FILE *vmstat = NULL;
	data_t data = 0;
	struct timespec delay;
	int fd;
	fd=open("/var/run/hddled.lock",O_RDONLY);
	if(fd!=-1){
		printf("already running\n");
		close(fd);
		exit(1);
	}

	fd=open("/var/run/hddled.lock",O_RDWR|O_CREAT,0664);
	if(fd==-1){
		printf("create lock file failed,exit\n");
		exit(1);
	}
	close(fd);
/*
	if(signal(SIGTERM,sig_hdl)==SIG_ERR){
		printf("can't handle SIGTERM\n");
		exit (1);
	}

	if(signal(SIGINT,sig_hdl)==SIG_ERR){
                printf("can't handle SIGINT\n");
                exit (1);
         }
*/
	/* Parse the command-line */
	parser.options = options;
	if (argp_parse(&parser, argc, argv, ARGP_NO_ARGS, NULL, NULL))
		goto out;

	delay.tv_sec = o_refresh / 1000;
	delay.tv_nsec = 1000000 * (o_refresh % 1000);

#ifdef X
	/* Open the X display */
	data = XOpenDisplay(o_display);
	if (data == NULL) {
		if (o_display)
			fprintf(stderr, "Could not open display: %s\n", o_display);
		else
			fprintf(stderr, "Could not open default display\n");
		goto out;
	}
#else
	/* Open the console */
//	data = open(o_console ? o_console : CONSOLE, O_RDONLY);
	data = open("/dev/console",O_NOCTTY);
	if (data < 0) {
		fprintf(stderr, "Could not open console: %s: %s\n",
			o_console ? o_console : CONSOLE, strerror(errno));
		goto out;
	}
#endif

	/* Open the vmstat file */
	vmstat = fopen(VMSTAT, "r");
	if (!vmstat) {
		perror("Could not open " VMSTAT " for reading");
		goto out;
	}

	/* Ensure the LED is off */
	led(data, 0);

	/* Save the current I/O stat values */
	if (activity(vmstat) < 0)
		goto out;

	/* Detach from terminal? */
	if (o_detach) {
		pid_t child = fork();
		if (child < 0) {
			perror("Could not detach from terminal");
			goto out;
		}
		if (child) {
			/* I am the parent */
#ifdef X
			/* Don't close the display on my child */
			data = NULL;
#endif
			status = EXIT_SUCCESS;
			goto out;
		}
	}

	/* We catch these signals so we can clean up */
	{
		struct sigaction action;
		memset(&action, 0, sizeof(action));
		action.sa_handler = shutdown;
		sigemptyset(&action.sa_mask);
		action.sa_flags = 0; /* We block on usleep; don't use SA_RESTART */
		sigaction(SIGHUP, &action, NULL);
		sigaction(SIGINT, &action, NULL);
		sigaction(SIGTERM, &action, NULL);
	}

	/* Loop until signal received */
	while (running) {
		int a;
		if (nanosleep(&delay, NULL) < 0)
			break;
		a = activity(vmstat);
		if (a < 0)
			break;
		led(data, a);
	}

	/* Ensure the LED is off */
	led(data, 0);

	status = EXIT_SUCCESS;

out:
	if (line) free(line);
	if (vmstat) fclose(vmstat);
#ifdef X
	if (data) XCloseDisplay(data);
	if (o_display) free(o_display);
#else
	if (data) close(data);
	if (o_console) free(o_console);
#endif

	return status;
}

这里还有一个内核模式下的LED设置程序:

/*
 *  kbleds.c - Blink keyboard leds until the module is unloaded.
 */

#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>
#include <linux/tty.h>		/* For fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h>		/* For KDSETLED */
#include <linux/console_struct.h>	/* For vc_cons */

MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
MODULE_AUTHOR("Daniele Paolo Scarpazza");
MODULE_LICENSE("GPL");

struct timer_list my_timer;
struct tty_driver *my_driver;
char kbledstatus = 0;

#define BLINK_DELAY   HZ/5
#define ALL_LEDS_ON   0x07
#define RESTORE_LEDS  0xFF

/*
 * Function my_timer_func blinks the keyboard LEDs periodically by invoking
 * command KDSETLED of ioctl() on the keyboard driver. To learn more on virtual
 * terminal ioctl operations, please see file:
 *     /usr/src/linux/drivers/char/vt_ioctl.c, function vt_ioctl().
 *
 * The argument to KDSETLED is alternatively set to 7 (thus causing the led
 * mode to be set to LED_SHOW_IOCTL, and all the leds are lit) and to 0xFF
 * (any value above 7 switches back the led mode to LED_SHOW_FLAGS, thus
 * the LEDs reflect the actual keyboard status).  To learn more on this,
 * please see file:
 *     /usr/src/linux/drivers/char/keyboard.c, function setledstate().
 *
 */

static void my_timer_func(unsigned long ptr)
{
	int *pstatus = (int *)ptr;

	if (*pstatus == ALL_LEDS_ON)
		*pstatus = RESTORE_LEDS;
	else
		*pstatus = ALL_LEDS_ON;

	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
			    *pstatus);

	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);
}

static int __init kbleds_init(void)
{
	int i;

	printk(KERN_INFO "kbleds: loading\n");
	printk(KERN_INFO "kbleds: fgconsole is %x\n", fg_console);
	for (i = 0; i < MAX_NR_CONSOLES; i++) {
		if (!vc_cons[i].d)
			break;
		printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
		       MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
		       (unsigned long)vc_cons[i].d->vc_tty);
	}
	printk(KERN_INFO "kbleds: finished scanning consoles\n");

	my_driver = vc_cons[fg_console].d->vc_tty->driver;
	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);

	/*
	 * Set up the LED blink timer the first time
	 */
	init_timer(&my_timer);
	my_timer.function = my_timer_func;
	my_timer.data = (unsigned long)&kbledstatus;
	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);

	return 0;
}

static void __exit kbleds_cleanup(void)
{
	printk(KERN_INFO "kbleds: unloading...\n");
	del_timer(&my_timer);
	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
			    RESTORE_LEDS);
}

module_init(kbleds_init);
module_exit(kbleds_cleanup);

再提供一个关于LED控制的用户工具
名称:setleds
使用权限:一般使用者
使用方式:
setleds [-v] [-L] [-D] [-F] [{+|-}num] [{+|-}caps] [{+|-}scroll]说明:
用来设定键盘上方三个 LED 的状态。在 Linux 中,每一个虚拟主控台都有独立的设定。
参数:
-F
预设的选项,设定虚拟主控台的状态。
-D
除了改变虚拟主控台的状态外,还改变预设的状态。
-L
不改变虚拟主控台的状态,但直接改变 LED 显示的状态。这会使得 LDE 显示和目前虚拟主控台的状态不符合。我们可以在稍后用 -L 且不含其它选项的 setleds 命令回复正常状态。
-num +num
将数字键打开或关闭。
-caps +caps
把大小写键打开或关闭。
-scroll +scroll
把选项键打开或关闭。
范例:
将数字键打开,其馀二个灯关闭。
# setleds +num -caps -scroll