mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
fix: Windows installs to Android storage no longer ask for an administrator (#1791)
This commit is contained in:
1 parent
3b9abf6302
commit
31c943c82a
4 files changed
+154
-2
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define FUSE_MAGIC 0x65735546
|
||||
#define SDCARDFS_MAGIC 0x5dca2df5
|
||||
|
||||
static int is_wineserver(void) {
|
||||
static int cached = -1;
|
||||
char exe[PATH_MAX];
|
||||
const char *base;
|
||||
ssize_t n;
|
||||
|
||||
if (cached >= 0) return cached;
|
||||
n = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
|
||||
if (n <= 0) {
|
||||
cached = 0;
|
||||
return cached;
|
||||
}
|
||||
exe[n] = '\0';
|
||||
base = strrchr(exe, '/');
|
||||
cached = strcmp(base ? base + 1 : exe, "wineserver") == 0;
|
||||
return cached;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden")))
|
||||
void bl_storage_owner(int fd, struct stat *st) {
|
||||
struct statfs fs;
|
||||
int saved = errno;
|
||||
uid_t uid;
|
||||
|
||||
if (st != NULL && is_wineserver()) {
|
||||
uid = getuid();
|
||||
if (st->st_uid != uid && fstatfs(fd, &fs) == 0 && (fs.f_type == FUSE_MAGIC || fs.f_type == SDCARDFS_MAGIC)) st->st_uid = uid;
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static int (*next_fstat)(int, struct stat *);
|
||||
void bl_storage_owner(int fd, struct stat *st) __attribute__((visibility("hidden")));
|
||||
static int (*next_fallocate)(int, int, off_t, off_t);
|
||||
static int (*next_posix_fallocate)(int, off_t, off_t);
|
||||
static ssize_t (*next_pwrite)(int, const void *, size_t, off_t);
|
||||
@@ -285,12 +286,17 @@ int fstat(int fd, struct stat *out) {
|
||||
if (next_fstat == NULL) { errno = ENOSYS; return -1; }
|
||||
initialize();
|
||||
errno = entry_errno;
|
||||
if (!enabled) return next_fstat(fd, out);
|
||||
if (!enabled) {
|
||||
int result = next_fstat(fd, out);
|
||||
if (result == 0) bl_storage_owner(fd, out);
|
||||
return result;
|
||||
}
|
||||
uint64_t start = now_ns();
|
||||
errno = entry_errno;
|
||||
int result = next_fstat(fd, out);
|
||||
int call_errno = errno;
|
||||
uint64_t elapsed = now_ns() - start;
|
||||
if (result == 0) bl_storage_owner(fd, out);
|
||||
if (result == 0 && on_selected_device(fd, out)) {
|
||||
add(&stats.fstat_calls, 1);
|
||||
add(&stats.fstat_elapsed_ns, elapsed);
|
||||
|
||||
Reference in new issue
Block a user