Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Linux Kernel
After i create device file by calling device_create:
device_create(test_class, parent, devt, test_dev, "%s", "test") 
i can list test file device when using ls command
# ls -l /dev/test
but when i using command:
# cat /dev/test
i get an error:
couldn't found '/dev/test' or address
 
Please explain for me how to solve that problem, thank so much!
Posted 2-Jul-12 21:04pm
Edited 2-Jul-12 21:33pm
v3
Comments
Richard MacCutchan at 3-Jul-12 4:17am
   
Please show the actual output of the ls and cat commands, not your interpretation of what you think they said.
mot sach at 4-Jul-12 3:42am
   
sorry, this is out put:
# ls -l /dev/test
output:
/dev/test
 
# cat /dev/test
output:
cat: can't open '/dev/test': No such device or address
 
i really don't understand difference between calling device_create function and mknod command
Richard MacCutchan at 4-Jul-12 4:05am
   
If that is all you are getting from ls -l then there is something wrong as your device has no connection to anything, it's just a name. If you do not understand device_create then I recommend reading the man pages and doing some Google research.
mot sach at 8-Jul-12 23:54pm
   
this is my source code:

#define DBG_MSG(msg) printk(KERN_INFO "[test] %s %s\n", __FUNCTION__, msg)
 
struct class* test_class;
dev_t devt;
struct device* dev;
static int __init test_init(void)
{
DBG_MSG("enter");
test_class = class_create(THIS_MODULE, "test_class");
if ( IS_ERR(test_class) ) {
printk ( "can't create test class\n" );
class_destroy(test_class);
return PTR_ERR(test_class);
}
//register test device
major = register_chrdev(FPGA_DYNAMIC_MAJOR, "test", &test_fops);
printk ( "[test] %d\n", major );
devt = MKDEV(major, 0);
dev = device_create(test_class, NULL, devt, NULL, "test");
device_register(dev);
DBG_MSG("exit succesfull");
return 0;
}

 
after installed modules, and called mdev -s command, i can read /sys/class/test_class/test/dev, but i can't read /dev/test. Could you help me solve this problem? Thank so much!
Richard MacCutchan at 9-Jul-12 4:10am
   
I already told you: /dev/test does not have a proper entry in the device table - you need to correct it so it is linked to a real device.
mot sach at 10-Jul-12 21:51pm
   
yeah, could you suggest for me how to solve that (sorry because i am newbie), ^_^.
Richard MacCutchan at 11-Jul-12 3:03am
   
Probably by the ln (link) command; it's a while since I did this on Linux.
 
You say you are a newbie, in which case, I strongly suggest you get hold of a good book on Linux and study the subject you are working on. You will never get to be an expert by asking piecemeal questions on forums like this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100