Tag Info

Hot answers tagged

48

One reason is that block level access is a bit lower level than ls would be able to work with. /dev/cdrom, or dev/sda1 may be your CD ROM drive and partition 1 of your hard drive, respectively, but they aren't implementing ISO 9660 / ext4 - they're just RAW pointers to those devices known as Device Files. One of the things mount determines is HOW to use ...


15

Basically, and to put it easily, the operating system needs to know how to access the files on that device. mount is not only "giving you access to the files", it's telling the OS the filesystem the drive has, if it's read only or read/write access, etc. /dev/cdrom is a low-level device, the operating system functions wouldn't know how to access them... ...


15

You cannot easily do that. You might consider writing your own kernel module providing such a device. I don't recommend that. You could write a tiny C program writing an infinite stream of same bytes on some pipe (or on stdout) or FIFO. You could use tr(1) to read from /dev/zero and translate every 0 byte to somethng else. You could use perhaps yes(1), ...


14

They're device nodes: In Unix-like operating systems, a device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file. [...] They allow software to interact with a device driver using standard input/output system calls, which simplifies many tasks and unifies user-space I/O ...


13

The following bash code is set to work with the byte being representred in binary. However you can easily change it to handle ocatal, decimal or hex by simply changing the radix r value of 2 to 8, 10 or 16 respectively and setting b= accordingly. r=2; b=01111110 printf -vo '\\%o' "$(($r#$b))"; </dev/zero tr '\0' "$o" EDIT - It does handle the full ...


12

There are various alternatives to udev out there. Seemingly Gentoo can use something called mdev. Another option would be to attempt to use udev's predecessor devfsd. Finally, you can always create all the device files you need with mknod. Note that with the latter there is no need to create everything at boot time since the nodes can be created on disk and ...


10

Well, if you literally want to achieve this, you can use a LD_PRELOAD hook. The basic idea is to rewrite a function from the C library and use it instead of the normal one. Here is a simple example where we override the read() function to XOR the output buffer with 0x42. #define _GNU_SOURCE #include <string.h> #include <errno.h> #include ...


9

Modern Linux kernels support the devtmpfs file system (do not confuse with ancient devfs), which creates all device nodes dynamically as soon as the kernel discovers them. (In fact, latest udev releases require this; you'll find that udev doesn't create any device nodes anymore, only symlinks.) Similarly, firmware loading has been moved into the kernel as ...


9

Because access to the underlying device is controlled only by file permissions by default, so if your USB stick contains a POSIX filesystem with a world-writable device node corresponding to a real device in the system, you can use that device node to access the corresponding device as a "plain" user. Imagine a device corresponding to one of the audio ...


8

You can read or write /dev/cdrom (eg, using dd or cat) but when you do that you are just reading or writing the raw bytes of the device. That can be useful in various circumstances (like cloning a partition), but generally we want to see the directories and files stored on the device. When you mount a device you're basically telling the kernel to use a ...


7

For consistency Imagine you have some partitions on the first hard drive in your system. For example, /dev/sda2. You later decide that the drive isn't large enough so you purchase a second one and add it to the system. All of a sudden, that becomes /dev/sda and your current drive becomes /dev/sdb. Your partition is now /dev/sdb2. Using your proposed ...


6

When fsck runs, it should first try to locate the superblock of a filesystem to begin traversing the filesystem's structure in order to validate it. Since the /dev/sda device corresponds to whole drive, the first portion of the disk will likely contain the partition table or Master Boot Record and fsck will not be able to locate the superblock for a ...


6

For tcp, just checking $?. If connection failed, $? won't be 0: $ >/dev/tcp/google.com/81 bash: connect: Network is unreachable bash: /dev/tcp/google.com/81: Network is unreachable $ echo $? 1 It will take time for bash to realize that the connection failed. You can use timeout to trigger bash: $ timeout 1 bash -c '>/dev/tcp/google.com/80' ...


6

You cannot mmap() /dev/random or /dev/urandom. Nor can you seek() them for that matter. And as a general rule, you cannot mmap() unseekable things. Pipes are another example of things you cannot mmap() because they are not seekable. /dev/random and /dev/urandom are fundamentally stream-based, sequential access, devices. They produce bytes on demand when you ...


6

Device files on Unix systems in general are just one way for user programs to access device drivers; there isn't a one-to-one mapping from devices files to physical hardware, and not all hardware has a device file (or even a device driver). The kernel itself doesn't use device files to interact with hardware. As pointed out by lcd047, network cards don't ...


6

It's kind of pointless to try and bitmask/xor zero bytes, isn't it? Taking a byte and xoring it with zero is a no-op. Just create a loop that gives you the bytes you want and put it behind a pipe or named pipe. It'll behave pretty much the same as a character device (won't waste CPU cycles when idle): mkfifo pipe while : ; do echo -n "a"; done > pipe ...


