int char_dev_register(const char *name, const struct kfile_operations *ops) { struct path node; struct nas *dev_nas; if (vfs_lookup("/dev", &node)) { return -1; } if (node.node == NULL) { return -ENODEV; } vfs_create_child(&node, name, S_IFCHR | S_IRALL | S_IWALL, &node); if (!(node.node)) { return -1; } dev_nas = node.node->nas; dev_nas->fs = filesystem_create("empty"); if (dev_nas->fs == NULL) { return -ENOMEM; } dev_nas->fs->file_op = ops; return 0; }
static int tmpfs_mount(void *dev, void *dir) { struct node *dir_node, *dev_node; struct nas *dir_nas, *dev_nas; struct tmpfs_file_info *fi; struct tmpfs_fs_info *fsi; struct node_fi *dev_fi; dev_node = dev; dev_nas = dev_node->nas; dir_node = dir; dir_nas = dir_node->nas; if (NULL == (dev_fi = dev_nas->fi)) { return -ENODEV; } if (NULL == (dir_nas->fs = filesystem_create("tmpfs"))) { return -ENOMEM; } dir_nas->fs->bdev = dev_fi->privdata; /* allocate this fs info */ if(NULL == (fsi = pool_alloc(&tmpfs_fs_pool))) { filesystem_free(dir_nas->fs); return -ENOMEM; } memset(fsi, 0, sizeof(struct tmpfs_fs_info)); dir_nas->fs->fsi = fsi; fsi->block_per_file = MAX_FILE_SIZE; fsi->block_size = PAGE_SIZE(); fsi->numblocks = block_dev(dev_fi->privdata)->size / PAGE_SIZE(); /* allocate this directory info */ if(NULL == (fi = pool_alloc(&tmpfs_file_pool))) { return -ENOMEM; } memset(fi, 0, sizeof(struct tmpfs_file_info)); fi->index = fi->mode = 0; dir_nas->fi->privdata = (void *) fi; return 0; }
int main(int argc, char* argv[]) { if (argc != 2) { LOG_ERROR("Usage: %s <mount location>", argv[0]); return 1; } filesystem_h fs = filesystem_create(); device_h* devices = NULL; size_t devices_count = 0; if (get_available_devices(&devices, &devices_count)) { for (size_t i = 0; i < devices_count; i++) { LOG_INFO("Found device %s (%s)", device_get_uid(devices[i]), device_get_name(devices[i])); char* db_location = device_get_photo_db_location(devices[i]); char* root_path = device_get_root_path(devices[i]); db_h db = db_create(db_location, device_get_name(devices[i]), root_path); if (db != NULL) { filesystem_add_database(fs, db); } free(db_location); free(root_path); device_free(devices[i]); } free(devices); } filesystem_run(fs, argv[1]); filesystem_free(fs); }
static mount_tty(struct tty* tty, const struct kfile_operations *file_ops) { struct path node; /* register char device */ node = vfs_lookup("/dev"); if (!node) { return -1; } mode = S_IFCHR | S_IRALL | S_IWALL; node = vfs_create_child(node, name, mode); if (!node) { return -1; } nas = node->nas; if (NULL == (nas->fs = filesystem_create("empty"))) { return -1; } nas->fs->file_op = file_ops; nas->fi = dev; }
static int blockdev_init(void) { blockdev_fs = filesystem_create("empty"); blockdev_fs->file_op = &blockdev_fop; return 0; }
bool bbruntime_create(){ if( blitz_create() ){ if( hook_create() ){ if( event_create() ){ if( math_create() ){ if( string_create() ){ if( stdio_create() ){ if( stream_create() ){ if( sockets_create() ){ if( enet_create() ){ if( runtime_create() ){ if( system_create() ){ if( bank_create() ){ if( system_windows_create() ){ if( filesystem_create() ){ if( filesystem_windows_create() ){ if( timer_windows_create() ){ if( input_create() ){ if( input_directinput8_create() ){ if( audio_create() ){ if( audio_fmod_create() ){ if( userlibs_create() ){ if( pixmap_create() ){ if( blitz2d_create() ){ if( graphics_create() ){ if( runtime_glfw3_create() ){ return true; }else sue( "runtime_glfw3_create failed" ); graphics_destroy(); }else sue( "graphics_create failed" ); blitz2d_destroy(); }else sue( "blitz2d_create failed" ); pixmap_destroy(); }else sue( "pixmap_create failed" ); userlibs_destroy(); }else sue( "userlibs_create failed" ); audio_fmod_destroy(); }else sue( "audio_fmod_create failed" ); audio_destroy(); }else sue( "audio_create failed" ); input_directinput8_destroy(); }else sue( "input_directinput8_create failed" ); input_destroy(); }else sue( "input_create failed" ); timer_windows_destroy(); }else sue( "timer_windows_create failed" ); filesystem_windows_destroy(); }else sue( "filesystem_windows_create failed" ); filesystem_destroy(); }else sue( "filesystem_create failed" ); system_windows_destroy(); }else sue( "system_windows_create failed" ); bank_destroy(); }else sue( "bank_create failed" ); system_destroy(); }else sue( "system_create failed" ); runtime_destroy(); }else sue( "runtime_create failed" ); enet_destroy(); }else sue( "enet_create failed" ); sockets_destroy(); }else sue( "sockets_create failed" ); stream_destroy(); }else sue( "stream_create failed" ); stdio_destroy(); }else sue( "stdio_create failed" ); string_destroy(); }else sue( "string_create failed" ); math_destroy(); }else sue( "math_create failed" ); event_destroy(); }else sue( "event_create failed" ); hook_destroy(); }else sue( "hook_create failed" ); blitz_destroy(); }else sue( "blitz_create failed" ); return false; }
static void handle_filesystem_request(int so) { int error; int operation; char key[(NAME_MAX + 1) + sizeof(union webdav_request)]; size_t num_bytes; char *bytes; union webdav_reply reply; /* get the request from the socket */ error = get_request(so, &operation, key, sizeof(key)); if ( !error ) { #if DEBUG LogMessage(kTrace, "handle_filesystem_request: %s(%d)\n", (operation==WEBDAV_LOOKUP) ? "LOOKUP" : (operation==WEBDAV_CREATE) ? "CREATE" : (operation==WEBDAV_OPEN) ? "OPEN" : (operation==WEBDAV_CLOSE) ? "CLOSE" : (operation==WEBDAV_GETATTR) ? "GETATTR" : (operation==WEBDAV_SETATTR) ? "SETATTR" : (operation==WEBDAV_READ) ? "READ" : (operation==WEBDAV_WRITE) ? "WRITE" : (operation==WEBDAV_FSYNC) ? "FSYNC" : (operation==WEBDAV_REMOVE) ? "REMOVE" : (operation==WEBDAV_RENAME) ? "RENAME" : (operation==WEBDAV_MKDIR) ? "MKDIR" : (operation==WEBDAV_RMDIR) ? "RMDIR" : (operation==WEBDAV_READDIR) ? "READDIR" : (operation==WEBDAV_STATFS) ? "STATFS" : (operation==WEBDAV_UNMOUNT) ? "UNMOUNT" : (operation==WEBDAV_INVALCACHES) ? "INVALCACHES" : "???", operation ); #endif bzero((void *)&reply, sizeof(union webdav_reply)); /* If the connection is down just return EBUSY, but always let UNMOUNT and INVALCACHES requests */ /* go through regardless of the state of the connection. */ if ( (get_connectionstate() == WEBDAV_CONNECTION_DOWN) && (operation != WEBDAV_UNMOUNT) && (operation != WEBDAV_INVALCACHES) ) { error = ETIMEDOUT; send_reply(so, (void *)&reply, sizeof(union webdav_reply), error); } else { /* call the function to handle the request */ switch ( operation ) { case WEBDAV_LOOKUP: error = filesystem_lookup((struct webdav_request_lookup *)key, (struct webdav_reply_lookup *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_lookup), error); break; case WEBDAV_CREATE: error = filesystem_create((struct webdav_request_create *)key, (struct webdav_reply_create *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_create), error); break; case WEBDAV_OPEN: error = filesystem_open((struct webdav_request_open *)key, (struct webdav_reply_open *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_open), error); break; case WEBDAV_CLOSE: error = filesystem_close((struct webdav_request_close *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_GETATTR: error = filesystem_getattr((struct webdav_request_getattr *)key, (struct webdav_reply_getattr *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_getattr), error); break; case WEBDAV_READ: bytes = NULL; num_bytes = 0; error = filesystem_read((struct webdav_request_read *)key, &bytes, &num_bytes); send_reply(so, (void *)bytes, (int)num_bytes, error); if (bytes) { free(bytes); } break; case WEBDAV_FSYNC: error = filesystem_fsync((struct webdav_request_fsync *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_REMOVE: error = filesystem_remove((struct webdav_request_remove *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_RENAME: error = filesystem_rename((struct webdav_request_rename *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_MKDIR: error = filesystem_mkdir((struct webdav_request_mkdir *)key, (struct webdav_reply_mkdir *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_mkdir), error); break; case WEBDAV_RMDIR: error = filesystem_rmdir((struct webdav_request_rmdir *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_READDIR: error = filesystem_readdir((struct webdav_request_readdir *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_STATFS: error = filesystem_statfs((struct webdav_request_statfs *)key, (struct webdav_reply_statfs *)&reply); send_reply(so, (void *)&reply, sizeof(struct webdav_reply_statfs), error); break; case WEBDAV_UNMOUNT: webdav_kill(-2); /* tell the main select loop to exit */ send_reply(so, (void *)0, 0, error); break; case WEBDAV_INVALCACHES: error = filesystem_invalidate_caches((struct webdav_request_invalcaches *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_WRITESEQ: error = filesystem_write_seq((struct webdav_request_writeseq *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_DUMP_COOKIES: dump_cookies((struct webdav_request_cookies *)key); send_reply(so, (void *)0, 0, error); break; case WEBDAV_CLEAR_COOKIES: reset_cookies((struct webdav_request_cookies *)key); send_reply(so, (void *)0, 0, error); break; default: error = ENOTSUP; break; } } #if DEBUG LogMessage(kError, "handle_filesystem_request: error %d, %s(%d)\n", error, (operation==WEBDAV_LOOKUP) ? "LOOKUP" : (operation==WEBDAV_CREATE) ? "CREATE" : (operation==WEBDAV_OPEN) ? "OPEN" : (operation==WEBDAV_CLOSE) ? "CLOSE" : (operation==WEBDAV_GETATTR) ? "GETATTR" : (operation==WEBDAV_SETATTR) ? "SETATTR" : (operation==WEBDAV_READ) ? "READ" : (operation==WEBDAV_WRITE) ? "WRITE" : (operation==WEBDAV_FSYNC) ? "FSYNC" : (operation==WEBDAV_REMOVE) ? "REMOVE" : (operation==WEBDAV_RENAME) ? "RENAME" : (operation==WEBDAV_MKDIR) ? "MKDIR" : (operation==WEBDAV_RMDIR) ? "RMDIR" : (operation==WEBDAV_READDIR) ? "READDIR" : (operation==WEBDAV_STATFS) ? "STATFS" : (operation==WEBDAV_UNMOUNT) ? "UNMOUNT" : (operation==WEBDAV_INVALCACHES) ? "INVALCACHES" : "???", operation ); #endif } else { LogMessage(kError, "handle_filesystem_request: get_request failed %d\n", error); send_reply(so, NULL, 0, error); } close(so); }