Unable to write on /dev/* files

kernel module write function
kernel module read
kernel driver read
test character device
simple character driver example linux
linux driver example
scull char device driver
character device driver projects

I'm writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows:

  1. alloc_chrdev_region() -> to use dynamic allocation of major number
  2. class_create() -> to create device class in sysfs
  3. device_creat() -> to create device under /dev/
  4. cdv_init() -> to initialize char device structure
  5. cdev_add() -> to add my device structure in kernel

I have added read, write, open, release methods in code.

When I try to read device file under /dev/ my read method is called. But when I try to write on /dev/ file using echo it gives error

"bash: /dev/scull: Permission denied"

I have checked permissions of file using ls -l, and I have permissions to read or write on this file.

This problem occurs for every device driver module I have written. It works well in on another machine.

I'm working on ubuntu 15.10, custom compiled kernel 4.3.0

  1. the result of ls -l /dev/scull:

    crw------- 1 root root 247, 0 Dec 30 18:06 /dev/scull
  2. the exact command I used to open the file

    $ sudo echo 54 > /dev/scull
  3. the source code for the open implementation

    ssize_t scull_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos){
         pr_alert("Device Written\n");
         return 0;

Behavior I'm seeking here is, I should be able to see 'Device Written' in dmesg ouput?

I assume that you are normally not root on your bash shell. Then this command line

sudo echo 54 > /dev/scull

does not what you think. The command is executed in two steps:

  1. The bash setups the output redirection, i.e., it tries to open /dev/scull with the current user privileges.
  2. The command sudo echo 54 is executed whereas stdout is connected to the file.

As you have no write-permissions as non-root user, the first step fails and the bash reports

"bash: /dev/scull: Permission denied"

You must already be root to setup the output redirection. Thus execute

sudo -i

which gives you an interactive shell with root privileges. The you can execute

echo 54 > /dev/scull

within that root shell.

usb, First try the command sudo hdparm -r0 /dev/sdb (method taken from another askubuntu answer). Then try remounting rw the partition. If these  Files are not only using up your disk space, but they are also using disk inodes which hold information about them. In practice, if you keep a lot of big files most likely, you will run out of space. But, if you have a lot of very small files most likely, you will run out of inodes. Even though, there will be still potential free space on your drive.

I know the thread is too old to answer but just in case if someone wants to know alternative method without switching to root user, here is the solution:

sudo bash -c 'echo "54" > /dev/my_dev'

fdisk: Unable to write /dev/sdg: Bad file descriptor – error while , How to format and a USB disk which was mounted in write-protected mode and shows the below error while trying to run fdisk: fdisk: Unable to write /dev/sdg:  fdisk: Unable to write /dev/sdg: Bad file descriptor. Solution. 1. The disk in this example is /dev/sxx. Disable read-only mode on the USB disk first.

I wanted to note that on your system only root (file owner) has read / write permissions. Your (normal) user account has not! So another (fast) solution would be to give all users read / write permissions.

Probably this is not the safest solution! Only do this in your test environment!

sudo chmod a+rw /dev/scull

But now you test your module with your user account (without sudo)

echo "hello, world!" > /dev/scull cat < /dev/scull

8 Tips to Solve Linux & Unix Systems Hard Disk Problems: Like Disk , Can't write to the hard disk on a Linux or Unix-like systems? rsync --remove-​source-files -azv /ftpusers/tmp/*.mov /mnt/usbdisk/ rsync remove disk from an array md0 ## mdadm --manage /dev/md0 --fail /dev/sdb1 mdadm  /dev/ is a special directory for device files. These are abstractions, they are not real files on disk. These are abstractions, they are not real files on disk. The directory is populated at boot and subject to change to reflect existing device interfaces, which are created and destroyed by the kernel and a userspace daemon, udevd .

You can do so while going root with the command

sudo su

and then going into the /dev folder and enter your command (to save data into /dev/scull).

cd /dev
echo 54 > scull

AUUGN, The security also affects the sharing of files for processes that are at different security call syslog, which is trusted to write to /dev/console at the appropriate level. One particular problem we found was that we were unable to run a word​  A write-protected hard drive allows you to access the data in it (if the drive is not corrupt), but you cannot write or paste new files and folders, which makes the drive literally unusable. To make it usable, you must remove write protection from the hard drive.

IBM PowerHA SystemMirror V7.2.1 for IBM AIX Updates, Example 4-21 The /var/adm/ras/syslog.caa file showing repository disk failure and not open cluster repository device /dev/rhdisk1: 5 Nov 12 09:13:30 primo_s2_n1 cl_chrepos.c destroy_old_repository 350 1 Failed to write repository data. In other words, the device files are themselves incapable of anything until they are supported by the underlying drivers. In fact, you can treat the device files to be an abstraction of the underlying driver! So, no driver, no use of device file :

"Input/output error" when accessing a directory, If the disc or the connection to it is failing, it'll be noted there. As I recall, the legacy ntfs driver had no stable write support and was You can issue a surface scan of your disk from Linux /sbin/badblocks /dev/sda . Inside the hard drive, I did a mkdir to create a directory and then moved some files to it,  Fix Unable to access "volume" Ubuntu issue. If you are dual booting your ubuntu operating system with Windows 8, you m Unable to access your drive or volume.

-bash: /dev/null: Permission denied, Someone evidently moved a regular file to /dev/null. for a Linux kernel;; chmod is setting the permissions for all users to be able to read and write to /dev/null . /dev/sr0 is read-only filesystem? I used to be able to do "dd if=xxx.iso of=/dev/sr0". Somewhere along the line this has gotten changed/broken and it now resolutely says that /dev/sr0 is a read-only filesystem.

  • Permission denied means you don't have permission to do the action. If you sudo it, it will get past that message. Most likely you need to update your udev rules to run it without sudo.
  • Thanks @Dom . but I already used sudo before echo command. And it still shows same error
  • they are special file and nobody can touch them,
  • Please edit your question and add the following information: 1. the result of ls -l /dev/null_driver 2. the exact command you used to open the file. 3. the source code for your file operations in the kernel driver, especially the open implementation
  • As you can see from my question file permission is crw-------. I have changed this permission to crw----rwx and its working fine now.
  • Thanks @Martin that solved my problem. Can you tell me how to come back to non-root prompt?
  • Got it its sudo -i -u <username>.
  • @hiabcwelcome No, this command opens another sub-shell. Press CTRL+D or type the exit command instead.