5

/dev/cdrom refers to a device file. This is not the contents of whatever disc you might wish to insert into your optical drive, but rather it is a reference to the bit of hardware (and probably software drivers) that you might call on to show that to you. When you mount /dev/cdrom to some path in your tree you attach its contents to your file system. The ...


5

I think about this in the following manner: mount is a tool that tells the system to interpret the contents of some files as directory trees. The filesystem has directories and files, and each file is a label for some string of bytes. /dev/cdrom is a file, it represents the string of bytes stored on the CD. You can read this very long string directly, but ...


5

There are several advantages to the current arrangement. They can be grouped into advantages of block special files and advantages of mountpoints. Special files are files that represent devices. One of the Ideas that unix was built on is everything is a file. This makes many things simple, for example user interaction is just file reads and writes on a tty ...


4

Not every file under /dev is a device file that has major/minor numbers. Example $ ls -l |grep initctl prw-------. 1 root root 0 Sep 17 13:27 initctl $ stat initctl File: ‘initctl’ Size: 0 Blocks: 0 IO Block: 4096 fifo Device: 5h/5d Inode: 8882 Links: 1 Access: (0600/prw-------) Uid: ( 0/ root) Gid: ...


4

It won't work, if the filesystem was installed in a partition (e. g. sda1). fsck and its brethren are tools for performing maintenance on filesystems (hence the name: filesystem ccheck), not of block devices. It is, I suppose, theoretically possible to put a filesystem directly onto a block device by way of something like mke2fs -j /dev/sda, but this is ...


4

The /sys filesystem (sysfs) contains files that provide information about devices: whether it's powered on, the vendor name and model, what bus the device is plugged into, etc. It's of interest to applications that manage devices. The /dev filesystem contains files that allow programs to access the devices themselves: write data to a serial port, read a ...


4

I'd call it historical reasons. Not that the other answers are wrong, but there's a bit more to the story. Compare Windows: Windows started as a single-computer, single-user OS. That single computer probably had one floppy drive and one hard drive, no network connection, no USB, no nothing. (Windows 3.11 had native networking capabilities; Windows 3.1 ...


4

Historical reasons. Originally, before devfs existed, these device files were created by hand or by a script called MAKEDEV. This is also why many drivers have a fixed device number assignment; because the device numbers had to be known so that the device files would work properly. There aren't really any common use cases for the mknod command on modern ...


4

In terms of speed, the fastest I found was: $ PERLIO=:unix perl -e '$s="\1" x 65536; for(;;){print $s}' | pv -a > /dev/null [4.02GiB/s] For comparison: $ tr '\0' '\1' < /dev/zero | pv -a > /dev/null [ 765MiB/s] $ busybox tr '\0' '\1' < /dev/zero | pv -a > /dev/null [ 399MiB/s] $ yes $'\1' | tr -d '\n' | pv -a > /dev/null [26.7MiB/s] ...


3

I would set the group of the repetierHost application to uucp and then set the SGID bit (as long as it is a real binary and not script): chgrp uucp repetierHost chmod g+s repetierHost If the repetierHost is a script you could consider moving that to repetierHost.sh and write a small C programming wrapper repetierHost that calls repetierHost.sh E.g.: ...


3

On Debian typically the selected syslogd package takes care of creating the /dev/xconsole pipe. You probably have rsyslog installed; look at the /etc/init.d/rsyslog script and search for create_xconsole which is the shell function that creates /dev/xconsole; it's trivial to modify that to create a second file.


3

I’ve been able to do this with an udev rule, after some trickery (and using lsusb to find out the vendor and product ID of the device in flash mode): $ cat /etc/udev/rules.d/nxt.rules # disable NXT in flash mode ACTION=="add", ATTR{idVendor}=="03eb", ATTR{idProduct}=="6124", RUN="/bin/sh -c '/bin/echo -n $kernel:1.0 | /usr/bin/tee ...


3

Yes. The camera light will be on while the camera is in use. In this case, Motion is taking the feed and streaming it through the Motion web server. This happens whether or not people are connected to your stream. Assuming you're only using Motion I would edit the motion.conf in order to add authentication for the stream and also enable logging (to see ...


3

I'm never quite sure if spelunking in sysfs is the best way to do things (am I supposed to use udevadm?), but at least it's discoverable $ DEV=p8p1 $ readlink /sys/class/net/$DEV/device/driver ../../../../bus/pci/drivers/tg3 It won't work for devices like lo which are "virtual" (/sys/devices/virtual/). They don't have the link to an underlying device ...



Only top voted, non community-wiki answers of a minimum length are eligible