#compsci ## Device types $ ls -l /dev ``` brw-rw---- 1 root disk 8, 0 Dec 20 20:13 sda crw-rw-rw- 1 root root 1, 3 Dec 20 20:13 null srw-rw-rw- 1 root root 0 Dec 20 20:13 log prw-r--r-- 1 root root 0 Dec 20 20:13 fdata ``` Columns L-R: - permissions - owner - group - major device number - minor device number - timestamp - name Device types: - c - character (These devices transfer data, but one a character at a time. You'll see a lot of pseudo devices (/dev/null) as character devices, these devices aren't really physically connected to the machine, but they allow the operating system greater functionality.) - b - block (These devices transfer data, but in large fixed-sized blocks. You'll most commonly see devices that utilize data blocks as block devices, such as harddrives, filesystems, etc.) - p - [[Piping in Linux|pipe]] (Named pipes allow two or more processes to communicate with each other, these are similar to character devices, but instead of having output sent to a device, it's sent to another process.) - s - socket (Socket devices facilitate communication between processes, similar to pipe devices but they can communicate with many processes at once.) Devices are characterised by their major and minor numbers: - the major number represents the generic type of the device - the minor number tells the kernel which specific device to use ## Common device names ### SCSI Pronounced "scuzzy" - Small Computer System Interface (a protocol used to allow comms between disks, printers, scanners, etc) Have a "sd" prefix Common devices: /dev/sda /dev/sdb ### Pseudo devices e.g /dev/zero, /dev/random, etc ## sysfs sysfs is a virtual filesystem usu mounted to /sys. Both directories /sys and /dev seem to be very similar and they are in some regards, but they do have major differences. Basically, the /dev directory is simple, it allows other programs to access devices themselves, while the /sys filesystem is used to view information and manage the device. ## udev As of today, instead of managing the devices manually, you can use **udev** (userspace /dev). There is a **udevd** daemon that is running on the system and it listens for messages from the kernel about devices connected to the system. Udevd will parse that information and it will match the data with the rules that are specified in **/etc/udev/rules.d**, depending on those rules it will most likely create device nodes and symbolic links for the devices. You can control udev using **udevadm**. ## Listing devices To list devices, use $ lsusb, $ lspci, $lsscsi ## dd dd is a tool that reads input from a file or data stream and writes it to a file or data stream: $ dd if=%inputfile% of=%outputfile% bs=%blocksize% count=%number of blocks to copy% You usu omit count tho