Skip to content

Commit

Permalink
Add filesystem management
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jun 17, 2020
1 parent 95dc3f5 commit a7c9107
Show file tree
Hide file tree
Showing 26 changed files with 3,389 additions and 247 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ xcuserdata/
.floo

cross-*.txt
alpine
alpine.tar.gz

node_modules
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libapps"]
path = deps/libapps
url = https://github.com/ish-app/libapps
[submodule "deps/libarchive"]
path = deps/libarchive
url = https://github.com/libarchive/libarchive
16 changes: 7 additions & 9 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "SceneDelegate.h"
#import "PasteboardDevice.h"
#import "LocationDevice.h"
#import "Roots.h"
#import "TerminalViewController.h"
#import "UserPreferences.h"
#include "kernel/init.h"
Expand Down Expand Up @@ -59,11 +60,8 @@ @implementation AppDelegate
- (int)boot {
NSFileManager *manager = [NSFileManager defaultManager];
NSURL *container = ContainerURL();
NSURL *alpineRoot = [container URLByAppendingPathComponent:@"roots/alpine"];
[manager createDirectoryAtURL:[container URLByAppendingPathComponent:@"roots"]
withIntermediateDirectories:YES
attributes:@{}
error:nil];
NSURL *roots = [container URLByAppendingPathComponent:@"roots"];
NSURL *root = [roots URLByAppendingPathComponent:Roots.instance.defaultRoot];

#if 0
// copy the files to the app container so I can more easily get them out
Expand All @@ -74,17 +72,17 @@ - (int)boot {
error:nil];
#endif

if (![manager fileExistsAtPath:alpineRoot.path]) {
if (![manager fileExistsAtPath:root.path]) {
NSURL *alpineMaster = [NSBundle.mainBundle URLForResource:@"alpine" withExtension:nil];
NSError *error = nil;
[manager copyItemAtURL:alpineMaster toURL:alpineRoot error:&error];
[manager copyItemAtURL:alpineMaster toURL:root error:&error];
if (error != nil) {
NSLog(@"%@", error);
exit(1);
}
}
alpineRoot = [alpineRoot URLByAppendingPathComponent:@"data"];
int err = mount_root(&fakefs, alpineRoot.fileSystemRepresentation);
root = [root URLByAppendingPathComponent:@"data"];
int err = mount_root(&fakefs, root.fileSystemRepresentation);
if (err < 0)
return err;

Expand Down
56 changes: 47 additions & 9 deletions app/Base.lproj/About.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<segue destination="ItN-wa-djf" kind="show" id="Kbq-17-aS2"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="xvW-ah-hsy" style="IBUITableViewCellStyleDefault" id="31N-0g-RhF" userLabel="Caps Lock">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="xvW-ah-hsy" style="IBUITableViewCellStyleDefault" id="31N-0g-RhF" userLabel="External Keyboard">
<rect key="frame" x="0.0" y="99.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="31N-0g-RhF" id="VWO-ke-dtY">
Expand Down Expand Up @@ -88,10 +88,34 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="u3N-3a-97w">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="dVs-7k-zeJ" style="IBUITableViewCellStyleDefault" id="HHU-Ju-BtM">
<rect key="frame" x="0.0" y="223.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="HHU-Ju-BtM" id="CqF-qp-HgQ">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Filesystems" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="dVs-7k-zeJ">
<rect key="frame" x="16" y="0.0" width="269" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="gsu-Hv-LDC" kind="show" id="tif-za-oNY"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection footerTitle="" id="DVR-sH-TdL">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="g6W-FX-yYa" style="IBUITableViewCellStyleDefault" id="gMm-4C-5X3">
<rect key="frame" x="0.0" y="223.5" width="320" height="44"/>
<rect key="frame" x="0.0" y="303.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="gMm-4C-5X3" id="mVT-2h-5kM">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
Expand All @@ -108,7 +132,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="Fe5-tr-fWm" style="IBUITableViewCellStyleDefault" id="F4i-eC-hQ6">
<rect key="frame" x="0.0" y="267.5" width="320" height="44"/>
<rect key="frame" x="0.0" y="347.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="F4i-eC-hQ6" id="gU6-0E-hOf">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
Expand All @@ -125,7 +149,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="xMw-wC-igF" style="IBUITableViewCellStyleDefault" id="K5r-jy-Dzl">
<rect key="frame" x="0.0" y="311.5" width="320" height="44"/>
<rect key="frame" x="0.0" y="391.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="K5r-jy-Dzl" id="UIr-IB-yu1">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
Expand All @@ -142,7 +166,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="wyO-AY-ccm" style="IBUITableViewCellStyleDefault" id="bge-GA-6p8">
<rect key="frame" x="0.0" y="355.5" width="320" height="44"/>
<rect key="frame" x="0.0" y="435.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="bge-GA-6p8" id="JXA-Ff-hkB">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
Expand All @@ -163,7 +187,7 @@
<tableViewSection headerTitle="Secret Advanced Debugging Options" footerTitle="Warning: Changing these can break everything! If that happens, there's a reset switch in the Settings app." id="d0T-DL-SuP">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="RKb-ed-FOs" userLabel="Init Command">
<rect key="frame" x="0.0" y="467" width="320" height="44"/>
<rect key="frame" x="0.0" y="547" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="RKb-ed-FOs" id="I4F-81-mWS">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
Expand Down Expand Up @@ -195,7 +219,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="Xc7-9V-RXm" userLabel="Boot Command">
<rect key="frame" x="0.0" y="511" width="320" height="44"/>
<rect key="frame" x="0.0" y="591" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Xc7-9V-RXm" id="IEt-PC-8fZ">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
Expand Down Expand Up @@ -227,14 +251,14 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="blue" indentationWidth="10" textLabel="83j-2z-XRR" style="IBUITableViewCellStyleDefault" id="OIE-9g-Btx" userLabel="Export">
<rect key="frame" x="0.0" y="555" width="320" height="44"/>
<rect key="frame" x="0.0" y="635" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="OIE-9g-Btx" id="uY3-tT-dwz">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Export container" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="83j-2z-XRR">
<rect key="frame" x="16" y="0.0" width="288" height="44"/>
<rect key="frame" x="15" y="0.0" width="297" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down Expand Up @@ -568,6 +592,10 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="56"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="iud-fF-geX">
<rect key="frame" x="0.0" y="-20" width="0.0" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
</toolbar>
<connections>
<segue destination="yJz-O7-jlW" kind="relationship" relationship="rootViewController" id="xMq-rt-IoW"/>
</connections>
Expand All @@ -576,5 +604,15 @@
</objects>
<point key="canvasLocation" x="-527" y="158"/>
</scene>
<!--Roots-->
<scene sceneID="g3o-GK-9cH">
<objects>
<viewControllerPlaceholder storyboardName="Roots" id="gsu-Hv-LDC" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="fgZ-7w-Ieb"/>
</viewControllerPlaceholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="h2H-l2-gZ6" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="292" y="641"/>
</scene>
</scenes>
</document>
40 changes: 25 additions & 15 deletions app/FileProvider/FileProviderExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,35 @@

@interface FileProviderExtension ()
@property NSURL *root;
@property struct mount *mount;
@property (readonly) struct mount *mount;
@end

@implementation FileProviderExtension
@synthesize mount = _mount;

- (instancetype)init {
if (self = [super init]) {
self.mount = malloc(sizeof(struct mount));
if (!self.mount)
return nil;
self.mount->fs = &fakefs;
NSURL *container = ContainerURL();
_root = [container URLByAppendingPathComponent:@"roots/alpine/data"];
self.mount->source = strdup(self.root.fileSystemRepresentation);
int err = self.mount->fs->mount(self.mount);
if (err < 0) {
NSLog(@"error opening root: %d", err);
return nil;
}
NSLog(@"yo");
return [super init];
}

- (struct mount *)mount {
if (_mount != NULL)
return _mount;
_mount = malloc(sizeof(struct mount));
if (!_mount)
return NULL;
_mount->fs = &fakefs;
NSURL *container = ContainerURL();
_root = [[[container URLByAppendingPathComponent:@"roots"]
URLByAppendingPathComponent:self.domain.identifier]
URLByAppendingPathComponent:@"data"];
_mount->source = strdup(self.root.fileSystemRepresentation);
int err = _mount->fs->mount(_mount);
if (err < 0) {
NSLog(@"error opening root: %d", err);
return NULL;
}
return self;
return _mount;
}

- (nullable NSFileProviderItem)itemForIdentifier:(NSFileProviderItemIdentifier)identifier error:(NSError * _Nullable *)error {
Expand All @@ -58,6 +66,8 @@ - (nullable NSURL *)URLForItemWithPersistentIdentifier:(NSFileProviderItemIdenti
if (item == nil)
return nil;
NSURL *storage = NSFileProviderManager.defaultManager.documentStorageURL;
if (self.domain != nil)
storage = [storage URLByAppendingPathComponent:self.domain.pathRelativeToDocumentStorage isDirectory:YES];
NSURL *url = [storage URLByAppendingPathComponent:identifier isDirectory:YES];
url = [url URLByAppendingPathComponent:item.path.lastPathComponent isDirectory:NO];
NSLog(@"url for id %@ = %@", identifier, url);
Expand Down
25 changes: 25 additions & 0 deletions app/Roots.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Roots.h
// iSH
//
// Created by Theodore Dubois on 6/7/20.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class Root;

@interface Roots : NSObject

+ (instancetype)instance;

@property (readonly) NSOrderedSet<NSString *> *roots;
@property NSString *defaultRoot;
- (BOOL)importRootFromArchive:(NSURL *)archive name:(NSString *)name error:(NSError **)error;
- (BOOL)destroyRootNamed:(NSString *)name error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit a7c9107

Please sign in to comment.