mirror of
https://github.com/ish-app/ish.git
synced 2026-05-28 21:10:35 +00:00
Import named pipes in fakefs as named pipes
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "fs/dev.h"
|
||||
#include "fs/real.h"
|
||||
#include "fs/tty.h"
|
||||
#include "util/fchdir.h"
|
||||
|
||||
static int getpath(int fd, char *buf) {
|
||||
#if defined(__linux__)
|
||||
@@ -32,17 +33,6 @@ static int getpath(int fd, char *buf) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// temporarily change directory and block other threads from doing so
|
||||
// useful for simulating mknodat on ios, dealing with long unix socket paths, etc
|
||||
lock_t fchdir_lock;
|
||||
static void lock_fchdir(int dirfd) {
|
||||
lock(&fchdir_lock);
|
||||
fchdir(dirfd);
|
||||
}
|
||||
static void unlock_fchdir() {
|
||||
unlock(&fchdir_lock);
|
||||
}
|
||||
|
||||
static int open_flags_real_from_fake(int flags) {
|
||||
int real_flags = 0;
|
||||
if (flags & O_RDONLY_) real_flags |= O_RDONLY;
|
||||
|
||||
@@ -238,6 +238,7 @@
|
||||
BBEF1994268066D1001225BD /* term.js in Resources */ = {isa = PBXBuildFile; fileRef = BB4A539C1FAA490C00A72ACE /* term.js */; };
|
||||
BBEF1995268066D1001225BD /* sprite64.png in Resources */ = {isa = PBXBuildFile; fileRef = BB0B880E2589662200208600 /* sprite64.png */; };
|
||||
BBEF1996268066D1001225BD /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = BB1B9A4223A5E96900414052 /* icon.png */; };
|
||||
BBF06F6C2CC4C134009F5DB5 /* fchdir.c in Sources */ = {isa = PBXBuildFile; fileRef = BB0DF6F22CC4B01000EFECAE /* fchdir.c */; };
|
||||
BBFB2C7E259026C200545EAB /* libish_emu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BBFB2C5B2590257E00545EAB /* libish_emu.a */; };
|
||||
BBFB2CEC2590296B00545EAB /* libish_emu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BBFB2C5B2590257E00545EAB /* libish_emu.a */; };
|
||||
BBFB55662158644C00DFE6DE /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BBFB55652158644C00DFE6DE /* libresolv.tbd */; };
|
||||
@@ -597,6 +598,8 @@
|
||||
BB0B88172589662A00208600 /* reworked.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = reworked.png; sourceTree = "<group>"; };
|
||||
BB0B88202589734A00208600 /* notsurewhatthisis.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = notsurewhatthisis.png; sourceTree = "<group>"; };
|
||||
BB0C03002AEEC85500E5ECBB /* gen_apk_repositories.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; name = gen_apk_repositories.py; path = app/gen_apk_repositories.py; sourceTree = "<group>"; };
|
||||
BB0DF6F22CC4B01000EFECAE /* fchdir.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = fchdir.c; sourceTree = "<group>"; };
|
||||
BB0DF6F32CC4B01000EFECAE /* fchdir.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fchdir.h; sourceTree = "<group>"; };
|
||||
BB0F552D239F8A790032A2A1 /* Icons.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Icons.plist; sourceTree = "<group>"; };
|
||||
BB0F552F239F8B360032A2A1 /* uninspired.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = uninspired.png; sourceTree = "<group>"; };
|
||||
BB0F553123A0AB9B0032A2A1 /* pydann1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pydann1.png; sourceTree = "<group>"; };
|
||||
@@ -1082,6 +1085,8 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
497F6CD3254E5CC800C82F46 /* bits.h */,
|
||||
BB0DF6F22CC4B01000EFECAE /* fchdir.c */,
|
||||
BB0DF6F32CC4B01000EFECAE /* fchdir.h */,
|
||||
497F6CCF254E5CC800C82F46 /* fifo.c */,
|
||||
497F6CCB254E5CC800C82F46 /* fifo.h */,
|
||||
497F6CD0254E5CC800C82F46 /* list.h */,
|
||||
@@ -2081,6 +2086,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
BBF06F6C2CC4C134009F5DB5 /* fchdir.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
+2
-2
@@ -291,7 +291,7 @@ static int fakefs_setattr(struct user_namespace *mnt_userns, struct dentry *dent
|
||||
if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) {
|
||||
db_begin(&info->db);
|
||||
struct ish_stat stat;
|
||||
inode_read_stat(&info->db, inode->i_ino, &stat);
|
||||
inode_read_stat_or_die(&info->db, inode->i_ino, &stat);
|
||||
if (attr->ia_valid & ATTR_MODE)
|
||||
stat.mode = attr->ia_mode;
|
||||
if (attr->ia_valid & ATTR_UID)
|
||||
@@ -563,7 +563,7 @@ static int restat_inode(struct inode *ino) {
|
||||
static int read_inode(struct inode *ino) {
|
||||
struct fakefs_super *info = ino->i_sb->s_fs_info;
|
||||
struct ish_stat ishstat;
|
||||
inode_read_stat(&info->db, ino->i_ino, &ishstat);
|
||||
inode_read_stat_or_die(&info->db, ino->i_ino, &ishstat);
|
||||
ino->i_mode = ishstat.mode;
|
||||
i_uid_write(ino, ishstat.uid);
|
||||
i_gid_write(ino, ishstat.gid);
|
||||
|
||||
@@ -146,6 +146,7 @@ if get_option('kernel') == 'ish'
|
||||
'util/timer.c',
|
||||
'util/sync.c',
|
||||
'util/fifo.c',
|
||||
'util/fchdir.c',
|
||||
|
||||
'emu/memory.c',
|
||||
|
||||
|
||||
+32
-8
@@ -12,6 +12,7 @@
|
||||
#include "fs/fake-db.h"
|
||||
#include "fs/sqlutil.h"
|
||||
#include "tools/fakefs.h"
|
||||
#include "util/fchdir.h"
|
||||
#include "misc.h"
|
||||
|
||||
#ifndef MAX_PATH
|
||||
@@ -162,28 +163,51 @@ bool fakefs_import(const char *archive_path, const char *fs, struct fakefsify_er
|
||||
free(entry_path_copy);
|
||||
|
||||
int fd = -1;
|
||||
if (archive_entry_filetype(entry) != AE_IFDIR) {
|
||||
fd = openat(root_fd, fix_path(entry_path), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
if (errno == EISDIR) continue; // assuming it's case insensitivity
|
||||
POSIX_ERR();
|
||||
}
|
||||
}
|
||||
|
||||
// first, create node
|
||||
switch (archive_entry_filetype(entry)) {
|
||||
case AE_IFREG:
|
||||
case AE_IFLNK:
|
||||
case AE_IFBLK:
|
||||
case AE_IFCHR:
|
||||
case AE_IFSOCK:
|
||||
fd = openat(root_fd, fix_path(entry_path), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
if (errno == EISDIR) continue; // assuming it's case insensitivity
|
||||
POSIX_ERR();
|
||||
}
|
||||
break;
|
||||
|
||||
case AE_IFDIR:
|
||||
err = mkdirat(root_fd, fix_path(entry_path), 0777);
|
||||
if (err < 0 && errno != EEXIST)
|
||||
POSIX_ERR();
|
||||
break;
|
||||
|
||||
case AE_IFIFO:
|
||||
lock_fchdir(root_fd);
|
||||
err = mkfifo(fix_path(entry_path), 0666);
|
||||
unlock_fchdir();
|
||||
break;
|
||||
}
|
||||
// second, fill in contents, if needed
|
||||
switch (archive_entry_filetype(entry)) {
|
||||
case AE_IFREG:
|
||||
if (archive_read_data_into_fd(archive, fd) != ARCHIVE_OK)
|
||||
ARCHIVE_ERR(archive);
|
||||
break;
|
||||
|
||||
case AE_IFLNK:
|
||||
err = (int) write(fd, archive_entry_symlink(entry), strlen(archive_entry_symlink(entry)));
|
||||
if (err < 0)
|
||||
POSIX_ERR();
|
||||
break;
|
||||
|
||||
case AE_IFDIR:
|
||||
case AE_IFBLK:
|
||||
case AE_IFCHR:
|
||||
case AE_IFSOCK:
|
||||
case AE_IFIFO:
|
||||
break;
|
||||
}
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
|
||||
+6
-1
@@ -37,7 +37,12 @@ if not libarchive.found()
|
||||
endif
|
||||
|
||||
if libarchive.found()
|
||||
fakefsify = executable('fakefsify', ['fakefsify.c', 'fakefs.c'], dependencies: [libarchive], link_with: [libfakefs], include_directories: [includes])
|
||||
fakefsify_src = [
|
||||
'fakefsify.c',
|
||||
'fakefs.c',
|
||||
'../util/fchdir.c',
|
||||
]
|
||||
fakefsify = executable('fakefsify', fakefsify_src, dependencies: [libarchive], link_with: [libfakefs], include_directories: [includes])
|
||||
custom_target('unfakefsify',
|
||||
build_by_default: true,
|
||||
command: ['ln', '-sf', 'fakefsify', '@OUTPUT@'],
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <unistd.h>
|
||||
#include "util/sync.h"
|
||||
|
||||
static lock_t fchdir_lock = LOCK_INITIALIZER;
|
||||
|
||||
void lock_fchdir(int dirfd) {
|
||||
lock(&fchdir_lock);
|
||||
fchdir(dirfd);
|
||||
}
|
||||
|
||||
void unlock_fchdir() {
|
||||
unlock(&fchdir_lock);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// temporarily change directory and block other threads from doing so
|
||||
// useful for simulating mknodat on ios, dealing with long unix socket paths, etc
|
||||
void lock_fchdir(int dirfd);
|
||||
void unlock_fchdir();
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdatomic.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <setjmp.h>
|
||||
#include "misc.h"
|
||||
#include "debug.h"
|
||||
|
||||
Reference in New Issue
Block a user