Skip to content

Commit

Permalink
Bug fixes and performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Apr 12, 2020
1 parent effa9a7 commit 7d58fc8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
23 changes: 11 additions & 12 deletions app/iOSFS.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ - (int)askForURL:(NSURL **)url {
_urls = nil;
unlock(&_lock);

assert(urls.count <= 1);
if (urls.count == 0)
return _ENODEV;
*url = urls[0];
Expand All @@ -85,12 +86,14 @@ - (void)dealloc {
}

NSURL *url_for_path_in_mount(struct mount *mount, const char *path) {
return [[url_for_mount(mount) URLByAppendingPathComponent:[NSString stringWithUTF8String:path]] URLByStandardizingPath];
if (path[0] == '/')
path++;
return [url_for_mount(mount) URLByAppendingPathComponent:[NSString stringWithUTF8String:path] isDirectory:NO];
}

const char *path_for_url_in_mount(struct mount *mount, NSURL *url, const char *fallback) {
NSString *mount_path = [[url_for_mount(mount) URLByStandardizingPath] path];
NSString *url_path = [[url URLByStandardizingPath] path];
NSString *mount_path = url_for_mount(mount).path;
NSString *url_path = url.path;

// The `/private` prefix is a special case as described in the documentation of `URLByStandardizingPath`.
if ([mount_path hasPrefix:@"/private/"]) mount_path = [mount_path substringFromIndex:8];
Expand All @@ -99,23 +102,18 @@ - (void)dealloc {
if (![url_path hasPrefix:mount_path])
return fallback;

NSURL *new_url = [NSURL fileURLWithPath:[url_path substringFromIndex:[mount_path length]]];
return [new_url ? [new_url path] : @"" cStringUsingEncoding:NSUTF8StringEncoding];
return [url_path substringFromIndex:[mount_path length]].UTF8String;
}

static int iosfs_stat(struct mount *mount, const char *path, struct statbuf *fake_stat);
const struct fd_ops iosfs_fdops;

static int posixErrorFromNSError(NSError *error) {
if (error != nil) {
NSError *underlyingError = [error.userInfo objectForKey:NSUnderlyingErrorKey];
if (underlyingError) {
return -(int)underlyingError.code;
} else {
return _EPERM;
while (error != nil) {
if (error.domain == NSPOSIXErrorDomain) {
return err_map((int) error.code);
}
}

return 0;
}

Expand All @@ -127,6 +125,7 @@ static int combine_error(NSError *coordinatorError, int err) {
static struct fd *iosfs_open(struct mount *mount, const char *path, int flags, int mode) {
NSURL *url = url_for_path_in_mount(mount, path);

// FIXME: this does a redundant file coordination operation
struct statbuf stats;
int err = iosfs_stat(mount, path, &stats);

Expand Down
4 changes: 3 additions & 1 deletion fs/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void fs_register(const struct fs_ops *fs) {
for (unsigned i = 0; i < MAX_FILESYSTEMS; i++) {
if (filesystems[i] == NULL) {
filesystems[i] = fs;
break;
return;
}
}
assert(!"reached filesystem limit");
Expand Down Expand Up @@ -63,6 +63,8 @@ int do_mount(const struct fs_ops *fs, const char *source, const char *point, int
if (fs->mount) {
int err = fs->mount(new_mount);
if (err < 0) {
free((void *) new_mount->point);
free((void *) new_mount->source);
free(new_mount);
return err;
}
Expand Down
5 changes: 0 additions & 5 deletions iSH.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
40616E3C236642B6008CDF19 /* mount.c in Sources */ = {isa = PBXBuildFile; fileRef = 40616E3B236642B5008CDF19 /* mount.c */; };
408A263A236440F8008A4E81 /* iOSFS.m in Sources */ = {isa = PBXBuildFile; fileRef = 408A2639236440F8008A4E81 /* iOSFS.m */; };
650B337422EA235C00B4C03E /* PasteboardDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 650B337322EA235C00B4C03E /* PasteboardDevice.m */; };
8632A7BF219A59FB00F02325 /* UserPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 8632A7BE219A59FB00F02325 /* UserPreferences.m */; };
Expand Down Expand Up @@ -101,7 +100,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
40616E3B236642B5008CDF19 /* mount.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mount.c; sourceTree = "<group>"; };
408A2639236440F8008A4E81 /* iOSFS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iOSFS.m; sourceTree = "<group>"; };
408A263B23644102008A4E81 /* iOSFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iOSFS.h; sourceTree = "<group>"; };
650B335A22E9E46A00B4C03E /* mem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mem.c; sourceTree = "<group>"; tabWidth = 4; };
Expand Down Expand Up @@ -996,7 +994,6 @@
9A28E4EA219A8B670073D200 /* AboutAppearanceViewController.m in Sources */,
BB1D9D93234A8FE100F364E8 /* AboutNavigationController.m in Sources */,
BB235534235D488500139E00 /* LocationDevice.m in Sources */,
40616E3C236642B6008CDF19 /* mount.c in Sources */,
BB792B581F96D90D00FFB7A4 /* TerminalViewController.m in Sources */,
BB78AB2B1FAD22440013E782 /* TerminalView.m in Sources */,
BB23F58D231E1D1400585522 /* ScrollbarView.m in Sources */,
Expand Down Expand Up @@ -1401,7 +1398,6 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = CK5SXRTBR7;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -1468,7 +1464,6 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = CK5SXRTBR7;
ENABLE_BITCODE = NO;
ENABLE_NS_ASSERTIONS = NO;
Expand Down
1 change: 0 additions & 1 deletion kernel/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ void mount_release(struct mount *mount);

// must hold mounts_lock while calling these, or traversing mounts
int do_mount(const struct fs_ops *fs, const char *source, const char *point, int flags);
int do_mount_with_data(const struct fs_ops *fs, const char *source, const char *point, int flags, void *data);
int do_umount(const char *point);
int mount_remove(struct mount *mount);
extern struct list mounts;
Expand Down

0 comments on commit 7d58fc8

Please sign in to comment.