{"action":"created","comment":{"url":"https://api.github.com/repos/reswitched/libtransistor/pulls/comments/171957437","pull_request_review_id":100906869,"id":171957437,"diff_hunk":"@@ -0,0 +1,179 @@\n+#include<libtransistor/fs/inode.h>\n+#include<libtransistor/fd.h>\n+#include<libtransistor/err.h>\n+\n+#include<errno.h>\n+#include<string.h>\n+#include<stdlib.h>\n+#include<sys/stat.h>\n+#include<stdio.h>\n+\n+#define max(a,b) ((a) > (b) ? (a) : (b))\n+\n+struct mountpoint {\n+\tstruct mountpoint *next;\n+\tconst char *name; // TODO: Static array ?\n+\ttrn_inode_t *fs;\n+\ttrn_inode_ops_t ops_clone;\n+};\n+\n+static struct trn_inode_ops_t rootfs_inode_ops;\n+static trn_dir_ops_t trn_rootfs_dir_ops;\n+\n+static result_t empty_release(void *inode) {\n+\treturn RESULT_OK;\n+}\n+\n+// This borrows the name. Maybe I should make a copy?\n+// It takes ownership of the mountpoint, and will call release on it automatically\n+// on umount.\n+result_t trn_rootfs_mount_fs(trn_inode_t *fs, const char *name, trn_inode_t *mountpoint) {\n+\tif (fs == NULL || fs->ops != &rootfs_inode_ops)\n+\t\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+\n+\tstruct mountpoint **cur_root = (struct mountpoint**)fs->data;\n+\n+\tstruct mountpoint *m = malloc(sizeof(struct mountpoint));\n+\tif (m == NULL)\n+\t\treturn LIBTRANSISTOR_ERR_OUT_OF_MEMORY;\n+\n+\tif (name[0] != '/')\n+\t\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+\n+\tsize_t i;\n+\tfor (i = 0; name[i] == '/'; i++) ;\n+\tfor (size_t j = i; name[j] != '\\0'; j++) {\n+\t\tif (name[j] == '/')\n+\t\t\treturn LIBTRANSISTOR_ERR_FS_INVALID_PATH;\n+\t}\n+\tm->name = name + i;\n+\tm->fs = mountpoint;\n+\tm->ops_clone = *m->fs->ops;\n+\tm->fs->ops->release = empty_release;\n+\n+\t// TODO: Locking\n+\tm->next = *cur_root;\n+\t*cur_root = m;\n+\n+\treturn RESULT_OK;\n+}\n+\n+static result_t trn_rootfs_is_dir(void *data, bool *out) {\n+\t// Everything is a dir in rootfs.\n+\t*out = 1;\n+\treturn RESULT_OK;\n+}\n+\n+static result_t trn_rootfs_lookup(void *data, trn_inode_t *out, const char *name, size_t name_length) {\n+\t// This should only have a single inode ever. So I don't need to check the data out.\n+\tstruct mountpoint **mounts = (struct mountpoint**)data;\n+\tstruct mountpoint *cur_mount = *mounts;\n+\tfor (; cur_mount != NULL; cur_mount = cur_mount->next) {\n+\t\tif (strncmp(cur_mount->name, name, name_length) == 0)\n+\t\t\tbreak;\n+\t}\n+\tif (cur_mount == NULL)\n+\t\treturn LIBTRANSISTOR_ERR_FS_NOT_FOUND;\n+\n+\t// Eh. That \"pointer begone\" thing is pretty ugly.\n+\t*out = *cur_mount->fs;\n+\treturn RESULT_OK;\n+}\n+\n+static result_t trn_rootfs_release(void *data) {\n+\tstruct mountpoint **mounts = (struct mountpoint**)data;\n+\tstruct mountpoint *cur_mount = *mounts;\n+\tresult_t r;\n+\n+\tfor (; cur_mount != NULL; cur_mount = cur_mount->next) {\n+\t\tprintf(\"Unmounting %s\\n\", cur_mount->name);\n+\t\t// Print the error, and discard it.\n+\t\tr = cur_mount->ops_clone.release(cur_mount->fs->data);\n+\t\tif (r != RESULT_OK)\n+\t\t\tprintf(\"Error unmounting %s: %lx\\n\", cur_mount->name, r);\n+\t}\n+\treturn RESULT_OK;\n+}\n+\n+static result_t trn_rootfs_create_file(void *data, const char *name) {\n+\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+}\n+\n+static result_t trn_rootfs_create_directory(void *data, const char *name) {\n+\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+}\n+\n+static result_t trn_rootfs_open_as_file(void *data, int mode, int *fd) {\n+\treturn LIBTRANSISTOR_ERR_FS_NOT_A_FILE;\n+}\n+\n+static result_t trn_rootfs_rename(void *inode, const char *newpath) {\n+\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+}\n+\n+static result_t trn_rootfs_remove_file(void *inode) {\n+\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+}\n+\n+static result_t trn_rootfs_remove_empty_directory(void *inode) {\n+\treturn LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR;\n+}\n+\n+static result_t trn_rootfs_open_as_dir(void *data, trn_dir_t *out) {\n+\t// TODO: Clone the linked list.","path":"lib/fs/rootfs.c","position":123,"original_position":123,"commit_id":"002bae65edf88f8cfc309dd3e23e0665f0ee026e","original_commit_id":"002bae65edf88f8cfc309dd3e23e0665f0ee026e","user":{"login":"roblabla","id":1069318,"avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"body":"Yes. What happens for instance if a filesystem is unmounted (not possible today, but could be) while we were currently on that filesystem ? We'll end up dereferencing a freed pointer, probably.","created_at":"2018-03-02T20:42:26Z","updated_at":"2018-03-02T20:42:27Z","html_url":"https://github.com/reswitched/libtransistor/pull/109#discussion_r171957437","pull_request_url":"https://api.github.com/repos/reswitched/libtransistor/pulls/109","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/comments/171957437"},"html":{"href":"https://github.com/reswitched/libtransistor/pull/109#discussion_r171957437"},"pull_request":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/109"}},"in_reply_to_id":171954166},"pull_request":{"url":"https://api.github.com/repos/reswitched/libtransistor/pulls/109","id":170545918,"html_url":"https://github.com/reswitched/libtransistor/pull/109","diff_url":"https://github.com/reswitched/libtransistor/pull/109.diff","patch_url":"https://github.com/reswitched/libtransistor/pull/109.patch","issue_url":"https://api.github.com/repos/reswitched/libtransistor/issues/109","number":109,"state":"open","locked":false,"title":"[WIP] sdcardfs","user":{"login":"roblabla","id":1069318,"avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"body":"- [x] IPC Bindings\r\n- [x] Rework of the mountpoint\r\n- [ ] Make VFS layer pass a pointer to data instead of the data itself. See [this comment](https://github.com/reswitched/libtransistor/pull/109/files#diff-fdf4309979f031411f65af4d9d1609e2R126)\r\n- [ ] cleanup commits.\r\n- [ ] ~~misson20000: You might want to make your typedefs for ifilesystem_t and such be anonymous structs~~ See https://github.com/reswitched/libtransistor/pull/109#issuecomment-368354540\r\n- [x] Error handling\r\n- [x] IFileSystem implementation\r\n  - [x] mount\r\n  - [x] stat\r\n  - [x] open\r\n    - [x] O_TRUNC\r\n    - [x] O_APPEND\r\n  - [x] read\r\n  - [x] create\r\n    - [x] O_EXCL\r\n  - [x] write\r\n  - [x] rename\r\n  - [x] unlink (deleting files)\r\n  - [x] opendir\r\n  - [x] readdir\r\n  - [x] mkdir\r\n  - [x] rmdir\r\n- [x] DOCUMENTATION !!!!","created_at":"2018-02-21T18:03:57Z","updated_at":"2018-03-02T20:42:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3198f2a09dd8361c5c59328a2a8dc8d0f61b6800","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/reswitched/libtransistor/pulls/109/commits","review_comments_url":"https://api.github.com/repos/reswitched/libtransistor/pulls/109/comments","review_comment_url":"https://api.github.com/repos/reswitched/libtransistor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/reswitched/libtransistor/issues/109/comments","statuses_url":"https://api.github.com/repos/reswitched/libtransistor/statuses/002bae65edf88f8cfc309dd3e23e0665f0ee026e","head":{"label":"roblabla:fs-sdcardfs","ref":"fs-sdcardfs","sha":"002bae65edf88f8cfc309dd3e23e0665f0ee026e","user":{"login":"roblabla","id":1069318,"avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"repo":{"id":110026379,"name":"libtransistor","full_name":"roblabla/libtransistor","owner":{"login":"roblabla","id":1069318,"avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roblabla/libtransistor","description":"Open source toolchain for Switch development","fork":true,"url":"https://api.github.com/repos/roblabla/libtransistor","forks_url":"https://api.github.com/repos/roblabla/libtransistor/forks","keys_url":"https://api.github.com/repos/roblabla/libtransistor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roblabla/libtransistor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roblabla/libtransistor/teams","hooks_url":"https://api.github.com/repos/roblabla/libtransistor/hooks","issue_events_url":"https://api.github.com/repos/roblabla/libtransistor/issues/events{/number}","events_url":"https://api.github.com/repos/roblabla/libtransistor/events","assignees_url":"https://api.github.com/repos/roblabla/libtransistor/assignees{/user}","branches_url":"https://api.github.com/repos/roblabla/libtransistor/branches{/branch}","tags_url":"https://api.github.com/repos/roblabla/libtransistor/tags","blobs_url":"https://api.github.com/repos/roblabla/libtransistor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roblabla/libtransistor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roblabla/libtransistor/git/refs{/sha}","trees_url":"https://api.github.com/repos/roblabla/libtransistor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roblabla/libtransistor/statuses/{sha}","languages_url":"https://api.github.com/repos/roblabla/libtransistor/languages","stargazers_url":"https://api.github.com/repos/roblabla/libtransistor/stargazers","contributors_url":"https://api.github.com/repos/roblabla/libtransistor/contributors","subscribers_url":"https://api.github.com/repos/roblabla/libtransistor/subscribers","subscription_url":"https://api.github.com/repos/roblabla/libtransistor/subscription","commits_url":"https://api.github.com/repos/roblabla/libtransistor/commits{/sha}","git_commits_url":"https://api.github.com/repos/roblabla/libtransistor/git/commits{/sha}","comments_url":"https://api.github.com/repos/roblabla/libtransistor/comments{/number}","issue_comment_url":"https://api.github.com/repos/roblabla/libtransistor/issues/comments{/number}","contents_url":"https://api.github.com/repos/roblabla/libtransistor/contents/{+path}","compare_url":"https://api.github.com/repos/roblabla/libtransistor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roblabla/libtransistor/merges","archive_url":"https://api.github.com/repos/roblabla/libtransistor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roblabla/libtransistor/downloads","issues_url":"https://api.github.com/repos/roblabla/libtransistor/issues{/number}","pulls_url":"https://api.github.com/repos/roblabla/libtransistor/pulls{/number}","milestones_url":"https://api.github.com/repos/roblabla/libtransistor/milestones{/number}","notifications_url":"https://api.github.com/repos/roblabla/libtransistor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roblabla/libtransistor/labels{/name}","releases_url":"https://api.github.com/repos/roblabla/libtransistor/releases{/id}","deployments_url":"https://api.github.com/repos/roblabla/libtransistor/deployments","created_at":"2017-11-08T20:23:58Z","updated_at":"2017-11-08T20:23:59Z","pushed_at":"2018-03-02T17:12:13Z","git_url":"git://github.com/roblabla/libtransistor.git","ssh_url":"git@github.com:roblabla/libtransistor.git","clone_url":"https://github.com/roblabla/libtransistor.git","svn_url":"https://github.com/roblabla/libtransistor","homepage":null,"size":2937,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"isc","name":"ISC License","spdx_id":"ISC","url":"https://api.github.com/licenses/isc"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"reswitched:development","ref":"development","sha":"38bde3191ed9ee0fe346649581da829ddc16fe05","user":{"login":"reswitched","id":26338222,"avatar_url":"https://avatars1.githubusercontent.com/u/26338222?v=4","gravatar_id":"","url":"https://api.github.com/users/reswitched","html_url":"https://github.com/reswitched","followers_url":"https://api.github.com/users/reswitched/followers","following_url":"https://api.github.com/users/reswitched/following{/other_user}","gists_url":"https://api.github.com/users/reswitched/gists{/gist_id}","starred_url":"https://api.github.com/users/reswitched/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reswitched/subscriptions","organizations_url":"https://api.github.com/users/reswitched/orgs","repos_url":"https://api.github.com/users/reswitched/repos","events_url":"https://api.github.com/users/reswitched/events{/privacy}","received_events_url":"https://api.github.com/users/reswitched/received_events","type":"Organization","site_admin":false},"repo":{"id":105481619,"name":"libtransistor","full_name":"reswitched/libtransistor","owner":{"login":"reswitched","id":26338222,"avatar_url":"https://avatars1.githubusercontent.com/u/26338222?v=4","gravatar_id":"","url":"https://api.github.com/users/reswitched","html_url":"https://github.com/reswitched","followers_url":"https://api.github.com/users/reswitched/followers","following_url":"https://api.github.com/users/reswitched/following{/other_user}","gists_url":"https://api.github.com/users/reswitched/gists{/gist_id}","starred_url":"https://api.github.com/users/reswitched/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reswitched/subscriptions","organizations_url":"https://api.github.com/users/reswitched/orgs","repos_url":"https://api.github.com/users/reswitched/repos","events_url":"https://api.github.com/users/reswitched/events{/privacy}","received_events_url":"https://api.github.com/users/reswitched/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/reswitched/libtransistor","description":"Open source toolchain for Switch development","fork":false,"url":"https://api.github.com/repos/reswitched/libtransistor","forks_url":"https://api.github.com/repos/reswitched/libtransistor/forks","keys_url":"https://api.github.com/repos/reswitched/libtransistor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reswitched/libtransistor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reswitched/libtransistor/teams","hooks_url":"https://api.github.com/repos/reswitched/libtransistor/hooks","issue_events_url":"https://api.github.com/repos/reswitched/libtransistor/issues/events{/number}","events_url":"https://api.github.com/repos/reswitched/libtransistor/events","assignees_url":"https://api.github.com/repos/reswitched/libtransistor/assignees{/user}","branches_url":"https://api.github.com/repos/reswitched/libtransistor/branches{/branch}","tags_url":"https://api.github.com/repos/reswitched/libtransistor/tags","blobs_url":"https://api.github.com/repos/reswitched/libtransistor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reswitched/libtransistor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reswitched/libtransistor/git/refs{/sha}","trees_url":"https://api.github.com/repos/reswitched/libtransistor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reswitched/libtransistor/statuses/{sha}","languages_url":"https://api.github.com/repos/reswitched/libtransistor/languages","stargazers_url":"https://api.github.com/repos/reswitched/libtransistor/stargazers","contributors_url":"https://api.github.com/repos/reswitched/libtransistor/contributors","subscribers_url":"https://api.github.com/repos/reswitched/libtransistor/subscribers","subscription_url":"https://api.github.com/repos/reswitched/libtransistor/subscription","commits_url":"https://api.github.com/repos/reswitched/libtransistor/commits{/sha}","git_commits_url":"https://api.github.com/repos/reswitched/libtransistor/git/commits{/sha}","comments_url":"https://api.github.com/repos/reswitched/libtransistor/comments{/number}","issue_comment_url":"https://api.github.com/repos/reswitched/libtransistor/issues/comments{/number}","contents_url":"https://api.github.com/repos/reswitched/libtransistor/contents/{+path}","compare_url":"https://api.github.com/repos/reswitched/libtransistor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reswitched/libtransistor/merges","archive_url":"https://api.github.com/repos/reswitched/libtransistor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reswitched/libtransistor/downloads","issues_url":"https://api.github.com/repos/reswitched/libtransistor/issues{/number}","pulls_url":"https://api.github.com/repos/reswitched/libtransistor/pulls{/number}","milestones_url":"https://api.github.com/repos/reswitched/libtransistor/milestones{/number}","notifications_url":"https://api.github.com/repos/reswitched/libtransistor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reswitched/libtransistor/labels{/name}","releases_url":"https://api.github.com/repos/reswitched/libtransistor/releases{/id}","deployments_url":"https://api.github.com/repos/reswitched/libtransistor/deployments","created_at":"2017-10-01T23:18:26Z","updated_at":"2018-03-02T08:48:31Z","pushed_at":"2018-03-02T17:12:15Z","git_url":"git://github.com/reswitched/libtransistor.git","ssh_url":"git@github.com:reswitched/libtransistor.git","clone_url":"https://github.com/reswitched/libtransistor.git","svn_url":"https://github.com/reswitched/libtransistor","homepage":null,"size":4805,"stargazers_count":120,"watchers_count":120,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":30,"mirror_url":null,"archived":false,"open_issues_count":30,"license":{"key":"isc","name":"ISC License","spdx_id":"ISC","url":"https://api.github.com/licenses/isc"},"forks":30,"open_issues":30,"watchers":120,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/109"},"html":{"href":"https://github.com/reswitched/libtransistor/pull/109"},"issue":{"href":"https://api.github.com/repos/reswitched/libtransistor/issues/109"},"comments":{"href":"https://api.github.com/repos/reswitched/libtransistor/issues/109/comments"},"review_comments":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/109/comments"},"review_comment":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/reswitched/libtransistor/pulls/109/commits"},"statuses":{"href":"https://api.github.com/repos/reswitched/libtransistor/statuses/002bae65edf88f8cfc309dd3e23e0665f0ee026e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"roblabla"}}