gboolean pcapng_write_enhanced_packet(GOutputStream *out, guint if_id, guint64 timestamp, guint captured_len, guint packet_len, const guint8 *packet_data, const ByteChain *options, GError **err) { static const guint8 pad[] = {0,0,0}; ByteChain chain[3]; guint8 header[20]; *(guint32*)(header) = if_id; *(guint32*)(header + 4) = timestamp >> 32; *(guint32*)(header + 8) = timestamp; *(guint32*)(header + 12) = captured_len; *(guint32*)(header + 16) = packet_len; chain[0].len = sizeof(header); chain[0].data.bytes = header; chain[0].next = &chain[1]; chain[1].len = captured_len; chain[1].data.bytes = packet_data; chain[1].next = &chain[2]; chain[2].len = PADLEN(packet_len,4); chain[2].data.bytes = chain[2].len > 0 ? pad : NULL; chain[2].next = (ByteChain*)default_options(options); return pcapng_write_block(out, 0x00000006, chain, err); }
virtual void SetUp() { instance = this; network_output_flag = NET_OUT_UNDEFINED; network_out_state = STATE_ERROR_UNSPECIFIED; m_state = BST_MODE_UNINITIALIZED; retry_advanced_connection = 0; next_connect_state = BST_STATE_NO_CONNECTION; connected_confirmed = false; bst_connect_options o = default_options(); bst_setup(o,NULL, 0, NULL, 0); useCurrentTimeOverwrite(); }
LsiRewriteDriverFactory::LsiRewriteDriverFactory( const ProcessContext &process_context, SystemThreadSystem *system_thread_system, StringPiece hostname, int port) : SystemRewriteDriverFactory(process_context, system_thread_system, NULL /* default shared memory runtime */, hostname, port), m_mainConf(NULL), m_bThreadsStarted(false), m_pLsiMessageHandler(new LsiMessageHandler(timer(), thread_system()->NewMutex())), m_pHtmlParseLsiMessageHandler( new LsiMessageHandler(timer(), thread_system()->NewMutex())), m_pSharedCircularBuffer(NULL), m_sHostname(hostname.as_string()), m_iPort(port) { InitializeDefaultOptions(); default_options()->set_beacon_url("/ls_pagespeed_beacon"); SystemRewriteOptions *system_options = dynamic_cast<SystemRewriteOptions *>(default_options()); system_options->set_file_cache_clean_inode_limit(500000); system_options->set_avoid_renaming_introspective_javascript(true); set_message_handler(m_pLsiMessageHandler); set_html_parse_message_handler(m_pHtmlParseLsiMessageHandler); }
Args::Args(int argc, char *argv[]) { default_options(); struct option long_options[] = { { "mandarin-data", 1, NULL, 'm' }, { "cantonese-data", 1, NULL, 'c' }, { "listen-host", 1, NULL, 'h' }, { "listen-port", 1, NULL, 'p' }, { "help", 0, NULL, '?' }, { "version", 0, NULL, 'v' }, { NULL, 0, NULL, 0 } }; int option_index, c; while ( (c = getopt_long( argc, argv, "m:c:h:p:?v", long_options, &option_index )) != -1 ) { switch (c) { case 'c': GET_ARG_STR(cantoneseDataPath); break; case 'm': GET_ARG_STR(mandarinDataPath); break; case 'h': GET_ARG_STR(listenHost); break; case 'p': GET_ARG_INT(listenPort); break; case '?': help(); exit(0); break; case 'v': version(); exit(0); break; } } }
TEST_F(StateMachineTests, InitialCredentialsWrong) { next_connect_state = BST_STATE_NO_CONNECTION; int len = sizeof("wifi1\0pwd_wrong\0test"); char data[] = "wifi1\0pwd_wrong\0test"; ASSERT_EQ(BST_STATE_NO_CONNECTION, bst_get_connection_state()); bst_setup(default_options(),data,len,NULL,0); // bst_setup will trigger a connection attempt, which will fail ASSERT_EQ(BST_MODE_CONNECTING_TO_DEST, bst_get_state()); ASSERT_EQ(BST_STATE_FAILED_CREDENTIALS_WRONG, bst_get_connection_state()); // The state will fallback to wait for bootstrap in the next run. bst_periodic(); ASSERT_EQ(BST_MODE_CONNECTING_TO_BOOTSTRAP, bst_get_state()); ASSERT_EQ(BST_STATE_CONNECTED, bst_get_connection_state()); }
gboolean pcapng_write_interface_description(GOutputStream *out, guint link_type, guint snap_len, const ByteChain *options, GError **err) { ByteChain chain[1]; guint8 body[8]; *(guint16*)(body) = link_type; *(guint16*)(body + 2) = 0; *(guint32*)(body + 4) = snap_len; chain[0].len = sizeof(body); chain[0].data.bytes = body; chain[0].next = (ByteChain*)default_options(options); return pcapng_write_block(out, 0x00000001, chain, err); }
gboolean pcapng_write_section_header(GOutputStream *out, gint64 section_len, const ByteChain *options, GError **err) { ByteChain chain[1]; static const guint32 magic = 0x1a2b3c4d; static const guint16 major_version = 1; static const guint16 minor_version = 0; guint8 body[16]; *(guint32*)body = magic; *(guint16*)(body + 4) = major_version; *(guint16*)(body + 6) = minor_version; *(gint64*)(body + 8) = section_len; chain[0].len = sizeof(body); chain[0].data.bytes = body; chain[0].next = (ByteChain*)default_options(options); return pcapng_write_block(out, 0x0a0d0d0a, chain, err); }
static int f2fs_remount(struct super_block *sb, int *flags, char *data) { struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_mount_info org_mount_opt; int err, active_logs; bool need_restart_gc = false; bool need_stop_gc = false; sync_filesystem(sb); /* * Save the old mount options in case we * need to restore them. */ org_mount_opt = sbi->mount_opt; active_logs = sbi->active_logs; sbi->mount_opt.opt = 0; default_options(sbi); /* parse mount options */ err = parse_options(sb, data); if (err) goto restore_opts; /* * Previous and new state of filesystem is RO, * so skip checking GC and FLUSH_MERGE conditions. */ if (f2fs_readonly(sb) && (*flags & MS_RDONLY)) goto skip; /* * We stop the GC thread if FS is mounted as RO * or if background_gc = off is passed in mount * option. Also sync the filesystem. */ if ((*flags & MS_RDONLY) || !test_opt(sbi, BG_GC)) { if (sbi->gc_thread) { stop_gc_thread(sbi); f2fs_sync_fs(sb, 1); need_restart_gc = true; } } else if (!sbi->gc_thread) { err = start_gc_thread(sbi); if (err) goto restore_opts; need_stop_gc = true; } /* * We stop issue flush thread if FS is mounted as RO * or if flush_merge is not passed in mount option. */ if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { destroy_flush_cmd_control(sbi); } else if (!SM_I(sbi)->cmd_control_info) { err = create_flush_cmd_control(sbi); if (err) goto restore_gc; } skip: /* Update the POSIXACL Flag */ sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); return 0; restore_gc: if (need_restart_gc) { if (start_gc_thread(sbi)) f2fs_msg(sbi->sb, KERN_WARNING, "background gc thread has stopped"); } else if (need_stop_gc) { stop_gc_thread(sbi); } restore_opts: sbi->mount_opt = org_mount_opt; sbi->active_logs = active_logs; return err; }
static int f2fs_fill_super(struct super_block *sb, void *data, int silent) { struct f2fs_sb_info *sbi; struct f2fs_super_block *raw_super; struct buffer_head *raw_super_buf; struct inode *root; long err; bool retry = true, need_fsck = false; char *options = NULL; int recovery, i; try_onemore: err = -EINVAL; raw_super = NULL; raw_super_buf = NULL; recovery = 0; /* allocate memory for f2fs-specific super block info */ sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); if (!sbi) return -ENOMEM; /* set a block size */ if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); goto free_sbi; } err = read_raw_super_block(sb, &raw_super, &raw_super_buf, &recovery); if (err) goto free_sbi; sb->s_fs_info = sbi; default_options(sbi); /* parse mount options */ options = kstrdup((const char *)data, GFP_KERNEL); if (data && !options) { err = -ENOMEM; goto free_sb_buf; } err = parse_options(sb, options); if (err) goto free_options; sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); sb->s_max_links = F2FS_LINK_MAX; get_random_bytes(&sbi->s_next_generation, sizeof(u32)); sb->s_op = &f2fs_sops; sb->s_xattr = f2fs_xattr_handlers; sb->s_export_op = &f2fs_export_ops; sb->s_magic = F2FS_SUPER_MAGIC; sb->s_time_gran = 1; sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); /* init f2fs-specific super block info */ sbi->sb = sb; sbi->raw_super = raw_super; sbi->raw_super_buf = raw_super_buf; mutex_init(&sbi->gc_mutex); mutex_init(&sbi->writepages); mutex_init(&sbi->cp_mutex); init_rwsem(&sbi->node_write); clear_sbi_flag(sbi, SBI_POR_DOING); spin_lock_init(&sbi->stat_lock); init_rwsem(&sbi->read_io.io_rwsem); sbi->read_io.sbi = sbi; sbi->read_io.bio = NULL; for (i = 0; i < NR_PAGE_TYPE; i++) { init_rwsem(&sbi->write_io[i].io_rwsem); sbi->write_io[i].sbi = sbi; sbi->write_io[i].bio = NULL; } init_rwsem(&sbi->cp_rwsem); init_waitqueue_head(&sbi->cp_wait); init_sb_info(sbi); /* get an inode for meta space */ sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); if (IS_ERR(sbi->meta_inode)) { f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); err = PTR_ERR(sbi->meta_inode); goto free_options; } err = get_valid_checkpoint(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); goto free_meta_inode; } /* sanity checking of checkpoint */ err = -EINVAL; if (sanity_check_ckpt(sbi)) { f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint"); goto free_cp; } sbi->total_valid_node_count = le32_to_cpu(sbi->ckpt->valid_node_count); sbi->total_valid_inode_count = le32_to_cpu(sbi->ckpt->valid_inode_count); sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); sbi->total_valid_block_count = le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->alloc_valid_block_count = 0; INIT_LIST_HEAD(&sbi->dir_inode_list); spin_lock_init(&sbi->dir_inode_lock); init_extent_cache_info(sbi); init_ino_entry_info(sbi); /* setup f2fs internal modules */ err = build_segment_manager(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to initialize F2FS segment manager"); goto free_sm; } err = build_node_manager(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to initialize F2FS node manager"); goto free_nm; } build_gc_manager(sbi); /* get an inode for node space */ sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); if (IS_ERR(sbi->node_inode)) { f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); err = PTR_ERR(sbi->node_inode); goto free_nm; } /* if there are nt orphan nodes free them */ recover_orphan_inodes(sbi); /* read root inode and dentry */ root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); if (IS_ERR(root)) { f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); err = PTR_ERR(root); goto free_node_inode; } if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { iput(root); err = -EINVAL; goto free_node_inode; } sb->s_root = d_make_root(root); /* allocate root dentry */ if (!sb->s_root) { err = -ENOMEM; goto free_root_inode; } err = f2fs_build_stats(sbi); if (err) goto free_root_inode; if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); if (sbi->s_proc) proc_create_data("segment_info", S_IRUGO, sbi->s_proc, &f2fs_seq_segment_info_fops, sb); if (test_opt(sbi, DISCARD)) { struct request_queue *q = bdev_get_queue(sb->s_bdev); if (!blk_queue_discard(q)) f2fs_msg(sb, KERN_WARNING, "mounting with \"discard\" option, but " "the device does not support discard"); clear_opt(sbi, DISCARD); } sbi->s_kobj.kset = f2fs_kset; init_completion(&sbi->s_kobj_unregister); err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, "%s", sb->s_id); if (err) goto free_proc; /* recover fsynced data */ if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { /* * mount should be failed, when device has readonly mode, and * previous checkpoint was not done by clean system shutdown. */ if (bdev_read_only(sb->s_bdev) && !is_set_ckpt_flags(sbi->ckpt, CP_UMOUNT_FLAG)) { err = -EROFS; goto free_kobj; } if (need_fsck) set_sbi_flag(sbi, SBI_NEED_FSCK); err = recover_fsync_data(sbi); if (err) { need_fsck = true; f2fs_msg(sb, KERN_ERR, "Cannot recover all fsync data errno=%ld", err); goto free_kobj; } } /* * If filesystem is not mounted as read-only then * do start the gc_thread. */ if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) { /* After POR, we can run background GC thread.*/ err = start_gc_thread(sbi); if (err) goto free_kobj; } kfree(options); /* recover broken superblock */ if (recovery && !f2fs_readonly(sb) && !bdev_read_only(sb->s_bdev)) { f2fs_msg(sb, KERN_INFO, "Recover invalid superblock"); f2fs_commit_super(sbi); } return 0; free_kobj: kobject_del(&sbi->s_kobj); free_proc: if (sbi->s_proc) { remove_proc_entry("segment_info", sbi->s_proc); remove_proc_entry(sb->s_id, f2fs_proc_root); } f2fs_destroy_stats(sbi); free_root_inode: dput(sb->s_root); sb->s_root = NULL; free_node_inode: iput(sbi->node_inode); free_nm: destroy_node_manager(sbi); free_sm: destroy_segment_manager(sbi); free_cp: kfree(sbi->ckpt); free_meta_inode: make_bad_inode(sbi->meta_inode); iput(sbi->meta_inode); free_options: kfree(options); free_sb_buf: brelse(raw_super_buf); free_sbi: kfree(sbi); /* give only one another chance */ if (retry) { retry = false; shrink_dcache_sb(sb); goto try_onemore; } return err; }
/*----------------------------------------------------------------------*/ int main(int argc, char **argv) { /* MBIO status variables */ int status = MB_SUCCESS; int error = MB_ERROR_NO_ERROR; /* MBIO read control parameters */ int read_datalist = MB_NO; void *datalist; int look_processed = MB_DATALIST_LOOK_UNSET; double file_weight; mb_path ifile; /* MBIO read values */ int read_data; /* counting variables */ counts filerecs; counts totrecs; /* processing variables */ options opts; mbdefaults mbdflts; /* set default options */ default_options(&opts); /* mb_mem_debug_on(opts.verbose, &error); */ /* get mbsystem default values */ status = mb_defaults(opts.verbose, &(mbdflts.format), &(mbdflts.pings_get), &(mbdflts.lonflip), mbdflts.bounds, mbdflts.btime_i, mbdflts.etime_i, &(mbdflts.speedmin), &(mbdflts.timegap)); if (status == MB_SUCCESS) { parse_options(opts.verbose, argc, argv, &opts, &error); } if (opts.errflg) { fprintf(stderr, "usage: %s\n", usage_message); fprintf(stderr, "\nProgram <%s> Terminated\n", program_name); error = MB_ERROR_BAD_USAGE; exit(error); } /* print starting debug statements */ if (opts.verbose >= 1) { print_mbdefaults(opts.verbose, &opts, &mbdflts, &error); } /* if help desired then print it and exit */ if (opts.help) { fprintf(stderr, "\nProgram %s\n", program_name); fprintf(stderr, "Version %s\n", rcs_id); fprintf(stderr, "MB-system Version %s\n", MB_VERSION); fprintf(stderr, "\nusage: %s\n", usage_message); fprintf(stderr, "\n%s\n", help_message); exit(error); } /* get format if required */ if (opts.format == 0) { mb_get_format(opts.verbose, opts.read_file, NULL, &(opts.format), &error); } /* determine whether to read one file or a list of files */ if (opts.format < 0) { read_datalist = MB_YES; } /* open file list */ if (read_datalist == MB_YES) { if ((status = mb_datalist_open(opts.verbose, &datalist, opts.read_file, look_processed, &error)) != MB_SUCCESS) { char message[MAX_ERROR_STRING]; sprintf(message, "Unable to open data list file: %s\n", opts.read_file); error_exit(opts.verbose, MB_ERROR_OPEN_FAIL, "mb_datalist_open", message); } if ((status = mb_datalist_read(opts.verbose, datalist, ifile, &(opts.format), &file_weight, &error)) == MB_SUCCESS) { read_data = MB_YES; } else { read_data = MB_NO; } } /* else copy single filename to be read */ else { strcpy(ifile, opts.read_file); read_data = MB_YES; } /* reset total record counter */ zero_counts(opts.verbose, &totrecs, &error); /* loop over files to be read */ while (read_data == MB_YES) { /* reset file record counter */ zero_counts(opts.verbose, &filerecs, &error); /* process the output files */ if (status == MB_SUCCESS) { status = process_output(opts.verbose, &mbdflts, &opts, ifile, &filerecs, &error); } /* output counts */ filerecs.files_read++; if (opts.verbose >= 1) { fprintf(stdout, "\nData records read from: %s\n", ifile); print_counts(opts.verbose, &filerecs, &error); } /* add this file's counts to total */ add_counts(opts.verbose, &totrecs, &filerecs, &error); /* figure out whether and what to read next */ if (read_datalist == MB_YES) { if ((status = mb_datalist_read(opts.verbose, datalist, ifile, &(opts.format), &file_weight, &error)) == MB_SUCCESS) { read_data = MB_YES; } else { read_data = MB_NO; } } else { read_data = MB_NO; } } /* end loop over files in list */ /* output counts */ if (opts.verbose >= 1) { fprintf(stdout, "\nTotal data records read:\n"); print_counts(opts.verbose, &totrecs, &error); } if (read_datalist == MB_YES) { mb_datalist_close(opts.verbose, &datalist, &error); } /* check memory */ status = mb_memory_list(opts.verbose, &error); /* mb_mem_debug_off(opts.verbose, &error); */ return (status); } /* main */
static int f2fs_fill_super(struct super_block *sb, void *data, int silent) { struct f2fs_sb_info *sbi; struct f2fs_super_block *raw_super; struct inode *root; long err; bool retry = true, need_fsck = false; char *options = NULL; int recovery, i, valid_super_block; struct curseg_info *seg_i; try_onemore: err = -EINVAL; raw_super = NULL; valid_super_block = -1; recovery = 0; /* allocate memory for f2fs-specific super block info */ sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); if (!sbi) return -ENOMEM; /* Load the checksum driver */ sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); if (IS_ERR(sbi->s_chksum_driver)) { f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver."); err = PTR_ERR(sbi->s_chksum_driver); sbi->s_chksum_driver = NULL; goto free_sbi; } /* set a block size */ if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); goto free_sbi; } err = read_raw_super_block(sb, &raw_super, &valid_super_block, &recovery); if (err) goto free_sbi; sb->s_fs_info = sbi; default_options(sbi); /* parse mount options */ options = kstrdup((const char *)data, GFP_KERNEL); if (data && !options) { err = -ENOMEM; goto free_sb_buf; } err = parse_options(sb, options); if (err) goto free_options; sbi->max_file_blocks = max_file_blocks(); sb->s_maxbytes = sbi->max_file_blocks << le32_to_cpu(raw_super->log_blocksize); sb->s_max_links = F2FS_LINK_MAX; get_random_bytes(&sbi->s_next_generation, sizeof(u32)); sb->s_op = &f2fs_sops; sb->s_cop = &f2fs_cryptops; sb->s_xattr = f2fs_xattr_handlers; sb->s_export_op = &f2fs_export_ops; sb->s_magic = F2FS_SUPER_MAGIC; sb->s_time_gran = 1; sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); /* init f2fs-specific super block info */ sbi->sb = sb; sbi->raw_super = raw_super; sbi->valid_super_block = valid_super_block; mutex_init(&sbi->gc_mutex); mutex_init(&sbi->writepages); mutex_init(&sbi->cp_mutex); init_rwsem(&sbi->node_write); /* disallow all the data/node/meta page writes */ set_sbi_flag(sbi, SBI_POR_DOING); spin_lock_init(&sbi->stat_lock); init_rwsem(&sbi->read_io.io_rwsem); sbi->read_io.sbi = sbi; sbi->read_io.bio = NULL; for (i = 0; i < NR_PAGE_TYPE; i++) { init_rwsem(&sbi->write_io[i].io_rwsem); sbi->write_io[i].sbi = sbi; sbi->write_io[i].bio = NULL; } init_rwsem(&sbi->cp_rwsem); init_waitqueue_head(&sbi->cp_wait); init_sb_info(sbi); /* get an inode for meta space */ sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); if (IS_ERR(sbi->meta_inode)) { f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); err = PTR_ERR(sbi->meta_inode); goto free_options; } err = get_valid_checkpoint(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); goto free_meta_inode; } sbi->total_valid_node_count = le32_to_cpu(sbi->ckpt->valid_node_count); sbi->total_valid_inode_count = le32_to_cpu(sbi->ckpt->valid_inode_count); sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); sbi->total_valid_block_count = le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->alloc_valid_block_count = 0; for (i = 0; i < NR_INODE_TYPE; i++) { INIT_LIST_HEAD(&sbi->inode_list[i]); spin_lock_init(&sbi->inode_lock[i]); } init_extent_cache_info(sbi); init_ino_entry_info(sbi); /* setup f2fs internal modules */ err = build_segment_manager(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to initialize F2FS segment manager"); goto free_sm; } err = build_node_manager(sbi); if (err) { f2fs_msg(sb, KERN_ERR, "Failed to initialize F2FS node manager"); goto free_nm; } /* For write statistics */ if (sb->s_bdev->bd_part) sbi->sectors_written_start = (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]); /* Read accumulated write IO statistics if exists */ seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); if (__exist_node_summaries(sbi)) sbi->kbytes_written = le64_to_cpu(seg_i->sum_blk->journal.info.kbytes_written); build_gc_manager(sbi); /* get an inode for node space */ sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); if (IS_ERR(sbi->node_inode)) { f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); err = PTR_ERR(sbi->node_inode); goto free_nm; } f2fs_join_shrinker(sbi); /* if there are nt orphan nodes free them */ err = recover_orphan_inodes(sbi); if (err) goto free_node_inode; /* read root inode and dentry */ root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); if (IS_ERR(root)) { f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); err = PTR_ERR(root); goto free_node_inode; } if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { iput(root); err = -EINVAL; goto free_node_inode; } sb->s_root = d_make_root(root); /* allocate root dentry */ if (!sb->s_root) { err = -ENOMEM; goto free_root_inode; } err = f2fs_build_stats(sbi); if (err) goto free_root_inode; if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); if (sbi->s_proc) proc_create_data("segment_info", S_IRUGO, sbi->s_proc, &f2fs_seq_segment_info_fops, sb); sbi->s_kobj.kset = f2fs_kset; init_completion(&sbi->s_kobj_unregister); err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL, "%s", sb->s_id); if (err) goto free_proc; /* recover fsynced data */ if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { /* * mount should be failed, when device has readonly mode, and * previous checkpoint was not done by clean system shutdown. */ if (bdev_read_only(sb->s_bdev) && !is_set_ckpt_flags(sbi->ckpt, CP_UMOUNT_FLAG)) { err = -EROFS; goto free_kobj; } if (need_fsck) set_sbi_flag(sbi, SBI_NEED_FSCK); err = recover_fsync_data(sbi); if (err) { need_fsck = true; f2fs_msg(sb, KERN_ERR, "Cannot recover all fsync data errno=%ld", err); goto free_kobj; } } /* recover_fsync_data() cleared this already */ clear_sbi_flag(sbi, SBI_POR_DOING); /* * If filesystem is not mounted as read-only then * do start the gc_thread. */ if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) { /* After POR, we can run background GC thread.*/ err = start_gc_thread(sbi); if (err) goto free_kobj; } kfree(options); /* recover broken superblock */ if (recovery && !f2fs_readonly(sb) && !bdev_read_only(sb->s_bdev)) { err = f2fs_commit_super(sbi, true); f2fs_msg(sb, KERN_INFO, "Try to recover %dth superblock, ret: %ld", sbi->valid_super_block ? 1 : 2, err); } f2fs_update_time(sbi, CP_TIME); f2fs_update_time(sbi, REQ_TIME); return 0; free_kobj: kobject_del(&sbi->s_kobj); kobject_put(&sbi->s_kobj); wait_for_completion(&sbi->s_kobj_unregister); free_proc: if (sbi->s_proc) { remove_proc_entry("segment_info", sbi->s_proc); remove_proc_entry(sb->s_id, f2fs_proc_root); } f2fs_destroy_stats(sbi); free_root_inode: dput(sb->s_root); sb->s_root = NULL; free_node_inode: mutex_lock(&sbi->umount_mutex); f2fs_leave_shrinker(sbi); iput(sbi->node_inode); mutex_unlock(&sbi->umount_mutex); free_nm: destroy_node_manager(sbi); free_sm: destroy_segment_manager(sbi); kfree(sbi->ckpt); free_meta_inode: make_bad_inode(sbi->meta_inode); iput(sbi->meta_inode); free_options: kfree(options); free_sb_buf: kfree(raw_super); free_sbi: if (sbi->s_chksum_driver) crypto_free_shash(sbi->s_chksum_driver); kfree(sbi); /* give only one another chance */ if (retry) { retry = false; shrink_dcache_sb(sb); goto try_onemore; } return err; }
int main(int argc, char *argv[]) { int c; int argind; char *infile = ""; eh_opts_t *options = XMALLOC(eh_opts_t, sizeof (eh_opts_t)); default_options(options); opterr = 0; /* Process command-line switches. */ while (1) { static struct option long_opts[] = { { "strict", no_argument, 0, 's' }, { "help", no_argument, 0, 'h' }, { "license", no_argument, 0, 'l' }, { 0, 0, 0, 0 } }; int opt_index = 0; c = getopt_long(argc, argv, "shl", long_opts, &opt_index); /* Detect end of options. */ if (c == -1) break; switch (c) { case 's': options->eo_strict = true; break; case 'l': license(); exit(EXIT_SUCCESS); break; case 'h': usage(EXIT_SUCCESS); break; case '?': fprintf(stderr, "%s: unknown option '%c'.\n", argv[0], optopt); /* Fall through is intentional. */ default: usage(EXIT_FAILURE); } } do { infile = "-"; argind = optind; /* Get input source as last remaining argument. */ if (optind < argc) { infile = argv[optind]; } /* Determine whether input source is stdin or an actual file. */ if ((infile[0] == '-') && (infile[1] == 0)) { egghead_eval_file(options, "-"); } else { /* Proceed only if a valid .bf or .b file was given. */ if ((STREQ(strrchr(infile, '.'), ".bf")) || (STREQ(strrchr(infile, '.'), ".b"))) { egghead_eval_file(options, infile); } else { fprintf(stderr, "[ERROR] File %s is not a valid brainfuck file.\n", infile); exit(EXIT_FAILURE); } } } while (++argind < argc); XFREE(options); return 0; }