#!/bin/sh
TEMP=/c/tmp
cd $TEMP
[ -f $TEMP/lsmod ] || cat > $TEMP/lsmod <<EOF
Module                  Size  Used by
joydev                 24576  0
dm_crypt               40960  1
dm_mod                155648  3 dm_crypt
ip6t_REJECT            16384  1
nf_reject_ipv6         16384  1 ip6t_REJECT
nft_chain_route_ipv6    16384  1
ipt_REJECT             16384  12
nf_reject_ipv4         16384  1 ipt_REJECT
xt_tcpudp              16384  13
xt_state               16384  0
kvm_intel             233472  0
nft_counter            16384  33
xt_conntrack           16384  5
algif_skcipher         16384  0
kvm                   757760  1 kvm_intel
nft_compat             20480  31
af_alg                 28672  1 algif_skcipher
snd_hda_codec_generic    86016  1
nft_chain_route_ipv4    16384  1
irqbypass              16384  1 kvm
snd_hda_intel          49152  3
crct10dif_pclmul       16384  0
crc32_pclmul           16384  0
snd_hda_codec         151552  2 snd_hda_codec_generic,snd_hda_intel
snd_hda_core           94208  3 snd_hda_codec_generic,snd_hda_intel,snd_hda_codec
nft_chain_nat_ipv4     16384  4
snd_hwdep              16384  1 snd_hda_codec
nf_nat_ipv4            16384  1 nft_chain_nat_ipv4
ghash_clmulni_intel    16384  0
virtio_gpu             61440  7
nf_nat                 36864  1 nf_nat_ipv4
snd_pcm               114688  3 snd_hda_intel,snd_hda_codec,snd_hda_core
nf_conntrack          172032  4 xt_conntrack,nf_nat,xt_state,nf_nat_ipv4
9p                     65536  2
ttm                   131072  1 virtio_gpu
pcspkr                 16384  0
serio_raw              16384  0
uinput                 20480  2
nf_defrag_ipv6         20480  1 nf_conntrack
snd_timer              36864  1 snd_pcm
drm_kms_helper        208896  1 virtio_gpu
loop                   36864  2
fscache               385024  1 9p
nf_defrag_ipv4         16384  1 nf_conntrack
9pnet_virtio           20480  2
snd                    94208  12 snd_hda_codec_generic,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_timer,snd_pcm
drm                   495616  10 drm_kms_helper,virtio_gpu,ttm
9pnet                  86016  2 9p,9pnet_virtio
virtio_console         32768  2
libcrc32c              16384  2 nf_conntrack,nf_nat
soundcore              16384  1 snd
qemu_fw_cfg            16384  0
evdev                  28672  9
nf_tables             143360  75 nft_chain_route_ipv4,nft_compat,nft_chain_nat_ipv4,nft_counter,nft_chain_route_ipv6
nfnetlink              16384  2 nft_compat,nf_tables
tirdad                 16384  0
jitterentropy_rng      16384  0
virtio_rng             16384  0
rng_core               16384  1 virtio_rng
ip_tables              28672  0
x_tables               45056  7 xt_conntrack,nft_compat,xt_state,xt_tcpudp,ipt_REJECT,ip_tables,ip6t_REJECT
autofs4                49152  2
ext4                  741376  1
crc16                  16384  1 ext4
mbcache                16384  1 ext4
jbd2                  122880  1 ext4
crc32c_generic         16384  0
fscrypto               32768  1 ext4
ecb                    16384  0
crc32c_intel           24576  3
aesni_intel           200704  2
virtio_net             53248  0
aes_x86_64             20480  1 aesni_intel
net_failover           20480  1 virtio_net
crypto_simd            16384  1 aesni_intel
virtio_blk             20480  2
failover               16384  1 net_failover
cryptd                 28672  4 crypto_simd,ghash_clmulni_intel,aesni_intel
psmouse               172032  0
glue_helper            16384  1 aesni_intel
ata_generic            16384  0
uhci_hcd               49152  0
ata_piix               36864  0
ehci_hcd               94208  0
libata                270336  2 ata_piix,ata_generic
usbcore               294912  2 ehci_hcd,uhci_hcd
virtio_pci             28672  0
scsi_mod              249856  1 libata
virtio_ring            28672  7 virtio_rng,virtio_console,9pnet_virtio,virtio_gpu,virtio_pci,virtio_blk,virtio_net
i2c_piix4              24576  0
usb_common             16384  1 usbcore
virtio                 16384  7 virtio_rng,virtio_console,9pnet_virtio,virtio_gpu,virtio_pci,virtio_blk,virtio_net
floppy                 86016  0
button                 16384  0

EOF

cp /dev/null vda_mods.errs
cp /dev/null vda_mods.elts
cp /dev/null vda_mods.modinfo
grep -v 'tirdad\|pcspkr\|v6\|ip6' $TEMP/lsmod |sort| \
    | sed -e 's/ .*//'|while read elt; do
    lsmod | grep -q ^$elt && continue
    modinfo $elt >> vda_mods.modinfo 2>>vda_mods.errs
    echo $elt>>vda_mods.elts
  done

exit 0
