summaryrefslogtreecommitdiffstats
path: root/hw/9pfs/9p-util.h
diff options
context:
space:
mode:
authorRichard Henderson2022-05-01 16:48:11 +0200
committerRichard Henderson2022-05-01 16:48:11 +0200
commitf5643914a9e8f79c606a76e6a9d7ea82a3fc3e65 (patch)
tree15dc267b4eec4822ffe6ebeb7c5b4c8849936bcb /hw/9pfs/9p-util.h
parentMerge tag 'pull-riscv-to-apply-20220429' of github.com:alistair23/qemu into s... (diff)
parent9pfs: fix qemu_mknodat() to always return -1 on error on macOS host (diff)
downloadqemu-f5643914a9e8f79c606a76e6a9d7ea82a3fc3e65.tar.gz
qemu-f5643914a9e8f79c606a76e6a9d7ea82a3fc3e65.tar.xz
qemu-f5643914a9e8f79c606a76e6a9d7ea82a3fc3e65.zip
Merge tag 'pull-9p-20220501' of https://github.com/cschoenebeck/qemu into staging
9pfs: various fixes * macOS: Fix recently (in QEMU 7.0) added 9p support for macOS hosts. * Tests: Fix inode sequencing in 'synth' driver. # -----BEGIN PGP SIGNATURE----- # # iQJLBAABCgA1FiEEltjREM96+AhPiFkBNMK1h2Wkc5UFAmJuhqEXHHFlbXVfb3Nz # QGNydWRlYnl0ZS5jb20ACgkQNMK1h2Wkc5U4fBAAofSRlDuxC0h2irHy0tRRGv+W # rH1gDVm0jzFChUumarUOs5/hZjG5C4H9nFA0g/6di9bSoiubtA839w/dDmUYV7Xn # S/8Jvauk/zZley1R1AKK5BEtOjJTlEYkbLqR1i9JPUrUk3Q9A+/f0FhgnW8NU2zu # KhqbzYZnUXb3P1RyRm4cTh9UCr904OI30mdqiM9U+oJag1Zd3us/Q9sPdqDCYs8e # vD4UXqG8c5UYpEN6C/ag2p3oJpAzpRa3CLkT5U59j/LhNgVtBPG/Pm5Q9qKHrxiN # 3p/+36NWLNXMtCKsU4Tf9TsA+tEB1G+QfObC5g8yM0e12dInW7K8KKUIOO7lE5Eq # a8aXZZC4yjW6y9vml0tC2E8p3n7n3r4MdLIrdY5VoOk72QLLBORq547DN/c5vt8A # Qsj2eZTvkrZNVmpQKpanwc8nsavslenFmQVVo+E6kuEOhTJpBeahsEx/ReH4D9rg # Hmq9O+xnPXodrj4DI1uqdwxN37A6bAn/4UAnQiPosnbzn+a6rZ3TZZ7x6ZZVwVub # MyPdWSwu0JujcD8Goina7f12tDOt2GaYrbegH4AG3B6kpMUQD6vwzcAFwZMP/0zZ # XMQnhR/lrvpsuBymuNA8cHRjccK6uGHxCEbstSsvKJCw0GqSonvTzMKY43HtgWmz # XjQe3jVk2+U5Aw8umTU= # =KBDF # -----END PGP SIGNATURE----- # gpg: Signature made Sun 01 May 2022 06:09:53 AM PDT # gpg: using RSA key 96D8D110CF7AF8084F88590134C2B58765A47395 # gpg: issuer "qemu_oss@crudebyte.com" # gpg: Good signature from "Christian Schoenebeck <qemu_oss@crudebyte.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: ECAB 1A45 4014 1413 BA38 4926 30DB 47C3 A012 D5F4 # Subkey fingerprint: 96D8 D110 CF7A F808 4F88 5901 34C2 B587 65A4 7395 * tag 'pull-9p-20220501' of https://github.com/cschoenebeck/qemu: 9pfs: fix qemu_mknodat() to always return -1 on error on macOS host 9pfs: fix removing non-existent POSIX ACL xattr on macOS host 9pfs: fix wrong errno being sent to Linux client on macOS host 9pfs: fix wrong encoding of rdev field in Rgetattr on macOS 9pfs: fix qemu_mknodat(S_IFSOCK) on macOS 9pfs: fix qemu_mknodat(S_IFREG) on macOS 9pfs: fix inode sequencing in 'synth' driver Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'hw/9pfs/9p-util.h')
-rw-r--r--hw/9pfs/9p-util.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 97e681e167..c3526144c9 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -19,6 +19,75 @@
#define O_PATH_9P_UTIL 0
#endif
+#if !defined(CONFIG_LINUX)
+
+/*
+ * Generates a Linux device number (a.k.a. dev_t) for given device major
+ * and minor numbers.
+ *
+ * To be more precise: it generates a device number in glibc's format
+ * (MMMM_Mmmm_mmmM_MMmm, 64 bits) actually, which is compatible with
+ * Linux's format (mmmM_MMmm, 32 bits), as described in <bits/sysmacros.h>.
+ */
+static inline uint64_t makedev_dotl(uint32_t dev_major, uint32_t dev_minor)
+{
+ uint64_t dev;
+
+ // from glibc sysmacros.h:
+ dev = (((uint64_t) (dev_major & 0x00000fffu)) << 8);
+ dev |= (((uint64_t) (dev_major & 0xfffff000u)) << 32);
+ dev |= (((uint64_t) (dev_minor & 0x000000ffu)) << 0);
+ dev |= (((uint64_t) (dev_minor & 0xffffff00u)) << 12);
+ return dev;
+}
+
+#endif
+
+/*
+ * Converts given device number from host's device number format to Linux
+ * device number format. As both the size of type dev_t and encoding of
+ * dev_t is system dependant, we have to convert them for Linux guests if
+ * host is not running Linux.
+ */
+static inline uint64_t host_dev_to_dotl_dev(dev_t dev)
+{
+#ifdef CONFIG_LINUX
+ return dev;
+#else
+ return makedev_dotl(major(dev), minor(dev));
+#endif
+}
+
+/* Translates errno from host -> Linux if needed */
+static inline int errno_to_dotl(int err) {
+#if defined(CONFIG_LINUX)
+ /* nothing to translate (Linux -> Linux) */
+#elif defined(CONFIG_DARWIN)
+ /*
+ * translation mandatory for macOS hosts
+ *
+ * FIXME: Only most important errnos translated here yet, this should be
+ * extended to as many errnos being translated as possible in future.
+ */
+ if (err == ENAMETOOLONG) {
+ err = 36; /* ==ENAMETOOLONG on Linux */
+ } else if (err == ENOTEMPTY) {
+ err = 39; /* ==ENOTEMPTY on Linux */
+ } else if (err == ELOOP) {
+ err = 40; /* ==ELOOP on Linux */
+ } else if (err == ENOATTR) {
+ err = 61; /* ==ENODATA on Linux */
+ } else if (err == ENOTSUP) {
+ err = 95; /* ==EOPNOTSUPP on Linux */
+ } else if (err == EOPNOTSUPP) {
+ err = 95; /* ==EOPNOTSUPP on Linux */
+ }
+#else
+#error Missing errno translation to Linux for this host system
+#endif
+ return err;
+}
+
#ifdef CONFIG_DARWIN
#define qemu_fgetxattr(...) fgetxattr(__VA_ARGS__, 0, 0)
#define qemu_lgetxattr(...) getxattr(__VA_ARGS__, 0, XATTR_NOFOLLOW)