Skip to content

Instantly share code, notes, and snippets.

@joseivanlopez
Last active July 22, 2026 15:48
Show Gist options
  • Select an option

  • Save joseivanlopez/572da37e41ca563d8b97e42c312b28fe to your computer and use it in GitHub Desktop.

Select an option

Save joseivanlopez/572da37e41ca563d8b97e42c312b28fe to your computer and use it in GitHub Desktop.

More options to search

I propose to do all the following (not everthing at once)

Adding more first-level criteria

We can add driver or transport to drive (which currently supports size and name).

We can add id to partition (which currently supports size, name and number).

And so on for logical volumes names and types, etc.

Adding and and or to combine conditions

It would look like this:

{
  "search": {
    "condition": {
      "and": [
        { "transport": "scsi" },
        { "size": { "less": "1TiB" } }
      ]
    }
  }
 }

An open questions about enums

Let's say I want to check whether the transport is "scsi" or "usb". There is an obvious way that is using or like this:

{
  "search": {
    "condition": {
      "or": [
        { "transport": "scsi" },
        { "transport": "usb" }
      ]
    }
  }
 }

But I wonder whether we should also add a syntax with an array like this:

{
  "search": {
    "condition": {
      "transport": ["scsi", "usb"]
    }
  }
 }

Adding not to invert conditions

Right now, if you want to skip a disk that matches a condition, you need an empty drive entry. For example, let's say you want to make sure USB disks are ignored. I fear then you need something like this:

{
  "storage": {
    "drives": [
      {
        "search": { "condition": { "transport": "usb" } },
        "alias": "thisMatchesTheDisksIWantToIgnore"
      },
      {
        "alias": "thisIsTheRealDriveEntryWithMyConfig"
        "partitions": [{ "search": "*", "delete": true }]
      }
    ],
  }
}

Having not would make this case more natural.

{
  "storage": {
    "drives": [
      {
        "search": { "condition": { "not": { "transport": "usb" } } },
        "alias": "thisIsTheRealDriveEntryWithMyConfig",
        "partitions": [{ "search": "*", "delete": true }]
      }
    ],
  }
}

Having not is also beneficial for filesystems (keep reading).

Checking for filesystems presence or properties

Add a filesystem field that can be true or a condition with type, label, and, or or not.

That is, checking whether the device is formatted:

{
  "search": {
    "condition": {
      "filesystem": true
    }
  }
}

Checking that is not formatted:

{
  "search": {
    "condition": {
      "not": { "filesystem": true }
    }
  }
}

Checking that is formatted as XFS.

{
  "search": {
    "condition": {
      "filesystem": { "type": "xfs" }
    }
  }
}

Checking that is formatted, but not as XFS.

{
  "search": {
    "condition": {
      "filesystem": { "not": { "type": "xfs" } }
    }
  }
}

Checking that is not formatted as XFS.

{
  "search": {
    "condition": {
      "not": { "filesystem": { "type": "xfs" } }
    }
  }
}

Searching with drives by their partitions

Would also work similarly for searching VGs based on their LVs or any other "collection".

It would work by adding a partitions key that can contain: "some", "none" or an object.

The object form has the fields min, max or condition (it must contain at least one of them). If condition is omitted, then it matches any partition. If both min and max are omitted, then it means "all partitions in the drive". The value for min and max has to be bigger than 0.

If partitions is an object, then it assumes there should be at least one partition.

Checking whether there are no partitions

{
  "search": {
    "condition": {
      "partitions": "none"
    }
  }
}

Checking whether there are some partitions (at least one)

{
  "search": {
    "condition": {
      "partitions": "some"
    }
  }
}

equivalent to:

{
  "search": {
    "condition": {
      "partitions": { "min": 1 }
    }
  }
}

Checking if all partitions matches a condition (it does not matches if there are no partitions)

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "size": {
            "greater": "10 GiB"
          }
        }
      }
    }
  }
}

Checking if at least one partitions matches a condition

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "size": {
            "greater": "10 GiB"
          },
          "min": 1
        }
      }
    }
  }
}

Checking if exactly 2 partitions matches a condition

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "size": {
            "greater": "10 GiB"
          },
          "min": 2,
          "max": 2
        }
      }
    }
  }
}

Checking if at least 2 partition and maximum 3 partitions matches a condition

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "size": {
            "greater": "10 GiB"
          },
          "min": 2,
          "max": 3
        }
      }
    }
  }
}

Checking if none of the partition matches a condition (it does not matches if there are no partitions)

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "not": {
            "size": {
              "greater": "10 GiB"
            }
          }
        }
      }
    }
  }
}

Checking if at least one partition does not match a condition

{
  "search": {
    "condition": {
      "partitions": {
        "condition": {
          "not": {
            "size": {
              "greater": "10 GiB"
            }
          }
        },
        "min": 1
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment