Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know, I can write to a hard disk just using dd command in Linux, such as dd if=/dev/zero of=/dev/sdb.

Since, every device is represented as file in Linux, I wonder what might happen if I intentionally or accidentally write to the audio device or any other device?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Depends on the device.
A user program, when granted access, writes to the device's data interface.
There's also a control interface to the device, which is utilized by the device driver or by ioctl() calls from the user program.

Normally data written to a device cannot affect its control, but there are exceptions such as ESCape control sequences (used by printers and display terminals). Such devices have a simple or no HW control interface (e.g. perhaps a 3-wire serial connection), and sharing the data and control channel is necessary.

Such devices typically use ASCII-coded data, and a control sequence uses the ASCII ESC character as a prefix. Binary data (instead of ASCII text) will probably contain occasional bytes of decimal value 27, so that the subsequent bytes would be treated as a control sequence. So garbage data sent to such a device will produce unpredictable operation.

Other devices, such as audio devices and storage drives, have a much more sophisticated control interface or a protocol for its shared data & control channel (e.g. ATAPI protocol for ATA drives). Data written to the device is always clearly marked as and handled as data, and will not affect the device's operation. Of course, sending garbage data would clobber stored data somewhere on a disk drive. Or output high slew rates (e.g. square waves) to a speaker connected to the audio device.

Writing /dev/zero to an audio device will probably produce maximum negative DC voltage to the speaker, which will sound like a thunk then silence. (Values to the DAC usually use biased representation; 0x8000 is a 16-bit value for zero volts.) Prolonged output may overheat the audio amplifier and speaker's voice coil.

Access to a device's firmware (for rewriting) is typically a protected operation. This would be true for char and block devices.

The previous comments refer to actual HW devices. Writing garbage to special device files such as /dev/mem and /dev/ports will be unpredictable and not advised.

share|improve this answer
add comment

You might erase data, corrupt memory, play some garbage on the sound device, etc... Not something you actually want to do.

For example:

cat /dev/urandom > /dev/audio

Wil play some random noise on the audio device (at least it did in the old times).

share|improve this answer
    
Can I damage my device by doing so, I mean can i write to the device firmware? –  Anwar Sep 15 '12 at 11:04
    
I think that would be unlikely, since device firmware is usually not directly exposed to the operating system (there are some devices that present themselves as a block device that contains a firmware file on it - in that case you could overwrite it by accident) –  Carko Sep 15 '12 at 11:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.