
* Fix: don't need sudo if we're root + other aesthetics
* Heavy refactoring, see PR #28
* Fix: avoid silent fatalities
demo: https://tcp.ac/i/JMSUc.gif
* Fix: Inverse check on `IsRoot`
* D.R.Y: check for permissions error in `common.ErrorCheck`
Reduce cognitive complexity.
* Fix: Issue with copying
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646535918
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646606680 and https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646594105
* Revert "Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646606680 and https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646594105"
This reverts commit ce15213009
.
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646730751
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package configs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/HikariKnight/quickpassthrough/internal/common"
|
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
|
)
|
|
|
|
// This function adds the disable vfio video output on host option to the config
|
|
// The function will use the given int as the value for the option
|
|
func DisableVFIOVideo(i int) {
|
|
// Get the config
|
|
config := GetConfig()
|
|
|
|
// Write to logger
|
|
logger.Printf("Adding vfio_pci.disable_vga=%v to %s\n", i, config.Path.CMDLINE)
|
|
|
|
// Get the current kernel arguments we have generated
|
|
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
|
|
|
// If the kernel argument is already in the file
|
|
if strings.Contains(kernel_args, "vfio_pci.disable_vga") {
|
|
// Remove the old file
|
|
err := os.Remove(config.Path.CMDLINE)
|
|
common.ErrorCheck(err, fmt.Sprintf("Could not rewrite %s", config.Path.CMDLINE))
|
|
|
|
// Enable or disable the VGA based on our given value
|
|
if i == 0 {
|
|
kernel_args = strings.Replace(kernel_args, "vfio_pci.disable_vga=1", "vfio_pci.disable_vga=0", 1)
|
|
|
|
} else {
|
|
kernel_args = strings.Replace(kernel_args, "vfio_pci.disable_vga=0", "vfio_pci.disable_vga=1", 1)
|
|
}
|
|
|
|
// Rewrite the kernel_args file
|
|
fileio.AppendContent(kernel_args, config.Path.CMDLINE)
|
|
} else {
|
|
// Add to the kernel arguments that we want to disable VFIO video output on the host
|
|
fileio.AppendContent(
|
|
fmt.Sprintf(
|
|
" vfio_pci.disable_vga=%v", i,
|
|
),
|
|
config.Path.CMDLINE,
|
|
)
|
|
}
|
|
}
|