Is a device being a block or character device determined purely by hardware?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












From https://unix.stackexchange.com/a/472920/674




A "character device" and "block device" are abstractions, usually used in Unix-style systems in classifying various devices.




Is a device being a block or character device determined by hardware (either device or device controller), device driver, file system, OS kernel I/O subsystem, and/or something else?



I thought they are concepts of purely hardware (either device or device controller), independent of device driver, file system, and OS kernel I/O subsystem.



From Are there implications between block/character device and random/sequential access?




the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis).




Is the buffer cache used by block devices provided by device driver, file systems, or by hardware (either the device or device controller)? If by the hardware, then does it mean that a device being a block or character device is determined purely by hardware (either device or device controller)?



Thanks.










share|improve this question

























    up vote
    2
    down vote

    favorite
    1












    From https://unix.stackexchange.com/a/472920/674




    A "character device" and "block device" are abstractions, usually used in Unix-style systems in classifying various devices.




    Is a device being a block or character device determined by hardware (either device or device controller), device driver, file system, OS kernel I/O subsystem, and/or something else?



    I thought they are concepts of purely hardware (either device or device controller), independent of device driver, file system, and OS kernel I/O subsystem.



    From Are there implications between block/character device and random/sequential access?




    the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis).




    Is the buffer cache used by block devices provided by device driver, file systems, or by hardware (either the device or device controller)? If by the hardware, then does it mean that a device being a block or character device is determined purely by hardware (either device or device controller)?



    Thanks.










    share|improve this question























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      From https://unix.stackexchange.com/a/472920/674




      A "character device" and "block device" are abstractions, usually used in Unix-style systems in classifying various devices.




      Is a device being a block or character device determined by hardware (either device or device controller), device driver, file system, OS kernel I/O subsystem, and/or something else?



      I thought they are concepts of purely hardware (either device or device controller), independent of device driver, file system, and OS kernel I/O subsystem.



      From Are there implications between block/character device and random/sequential access?




      the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis).




      Is the buffer cache used by block devices provided by device driver, file systems, or by hardware (either the device or device controller)? If by the hardware, then does it mean that a device being a block or character device is determined purely by hardware (either device or device controller)?



      Thanks.










      share|improve this question













      From https://unix.stackexchange.com/a/472920/674




      A "character device" and "block device" are abstractions, usually used in Unix-style systems in classifying various devices.




      Is a device being a block or character device determined by hardware (either device or device controller), device driver, file system, OS kernel I/O subsystem, and/or something else?



      I thought they are concepts of purely hardware (either device or device controller), independent of device driver, file system, and OS kernel I/O subsystem.



      From Are there implications between block/character device and random/sequential access?




      the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis).




      Is the buffer cache used by block devices provided by device driver, file systems, or by hardware (either the device or device controller)? If by the hardware, then does it mean that a device being a block or character device is determined purely by hardware (either device or device controller)?



      Thanks.







      io block-device character-device






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 4 at 12:52









      Tim

      23.9k67232418




      23.9k67232418




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          No, it is determined by the OS.




          FreeBSD Architecture Handbook dated 2018-09-23 11:38:04.



          9.4 Block Devices (Are Gone)



          Other UNIX® systems may support a second type of disk device known as block devices. Block devices are disk devices for which the kernel provides caching [...] FreeBSD dropped support for cached disk devices as part of the modernization of the disk I/O infrastructure.




          FreeBSD still has "raw" devices, which are character devices that allow reading and writing disk blocks.



          Do not be confused by the names. Block devices provide buffering - which allows you to read and write in units of bytes. Raw devices are a type of character device - but they require you to read and write in units of blocks. The block size depends on the specific disk hardware.



          "Character devices" were probably originally named after teletype terminals, which physically work one character at a time. Block devices were a specific case where read() and write() interacted with the buffer cache, instead of directly with the device driver. Character devices became the general case, used for every other device file. The interface is flexible, because as well as device-specific read() and write(), it can support arbitrary commands with ioctl().




          https://en.wikipedia.org/wiki/Device_file#Block_devices



          Most systems create both block and character devices to represent hardware like hard disks. FreeBSD and Linux notably do not; the former has removed support for block devices,[6] while the latter creates only block devices. In Linux, to get a character device for a disk one must use the "raw" driver, though one can get the same effect as opening a character device by opening the block device with the Linux-specific O_DIRECT flag.



          Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment. The downside is that because block devices are buffered, the programmer does not know how long it will take before written data is passed from the kernel's buffers to the actual device, or indeed in what order two separate writes will arrive at the physical device. Additionally, if the same hardware exposes both character and block devices, there is a risk of data corruption due to clients using the character device being unaware of changes made in the buffers of the block device.







          share|improve this answer


















          • 1




            I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
            – JdeBP
            Oct 4 at 15:16










          • @JdeBP I an sorry.
            – Tim
            Oct 4 at 15:26






          • 1




            @Tim to represent hardware like hard disks
            – sourcejedi
            Oct 4 at 15:32






          • 1




            @Tim it is not like a hard disk :).
            – sourcejedi
            Oct 4 at 15:34






          • 1




            For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
            – JdeBP
            Oct 4 at 16:27










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473230%2fis-a-device-being-a-block-or-character-device-determined-purely-by-hardware%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          No, it is determined by the OS.




          FreeBSD Architecture Handbook dated 2018-09-23 11:38:04.



          9.4 Block Devices (Are Gone)



          Other UNIX® systems may support a second type of disk device known as block devices. Block devices are disk devices for which the kernel provides caching [...] FreeBSD dropped support for cached disk devices as part of the modernization of the disk I/O infrastructure.




          FreeBSD still has "raw" devices, which are character devices that allow reading and writing disk blocks.



          Do not be confused by the names. Block devices provide buffering - which allows you to read and write in units of bytes. Raw devices are a type of character device - but they require you to read and write in units of blocks. The block size depends on the specific disk hardware.



          "Character devices" were probably originally named after teletype terminals, which physically work one character at a time. Block devices were a specific case where read() and write() interacted with the buffer cache, instead of directly with the device driver. Character devices became the general case, used for every other device file. The interface is flexible, because as well as device-specific read() and write(), it can support arbitrary commands with ioctl().




          https://en.wikipedia.org/wiki/Device_file#Block_devices



          Most systems create both block and character devices to represent hardware like hard disks. FreeBSD and Linux notably do not; the former has removed support for block devices,[6] while the latter creates only block devices. In Linux, to get a character device for a disk one must use the "raw" driver, though one can get the same effect as opening a character device by opening the block device with the Linux-specific O_DIRECT flag.



          Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment. The downside is that because block devices are buffered, the programmer does not know how long it will take before written data is passed from the kernel's buffers to the actual device, or indeed in what order two separate writes will arrive at the physical device. Additionally, if the same hardware exposes both character and block devices, there is a risk of data corruption due to clients using the character device being unaware of changes made in the buffers of the block device.







          share|improve this answer


















          • 1




            I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
            – JdeBP
            Oct 4 at 15:16










          • @JdeBP I an sorry.
            – Tim
            Oct 4 at 15:26






          • 1




            @Tim to represent hardware like hard disks
            – sourcejedi
            Oct 4 at 15:32






          • 1




            @Tim it is not like a hard disk :).
            – sourcejedi
            Oct 4 at 15:34






          • 1




            For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
            – JdeBP
            Oct 4 at 16:27














          up vote
          4
          down vote



          accepted










          No, it is determined by the OS.




          FreeBSD Architecture Handbook dated 2018-09-23 11:38:04.



          9.4 Block Devices (Are Gone)



          Other UNIX® systems may support a second type of disk device known as block devices. Block devices are disk devices for which the kernel provides caching [...] FreeBSD dropped support for cached disk devices as part of the modernization of the disk I/O infrastructure.




          FreeBSD still has "raw" devices, which are character devices that allow reading and writing disk blocks.



          Do not be confused by the names. Block devices provide buffering - which allows you to read and write in units of bytes. Raw devices are a type of character device - but they require you to read and write in units of blocks. The block size depends on the specific disk hardware.



          "Character devices" were probably originally named after teletype terminals, which physically work one character at a time. Block devices were a specific case where read() and write() interacted with the buffer cache, instead of directly with the device driver. Character devices became the general case, used for every other device file. The interface is flexible, because as well as device-specific read() and write(), it can support arbitrary commands with ioctl().




          https://en.wikipedia.org/wiki/Device_file#Block_devices



          Most systems create both block and character devices to represent hardware like hard disks. FreeBSD and Linux notably do not; the former has removed support for block devices,[6] while the latter creates only block devices. In Linux, to get a character device for a disk one must use the "raw" driver, though one can get the same effect as opening a character device by opening the block device with the Linux-specific O_DIRECT flag.



          Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment. The downside is that because block devices are buffered, the programmer does not know how long it will take before written data is passed from the kernel's buffers to the actual device, or indeed in what order two separate writes will arrive at the physical device. Additionally, if the same hardware exposes both character and block devices, there is a risk of data corruption due to clients using the character device being unaware of changes made in the buffers of the block device.







          share|improve this answer


















          • 1




            I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
            – JdeBP
            Oct 4 at 15:16










          • @JdeBP I an sorry.
            – Tim
            Oct 4 at 15:26






          • 1




            @Tim to represent hardware like hard disks
            – sourcejedi
            Oct 4 at 15:32






          • 1




            @Tim it is not like a hard disk :).
            – sourcejedi
            Oct 4 at 15:34






          • 1




            For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
            – JdeBP
            Oct 4 at 16:27












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          No, it is determined by the OS.




          FreeBSD Architecture Handbook dated 2018-09-23 11:38:04.



          9.4 Block Devices (Are Gone)



          Other UNIX® systems may support a second type of disk device known as block devices. Block devices are disk devices for which the kernel provides caching [...] FreeBSD dropped support for cached disk devices as part of the modernization of the disk I/O infrastructure.




          FreeBSD still has "raw" devices, which are character devices that allow reading and writing disk blocks.



          Do not be confused by the names. Block devices provide buffering - which allows you to read and write in units of bytes. Raw devices are a type of character device - but they require you to read and write in units of blocks. The block size depends on the specific disk hardware.



          "Character devices" were probably originally named after teletype terminals, which physically work one character at a time. Block devices were a specific case where read() and write() interacted with the buffer cache, instead of directly with the device driver. Character devices became the general case, used for every other device file. The interface is flexible, because as well as device-specific read() and write(), it can support arbitrary commands with ioctl().




          https://en.wikipedia.org/wiki/Device_file#Block_devices



          Most systems create both block and character devices to represent hardware like hard disks. FreeBSD and Linux notably do not; the former has removed support for block devices,[6] while the latter creates only block devices. In Linux, to get a character device for a disk one must use the "raw" driver, though one can get the same effect as opening a character device by opening the block device with the Linux-specific O_DIRECT flag.



          Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment. The downside is that because block devices are buffered, the programmer does not know how long it will take before written data is passed from the kernel's buffers to the actual device, or indeed in what order two separate writes will arrive at the physical device. Additionally, if the same hardware exposes both character and block devices, there is a risk of data corruption due to clients using the character device being unaware of changes made in the buffers of the block device.







          share|improve this answer














          No, it is determined by the OS.




          FreeBSD Architecture Handbook dated 2018-09-23 11:38:04.



          9.4 Block Devices (Are Gone)



          Other UNIX® systems may support a second type of disk device known as block devices. Block devices are disk devices for which the kernel provides caching [...] FreeBSD dropped support for cached disk devices as part of the modernization of the disk I/O infrastructure.




          FreeBSD still has "raw" devices, which are character devices that allow reading and writing disk blocks.



          Do not be confused by the names. Block devices provide buffering - which allows you to read and write in units of bytes. Raw devices are a type of character device - but they require you to read and write in units of blocks. The block size depends on the specific disk hardware.



          "Character devices" were probably originally named after teletype terminals, which physically work one character at a time. Block devices were a specific case where read() and write() interacted with the buffer cache, instead of directly with the device driver. Character devices became the general case, used for every other device file. The interface is flexible, because as well as device-specific read() and write(), it can support arbitrary commands with ioctl().




          https://en.wikipedia.org/wiki/Device_file#Block_devices



          Most systems create both block and character devices to represent hardware like hard disks. FreeBSD and Linux notably do not; the former has removed support for block devices,[6] while the latter creates only block devices. In Linux, to get a character device for a disk one must use the "raw" driver, though one can get the same effect as opening a character device by opening the block device with the Linux-specific O_DIRECT flag.



          Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment. The downside is that because block devices are buffered, the programmer does not know how long it will take before written data is passed from the kernel's buffers to the actual device, or indeed in what order two separate writes will arrive at the physical device. Additionally, if the same hardware exposes both character and block devices, there is a risk of data corruption due to clients using the character device being unaware of changes made in the buffers of the block device.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 4 at 17:17

























          answered Oct 4 at 15:01









          sourcejedi

          20.6k42888




          20.6k42888







          • 1




            I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
            – JdeBP
            Oct 4 at 15:16










          • @JdeBP I an sorry.
            – Tim
            Oct 4 at 15:26






          • 1




            @Tim to represent hardware like hard disks
            – sourcejedi
            Oct 4 at 15:32






          • 1




            @Tim it is not like a hard disk :).
            – sourcejedi
            Oct 4 at 15:34






          • 1




            For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
            – JdeBP
            Oct 4 at 16:27












          • 1




            I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
            – JdeBP
            Oct 4 at 15:16










          • @JdeBP I an sorry.
            – Tim
            Oct 4 at 15:26






          • 1




            @Tim to represent hardware like hard disks
            – sourcejedi
            Oct 4 at 15:32






          • 1




            @Tim it is not like a hard disk :).
            – sourcejedi
            Oct 4 at 15:34






          • 1




            For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
            – JdeBP
            Oct 4 at 16:27







          1




          1




          I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
          – JdeBP
          Oct 4 at 15:16




          I mentioned this at Tim's earlier question unix.stackexchange.com/questions/471376 too.
          – JdeBP
          Oct 4 at 15:16












          @JdeBP I an sorry.
          – Tim
          Oct 4 at 15:26




          @JdeBP I an sorry.
          – Tim
          Oct 4 at 15:26




          1




          1




          @Tim to represent hardware like hard disks
          – sourcejedi
          Oct 4 at 15:32




          @Tim to represent hardware like hard disks
          – sourcejedi
          Oct 4 at 15:32




          1




          1




          @Tim it is not like a hard disk :).
          – sourcejedi
          Oct 4 at 15:34




          @Tim it is not like a hard disk :).
          – sourcejedi
          Oct 4 at 15:34




          1




          1




          For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
          – JdeBP
          Oct 4 at 16:27




          For the answers to Tim's answer-comment-questions about /dev/tty, see unix.stackexchange.com/questions/447197 , unix.stackexchange.com/questions/446166 , and unix.stackexchange.com/questions/149236 where answerers explain what /dev/tty is.
          – JdeBP
          Oct 4 at 16:27

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473230%2fis-a-device-being-a-block-or-character-device-determined-purely-by-hardware%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?