Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Created December 26, 2020 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhenakh/d76adb669deec2d4db3816dd76d5d0e7 to your computer and use it in GitHub Desktop.
Save akhenakh/d76adb669deec2d4db3816dd76d5d0e7 to your computer and use it in GitHub Desktop.
spice-gtk.diff compile spice-gtk 0.39 on osx m1
diff --git a/src/cd-scsi.h b/src/cd-scsi.h
index 6351f4a..feb935e 100644
--- a/src/cd-scsi.h
+++ b/src/cd-scsi.h
@@ -26,6 +26,8 @@
#include "cd-usb-bulk-msd.h"
#include "scsi-constants.h"
+#include <CoreFoundation/CoreFoundation.h>
+
#if defined(G_OS_WIN32)
#include <winsock2.h>
#include <windows.h>
@@ -35,6 +37,11 @@
#define htobe32(x) htonl(x)
#endif
+#define be32toh(x) CFSwapInt32BigToHost(x)
+#define htobe32(x) CFSwapInt32HostToBig(x)
+#define le32toh(x) CFSwapInt32LittleToHost(x)
+#define htole32(x) CFSwapInt32HostToLittle(x)
+
typedef enum ScsiXferDir {
SCSI_XFER_NONE = 0, /* TEST_UNIT_READY, ... */
SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
diff --git a/src/cd-usb-bulk-msd.h b/src/cd-usb-bulk-msd.h
index e2a0e52..be2abd4 100644
--- a/src/cd-usb-bulk-msd.h
+++ b/src/cd-usb-bulk-msd.h
@@ -21,6 +21,7 @@
#pragma once
#include <gio/gio.h>
+#include <CoreFoundation/CoreFoundation.h>
#include "cd-scsi-dev-params.h"
diff --git a/src/usb-device-cd.c b/src/usb-device-cd.c
index b9fa317..8cc5a3c 100644
--- a/src/usb-device-cd.c
+++ b/src/usb-device-cd.c
@@ -37,8 +37,6 @@
#else
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <linux/fs.h>
-#include <linux/cdrom.h>
#endif
#include "usb-emulation.h"
@@ -94,93 +92,17 @@ typedef struct SpiceUsbEmulatedDevice UsbCd;
static int cd_device_open_stream(SpiceCdLU *unit, const char *filename)
{
- unit->device = 0;
-
- if (!unit->filename && !filename) {
- SPICE_DEBUG("%s: file name not provided", __FUNCTION__);
- return -1;
- }
- if (unit->filename && filename) {
- g_free(unit->filename);
- unit->filename = NULL;
- }
- if (filename) {
- unit->filename = g_strdup(filename);
- }
-
- int fd = open(unit->filename, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- SPICE_DEBUG("%s: can't open file %s", __FUNCTION__, unit->filename);
- return -1;
- }
-
- struct stat file_stat = { 0 };
- if (fstat(fd, &file_stat) || file_stat.st_size == 0) {
- file_stat.st_size = 0;
- unit->device = 1;
- if (!ioctl(fd, BLKGETSIZE64, &file_stat.st_size) &&
- !ioctl(fd, BLKSSZGET, &unit->blockSize)) {
- }
- }
- unit->size = file_stat.st_size;
- close(fd);
- if (unit->size) {
- GFile *file_object = g_file_new_for_path(unit->filename);
- unit->stream = g_file_read(file_object, NULL, NULL);
- g_clear_object(&file_object);
- }
- if (!unit->stream) {
- SPICE_DEBUG("%s: can't open stream on %s", __FUNCTION__, unit->filename);
- return -1;
- }
-
- return 0;
+ return -1;
}
static int cd_device_load(SpiceCdLU *unit, gboolean load)
{
- int error;
- if (!unit->device || !unit->filename) {
- return -1;
- }
- int fd = open(unit->filename, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
return -1;
- }
- if (load) {
- error = ioctl(fd, CDROMCLOSETRAY, 0);
- } else {
- ioctl(fd, CDROM_LOCKDOOR, 0);
- error = ioctl(fd, CDROMEJECT, 0);
- }
- if (error) {
- // note that ejecting might be available only for root
- // loading might be available also for regular user
- SPICE_DEBUG("%s: can't %sload %s, res %d, errno %d",
- __FUNCTION__, load ? "" : "un", unit->filename, error, errno);
- }
- close(fd);
- return error;
}
static int cd_device_check(SpiceCdLU *unit)
{
- int error;
- if (!unit->device || !unit->filename) {
return -1;
- }
- int fd = open(unit->filename, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- return -1;
- }
- error = ioctl(fd, CDROM_DRIVE_STATUS, 0);
- error = (error == CDS_DISC_OK) ? 0 : -1;
- if (!error) {
- error = ioctl(fd, CDROM_DISC_STATUS, 0);
- error = (error == CDS_DATA_1) ? 0 : -1;
- }
- close(fd);
- return error;
}
#else
@akhenakh
Copy link
Author

akhenakh commented Dec 26, 2020

using brew for all dependencies
==> Dependencies
Build: autoconf ✔, autogen ✔, automake ✔, gobject-introspection ✔, intltool ✔, libtool ✔, pkg-config ✔, vala ✔, meson ✔
Required: atk ✔, cairo ✔, gdk-pixbuf ✔, gettext ✔, glib ✔, gstreamer ✔, gtk+3 ✔, jpeg ✔, json-glib ✔, libusb ✔, lz4 ✔, openssl@1.1 ✔, opus ✔, pango ✔, pixman ✔, spice-protocol ✔, usbredir ✔

export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig:/opt/homebrew/opt/libxml2/lib/pkgconfig:/opt/homebrew/opt/gtk+3/lib/pkgconfig:/opt/homebrew/opt/expat/lib/pkgconfig:/opt/homebrew/opt/openssl@1.1/lib/pkgconfig:/opt/homebrew/opt/spice-gtk/lib/pkgconfig"
   /opt/homebrew/opt/python@3.9/bin/pip3 install six
   /opt/homebrew/opt/python@3.9/bin/pip3 install pyparsing
   meson --prefix=/opt/homebrew/Cellar/spice-gtk/0.39 build  -Dusbredir=disabled -Dusb-ids-path=disabled
  ninja -C build
 ninja -C build install
ln -s /opt/homebrew/Cellar/spice-gtk/0.39 /opt/homebrew/opt/spice-gtk

   virt-viewer
  ./configure --without-gtk-vnc  --without-libvirt
 make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment