|
发表于 2007-9-25 21:44:05
|
显示全部楼层
ot@linux-58 scull]# echo ldalkfsajkklj >/dev/scull
[root@linux-58 scull]# cat /dev/scull
enter in read function in module
dev is c7124ad0 and devsize is 14
enter in read function in module1.1
*f_pos is 0 and dev size is 0
*f_pos is 0 and dev size is 14
ldalkfsajkklj
enter in read function in module
dev is c7124ad0 and devsize is 14
enter in read function in module1.1
*f_pos is 14 and dev size is 14
/lib/modules/2.6.6/build M=/phydisk/scull modules
make[1]: Entering directory `/phydisk/linux-2.6.6'
CC [M] /phydisk/scull/main.o
/phydisk/scull/main.c: In function `scull_read':
/phydisk/scull/main.c:324: warning: int format, different type arg (arg 2)
/phydisk/scull/main.c:325: warning: int format, long unsigned int arg (arg 3)
source:
ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
loff_t *f_pos)
{
struct scull_dev *dev = filp->private_data;
struct scull_qset *dptr; /* the first listitem */
int quantum = dev->quantum, qset = dev->qset;
int itemsize = quantum * qset; /* how many bytes in the listitem */
int item, s_pos, q_pos, rest;
ssize_t retval = 0;
// PTRACE();
printk(KERN_ALERT"enter in read function in module\n");
printk(KERN_ALERT"dev is %p and devsize is %lu\n",dev,dev->size);
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
printk(KERN_ALERT"enter in read function in module1.1\n");
printk(KERN_ALERT"*f_pos is %d and dev size is %lu\n",*f_pos,dev->size);
printk(KERN_ALERT"*f_pos is %lld and dev size is %d\n",*f_pos,dev->size);
编译有警告,输出不正常 ,的确像你说的那样
/lib/modules/2.6.6/build M=/phydisk/scull modules
make[1]: Entering directory `/phydisk/linux-2.6.6'
CC [M] /phydisk/scull/main.o
LD [M] /phydisk/scull/scull.o
Building modules, stage 2.
MODPOST
LD [M] /phydisk/scull/scull.ko
make[1]: Leaving directory `/phydisk/linux-2.6.6'
[root@linux-58 scull]# ./scull_load
scullsingle registered at fe00008
sculluid registered at fe00009
scullwuid registered at fe0000a
sullpriv registered at fe0000b
[root@linux-58 scull]# echo "dsaldfkakfjkfddflkkdakl" >/dev/scull
[root@linux-58 scull]# cat /dev/scull
enter in read function in module
dev is c6f78444 and devsize is 24
enter in read function in module1.1
*f_pos is 0 and dev size is 24
dsaldfkakfjkfddflkkdakl
enter in read function in module
dev is c6f78444 and devsize is 24
enter in read function in module1.1
*f_pos is 24 and dev size is 24
[root@linux-58 scull]#
ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
loff_t *f_pos)
{
struct scull_dev *dev = filp->private_data;
struct scull_qset *dptr; /* the first listitem */
int quantum = dev->quantum, qset = dev->qset;
int itemsize = quantum * qset; /* how many bytes in the listitem */
int item, s_pos, q_pos, rest;
ssize_t retval = 0;
// PTRACE();
printk(KERN_ALERT"enter in read function in module\n");
printk(KERN_ALERT"dev is %p and devsize is %d\n",dev,dev->size);
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
printk(KERN_ALERT"enter in read function in module1.1\n");
printk(KERN_ALERT"*f_pos is %lld and dev size is %lu\n",*f_pos,dev->size);
if (*f_pos >= dev->size)
goto out;
编译正常,输出正常
source:
ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
loff_t *f_pos)
{
struct scull_dev *dev = filp->private_data;
struct scull_qset *dptr; /* the first listitem */
int quantum = dev->quantum, qset = dev->qset;
int itemsize = quantum * qset; /* how many bytes in the listitem */
int item, s_pos, q_pos, rest;
ssize_t retval = 0;
// PTRACE();
printk(KERN_ALERT"enter in read function in module\n");
printk(KERN_ALERT"dev is %p and devsize is %lu\n",dev,dev->size);
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
printk(KERN_ALERT"enter in read function in module1.1\n");
printk(KERN_ALERT"*f_pos is %lld and dev size is %d\n",*f_pos,dev->size); |
|