Reasonably filtered list of disks (block devices)

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











up vote
0
down vote

favorite












I am trying to improve an installation script with interactive selection of source and destination disks. It currently gets the list of entries from /sys/block and filters it through sr[0-9]|sd[a-z]|hd[a-z]|scd[0-5] — effecively excluding other appropriate types of devices. My idea was to remove the hardcoded mask and approach with more general method. As an example of satisfying result, lsblk works as needed by default, and I thought it will be that simple to merely look into its sources to copy the logic, but that was not the case as it turned out.



According to set_cxt() function, the device is excluded if it has size of zero, or is non-SCSI, which in turn is checked by sysfs_blkdev_scsi_get_hctl() — the one I could not get totally through: it is supposed to inspect something (namely, HCTL — Host, Channel, Target, LUN) in the device subtree, which is probably represented by scsi_device and scsi_disk directories, however there is no scsi at all in hda subtree of a memory card device, for example, neither there is a device subtree in etherd!e42.0 of an ATA-over-Ethernet storage, yet they are included in lsblk output by default.



What else may one check to reliably filter out dummy devices like ram15? Those are pre-created in big numbers, having size > 0 and ro = 0, making it hard to distinguish them from regular disks. In simple terms, the result should ideally be identical to lsblk -d -n -o NAME — as a last resort I will just parse that output, but I just wanted to understand the things better myself.










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am trying to improve an installation script with interactive selection of source and destination disks. It currently gets the list of entries from /sys/block and filters it through sr[0-9]|sd[a-z]|hd[a-z]|scd[0-5] — effecively excluding other appropriate types of devices. My idea was to remove the hardcoded mask and approach with more general method. As an example of satisfying result, lsblk works as needed by default, and I thought it will be that simple to merely look into its sources to copy the logic, but that was not the case as it turned out.



    According to set_cxt() function, the device is excluded if it has size of zero, or is non-SCSI, which in turn is checked by sysfs_blkdev_scsi_get_hctl() — the one I could not get totally through: it is supposed to inspect something (namely, HCTL — Host, Channel, Target, LUN) in the device subtree, which is probably represented by scsi_device and scsi_disk directories, however there is no scsi at all in hda subtree of a memory card device, for example, neither there is a device subtree in etherd!e42.0 of an ATA-over-Ethernet storage, yet they are included in lsblk output by default.



    What else may one check to reliably filter out dummy devices like ram15? Those are pre-created in big numbers, having size > 0 and ro = 0, making it hard to distinguish them from regular disks. In simple terms, the result should ideally be identical to lsblk -d -n -o NAME — as a last resort I will just parse that output, but I just wanted to understand the things better myself.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to improve an installation script with interactive selection of source and destination disks. It currently gets the list of entries from /sys/block and filters it through sr[0-9]|sd[a-z]|hd[a-z]|scd[0-5] — effecively excluding other appropriate types of devices. My idea was to remove the hardcoded mask and approach with more general method. As an example of satisfying result, lsblk works as needed by default, and I thought it will be that simple to merely look into its sources to copy the logic, but that was not the case as it turned out.



      According to set_cxt() function, the device is excluded if it has size of zero, or is non-SCSI, which in turn is checked by sysfs_blkdev_scsi_get_hctl() — the one I could not get totally through: it is supposed to inspect something (namely, HCTL — Host, Channel, Target, LUN) in the device subtree, which is probably represented by scsi_device and scsi_disk directories, however there is no scsi at all in hda subtree of a memory card device, for example, neither there is a device subtree in etherd!e42.0 of an ATA-over-Ethernet storage, yet they are included in lsblk output by default.



      What else may one check to reliably filter out dummy devices like ram15? Those are pre-created in big numbers, having size > 0 and ro = 0, making it hard to distinguish them from regular disks. In simple terms, the result should ideally be identical to lsblk -d -n -o NAME — as a last resort I will just parse that output, but I just wanted to understand the things better myself.










      share|improve this question













      I am trying to improve an installation script with interactive selection of source and destination disks. It currently gets the list of entries from /sys/block and filters it through sr[0-9]|sd[a-z]|hd[a-z]|scd[0-5] — effecively excluding other appropriate types of devices. My idea was to remove the hardcoded mask and approach with more general method. As an example of satisfying result, lsblk works as needed by default, and I thought it will be that simple to merely look into its sources to copy the logic, but that was not the case as it turned out.



      According to set_cxt() function, the device is excluded if it has size of zero, or is non-SCSI, which in turn is checked by sysfs_blkdev_scsi_get_hctl() — the one I could not get totally through: it is supposed to inspect something (namely, HCTL — Host, Channel, Target, LUN) in the device subtree, which is probably represented by scsi_device and scsi_disk directories, however there is no scsi at all in hda subtree of a memory card device, for example, neither there is a device subtree in etherd!e42.0 of an ATA-over-Ethernet storage, yet they are included in lsblk output by default.



      What else may one check to reliably filter out dummy devices like ram15? Those are pre-created in big numbers, having size > 0 and ro = 0, making it hard to distinguish them from regular disks. In simple terms, the result should ideally be identical to lsblk -d -n -o NAME — as a last resort I will just parse that output, but I just wanted to understand the things better myself.







      linux block-device lsblk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 15 mins ago









      Anton Samsonov

      1977




      1977

























          active

          oldest

          votes











          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%2f475151%2freasonably-filtered-list-of-disks-block-devices%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475151%2freasonably-filtered-list-of-disks-block-devices%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?