static int print_data_handler(int id, const char *pool, zinject_record_t *record, void *data) { int *count = data; if (record->zi_guid != 0 || record->zi_func[0] != '\0') return (0); if (*count == 0) { (void) printf("%3s %-15s %-6s %-6s %-8s %3s %-15s\n", "ID", "POOL", "OBJSET", "OBJECT", "TYPE", "LVL", "RANGE"); (void) printf("--- --------------- ------ " "------ -------- --- ---------------\n"); } *count += 1; (void) printf("%3d %-15s %-6llu %-6llu %-8s %3d ", id, pool, (u_longlong_t)record->zi_objset, (u_longlong_t)record->zi_object, type_to_name(record->zi_type), record->zi_level); if (record->zi_start == 0 && record->zi_end == -1ULL) (void) printf("all\n"); else (void) printf("[%llu, %llu]\n", (u_longlong_t)record->zi_start, (u_longlong_t)record->zi_end); return (0); }
/* * f_prtmtab - Prints out a header, then entries from both magic * tables, mtab1 and mtab2, if any exist. */ void f_prtmtab(void) { Entry *mtab; Entry *ep; int count; (void) printf("%-7s %-7s %-10s %-7s %-11s %s\n", "level", "off", "type", "opcode", "value", "string"); for (mtab = mtab1, count = 1; count <= 2; count++, mtab = mtab2) { if (mtab == (Entry *)NULL) { continue; } for (ep = mtab; ep->e_off != -1L; ep++) { (void) printf("%-7d %-7ld %-10s %-7c ", ep->e_level, ep->e_off, type_to_name(ep), op_to_name(ep->e_opcode)); if (ep->e_type == STR) { showstr(ep->e_value.str, 10); } else { /* numeric */ (void) printf("%-#11llo", ep->e_value.num); } (void) printf(" %s", ep->e_str); if (ep->e_opcode & SUB) (void) printf("\tsubst"); (void) printf("\n"); } } }
static void state_changed_cb (UrfKillswitch *killswitch, const int state) { const char *type_name; type_name = type_to_name (urf_killswitch_get_switch_type (killswitch)); g_print ("CHANGE Type %s state %d\n", type_name, state); }
static void print_type(uint8_t type, int numeric) { const char *name; if (numeric || !(name = type_to_name(type))) printf("%u", type); else printf("%s", name); }
void print_message (DBusMessage *message, dbus_bool_t literal) { DBusMessageIter iter; const char *sender; const char *destination; int message_type; message_type = dbus_message_get_type (message); sender = dbus_message_get_sender (message); destination = dbus_message_get_destination (message); if (!literal) { printf ("%s sender=%s -> dest=%s", type_to_name (message_type), sender ? sender : "(null sender)", destination ? destination : "(null destination)"); switch (message_type) { case DBUS_MESSAGE_TYPE_METHOD_CALL: case DBUS_MESSAGE_TYPE_SIGNAL: printf (" serial=%u path=%s; interface=%s; member=%s\n", dbus_message_get_serial (message), dbus_message_get_path (message), dbus_message_get_interface (message), dbus_message_get_member (message)); break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: printf (" reply_serial=%u\n", dbus_message_get_reply_serial (message)); break; case DBUS_MESSAGE_TYPE_ERROR: printf (" error_name=%s reply_serial=%u\n", dbus_message_get_error_name (message), dbus_message_get_reply_serial (message)); break; default: printf ("\n"); break; } } dbus_message_iter_init (message, &iter); print_iter (&iter, literal, 1); fflush (stdout); }
static void show_state (UrfKillswitch *killswitch) { const char *type_name; int state; type_name = type_to_name (urf_killswitch_get_switch_type (killswitch)); g_object_get (killswitch, "state", &state, NULL); g_print ("Type %s state %d\n", type_name, state); }
const sensor_cal_algo_t* CalibrationManager::getCalAlgo(const sensor_t *s/* = NULL*/) { uint32_t i = 0; int j = 0; const sensor_cal_algo_t **list = algo_list; const sensor_cal_algo_t *tmp = NULL; if (s == NULL) { ALOGW("No available algo found!"); return NULL; } for (i = 0; i < algo_count; i++) { if ((list[i]->type != s->type) || check_algo(list[i])) continue; j = 0; while (list[i]->compatible[j] != NULL) { if (strcmp(list[i]->compatible[j], s->name) == 0) break; if (strcmp(list[i]->compatible[j], type_to_name(s->type)) == 0) tmp = list[i]; j++; } /* Exactly compatible */ if (list[i]->compatible[j] != NULL) break; } if (i != algo_count) { ALOGI("found exactly compatible algo for type %d", s->type); return list[i]; } if (tmp != NULL) ALOGI("found compatible algo for type %d", s->type); return tmp; }
static void dump_journal(char *cmdname, FILE *out_file, struct journal_source *source) { struct ext2_super_block *sb; char jsb_buffer[1024]; char buf[8192]; journal_superblock_t *jsb; unsigned int blocksize = 1024; unsigned int got; int retval; __u32 magic, sequence, blocktype; journal_header_t *header; tid_t transaction; unsigned int blocknr = 0; /* First, check to see if there's an ext2 superblock header */ retval = read_journal_block(cmdname, source, 0, buf, 2048, &got); if (retval) return; jsb = (journal_superblock_t *) buf; sb = (struct ext2_super_block *) (buf+1024); #ifdef ENABLE_SWAPFS if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ext2fs_swap_super(sb); #endif if ((be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) && (sb->s_magic == EXT2_SUPER_MAGIC) && (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { blocksize = EXT2_BLOCK_SIZE(sb); blocknr = (blocksize == 1024) ? 2 : 1; uuid_unparse(sb->s_uuid, jsb_buffer); fprintf(out_file, "Ext2 superblock header found.\n"); if (dump_all) { fprintf(out_file, "\tuuid=%s\n", jsb_buffer); fprintf(out_file, "\tblocksize=%d\n", blocksize); fprintf(out_file, "\tjournal data size %ld\n", (long) sb->s_blocks_count); } } /* Next, read the journal superblock */ retval = read_journal_block(cmdname, source, blocknr*blocksize, jsb_buffer, 1024, &got); if (retval) return; jsb = (journal_superblock_t *) jsb_buffer; if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) { fprintf(out_file, "Journal superblock magic number invalid!\n"); return; } blocksize = be32_to_cpu(jsb->s_blocksize); transaction = be32_to_cpu(jsb->s_sequence); blocknr = be32_to_cpu(jsb->s_start); fprintf(out_file, "Journal starts at block %u, transaction %u\n", blocknr, transaction); if (!blocknr) /* Empty journal, nothing to do. */ return; while (1) { retval = read_journal_block(cmdname, source, blocknr*blocksize, buf, blocksize, &got); if (retval || got != blocksize) return; header = (journal_header_t *) buf; magic = be32_to_cpu(header->h_magic); sequence = be32_to_cpu(header->h_sequence); blocktype = be32_to_cpu(header->h_blocktype); if (magic != JFS_MAGIC_NUMBER) { fprintf (out_file, "No magic number at block %u: " "end of journal.\n", blocknr); return; } if (sequence != transaction) { fprintf (out_file, "Found sequence %u (not %u) at " "block %u: end of journal.\n", sequence, transaction, blocknr); return; } if (dump_descriptors) { fprintf (out_file, "Found expected sequence %u, " "type %u (%s) at block %u\n", sequence, blocktype, type_to_name(blocktype), blocknr); } switch (blocktype) { case JFS_DESCRIPTOR_BLOCK: dump_descriptor_block(out_file, source, buf, jsb, &blocknr, blocksize, transaction); continue; case JFS_COMMIT_BLOCK: transaction++; blocknr++; WRAP(jsb, blocknr); continue; case JFS_REVOKE_BLOCK: dump_revoke_block(out_file, buf, jsb, blocknr, blocksize, transaction); blocknr++; WRAP(jsb, blocknr); continue; default: fprintf (out_file, "Unexpected block type %u at " "block %u.\n", blocktype, blocknr); return; } } }
/* * UNDO function using parsed primary data and parsed UNDO data. This * must typically */ static int dump_mirror_rebuild_undo(u_int16_t rectype, struct jstream *js, struct jattr *jattr) { struct jattr_data *data; int error = 0; int fd; if (verbose_opt > 2) { fprintf(stderr, "UNDO %04x %s %s\n", js->js_head->streamid, type_to_name(rectype), jattr->pathref ? jattr->pathref : jattr->path1); } switch(rectype) { case JTYPE_SETATTR: if (jattr->pathref) dosetattr(jattr->pathref, -1, jattr); break; case JTYPE_WRITE: case JTYPE_PUTPAGES: if (jattr->pathref && jattr->seekpos != -1) { if ((fd = open(jattr->pathref, O_RDWR)) >= 0) { lseek(fd, jattr->seekpos, 0); for (data = &jattr->data; data; data = data->next) { if (data->bytes) jsreadcallback(js, write, fd, data->off, data->bytes); } close(fd); } } if (jattr->size != -1) truncate(jattr->pathref, jattr->size); break; case JTYPE_SETACL: break; case JTYPE_SETEXTATTR: break; case JTYPE_CREATE: /* * note: both path1 and pathref will exist. */ if (jattr->path1) remove(jattr->path1); break; case JTYPE_MKNOD: if (jattr->path1) remove(jattr->path1); break; case JTYPE_LINK: if (jattr->path1) { undo_recreate(jattr->path1, js, jattr); } break; case JTYPE_SYMLINK: if (jattr->symlinkdata && jattr->path1) { undo_recreate(jattr->path1, js, jattr); } break; case JTYPE_WHITEOUT: /* XXX */ break; case JTYPE_REMOVE: if (jattr->path1) { undo_recreate(jattr->path1, js, jattr); } break; case JTYPE_MKDIR: if (jattr->path1) { rmdir(jattr->path1); } break; case JTYPE_RMDIR: if (jattr->path1 && jattr->modes != (mode_t)-1) { mkdir(jattr->path1, jattr->modes); } break; case JTYPE_RENAME: if (jattr->path2) { undo_recreate(jattr->path2, js, jattr); } break; } return(error); }
int test_xi2(Display *display, int argc, char *argv[], char *name, char *desc) { XIEventMask mask[2]; XIEventMask *m; Window win; int deviceid = -1; int use_root = 0; int rc; setvbuf(stdout, NULL, _IOLBF, 0); if (argc >= 1 && strcmp(argv[0], "--root") == 0) { use_root = 1; argc--; argv++; } rc = list(display, argc, argv, name, desc); if (rc != EXIT_SUCCESS) return rc; if (use_root) win = DefaultRootWindow(display); else win = create_win(display); if (argc >= 1) { XIDeviceInfo *info; info = xi2_find_device_info(display, argv[0]); deviceid = info->deviceid; } /* Select for motion events */ m = &mask[0]; m->deviceid = (deviceid == -1) ? XIAllDevices : deviceid; m->mask_len = XIMaskLen(XI_LASTEVENT); m->mask = calloc(m->mask_len, sizeof(char)); XISetMask(m->mask, XI_ButtonPress); XISetMask(m->mask, XI_ButtonRelease); XISetMask(m->mask, XI_KeyPress); XISetMask(m->mask, XI_KeyRelease); XISetMask(m->mask, XI_Motion); XISetMask(m->mask, XI_DeviceChanged); XISetMask(m->mask, XI_Enter); XISetMask(m->mask, XI_Leave); XISetMask(m->mask, XI_FocusIn); XISetMask(m->mask, XI_FocusOut); #ifdef HAVE_XI22 XISetMask(m->mask, XI_TouchBegin); XISetMask(m->mask, XI_TouchUpdate); XISetMask(m->mask, XI_TouchEnd); #endif if (m->deviceid == XIAllDevices) XISetMask(m->mask, XI_HierarchyChanged); XISetMask(m->mask, XI_PropertyEvent); m = &mask[1]; m->deviceid = (deviceid == -1) ? XIAllMasterDevices : deviceid; m->mask_len = XIMaskLen(XI_LASTEVENT); m->mask = calloc(m->mask_len, sizeof(char)); XISetMask(m->mask, XI_RawKeyPress); XISetMask(m->mask, XI_RawKeyRelease); XISetMask(m->mask, XI_RawButtonPress); XISetMask(m->mask, XI_RawButtonRelease); XISetMask(m->mask, XI_RawMotion); #ifdef HAVE_XI22 XISetMask(m->mask, XI_RawTouchBegin); XISetMask(m->mask, XI_RawTouchUpdate); XISetMask(m->mask, XI_RawTouchEnd); #endif XISelectEvents(display, win, &mask[0], use_root ? 2 : 1); if (!use_root) { XISelectEvents(display, DefaultRootWindow(display), &mask[1], 1); XMapWindow(display, win); } XSync(display, False); free(mask[0].mask); free(mask[1].mask); if (!use_root) { XEvent event; XMaskEvent(display, ExposureMask, &event); XSelectInput(display, win, 0); } /* test_sync_grab(display, win); */ while(1) { XEvent ev; XGenericEventCookie *cookie = (XGenericEventCookie*)&ev.xcookie; XNextEvent(display, (XEvent*)&ev); if (XGetEventData(display, cookie) && cookie->type == GenericEvent && cookie->extension == xi_opcode) { printf("EVENT type %d (%s)\n", cookie->evtype, type_to_name(cookie->evtype)); switch (cookie->evtype) { case XI_DeviceChanged: print_devicechangedevent(display, cookie->data); break; case XI_HierarchyChanged: print_hierarchychangedevent(cookie->data); break; case XI_RawKeyPress: case XI_RawKeyRelease: case XI_RawButtonPress: case XI_RawButtonRelease: case XI_RawMotion: case XI_RawTouchBegin: case XI_RawTouchUpdate: case XI_RawTouchEnd: print_rawevent(cookie->data); break; case XI_Enter: case XI_Leave: case XI_FocusIn: case XI_FocusOut: print_enterleave(cookie->data); break; case XI_PropertyEvent: print_propertyevent(display, cookie->data); break; default: print_deviceevent(cookie->data); break; } } XFreeEventData(display, cookie); } XDestroyWindow(display, win); return EXIT_SUCCESS; }