void lt_set_level_custom(struct lt_facility *facility, lt_mask_t mask_bits, lt_level_t level) { lt_level_t i; char bits[128]; FUNC_ENTER; bits_to_string((uint64_t)mask_bits, sizeof(mask_bits) * 8, bits, sizeof(bits)); DEBG("mask_bits: %s\n", bits); /* Set the requested bit in each mask up to level. */ for (i = 0 ; i <= level ; i++) { (*facility).masks[i] |= mask_bits; } /* Unset the requested bit in the rest of the masks. */ mask_bits = ~mask_bits; for ( ; i < NUM_LT_LEVELS ; i++) { (*facility).masks[i] &= mask_bits; } FUNC_RETURN; }
char* boolfuck (char *code, char *in) { char data[BUFSIZE]; memset(data, 0, sizeof(data)); int dp = BUFSIZE / 2; Bits *tape = string_to_bits(in); Bits *bits = bits_alloc(); int bp = 0; while (*code != '\0') { switch (*code) { case '+': data[dp] = !data[dp]; break; case ',': data[dp] = fetch_bit(tape, bp++); break; case ';': bits = append(bits, data[dp]); break; case '>': dp++; break; case '<': dp--; break; case '[': if (!data[dp]) { int ct = 0; while (!(*code == ']' && ct == 1)) { if (*code == ']') ct--; else if (*code == '[') ct++; code++; } } break; case ']': if (data[dp]) { int ct = 0; while (!(*code == '[' && ct == 1)) { if (*code == ']') ct++; else if (*code == '[') ct--; code--; } } break; } code++; } char *s = bits_to_string(bits); free(tape); free(bits); return s; }
void lt(struct lt_facility *custom_facility, lt_mask_t mask, lt_level_t level, const char *file, const char *function, int line, const char *fmt, ...) { va_list args; struct lt_facility *facility; char msg[MAX_LT_MSG_LEN]; char file_func_line[MAX_FUNCTION_NAME_LEN]; char bits[128]; size_t used = 0, func_name_used; int i; bits_to_string((uint64_t)mask, sizeof(mask), bits, sizeof(bits)); facility = (custom_facility ? custom_facility : &default_facility); if ((*facility).masks[level] & mask) { func_name_used = syscalls_snprintf(file_func_line, sizeof(file_func_line), "%s:%d %s ", file, line, function); for (i = 0 ; i < MAX_FUNCTION_NAME_LEN ; i++) { func_name_used += syscalls_snprintf(file_func_line + func_name_used, sizeof(file_func_line) - func_name_used, " "); } used += syscalls_snprintf(msg + used, sizeof(msg) - used, "%s ", file_func_line); va_start(args, fmt); used += syscalls_vsnprintf(msg + used, sizeof(msg) - used, fmt, args); va_end(args); if (used == MAX_LT_MSG_LEN) { msg[MAX_LT_MSG_LEN - 1] = '\n'; } LOG_OUTPUT("%s", msg); } return; }
void CHSInterface::SetFlag(HS_DBREF dbObject, const char *iFlag, HS_BOOL8 bAbsolute) { if (bAbsolute) { Flags(dbObject) = string_to_bits("FLAG", iFlag); } else { char buff[BUFFER_LEN]; strcpy_s(buff, bits_to_string("FLAG", Flags(dbObject), dbObject, dbObject)); strcat_s(buff, " "); strcat_s(buff, iFlag); Flags(dbObject) = string_to_bits("FLAG", buff); } }
void lt_show_facility_custom(struct lt_facility *facility) { int i; char bits[128]; FUNC_ENTER; for (i = 0 ; i < NUM_LT_LEVELS ; i++) { bits_to_string((uint64_t)(*facility).masks[i], sizeof(lt_mask_t) * 8, bits, sizeof(bits)); EMRG("level %d: %s\n", i, bits); } FUNC_RETURN; return; }
static int do_status(const char *cname, int argc, char **argv) { struct changer_element_status_request cmd; struct changer_params data; struct changer_element_status *ces; int i, chet, count, echet, flags, have_ucount, have_unit; int schet, ucount, unit; size_t size; flags = 0; ucount = 0; unit = 0; have_ucount = 0; have_unit = 0; /* * On a status command, we expect the following: * * [<ET> [unit [count]]] [voltags] * * where ET == element type. * * If we get no element-related arguments, we get the status of all * known element types. */ if (argc > 4) { warnx("%s: too many arguments", cname); usage(); /*NOTREACHED*/ } /* * Get params from changer. Specifically, we need the element * counts. */ (void)memset(&data, 0, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, &data)) err(EXIT_FAILURE, "%s: CHIOGPARAMS", changer_name); /* NOTREACHED */ schet = CHET_MT; echet = CHET_DT; for (; argc != 0; argc--, argv++) { /* * If we have the voltags modifier, it must be the * last argument. */ if (is_special(argv[0])) { if (argc != 1) { warnx("%s: malformed command line", cname); usage(); /*NOTREACHED*/ } if (parse_special(argv[0]) != SW_VOLTAGS) errx(EXIT_FAILURE, "%s: inappropriate special word: %s", cname, argv[0]); /* NOTREACHED */ flags |= CESR_VOLTAGS; continue; } /* * If we get an element type, we can't have specified * anything else. */ if (isdigit((unsigned char)*argv[0]) == 0) { if (schet == echet || flags != 0 || have_unit || have_ucount) { warnx("%s: malformed command line", cname); usage(); /*NOTREACHED*/ } schet = echet = parse_element_type(argv[0]); continue; } /* * We know we have a digit here. If we do, we must * have specified an element type. */ if (schet != echet) { warnx("%s: malformed command line", cname); usage(); /*NOTREACHED*/ } i = parse_element_unit(argv[0]); if (have_unit == 0) { unit = i; have_unit = 1; } else if (have_ucount == 0) { ucount = i; have_ucount = 1; } else { warnx("%s: malformed command line", cname); usage(); /*NOTREACHED*/ } } for (chet = schet; chet <= echet; ++chet) { switch (chet) { case CHET_MT: count = data.cp_npickers; break; case CHET_ST: count = data.cp_nslots; break; case CHET_IE: count = data.cp_nportals; break; case CHET_DT: count = data.cp_ndrives; break; default: /* To appease gcc -Wuninitialized. */ count = 0; } if (count == 0) { if (schet != echet) continue; else { (void)printf("%s: no %s elements\n", changer_name, elements[chet].et_name); return (0); } } /* * If we have a unit, we may or may not have a count. * If we don't have a unit, we don't have a count, either. * * Make sure both are initialized. */ if (have_unit) { if (have_ucount == 0) ucount = 1; } else { unit = 0; ucount = count; } if ((unit + ucount) > count) errx(EXIT_FAILURE, "%s: unvalid unit/count %d/%d", cname, unit, ucount); /* NOTREACHED */ size = ucount * sizeof(struct changer_element_status); /* Allocate storage for the status bytes. */ if ((ces = malloc(size)) == NULL) errx(EXIT_FAILURE, "can't allocate status storage"); /* NOTREACHED */ (void)memset(ces, 0, size); (void)memset(&cmd, 0, sizeof(cmd)); cmd.cesr_type = chet; cmd.cesr_unit = unit; cmd.cesr_count = ucount; cmd.cesr_flags = flags; cmd.cesr_data = ces; /* * Should we deal with this eventually? */ cmd.cesr_vendor_data = NULL; if (ioctl(changer_fd, CHIOGSTATUS, &cmd)) { free(ces); err(EXIT_FAILURE, "%s: CHIOGSTATUS", changer_name); /* NOTREACHED */ } /* Dump the status for each element of this type. */ for (i = 0; i < ucount; i++) { (void)printf("%s %d: ", elements[chet].et_name, unit + i); if ((ces[i].ces_flags & CESTATUS_STATUS_VALID) == 0) { (void)printf("status not available\n"); continue; } (void)printf("%s", bits_to_string(ces[i].ces_flags, CESTATUS_BITS)); if (ces[i].ces_flags & CESTATUS_XNAME_VALID) (void)printf(" (%s)", ces[i].ces_xname); (void)printf("\n"); if (ces[i].ces_flags & CESTATUS_PVOL_VALID) (void)printf("\tPrimary volume tag: %s " "ver. %d\n", ces[i].ces_pvoltag.cv_tag, ces[i].ces_pvoltag.cv_serial); if (ces[i].ces_flags & CESTATUS_AVOL_VALID) (void)printf("\tAlternate volume tag: %s " "ver. %d\n", ces[i].ces_avoltag.cv_tag, ces[i].ces_avoltag.cv_serial); if (ces[i].ces_flags & CESTATUS_FROM_VALID) (void)printf("\tFrom: %s %d\n", elements[ces[i].ces_from_type].et_name, ces[i].ces_from_unit); if (ces[i].ces_vendor_len) (void)printf("\tVendor-specific data size: " "%lu\n", (u_long)ces[i].ces_vendor_len); } free(ces); } return (0); }
static int do_status(const char *cname, int argc, char **argv) { struct changer_params cp; struct changer_element_status_request cesr; int i; u_int16_t base, count, chet, schet, echet; const char *description; int pvoltag = 0; int avoltag = 0; int sense = 0; int scsi = 0; int source = 0; int intaddr = 0; int c; count = 0; base = 0; description = NULL; optind = optreset = 1; while ((c = getopt(argc, argv, "vVsSbaI")) != -1) { switch (c) { case 'v': pvoltag = 1; break; case 'V': avoltag = 1; break; case 's': sense = 1; break; case 'S': source = 1; break; case 'b': scsi = 1; break; case 'I': intaddr = 1; break; case 'a': pvoltag = avoltag = source = sense = scsi = intaddr = 1; break; default: warnx("%s: bad option", cname); goto usage; } } argc -= optind; argv += optind; /* * On a status command, we expect the following: * * [<ET> [<start> [<end>] ] ] * * where ET == element type, start == first element to report, * end == number of elements to report * * If we get no arguments, we get the status of all * known element types. */ if (argc > 3) { warnx("%s: too many arguments", cname); goto usage; } /* * Get params from changer. Specifically, we need the element * counts. */ if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp)) err(1, "%s: CHIOGPARAMS", changer_name); if (argc > 0) schet = echet = parse_element_type(argv[0]); else { schet = CHET_MT; echet = CHET_DT; } if (argc > 1) { base = (u_int16_t)atol(argv[1]); count = 1; } if (argc > 2) count = (u_int16_t)atol(argv[2]) - base + 1; for (chet = schet; chet <= echet; ++chet) { switch (chet) { case CHET_MT: if (count == 0) count = cp.cp_npickers; else if (count > cp.cp_npickers) errx(1, "not that many pickers in device"); description = "picker"; break; case CHET_ST: if (count == 0) count = cp.cp_nslots; else if (count > cp.cp_nslots) errx(1, "not that many slots in device"); description = "slot"; break; case CHET_IE: if (count == 0) count = cp.cp_nportals; else if (count > cp.cp_nportals) errx(1, "not that many portals in device"); description = "portal"; break; case CHET_DT: if (count == 0) count = cp.cp_ndrives; else if (count > cp.cp_ndrives) errx(1, "not that many drives in device"); description = "drive"; break; default: /* To appease gcc -Wuninitialized. */ count = 0; description = NULL; } if (count == 0) { if (argc == 0) continue; else { printf("%s: no %s elements\n", changer_name, description); return (0); } } bzero(&cesr, sizeof(cesr)); cesr.cesr_element_type = chet; cesr.cesr_element_base = base; cesr.cesr_element_count = count; /* Allocate storage for the status structures. */ cesr.cesr_element_status = (struct changer_element_status *) calloc((size_t)count, sizeof(struct changer_element_status)); if (!cesr.cesr_element_status) errx(1, "can't allocate status storage"); if (avoltag || pvoltag) cesr.cesr_flags |= CESR_VOLTAGS; if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) { free(cesr.cesr_element_status); err(1, "%s: CHIOGSTATUS", changer_name); } /* Dump the status for each reported element. */ for (i = 0; i < count; ++i) { struct changer_element_status *ces = &(cesr.cesr_element_status[i]); printf("%s %d: %s", description, ces->ces_addr, bits_to_string(ces->ces_flags, CESTATUS_BITS)); if (sense) printf(" sense: <0x%02x/0x%02x>", ces->ces_sensecode, ces->ces_sensequal); if (pvoltag) printf(" voltag: <%s:%d>", ces->ces_pvoltag.cv_volid, ces->ces_pvoltag.cv_serial); if (avoltag) printf(" avoltag: <%s:%d>", ces->ces_avoltag.cv_volid, ces->ces_avoltag.cv_serial); if (source) { if (ces->ces_flags & CES_SOURCE_VALID) printf(" source: <%s %d>", element_type_name( ces->ces_source_type), ces->ces_source_addr); else printf(" source: <>"); } if (intaddr) printf(" intaddr: <%d>", ces->ces_int_addr); if (scsi) { printf(" scsi: <"); if (ces->ces_flags & CES_SCSIID_VALID) printf("%d", ces->ces_scsi_id); else putchar('?'); putchar(':'); if (ces->ces_flags & CES_LUN_VALID) printf("%d", ces->ces_scsi_lun); else putchar('?'); putchar('>'); } if (ces->ces_designator_length > 0) print_designator(ces->ces_designator, ces->ces_code_set, ces->ces_designator_length); putchar('\n'); } free(cesr.cesr_element_status); count = 0; } return (0); usage: (void) fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n", getprogname(), cname); return (1); }
static int do_status(char *cname, int argc, char *argv[]) { struct changer_element_status_request cmd; struct changer_params data; int i, chet, schet, echet, c; char *description; size_t count; #ifdef lint count = 0; description = NULL; #endif optreset = 1; optind = 1; while ((c = getopt(argc, argv, "vVa")) != -1) { switch (c) { case 'v': pvoltag = 1; break; case 'V': avoltag = 1; break; case 'a': pvoltag = avoltag = 1; break; default: goto usage; } } argc -= optind; argv += optind; /* * On a status command, we expect the following: * * [<ET>] * * where ET == element type. * * If we get no arguments, we get the status of all * known element types. */ if (argc > 1) { warnx("%s: too many arguments", cname); goto usage; } /* * Get params from changer. Specifically, we need the element * counts. */ bzero(&data, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, &data)) err(1, "%s: CHIOGPARAMS", changer_name); if (argc) schet = echet = parse_element_type(*argv); else { schet = CHET_MT; echet = CHET_DT; } for (chet = schet; chet <= echet; ++chet) { switch (chet) { case CHET_MT: count = data.cp_npickers; description = "picker"; break; case CHET_ST: count = data.cp_nslots; description = "slot"; break; case CHET_IE: count = data.cp_nportals; description = "portal"; break; case CHET_DT: count = data.cp_ndrives; description = "drive"; break; } if (count == 0) { if (argc == 0) continue; else { printf("%s: no %s elements\n", changer_name, description); return (0); } } bzero(&cmd, sizeof(cmd)); cmd.cesr_type = chet; /* Allocate storage for the status info. */ cmd.cesr_data = calloc(count, sizeof(*cmd.cesr_data)); if ((cmd.cesr_data) == NULL) errx(1, "can't allocate status storage"); if (avoltag || pvoltag) cmd.cesr_flags |= CESR_VOLTAGS; if (ioctl(changer_fd, CHIOGSTATUS, &cmd)) { free(cmd.cesr_data); err(1, "%s: CHIOGSTATUS", changer_name); } /* Dump the status for each element of this type. */ for (i = 0; i < count; ++i) { struct changer_element_status *ces = &(cmd.cesr_data[i]); printf("%s %d: %s", description, i, bits_to_string(ces->ces_flags, CESTATUS_BITS)); if (pvoltag) printf(" voltag: <%s:%d>", ces->ces_pvoltag.cv_volid, ces->ces_pvoltag.cv_serial); if (avoltag) printf(" avoltag: <%s:%d>", ces->ces_avoltag.cv_volid, ces->ces_avoltag.cv_serial); printf("\n"); } free(cmd.cesr_data); } return (0); usage: fprintf(stderr, "usage: %s %s [<element type>]\n", __progname, cname); return (1); }