Skip to content

Commit

Permalink
Revert "Add some indexing to block_devices" (osquery#8151)
Browse files Browse the repository at this point in the history
  • Loading branch information
directionless authored Oct 5, 2023
1 parent c8b902f commit ee5490a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
51 changes: 14 additions & 37 deletions osquery/tables/system/linux/block_devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,46 +150,23 @@ QueryData genBlockDevs(QueryContext &context) {
return {};
}

bool runSelectAll(true);

auto constraint_it = context.constraints.find("name");
if (constraint_it != context.constraints.end()) {
std::map<std::string, std::string> lvm_lv2pv;
const auto& constraints = constraint_it->second;
for (const auto& name : constraints.getAll(EQUALS)) {
runSelectAll = false;

struct stat sb;
if (stat(name.c_str(), &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFBLK) {
if (struct udev_device* dev =
udev_device_new_from_devnum(udev, 'b', sb.st_rdev)) {
getBlockDevice(dev, results, lvm_lv2pv);
udev_device_unref(dev);
}
}
struct udev_enumerate* enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "block");
udev_enumerate_scan_devices(enumerate);

std::map<std::string, std::string> lvm_lv2pv;
struct udev_list_entry *devices, *dev_list_entry;
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices) {
const char* path = udev_list_entry_get_name(dev_list_entry);
struct udev_device* dev = udev_device_new_from_syspath(udev, path);
if (path != nullptr && dev != nullptr) {
getBlockDevice(dev, results, lvm_lv2pv);
}
udev_device_unref(dev);
}

if (runSelectAll) {
struct udev_enumerate* enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "block");
udev_enumerate_scan_devices(enumerate);

std::map<std::string, std::string> lvm_lv2pv;
struct udev_list_entry *devices, *dev_list_entry;
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices) {
const char* path = udev_list_entry_get_name(dev_list_entry);
struct udev_device* dev = udev_device_new_from_syspath(udev, path);
if (path != nullptr && dev != nullptr) {
getBlockDevice(dev, results, lvm_lv2pv);
}
udev_device_unref(dev);
}

udev_enumerate_unref(enumerate);
}

udev_enumerate_unref(enumerate);
udev_unref(udev);

return results;
Expand Down
2 changes: 1 addition & 1 deletion specs/posix/block_devices.table
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
table_name("block_devices")
description("Block (buffered access) device file nodes: disks, ramdisks, and DMG containers.")
schema([
Column("name", TEXT, "Block device name", additional=True),
Column("name", TEXT, "Block device name"),
Column("parent", TEXT, "Block device parent name"),
Column("vendor", TEXT, "Block device vendor string"),
Column("model", TEXT, "Block device model string identifier"),
Expand Down

0 comments on commit ee5490a

Please sign in to comment.