int main(int argc, char *argv[]) { cf_x_core_uuid_t *uuid_a; cf_x_core_uuid_t *uuid_a_copy; cf_x_core_uuid_t *uuid_b; int compare_result; cf_x_core_uuid_t *uuid_c; unsigned long each_uuid; uuid_a = cf_x_core_uuid_create(); if (!uuid_a) { cf_x_core_trace_exit("x_core_uuid_create"); } print_uuid(uuid_a, "uuid_a"); uuid_b = cf_x_core_uuid_create(); if (!uuid_b) { cf_x_core_trace_exit("x_core_uuid_create"); } print_uuid(uuid_b, "uuid_b"); uuid_a_copy = cf_x_core_uuid_copy(uuid_a); if (!uuid_a_copy) { cf_x_core_trace_exit("x_core_uuid_copy"); } print_uuid(uuid_a_copy, "uuid_a_copy"); compare_result = cf_x_core_uuid_compare(uuid_a, uuid_a); printf("cmp(uuid_a,uuid_a): %d\n", compare_result); compare_result = cf_x_core_uuid_compare(uuid_a, uuid_b); printf("cmp(uuid_a,uuid_b): %d\n", compare_result); compare_result = cf_x_core_uuid_compare(uuid_b, uuid_a); printf("cmp(uuid_b,uuid_a): %d\n", compare_result); compare_result = cf_x_core_uuid_compare(uuid_b, uuid_b); printf("cmp(uuid_b,uuid_b): %d\n", compare_result); compare_result = cf_x_core_uuid_compare(uuid_a, uuid_a_copy); printf("cmp(uuid_a,uuid_a_copy): %d\n", compare_result); if (cf_x_core_bool_false) { printf("creating/destroying a uuid %d times\n", REPETITIONS); for (each_uuid = 0; each_uuid < REPETITIONS; each_uuid++) { uuid_c = cf_x_core_uuid_create(); if (!uuid_c) { cf_x_core_trace_exit("x_core_uuid_create"); } cf_x_core_uuid_destroy(uuid_c); } } cf_x_core_uuid_destroy(uuid_a); cf_x_core_uuid_destroy(uuid_a_copy); cf_x_core_uuid_destroy(uuid_b); return 0; }
static int dev_uuid_test(void) { int fd; ssize_t rc; uuid_t uuid; fd = tipc_connect(dev_name, uuid_name); if (fd < 0) { fprintf(stderr, "Failed to connect to '%s' service\n", "uuid"); return fd; } /* wait for test to complete */ rc = read(fd, &uuid, sizeof(uuid)); if (rc < 0) { perror("dev_uuid_test: read"); } else if (rc != sizeof(uuid)) { fprintf(stderr, "unexpected uuid size (%d vs. %d)\n", (int)rc, (int)sizeof(uuid)); } else { print_uuid(dev_name, &uuid); } tipc_close(fd); return 0; }
/** * Print super sector for debug. * This will be obsolute. Use print_super_sector() instead. */ void print_super_sector_raw(const struct walb_super_sector* super_sect) { ASSERT(super_sect); printf("checksum: %08x\n" "logical_bs: %u\n" "physical_bs: %u\n" "metadata_size: %u\n" "log_checksum_salt: %"PRIu32"\n", super_sect->checksum, super_sect->logical_bs, super_sect->physical_bs, super_sect->metadata_size, super_sect->log_checksum_salt); printf("uuid: "); print_uuid(super_sect->uuid); printf("\n" "name: \"%s\"\n" "ring_buffer_size: %lu\n" "oldest_lsid: %lu\n" "written_lsid: %lu\n" "device_size: %lu\n", super_sect->name, super_sect->ring_buffer_size, super_sect->oldest_lsid, super_sect->written_lsid, super_sect->device_size); printf("ring_buffer_offset: %lu\n", get_ring_buffer_offset_2(super_sect)); }
static void print_desc(struct gatt_db_attribute *attr, void *user_data) { printf("\t\t " COLOR_MAGENTA "descr" COLOR_OFF " - handle: 0x%04x, uuid: ", gatt_db_attribute_get_handle(attr)); print_uuid(gatt_db_attribute_get_type(attr)); }
int main(int argc, char *argv[]) { FILE *secret, *pub, *out; int len = 0; uuid_t uuid; if( argc != 4 ) { printf( "Usage: catkeys <secret key file> <pubkey file> <outputfile>\n" ); } secret = fopen(argv[1], "rb"); if( secret == NULL ) { printf( "Can't open secret key file %s, failing.\n", argv[1] ); exit(0); } pub = fopen( argv[2], "r" ); if( pub == NULL ) { printf( "Can't open public key file %s, failing.\n", argv[2] ); exit(0); } out = fopen( argv[3], "wb" ); if( out == NULL ) { printf( "Can't open binary output file %s, failing.\n", argv[3] ); exit(0); } len = 0; while( !feof(secret) ){ len ++; fputc(fgetc(secret), out); } if( len >= SECLEN ) { printf( "Warning! Secret key input larger than 2k.\n" ); } while( len < SECLEN ) { len++; fputc(0, out); // pad 0's to 2k length } while( !feof(pub) ) { len++; fputc(fgetc(pub), out); } if( len >= (SECLEN + PUBLEN)) { printf( "Warning! public key length too long.\n" ); } while( len < (SECLEN + PUBLEN) ) { len++; fputc(0, out); // pad 0's to almost 4k length } uuid_generate(uuid); fwrite( uuid, sizeof(uuid), 1, out ); print_uuid(&uuid); fclose(out); fclose(secret); fclose(pub); }
int main(int argc, char *argv[]) { uuid_t u; CWT_UNUSED2(argc, argv); uuid_create(&u); print_uuid(u); return 0; }
/** * Handle services discovered. * * The GattClient invokes this function when a service has been discovered. * * @see GattClient::launchServiceDiscovery */ void when_service_discovered(const DiscoveredService *discovered_service) { // print information of the service discovered printf("Service discovered: value = "); print_uuid(discovered_service->getUUID()); printf(", start = %u, end = %u.\r\n", discovered_service->getStartHandle(), discovered_service->getEndHandle() ); }
/** * Handle the discovery of the characteristic descriptors. * * If the descriptor found is a CCCD then stop the discovery. Once the * process has ended subscribe to server initiated events by writing the * value of the CCCD. */ void when_descriptor_discovered(const DiscoveryCallbackParams_t* event) { printf("\tDescriptor discovered at %u, UUID: ", event->descriptor.getAttributeHandle()); print_uuid(event->descriptor.getUUID()); printf(".\r\n"); if (event->descriptor.getUUID() == BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG) { _descriptor_handle = event->descriptor.getAttributeHandle(); _client->terminateCharacteristicDescriptorDiscovery( event->characteristic ); } }
static void print_service(const bt_gatt_service_t *service) { struct bt_gatt_characteristic_iter iter; const bt_gatt_characteristic_t *chrc; size_t i; if (!bt_gatt_characteristic_iter_init(&iter, service)) { PRLOG("Failed to initialize characteristic iterator\n"); return; } printf(COLOR_RED "service" COLOR_OFF " - start: 0x%04x, " "end: 0x%04x, uuid: ", service->start_handle, service->end_handle); print_uuid(service->uuid); while (bt_gatt_characteristic_iter_next(&iter, &chrc)) { printf("\t " COLOR_YELLOW "charac" COLOR_OFF " - start: 0x%04x, end: 0x%04x, " "value: 0x%04x, props: 0x%02x, uuid: ", chrc->start_handle, chrc->end_handle, chrc->value_handle, chrc->properties); print_uuid(chrc->uuid); for (i = 0; i < chrc->num_descs; i++) { printf("\t\t " COLOR_MAGENTA "descr" COLOR_OFF " - handle: 0x%04x, uuid: ", chrc->descs[i].handle); print_uuid(chrc->descs[i].uuid); } } printf("\n"); }
void hd_print(FILE *f, struct field *fld) { switch (fld->type) { case 0x2 ... 0x3: case 0x5 ... 0xb: case 0xf ... 0x11: pws(f, fld->val, fld->len); break; case 0x1: print_uuid(fld->val); break; case 0x4: print_time(fld->val); break; } }
void db_print(FILE *f, struct field *fld) { switch (fld->type) { case 0x2 ... 0x6: case 0xd ... 0x10: case 0x14: case 0x16: pws(f, fld->val, fld->len); break; case 0x7 ... 0xa: case 0xc: print_time(fld->val); break; case 0x1: print_uuid(fld->val); break; } }
static void print_chrc(struct gatt_db_attribute *attr, void *user_data) { uint16_t handle, value_handle; uint8_t properties; bt_uuid_t uuid; if (!gatt_db_attribute_get_char_data(attr, &handle, &value_handle, &properties, &uuid)) return; printf("\t " COLOR_YELLOW "charac" COLOR_OFF " - start: 0x%04x, value: 0x%04x, " "props: 0x%02x, uuid: ", handle, value_handle, properties); print_uuid(&uuid); gatt_db_service_foreach_desc(attr, print_desc, NULL); }
static void print_service(struct gatt_db_attribute *attr, void *user_data) { struct server *server = user_data; uint16_t start, end; bool primary; bt_uuid_t uuid; if (!gatt_db_attribute_get_service_data(attr, &start, &end, &primary, &uuid)) return; printf(COLOR_RED "service" COLOR_OFF " - start: 0x%04x, " "end: 0x%04x, type: %s, uuid: ", start, end, primary ? "primary" : "secondary"); print_uuid(&uuid); gatt_db_service_foreach_incl(attr, print_incl, server); gatt_db_service_foreach_char(attr, print_chrc, NULL); printf("\n"); }
static void print_incl(struct gatt_db_attribute *attr, void *user_data) { struct server *server = user_data; uint16_t handle, start, end; struct gatt_db_attribute *service; bt_uuid_t uuid; if (!gatt_db_attribute_get_incl_data(attr, &handle, &start, &end)) return; service = gatt_db_get_attribute(server->db, start); if (!service) return; gatt_db_attribute_get_service_uuid(service, &uuid); printf("\t " COLOR_GREEN "include" COLOR_OFF " - handle: " "0x%04x, - start: 0x%04x, end: 0x%04x," "uuid: ", handle, start, end); print_uuid(&uuid); }
/** * Handle characteristics discovered. * * The GattClient invoke this function when a characteristic has been * discovered. * * @see GattClient::launchServiceDiscovery */ void when_characteristic_discovered(const DiscoveredCharacteristic *discovered_characteristic) { // print characteristics properties printf("\tCharacteristic discovered: uuid = "); print_uuid(discovered_characteristic->getUUID()); printf(", properties = "); print_properties(discovered_characteristic->getProperties()); printf( ", decl handle = %u, value handle = %u, last handle = %u.\r\n", discovered_characteristic->getDeclHandle(), discovered_characteristic->getValueHandle(), discovered_characteristic->getLastHandle() ); // add the characteristic into the list of discovered characteristics bool success = add_characteristic(discovered_characteristic); if (!success) { printf("Error: memory allocation failure while adding the discovered characteristic.\r\n"); _client->terminateServiceDiscovery(); stop(); return; } }
void print_adv_fields(const struct ble_hs_adv_fields *fields) { char s[BLE_HS_ADV_MAX_SZ]; const uint8_t *u8p; int i; if (fields->flags != 0) { BSNCENT_LOG(DEBUG, " flags=0x%02x\n", fields->flags); } if (fields->uuids16 != NULL) { BSNCENT_LOG(DEBUG, " uuids16(%scomplete)=", fields->uuids16_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids16; i++) { print_uuid(&fields->uuids16[i].u); BSNCENT_LOG(DEBUG, " "); } BSNCENT_LOG(DEBUG, "\n"); } if (fields->uuids32 != NULL) { BSNCENT_LOG(DEBUG, " uuids32(%scomplete)=", fields->uuids32_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids32; i++) { print_uuid(&fields->uuids32[i].u); BSNCENT_LOG(DEBUG, " "); } BSNCENT_LOG(DEBUG, "\n"); } if (fields->uuids128 != NULL) { BSNCENT_LOG(DEBUG, " uuids128(%scomplete)=", fields->uuids128_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids128; i++) { print_uuid(&fields->uuids128[i].u); BSNCENT_LOG(DEBUG, " "); } BSNCENT_LOG(DEBUG, "\n"); } if (fields->name != NULL) { assert(fields->name_len < sizeof s - 1); memcpy(s, fields->name, fields->name_len); s[fields->name_len] = '\0'; BSNCENT_LOG(DEBUG, " name(%scomplete)=%s\n", fields->name_is_complete ? "" : "in", s); } if (fields->tx_pwr_lvl_is_present) { BSNCENT_LOG(DEBUG, " tx_pwr_lvl=%d\n", fields->tx_pwr_lvl); } if (fields->slave_itvl_range != NULL) { BSNCENT_LOG(DEBUG, " slave_itvl_range="); print_bytes(fields->slave_itvl_range, BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN); BSNCENT_LOG(DEBUG, "\n"); } if (fields->svc_data_uuid16 != NULL) { BSNCENT_LOG(DEBUG, " svc_data_uuid16="); print_bytes(fields->svc_data_uuid16, fields->svc_data_uuid16_len); BSNCENT_LOG(DEBUG, "\n"); } if (fields->public_tgt_addr != NULL) { BSNCENT_LOG(DEBUG, " public_tgt_addr="); u8p = fields->public_tgt_addr; for (i = 0; i < fields->num_public_tgt_addrs; i++) { BSNCENT_LOG(DEBUG, "public_tgt_addr=%s ", addr_str(u8p)); u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; } BSNCENT_LOG(DEBUG, "\n"); } if (fields->appearance_is_present) { BSNCENT_LOG(DEBUG, " appearance=0x%04x\n", fields->appearance); } if (fields->adv_itvl_is_present) { BSNCENT_LOG(DEBUG, " adv_itvl=0x%04x\n", fields->adv_itvl); } if (fields->svc_data_uuid32 != NULL) { BSNCENT_LOG(DEBUG, " svc_data_uuid32="); print_bytes(fields->svc_data_uuid32, fields->svc_data_uuid32_len); BSNCENT_LOG(DEBUG, "\n"); } if (fields->svc_data_uuid128 != NULL) { BSNCENT_LOG(DEBUG, " svc_data_uuid128="); print_bytes(fields->svc_data_uuid128, fields->svc_data_uuid128_len); BSNCENT_LOG(DEBUG, "\n"); } if (fields->uri != NULL) { BSNCENT_LOG(DEBUG, " uri="); print_bytes(fields->uri, fields->uri_len); BSNCENT_LOG(DEBUG, "\n"); } if (fields->mfg_data != NULL) { BSNCENT_LOG(DEBUG, " mfg_data="); print_bytes(fields->mfg_data, fields->mfg_data_len); BSNCENT_LOG(DEBUG, "\n"); } }
wiced_result_t wiced_bt_smart_attribute_print( const wiced_bt_smart_attribute_t* attribute ) { wiced_bt_smart_attribute_t* curr_attr = (wiced_bt_smart_attribute_t*)attribute; if ( attribute == NULL ) { return WICED_BT_BADARG; } WPRINT_LIB_INFO( ( "----------------------------------------------------\n" ) ); print_type( &curr_attr->type ); WPRINT_LIB_INFO( ( "\n" ) ); WPRINT_LIB_INFO( ( "Handle : %d\n", (int)curr_attr->handle ) ); WPRINT_LIB_INFO( ( "Type : " ) ); print_uuid( &curr_attr->type ); WPRINT_LIB_INFO( ( "Permission : %d\n", (int)curr_attr->permission ) ); WPRINT_LIB_INFO( ( "Value Length : %d\n", (int)curr_attr->value_length ) ); if ( curr_attr->type.size == UUID_16BIT ) { switch ( curr_attr->type.value.value_16_bit ) { case 0x2800: { WPRINT_LIB_INFO( ( "Start Handle : %d\n", (int)curr_attr->value.service.start_handle ) ); WPRINT_LIB_INFO( ( "End Handle : %d\n", (int)curr_attr->value.service.end_handle ) ); WPRINT_LIB_INFO( ( "Service UUID : ") ); print_uuid( &curr_attr->value.service.uuid ); break; } case 0x2802: { WPRINT_LIB_INFO( ( "Start Handle : %d\n", (int)curr_attr->value.include.included_service_handle ) ); WPRINT_LIB_INFO( ( "End Handle : %d\n", (int)curr_attr->value.include.end_group_handle ) ); WPRINT_LIB_INFO( ( "Service UUID : ") ); print_uuid( &curr_attr->value.include.uuid ); break; } case 0x2803: { WPRINT_LIB_INFO( ( "Properties : %d\n", (int)curr_attr->value.characteristic.properties ) ); WPRINT_LIB_INFO( ( "Value Handle : %d\n", (int)curr_attr->value.characteristic.value_handle ) ); WPRINT_LIB_INFO( ( "Value UUID : ") ); print_uuid( &curr_attr->value.characteristic.uuid ); break; } case 0x2900: { WPRINT_LIB_INFO( ( "Extended Properties : %d\n", (int)curr_attr->value.extended_properties.properties ) ); break; } case 0x2901: { WPRINT_LIB_INFO( ( "Extended Properties : %s\n", curr_attr->value.user_description.string ) ); break; } case 0x2902: { WPRINT_LIB_INFO( ( "Client Configuration : %d\n", (int)curr_attr->value.client_config.config_bits ) ); break; } case 0x2903: { WPRINT_LIB_INFO( ( "Server Configuration : %d\n", (int)curr_attr->value.server_config.config_bits ) ); break; } case 0x2904: { WPRINT_LIB_INFO( ( "Format : %d\n", (int)curr_attr->value.presentation_format.format ) ); WPRINT_LIB_INFO( ( "Exponent : %d\n", (int)curr_attr->value.presentation_format.exponent ) ); WPRINT_LIB_INFO( ( "Unit : %d\n", (int)curr_attr->value.presentation_format.unit ) ); WPRINT_LIB_INFO( ( "Namespace : %d\n", (int)curr_attr->value.presentation_format.name_space ) ); WPRINT_LIB_INFO( ( "Description : %d\n", (int)curr_attr->value.presentation_format.description ) ); break; } case 0x2905: { uint32_t i; WPRINT_LIB_INFO( ( "List of Handles : \n" ) ); for ( i = 0; i < curr_attr->value_length / 2; i ++ ) { WPRINT_LIB_INFO( ( "%02d ", (int)curr_attr->value.aggregate_format.handle_list[i] ) ); } WPRINT_LIB_INFO( ( "\n" ) ); break; } case 0x2A00: { WPRINT_LIB_INFO( ( "Device Name : %s\n", curr_attr->value.device_name.device_name ) ); break; } case 0x2A01: { WPRINT_LIB_INFO( ( "Appearance : %d\n", (int)curr_attr->value.appearance.appearance ) ); break; } case 0x2A02: { WPRINT_LIB_INFO( ( "Peripheral Privacy Flag : %d\n", (int)curr_attr->value.periph_privacy_flag.periph_privacy_flag ) ); break; } case 0x2A03: { WPRINT_LIB_INFO( ( "Reconnection Address : %02x:%02x:%02x:%02x:%02x:%02x\n", (int)curr_attr->value.reconn_address.reconn_address[0], (int)curr_attr->value.reconn_address.reconn_address[1], (int)curr_attr->value.reconn_address.reconn_address[2], (int)curr_attr->value.reconn_address.reconn_address[3], (int)curr_attr->value.reconn_address.reconn_address[4], (int)curr_attr->value.reconn_address.reconn_address[5] ) ); break; } case 0x2A04: { WPRINT_LIB_INFO( ( "Max Connection Interval : %d\n", (int)curr_attr->value.periph_preferred_conn_params.max_conn_interval ) ); WPRINT_LIB_INFO( ( "Min Connection Interval : %d\n", (int)curr_attr->value.periph_preferred_conn_params.min_conn_interval ) ); WPRINT_LIB_INFO( ( "Slave Latency : %d\n", (int)curr_attr->value.periph_preferred_conn_params.slave_latency ) ); WPRINT_LIB_INFO( ( "Supervision Timeout Multiplier : %d\n", (int)curr_attr->value.periph_preferred_conn_params.conn_supervision_timeout_multiplier ) ); break; } default: { uint32_t i; WPRINT_LIB_INFO( ( "Value : \n" ) ); for ( i = 0; i < curr_attr->value_length; i ++ ) { WPRINT_LIB_INFO( ( "%02x ", (int)curr_attr->value.value[i] ) ); } WPRINT_LIB_INFO( ( "\n" ) ); break; } } } WPRINT_LIB_INFO( ( "----------------------------------------------------\n" ) ); return WICED_BT_SUCCESS; }
int main(int argc, char **argv) { char *filename; int64_t blkno, blksize; o2fsck_state *ost = &_ost; int c, open_flags = OCFS2_FLAG_RW | OCFS2_FLAG_STRICT_COMPAT_CHECK; int sb_num = 0; int fsck_mask = FSCK_OK; int slot_recover_err = 0; errcode_t ret; int mount_flags; int proceed = 1; memset(ost, 0, sizeof(o2fsck_state)); ost->ost_ask = 1; ost->ost_dirblocks.db_root = RB_ROOT; ost->ost_dir_parents = RB_ROOT; ost->ost_refcount_trees = RB_ROOT; /* These mean "autodetect" */ blksize = 0; blkno = 0; initialize_ocfs_error_table(); initialize_o2dl_error_table(); initialize_o2cb_error_table(); setlinebuf(stderr); setlinebuf(stdout); tools_progress_disable(); while ((c = getopt(argc, argv, "b:B:DfFGnupavVytPr:")) != EOF) { switch (c) { case 'b': blkno = read_number(optarg); if (blkno < OCFS2_SUPER_BLOCK_BLKNO) { fprintf(stderr, "Invalid blkno: %s\n", optarg); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } break; case 'B': blksize = read_number(optarg); if (blksize < OCFS2_MIN_BLOCKSIZE) { fprintf(stderr, "Invalid blksize: %s\n", optarg); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } break; case 'D': ost->ost_compress_dirs = 1; break; case 'F': ost->ost_skip_o2cb = 1; break; case 'f': ost->ost_force = 1; break; case 'G': ost->ost_fix_fs_gen = 1; break; case 'n': open_flags &= ~OCFS2_FLAG_RW; open_flags |= OCFS2_FLAG_RO; /* Fall through */ case 'a': case 'p': /* * Like extN, -a maps to -p, which is * 'preen'. This means only fix things * that don't require human interaction. * Unlike extN, this is only journal * replay for now. To make it smarter, * ost->ost_answer needs to learn a * new mode. */ ost->ost_ask = 0; ost->ost_answer = 0; break; case 'P': tools_progress_enable(); break; case 'y': ost->ost_ask = 0; ost->ost_answer = 1; break; case 'u': open_flags |= OCFS2_FLAG_BUFFERED; break; case 'v': verbose = 1; break; case 'V': print_version(); exit(FSCK_USAGE); break; case 'r': sb_num = read_number(optarg); break; case 't': if (ost->ost_show_stats) ost->ost_show_extended_stats = 1; ost->ost_show_stats = 1; break; default: fsck_mask |= FSCK_USAGE; print_usage(); goto out; break; } } if (!(open_flags & OCFS2_FLAG_RW) && ost->ost_compress_dirs) { fprintf(stderr, "Compress directories (-D) incompatible with read-only mode\n"); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } if (blksize % OCFS2_MIN_BLOCKSIZE) { fprintf(stderr, "Invalid blocksize: %"PRId64"\n", blksize); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } if (optind >= argc) { fprintf(stderr, "Missing filename\n"); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } filename = argv[optind]; print_version(); ret = ocfs2_check_if_mounted(filename, &mount_flags); if (ret) { com_err(whoami, ret, "while determining whether %s is mounted.", filename); fsck_mask |= FSCK_ERROR; goto out; } if (mount_flags & (OCFS2_MF_MOUNTED | OCFS2_MF_BUSY)) { if (!(open_flags & OCFS2_FLAG_RW)) fprintf(stdout, "\nWARNING!!! Running fsck.ocfs2 (read-" "only) on a mounted filesystem may detect " "invalid errors.\n\n"); else fprintf(stdout, "\nWARNING!!! Running fsck.ocfs2 on a " "mounted filesystem may cause SEVERE " "filesystem damage.\n\n"); proceed = 0; } if (proceed && ost->ost_skip_o2cb) { fprintf(stdout, "\nWARNING!!! You have disabled the cluster check. " "Continue only if you\nare absolutely sure that NO " "node has this filesystem mounted or is\notherwise " "accessing it. If unsure, do NOT continue.\n\n"); proceed = 0; } if (!proceed) { fprintf(stdout, "Do you really want to continue (y/N): "); if (toupper(getchar()) != 'Y') { printf("Aborting operation.\n"); fsck_mask |= FSCK_CANCELED; goto out; } } if (signal(SIGTERM, handle_signal) == SIG_ERR) { com_err(whoami, 0, "Could not set SIGTERM"); exit(1); } if (signal(SIGINT, handle_signal) == SIG_ERR) { com_err(whoami, 0, "Could not set SIGINT"); exit(1); } /* recover superblock should be called at first. */ if (sb_num) { ret = recover_backup_super(ost, filename, sb_num); if (ret) { com_err(whoami, ret, "recover superblock failed.\n"); fsck_mask |= FSCK_ERROR; goto out; } } ret = open_and_check(ost, filename, open_flags, blkno, blksize); if (ret) { fsck_mask |= FSCK_ERROR; goto out; } if (open_flags & OCFS2_FLAG_RW && !ost->ost_skip_o2cb && !ocfs2_mount_local(ost->ost_fs)) { ret = o2cb_init(); if (ret) { com_err(whoami, ret, "while initializing the cluster"); goto close; } block_signals(SIG_BLOCK); ret = ocfs2_initialize_dlm(ost->ost_fs, whoami); if (ret == O2CB_ET_INVALID_STACK_NAME || ret == O2CB_ET_INVALID_CLUSTER_NAME || ret == O2CB_ET_INVALID_HEARTBEAT_MODE) { block_signals(SIG_UNBLOCK); ret = recover_cluster_info(ost); if (ret) { com_err(whoami, ret, "while recovering cluster information"); goto close; } block_signals(SIG_BLOCK); ret = ocfs2_initialize_dlm(ost->ost_fs, whoami); } if (ret) { block_signals(SIG_UNBLOCK); com_err(whoami, ret, "while initializing the DLM"); goto close; } ret = ocfs2_lock_down_cluster(ost->ost_fs); if (ret) { block_signals(SIG_UNBLOCK); com_err(whoami, ret, "while locking down the cluster"); goto close; } cluster_locked = 1; block_signals(SIG_UNBLOCK); } printf("Checking OCFS2 filesystem in %s:\n", filename); printf(" Label: "); print_label(ost); printf(" UUID: "); print_uuid(ost); printf(" Number of blocks: %"PRIu64"\n", ost->ost_fs->fs_blocks); printf(" Block size: %u\n", ost->ost_fs->fs_blocksize); printf(" Number of clusters: %"PRIu32"\n", ost->ost_fs->fs_clusters); printf(" Cluster size: %u\n", ost->ost_fs->fs_clustersize); printf(" Number of slots: %u\n\n", OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_max_slots); /* Let's get enough of a cache to replay the journals */ o2fsck_init_cache(ost, O2FSCK_CACHE_MODE_JOURNAL); if (open_flags & OCFS2_FLAG_RW) { ret = o2fsck_check_journals(ost); if (ret) { printf("fsck saw unrecoverable errors in the journal " "files and will not continue.\n"); goto unlock; } } ret = maybe_replay_journals(ost, filename, open_flags, blkno, blksize); if (ret) { printf("fsck encountered unrecoverable errors while " "replaying the journals and will not continue\n"); fsck_mask |= FSCK_ERROR; goto unlock; } /* Grow the cache */ o2fsck_init_cache(ost, O2FSCK_CACHE_MODE_FULL); /* allocate all this junk after we've replayed the journal and the * sb should be stable */ if (o2fsck_state_init(ost->ost_fs, ost)) { fprintf(stderr, "error allocating run-time state, exiting..\n"); fsck_mask |= FSCK_ERROR; goto unlock; } ret = o2fsck_slot_recovery(ost); if (ret) { printf("fsck encountered errors while recovering slot " "information, check forced.\n"); slot_recover_err = 1; ost->ost_force = 1; } if (fs_is_clean(ost, filename)) { fsck_mask = FSCK_OK; goto clear_dirty_flag; } #if 0 o2fsck_mark_block_used(ost, 0); o2fsck_mark_block_used(ost, 1); o2fsck_mark_block_used(ost, OCFS2_SUPER_BLOCK_BLKNO); #endif mark_magical_clusters(ost); /* XXX we don't use the bad blocks inode, do we? */ /* XXX for now it is assumed that errors returned from a pass * are fatal. these can be fixed over time. */ ret = o2fsck_pass0(ost); if (ret) { com_err(whoami, ret, "while performing pass 0"); goto done; } ret = o2fsck_pass1(ost); if (ret) { com_err(whoami, ret, "while performing pass 1"); goto done; } ret = o2fsck_pass2(ost); if (ret) { com_err(whoami, ret, "while performing pass 2"); goto done; } ret = o2fsck_pass3(ost); if (ret) { com_err(whoami, ret, "while performing pass 3"); goto done; } ret = o2fsck_pass4(ost); if (ret) { com_err(whoami, ret, "while performing pass 4"); goto done; } ret = o2fsck_pass5(ost); if (ret) { com_err(whoami, ret, "while performing pass 5"); goto done; } done: if (ret) fsck_mask |= FSCK_ERROR; else { fsck_mask = FSCK_OK; ost->ost_saw_error = 0; printf("All passes succeeded.\n\n"); o2fsck_print_resource_track(NULL, ost, &ost->ost_rt, ost->ost_fs->fs_io); show_stats(ost); } clear_dirty_flag: if (ost->ost_fs->fs_flags & OCFS2_FLAG_RW) { ret = write_out_superblock(ost); if (ret) com_err(whoami, ret, "while writing back the " "superblock(s)"); if (fsck_mask == FSCK_OK) { if (slot_recover_err) { ret = o2fsck_slot_recovery(ost); if (ret) { com_err(whoami, ret, "while doing slot " "recovery."); goto unlock; } } ret = o2fsck_clear_journal_flags(ost); if (ret) { com_err(whoami, ret, "while clear dirty " "journal flag."); goto unlock; } ret = ocfs2_format_slot_map(ost->ost_fs); if (ret) com_err(whoami, ret, "while format slot " "map."); } } unlock: block_signals(SIG_BLOCK); if (ost->ost_fs->fs_dlm_ctxt) ocfs2_release_cluster(ost->ost_fs); cluster_locked = 0; block_signals(SIG_UNBLOCK); close: block_signals(SIG_BLOCK); if (ost->ost_fs->fs_dlm_ctxt) ocfs2_shutdown_dlm(ost->ost_fs, whoami); block_signals(SIG_UNBLOCK); ret = ocfs2_close(ost->ost_fs); if (ret) { com_err(whoami, ret, "while closing file \"%s\"", filename); /* XXX I wonder about this error.. */ fsck_mask |= FSCK_ERROR; } out: return fsck_mask; }