Click here to Skip to main content
11,803,861 members (78,994 online)
Rate this: bad
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 20:04pm
Edited 2-Jul-12 20:33pm
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

# cat /dev/test
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)
test_class = class_create(THIS_MODULE, "test_class");
if ( IS_ERR(test_class) ) {
printk ( "can't create test class\n" );
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");
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 450
1 CPallini 320
2 F-ES Sitecore 240
3 Sergey Alexandrovich Kryukov 234
4 CHill60 220
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2015
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