Skip to content

Commit

Permalink
Added ls(pci|usb|cpu) (#30)
Browse files Browse the repository at this point in the history
Fixes #23. Adds `lscpu`, `lspci`, and `lsusb` based on the contents of
the existing `/proc/cpuinfo` and a DigitalOcean droplet.
  • Loading branch information
josephlewis42 authored Dec 24, 2023
1 parent ce70d76 commit dd47316
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
68 changes: 68 additions & 0 deletions commands/lscpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package commands

import (
"fmt"
"strings"

"github.com/josephlewis42/honeyssh/core/vos"
)

var (
// Match procfs.go
lscpuText = strings.TrimSpace(`
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 40 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Vendor ID: GenuineIntel
BIOS Vendor ID: unknown
Model name: unknown
BIOS CPU family: 1
CPU family: 6
Model: 63
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
Stepping: 2
BogoMIPS: 1234.59
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx
fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm pni pclmulqdq dtes64 monitor ds_cpl
vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer
aes xsave avx xsaveopt
Virtualization features:
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
Caches (sum of all):
L1d: 32 KiB (1 instance)
L1i: 32 KiB (1 instance)
L2: 4 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0
`)
)

// Lscpu implements the lscpu command.
func Lscpu(virtOS vos.VOS) int {
cmd := &SimpleCommand{
Use: "lscpu [OPTION...]",
Short: "Display information about the CPU architecture.",

// Never bail, even if args are bad.
NeverBail: true,
}

return cmd.Run(virtOS, func() int {
fmt.Fprintln(virtOS.Stdout(), lscpuText)
return 0
})
}

var _ vos.ProcessFunc = Lscpu

func init() {
addBinCmd("lscpu", Lscpu)
}
47 changes: 47 additions & 0 deletions commands/lspci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package commands

import (
"fmt"
"strings"

"github.com/josephlewis42/honeyssh/core/vos"
)

var (
lspciText = strings.TrimSpace(`
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Red Hat, Inc. Virtio 1.0 GPU (rev 01)
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:05.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI
00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:07.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:08.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
`)
)

// Lspci implements the lspci command.
func Lspci(virtOS vos.VOS) int {
cmd := &SimpleCommand{
Use: "lspci [OPTION...]",
Short: "List PCI devices.",

// Never bail, even if args are bad.
NeverBail: true,
}

return cmd.Run(virtOS, func() int {
fmt.Fprintln(virtOS.Stdout(), lspciText)
return 0
})
}

var _ vos.ProcessFunc = Lspci

func init() {
addBinCmd("lspci", Lspci)
}
36 changes: 36 additions & 0 deletions commands/lsusb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package commands

import (
"fmt"
"strings"

"github.com/josephlewis42/honeyssh/core/vos"
)

var (
lsusbText = strings.TrimSpace(`
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
`)
)

// Lsusb implements the lsusb command.
func Lsusb(virtOS vos.VOS) int {
cmd := &SimpleCommand{
Use: "lspci [OPTION...]",
Short: "List USB devices.",

// Never bail, even if args are bad.
NeverBail: true,
}

return cmd.Run(virtOS, func() int {
fmt.Fprintln(virtOS.Stdout(), lsusbText)
return 0
})
}

var _ vos.ProcessFunc = Lsusb

func init() {
addBinCmd("lsusb", Lsusb)
}
2 changes: 1 addition & 1 deletion core/vos/procfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io/fs"
"time"

"github.com/spf13/afero"
"github.com/josephlewis42/honeyssh/third_party/memmapfs/mem"
"github.com/spf13/afero"
)

type procFile struct {
Expand Down

0 comments on commit dd47316

Please sign in to comment.