void do_testb(int argc, char *argv[]) { unsigned int block, num; int err; int test_result; if (check_fs_open(argv[0])) return; if (argc != 2 && argc != 3) { com_err(argv[0], 0, "Usage: testb <block> [num]"); return; } block = parse_ulong(argv[1], argv[0], "block", &err); if (err) return; if (argc == 3) { num = parse_ulong(argv[2], argv[0], "num", &err); if (err) return; test_result = ext2fs_test_block_bitmap_range2(test_fs->block_map, block, num); printf("Blocks %u to %u are %sall clear.\n", block, block + num - 1, test_result ? "" : "NOT "); return; } test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); printf("Block %u is %s\n", block, test_result ? "set" : "clear"); }
void do_insert_node(int argc, char *argv[]) { const char *usage = "[--after] [--uninit] <lblk> <len> <pblk>"; errcode_t retval; struct ext2fs_extent extent; char *cmd; int err; int flags = 0; if (common_extent_args_process(argc, argv, 3, 6, "insert_node", usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) return; cmd = argv[0]; extent.e_flags = 0; while (argc > 2) { if (!strcmp(argv[1], "--after")) { argc--; argv++; flags |= EXT2_EXTENT_INSERT_AFTER; continue; } if (!strcmp(argv[1], "--uninit")) { argc--; argv++; extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; continue; } break; } if (argc != 4) { fprintf(stderr, "usage: %s %s\n", cmd, usage); return; } extent.e_lblk = parse_ulong(argv[1], cmd, "logical block", &err); if (err) return; extent.e_len = parse_ulong(argv[2], cmd, "length", &err); if (err) return; extent.e_pblk = parse_ulong(argv[3], cmd, "pysical block", &err); if (err) return; retval = ext2fs_extent_insert(current_handle, flags, &extent); if (retval) { com_err(cmd, retval, 0); return; } generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT); }
void do_open_filesys(int argc, char **argv) { int c, err; int catastrophic = 0; blk_t superblock = 0; blk_t blocksize = 0; int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES; char *data_filename = 0; reset_getopt(); while ((c = getopt (argc, argv, "iwfecb:s:d:")) != EOF) { switch (c) { case 'i': open_flags |= EXT2_FLAG_IMAGE_FILE; break; case 'w': open_flags |= EXT2_FLAG_RW; break; case 'f': open_flags |= EXT2_FLAG_FORCE; break; case 'e': open_flags |= EXT2_FLAG_EXCLUSIVE; break; case 'c': catastrophic = 1; break; case 'd': data_filename = optarg; break; case 'b': blocksize = parse_ulong(optarg, argv[0], "block size", &err); if (err) return; break; case 's': superblock = parse_ulong(optarg, argv[0], "superblock number", &err); if (err) return; break; default: goto print_usage; } } if (optind != argc-1) { goto print_usage; } if (check_fs_not_open(argv[0])) return; open_filesystem(argv[optind], open_flags, superblock, blocksize, catastrophic, data_filename); return; print_usage: fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] " "[-c] [-w] <device>\n", argv[0]); }
void do_ffsi(int argc, char *argv[]) { unsigned int start, end; int err; errcode_t retval; ext2_ino_t out; if (check_fs_open(argv[0])) return; if (argc != 3 && argc != 3) { com_err(argv[0], 0, "Usage: ffsi <start> <end>"); return; } start = parse_ulong(argv[1], argv[0], "start", &err); if (err) return; end = parse_ulong(argv[2], argv[0], "end", &err); if (err) return; retval = ext2fs_find_first_set_inode_bitmap2(test_fs->inode_map, start, end, &out); if (retval) { printf("ext2fs_find_first_set_inode_bitmap2() returned %s\n", error_message(retval)); return; } printf("First marked inode is %u\n", out); }
static int proc_args(int argc, char *argv[]) { unsigned short cnt, idle_time, tolerance; short length; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "packet", strlen("packet")) == 0) { if (argc != 3) { printf( "test_packet: wrong no of arguments for test of test_packet \n"); return EXIT_FAILURE; } cnt = parse_ulong(argv[2], 10); printf("test:: packet(%d)\n", (unsigned short) cnt); if (cnt == ULONG_MAX || cnt < 1) return EXIT_FAILURE; test_packet(cnt); return EXIT_SUCCESS; } else if (strncmp(argv[1], "async", strlen("async")) == 0) { if (argc != 3) { printf( "test_async: wrong no of arguments for test of test_async() \n"); return EXIT_FAILURE; } idle_time = parse_ulong(argv[2], 10); printf("test:: async(%d)\n", (unsigned short) idle_time); if (idle_time == ULONG_MAX) return EXIT_FAILURE; test_async(idle_time); return EXIT_SUCCESS; } else if (strncmp(argv[1], "config", strlen("config")) == 0) { if (argc != 2) { printf( "test_config: wrong no of arguments for test of test_config() \n"); return EXIT_FAILURE; } printf("test:: config()\n"); test_config(); return EXIT_SUCCESS; } /*else if (strncmp(argv[1], "gesture", strlen("gesture")) == 0) { if (argc != 4) { printf( "test_gesture: wrong no of arguments for test of test_gesture() \n"); return EXIT_FAILURE; } length = parse_ulong(argv[2], 10); tolerance = parse_ulong(argv[3], 10); printf("test:: gesture(%d, %d)\n", (unsigned short) length, (unsigned short) tolerance); if (length == ULONG_MAX) return EXIT_FAILURE; if (tolerance == ULONG_MAX) return EXIT_FAILURE; test_gesture(length, tolerance); return EXIT_SUCCESS; }*/ }
void do_open_filesys(int argc, char **argv) { const char *usage = "Usage: open [-s superblock] [-b blocksize] [-c] [-w] <device>"; int c, err; int catastrophic = 0; blk_t superblock = 0; blk_t blocksize = 0; int open_flags = 0; char *data_filename = 0; reset_getopt(); while ((c = getopt (argc, argv, "iwfcb:s:d:")) != EOF) { switch (c) { case 'i': open_flags |= EXT2_FLAG_IMAGE_FILE; break; case 'w': open_flags |= EXT2_FLAG_RW; break; case 'f': open_flags |= EXT2_FLAG_FORCE; break; case 'c': catastrophic = 1; break; case 'd': data_filename = optarg; break; case 'b': blocksize = parse_ulong(optarg, argv[0], "block size", &err); if (err) return; break; case 's': superblock = parse_ulong(optarg, argv[0], "superblock number", &err); if (err) return; break; default: com_err(argv[0], 0, usage); return; } } if (optind != argc-1) { com_err(argv[0], 0, usage); return; } if (check_fs_not_open(argv[0])) return; open_filesystem(argv[optind], open_flags, superblock, blocksize, catastrophic, data_filename); }
static int proc_args(int argc, char *argv[]) { unsigned long cnt, idle_time, tolerance; long length; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "packet", strlen("packet")) == 0) { if( argc != 3 ) { printf("mouse: wrong no of arguments for test of test_packet() \n"); return 1; } if( (cnt = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("mouse:: test_packet(%lu)\n", cnt); return test_packet(cnt); } else if (strncmp(argv[1], "async", strlen("async")) == 0) { if( argc != 3 ) { printf("mouse: wrong no of arguments for test_async() \n"); return 1; } if( (idle_time = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("mouse:: test_async(%lu)\n", idle_time); return test_async(idle_time); } else if (strncmp(argv[1], "config", strlen("config")) == 0) { if( argc != 2 ) { printf("mouse: wrong no of arguments for test_config() \n"); return 1; } printf("mouse:: test_config()\n"); return test_config(); } else if (strncmp(argv[1], "gesture", strlen("gesture")) == 0) { if( argc != 4 ) { printf("mouse: wrong no of arguments for test_gesture() \n"); return 1; } if( (length = parse_long(argv[2], 10)) == LONG_MAX ) return 1; if( (tolerance = parse_ulong(argv[3], 10)) == ULONG_MAX ) return 1; printf("mouse:: test_gesture(%ld, %lu)\n", length, tolerance); return test_gesture(length, tolerance); } else { printf("mouse: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned short number, time, tolerance; short length; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "test_packet", strlen("test_packet")) == 0) { if( argc != 3 ) { printf("Keyboard: wrong no of arguments for test of test_packet() \n"); return 1; } if((number = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; printf("Mouse:: test_packet(%u)\n\n", number); /* Actually, it was already invoked */ return test_packet(number); } else if (strncmp(argv[1], "test_async", strlen("test_async")) == 0) { if( argc != 3) { printf("Mouse: wrong no of arguments for test of test_async() \n"); return 1; } if((time = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; if(time <= 0) return 1; printf("Mouse:: test_async(%u)\n\n", time); return test_async(time); } else if (strncmp(argv[1], "test_config", strlen("test_config")) == 0) { if( argc != 2 ) { printf("Mouse: wrong no of arguments for test of test_config() \n"); return 1; } printf("Mouse:: test_config()\n\n"); return test_config(); } else if (strncmp(argv[1], "test_gesture", strlen("test_gesture")) == 0) { if( argc != 4 ) { printf("Mouse: wrong no of arguments for test of test_gesture() \n"); return 1; } if((length = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; if((tolerance = parse_ulong(argv[3], 10)) == ULONG_MAX) return 1; printf("Mouse:: test_gesture(%d, %u)\n\n", length, tolerance); return test_gesture(length, tolerance); } else { printf("Mouse: non valid function \"%s\" to test\n", argv[1]); return 1; } }
void do_set_bmap(int argc, char **argv) { const char *usage = "[--uninit] <lblk> <pblk>"; struct ext2fs_extent extent; errcode_t retval; blk_t logical; blk_t physical; char *cmd = argv[0]; int flags = 0; int err; if (common_extent_args_process(argc, argv, 3, 5, "set_bmap", usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) return; if (argc > 2 && !strcmp(argv[1], "--uninit")) { argc--; argv++; flags |= EXT2_EXTENT_SET_BMAP_UNINIT; } if (argc != 3) { fprintf(stderr, "Usage: %s %s\n", cmd, usage); return; } logical = parse_ulong(argv[1], cmd, "logical block", &err); if (err) return; physical = parse_ulong(argv[2], cmd, "physical block", &err); if (err) return; retval = ext2fs_extent_set_bmap(current_handle, logical, (blk64_t) physical, flags); if (retval) { com_err(cmd, retval, 0); return; } retval = ext2fs_extent_get(current_handle, EXT2_EXTENT_CURRENT, &extent); if (retval) return; dbg_print_extent(0, &extent); }
void do_cleari(int argc, char *argv[]) { unsigned int inode; int err; int test_result, op_result; if (check_fs_open(argv[0])) return; if (argc != 2) { com_err(argv[0], 0, "Usage: clearb <inode>"); return; } inode = parse_ulong(argv[1], argv[0], "inode", &err); if (err) return; test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); op_result = ext2fs_unmark_inode_bitmap2(test_fs->inode_map, inode); printf("Clearing inode %u, was %s before\n", inode, op_result ? "set" : "clear"); if (!test_result != !op_result) { com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", test_result, op_result); exit_status++; } }
void do_init_filesys(int argc, char **argv) { struct ext2_super_block param; errcode_t retval; int err; if (common_args_process(argc, argv, 3, 3, "initialize", "<device> <blocksize>", CHECK_FS_NOTOPEN)) return; memset(¶m, 0, sizeof(struct ext2_super_block)); param.s_blocks_count = parse_ulong(argv[2], argv[0], "blocks count", &err); if (err) return; retval = ext2fs_initialize(argv[1], 0, ¶m, unix_io_manager, ¤t_fs); if (retval) { com_err(argv[1], retval, "while initializing filesystem"); current_fs = NULL; return; } root = cwd = EXT2_ROOT_INO; return; }
void do_goto_block(int argc, char **argv) { errcode_t retval; blk64_t blk; int level = 0, err; if (common_extent_args_process(argc, argv, 2, 3, "goto_block", "block [level]", 0)) return; if (strtoblk(argv[0], argv[1], &blk)) return; if (argc == 3) { level = parse_ulong(argv[2], argv[0], "level", &err); if (err) return; } retval = ext2fs_extent_goto2(current_handle, level, (blk64_t) blk); if (retval) { com_err(argv[0], retval, "while trying to go to block %llu, level %d", (unsigned long long) blk, level); return; } generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT); }
static int proc_args(int argc, char *argv[]) { unsigned long seconds, timer, freq; char *str; long num; /*check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "timer", strlen("timer")) == 0) { if( argc != 3 ) { printf("wrong no of arguments for test of timer_test_config() \n"); return 1; } if( (timer = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; if(timer!=0 && timer!=1 && timer!=2){ printf("argument timer ranges from 0 to 2\n"); return 1; } printf("timer_test_config(%lu)\n",timer); /* Actually, it was already invoked */ timer_test_config(timer); return 0; } else if (strncmp(argv[1], "freq", strlen("freq")) == 0) { if( argc != 3 ) { printf("wrong no of arguments for test of timer_test_square() \n"); return 1; } if( (freq = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("timer_test_square(%lu)\n",freq); timer_test_square(freq); return 0; } else if (strncmp(argv[1], "chronometer", strlen("chronometer")) == 0) { if( argc != 3 ) { printf("wrong no of arguments for test of timer_test_int() \n"); return 1; } if( (seconds = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("timer_test_int(%lu)\n",seconds); timer_test_int(seconds); return 0; } else { printf(" non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned long freq, timer, time; char *str; long num; if (strncmp(argv[1], "test_square", strlen("test_square")) == 0) { if (argc != 3) { printf( "lab2: wrong no of arguments for test of timer_test_square() \n"); return 1; } if ((freq = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; printf("lab2::timer_test_square(%d)\n", (unsigned) freq); timer_test_square(freq); return 0; } else if (strncmp(argv[1], "test_config", strlen("test_config")) == 0) { if (argc != 3) { printf( "lab2: wrong no of arguments for test of timer_test_config() \n"); return 1; } if ((timer = parse_ulong(argv[2], 16)) == ULONG_MAX) return 1; printf("lab2::timer_test_config(0x%X)\n", (unsigned) timer); timer_test_config(timer); return 0; } else if (strncmp(argv[1], "test_int", strlen("test_int")) == 0) { if (argc != 3) { printf( "lab2: wrong no of arguments for test of timer_set_square() \n"); return 1; } if ((time = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; printf("lab2::timer_set_square(%d)\n", (unsigned) time); timer_test_int(time); return 0; } else { printf("lab2: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned short number_packets, idle_time, length, tolerance; if (strncmp(argv[1], "packet", strlen("packet")) == 0) { if (argc != 3) { printf("mouse:: wrong no of arguments for test_packet() \n"); return 1; } number_packets = parse_ulong(argv[2], 10); printf("mouse:: packets()\n"); /* Actually, it was already invoked */ test_packet(number_packets); return 0; } else if (strncmp(argv[1], "async", strlen("async")) == 0) { if (argc != 3) { printf("mouse:: wrong no of arguments for test_async() \n"); return 1; } printf("mouse:: async()\n"); /* Actually, it was already invoked */ idle_time = parse_ulong(argv[2], 10); mouse_packet_async(idle_time); return 0; } else if (strncmp(argv[1], "config", strlen("config")) == 0) { if (argc != 2) { printf("mouse: wrong no of arguments for test of test_config() \n"); return 1; } printf("mouse:: config()\n"); /* Actually, it was already invoked */ test_config(); return 0; } else if (strncmp(argv[1], "gesture", strlen("gesture")) == 0) { if (argc != 4) { printf("mouse:: wrong no of arguments for test_gesture() \n"); return 1; } printf("mouse:: gesture()\n"); /* Actually, it was already invoked */ length = parse_ulong(argv[2], 10); tolerance = parse_ulong(argv[3], 10); mouse_gesture(length,tolerance); return 0; } }
void do_replace_node(int argc, char *argv[]) { const char *usage = "[--uninit] <lblk> <len> <pblk>"; errcode_t retval; struct ext2fs_extent extent; int err; if (common_extent_args_process(argc, argv, 3, 5, "replace_node", usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) return; extent.e_flags = 0; if (!strcmp(argv[1], "--uninit")) { argc--; argv++; extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; } if (argc != 4) { fprintf(stderr, "Usage: %s %s\n", argv[0], usage); return; } extent.e_lblk = parse_ulong(argv[1], argv[0], "logical block", &err); if (err) return; extent.e_len = parse_ulong(argv[2], argv[0], "logical block", &err); if (err) return; extent.e_pblk = parse_ulong(argv[3], argv[0], "logical block", &err); if (err) return; retval = ext2fs_extent_replace(current_handle, 0, &extent); if (retval) { com_err(argv[0], retval, 0); return; } generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT); }
void setup_cmd(int argc, char **argv) { int c, err; unsigned int blocks = 128; unsigned int inodes = 0; unsigned int type = EXT2FS_BMAP64_BITARRAY; int flags = EXT2_FLAG_64BITS; if (test_fs) ext2fs_close_free(&test_fs); reset_getopt(); while ((c = getopt(argc, argv, "b:i:lt:")) != EOF) { switch (c) { case 'b': blocks = parse_ulong(optarg, argv[0], "number of blocks", &err); if (err) return; break; case 'i': inodes = parse_ulong(optarg, argv[0], "number of blocks", &err); if (err) return; break; case 'l': /* Legacy bitmaps */ flags = 0; break; case 't': type = parse_ulong(optarg, argv[0], "bitmap backend type", &err); if (err) return; break; default: fprintf(stderr, "%s: usage: setup [-b blocks] " "[-i inodes] [-t type]\n", argv[0]); return; } } setup_filesystem(argv[0], blocks, inodes, type, flags); }
/* * This function will convert a string to a block number. It returns * 0 on success, 1 on failure. */ int strtoblk(const char *cmd, const char *str, blk_t *ret) { blk_t blk; int err; blk = parse_ulong(str, cmd, "block number", &err); *ret = blk; if (err) com_err(cmd, 0, "Invalid block number: %s", str); return err; }
static int proc_args(int argc, char *argv[]) { unsigned long freq, time; unsigned char conf; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "display_conf", strlen("display_conf")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_display_conf() \n"); return 1; } if( (conf = parse_ulong(argv[2], 0)) == ULONG_MAX ) return 1; printf("timer:: timer_display_conf(%d)\n", conf); timer_display_conf(conf); return 0; } else if (strncmp(argv[1], "test_int", strlen("test_int")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_int() \n"); return 1; } if( (time = parse_ulong(argv[2], 16)) == ULONG_MAX ) return 1; printf("timer:: timer_test_int(%d)\n", time); timer_test_int(time); return 0; } else if (strncmp(argv[1], "test_square", strlen("test_square")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_square() \n"); return 1; } if( (freq = parse_ulong(argv[2], 16)) == ULONG_MAX ) return 1; printf("timer:: timer_test_square(%d)\n", freq); return timer_test_square(freq); } else { printf("timer: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned long timer, freq, time; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "config", strlen("config")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_config() \n"); return 1; } if( (timer = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("timer:: timer_test_config(%lu)\n", timer); return timer_test_config(timer); } else if (strncmp(argv[1], "square", strlen("square")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_square() \n"); return 1; } if( (freq = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("timer:: timer_test_square(%lu)\n", freq); return timer_test_square(freq);; } else if (strncmp(argv[1], "test_int", strlen("test_int")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_int() \n"); return 1; } if( (time = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; printf("timer:: timer_test_int(%lu)\n", time); return timer_test_int(time);; } else { printf("timer: non valid function \"%s\" to test\n", argv[1]); return 1; } }
void do_clearb(int argc, char *argv[]) { unsigned int block, num; int err; int test_result, op_result; if (check_fs_open(argv[0])) return; if (argc != 2 && argc != 3) { com_err(argv[0], 0, "Usage: clearb <block> [num]"); return; } block = parse_ulong(argv[1], argv[0], "block", &err); if (err) return; if (argc == 3) { num = parse_ulong(argv[2], argv[0], "num", &err); if (err) return; ext2fs_unmark_block_bitmap_range2(test_fs->block_map, block, num); printf("Clearing blocks %u to %u\n", block, block + num - 1); return; } test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block); op_result = ext2fs_unmark_block_bitmap2(test_fs->block_map, block); printf("Clearing block %u, was %s before\n", block, op_result ? "set" : "clear"); if (!test_result != !op_result) com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)", test_result, op_result); }
static int proc_args(int argc, char *argv[]) { unsigned short base_addr; unsigned long returnVal, bits, stop,parity, rate; if (strncmp(argv[1], "conf", strlen("conf")) == 0) { if (argc != 3) { printf("test_conf: wrong number of arguments for test of test_conf() \n"); return 1; } if ((base_addr = parse_ulong(argv[2], 16)) == ULONG_MAX) return 1; returnVal = test_conf((unsigned short)base_addr); printf("\n"); return returnVal; } else if (strncmp(argv[1], "set", strlen("set")) == 0) { if (argc != 7) { printf("test_set: wrong number of arguments for test of test_set() \n"); return 1; } if ((base_addr = parse_ulong(argv[2], 10)) == ULONG_MAX) return 1; if ((bits = parse_ulong(argv[3], 10)) == ULONG_MAX) return 1; if ((stop = parse_ulong(argv[4], 10)) == ULONG_MAX) return 1; if ((parity = parse_ulong(argv[5], 10)) == ULONG_MAX) return 1; if ((rate = parse_ulong(argv[6], 10)) == ULONG_MAX) return 1; returnVal = test_set(base_addr, bits,stop,parity,rate); printf("\n"); return returnVal; } else if (strncmp(argv[1], "poll", strlen("poll")) == 0) { return 0; } else if (strncmp(argv[1], "int", strlen("int")) == 0) { return 0; } else if (strncmp(argv[1], "fifo", strlen("fifo")) == 0) { return 0; } else { printf("test: non valid function \"%s\" to test\n", argv[1]); return 1; } }
void do_testi(int argc, char *argv[]) { unsigned int inode; int err; int test_result; if (check_fs_open(argv[0])) return; if (argc != 2) { com_err(argv[0], 0, "Usage: testb <inode>"); return; } inode = parse_ulong(argv[1], argv[0], "inode", &err); if (err) return; test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode); printf("Inode %u is %s\n", inode, test_result ? "set" : "clear"); }
/* * This is a helper function used by do_freeb, do_setb, and do_testb */ int common_block_args_process(int argc, char *argv[], blk_t *block, blk_t *count) { int err; if (common_args_process(argc, argv, 2, 3, argv[0], "<block> [count]", CHECK_FS_BITMAPS)) return 1; if (strtoblk(argv[0], argv[1], block)) return 1; if (*block == 0) { com_err(argv[0], 0, "Invalid block number 0"); err = 1; } if (argc > 2) { *count = parse_ulong(argv[2], argv[0], "count", &err); if (err) return 1; } return 0; }
void do_get_quota(int argc, char *argv[]) { int err, type; struct quota_handle *qh; struct dquot *dq; qid_t id; if (load_quota_ctx(argv[0])) return; if (argc != 3) { com_err(0, 0, "Usage: get_quota <quota_type> <id>\n"); return; } type = parse_quota_type(argv[0], argv[1]); if (type < 0) return; id = parse_ulong(argv[2], argv[0], "id", &err); if (err) return; printf("%8s %8s %8s %8s %8s %8s %8s\n", (type == 0) ? "user id" : "group id", "blocks", "quota", "limit", "inodes", "quota", "limit"); qh = current_qctx->quota_file[type]; dq = qh->qh_ops->read_dquot(qh, id); if (dq) { list_quota_callback(dq, NULL); ext2fs_free_mem(&dq); } else { com_err(argv[0], 0, "couldn't read quota record"); } }
static int proc_args(int argc, char *argv[]) { unsigned short base_addr; unsigned long bits, stop, parity, rate; unsigned char tx; int i, stringc = 1; char **strings; char *temp; /* check the function to test: if the first characters match, accept it */ if (argc == 1) { print_usage(argv); return 1; } else if (strncmp(argv[1], "conf", strlen("conf")) == 0) { if (argc != 3) { printf("VBE: wrong no of arguments for conf() \n"); return 1; } if ((base_addr = parse_ushort(argv[2], 16)) == USHRT_MAX) return 1; printf("lab7:: conf(%d)\n", base_addr); ser_test_conf(base_addr); return 0; } else if (strncmp(argv[1], "set", strlen("set")) == 0) { if (argc != 7) { printf("lab7: wrong no of arguments for set() \n"); return 1; } if ((base_addr = parse_ushort(argv[2], 10)) == USHRT_MAX) return 1; if ((bits = parse_ulong(argv[3], 10)) == ULONG_MAX) return 1; if ((stop = parse_ulong(argv[4], 10)) == ULONG_MAX) return 1; if(strncmp(argv[5],"even",strlen("even")) == 0) parity = 2; else if(strncmp(argv[5], "odd",strlen("odd")) == 0) parity = 1; else if(strncmp(argv[5],"none",strlen("none")) == 0) parity = 0; if((rate = parse_ulong(argv[6],10)) == ULONG_MAX) return 1; printf("lab7::set(%d, %d, %d, %d, %d)\n", base_addr, bits, stop, parity, rate); return ser_test_set(base_addr, bits, stop, parity, rate); } else if (strncmp(argv[1], "com", strlen("com")) == 0) { if (argc != 8) { printf("lab7::wrong num of args for com() \n"); return 1; } if (base_addr = parse_ushort(argv[2], 10) == USHRT_MAX) return 1; if ((tx = parse_uchar(argv[3],10)) == UCHAR_MAX) return 1; if((bits = parse_ulong(argv[4],10)) == ULONG_MAX) return 1; if((stop = parse_ulong(argv[5],10)) == ULONG_MAX) return 1; if((rate = parse_ulong(argv[7],10)) == ULONG_MAX) return 1; if(strncmp(argv[6],"even",strlen("even")) == 0) parity = 2; else if(strncmp(argv[6], "odd",strlen("odd")) == 0) parity = 1; else if(strncmp(argv[6],"none",strlen("none")) == 0) parity = 0; /*strings = (char **)malloc(0); for(i = 8; i < argc; i++){ strings = realloc(strings,stringc * sizeof(char*)); strings[stringc - 1] =(char *) malloc(sizeof(argv[i])); strings[stringc - 1] = argv[i]; printf("%s ", strings[stringc - 1]); stringc++; }*/ printf("lab7::set(%d, %d, %d, %d, %d, %d)\n", base_addr, tx, bits, stop, parity, rate, stringc); return ser_test_poll(1, tx, bits, stop, parity, rate); } else { printf("lab7: non valid function \"%s\" to test\n", argv[1]); return 1; } }
void parse_config(FILE *fptr) { char *line; unsigned char keywords_found; line=(char *)xmalloc(512); keywords_found=0; while (!feof(fptr)) { fgets(line, 512, fptr); if (isalnum(line[0])) { switch(find_keyword(line)) { case -1: fprintf(stderr, "\nPARSE_CONFIG: unknown option: %s\n", line); break; case 0: boot_filename=parse_filename(line); printf(" Boot image: %s\n", boot_filename); keywords_found++; break; case 1: loader_filename=parse_filename(line); printf(" Kernel loader image: %s\n", loader_filename); keywords_found++; break; case 2: kernel_filename=parse_filename(line); printf(" Kernel image: %s\n", kernel_filename); keywords_found++; break; case 3: output_filename=parse_filename(line); printf(" Output image: %s\n", output_filename); keywords_found++; break; case 4: output_sectors=parse_ulong(line); printf(" Output sectors: %lu\n", output_sectors); keywords_found++; break; // case 5: boot_setup.heads=parse_int(line); // printf(" Number of heads: %d\n", boot_setup.heads); // keywords_found++; // break; // case 6: boot_setup.sectors=parse_int(line); // printf(" Sectors per track: %d\n", boot_setup.sectors); // keywords_found++; // break; case 7: boot_setup.bytes_per_sector=parse_ulong(line); printf(" Bytes per sector: %d\n", boot_setup.bytes_per_sector); keywords_found++; break; default: fprintf(stderr, "\nPARSE_CONFIG: unknown option: %s", line); break; } } } free(line); printf("\n"); if (keywords_found!=keywords) { fprintf(stderr, "\nPARSE_CONFIG: missing options in boot.cfg\n"); die(); } }
int main(int argc, char **argv) { unsigned int blocks = 128; unsigned int inodes = 0; unsigned int type = EXT2FS_BMAP64_BITARRAY; int c, err, code; char *request = (char *)NULL; char *cmd_file = 0; int sci_idx; int flags = EXT2_FLAG_64BITS; add_error_table(&et_ss_error_table); add_error_table(&et_ext2_error_table); while ((c = getopt (argc, argv, "b:i:lt:R:f:")) != EOF) { switch (c) { case 'b': blocks = parse_ulong(optarg, argv[0], "number of blocks", &err); if (err) exit(1); break; case 'i': inodes = parse_ulong(optarg, argv[0], "number of blocks", &err); if (err) exit(1); break; case 'l': /* Legacy bitmaps */ flags = 0; break; case 't': type = parse_ulong(optarg, argv[0], "bitmap backend type", &err); if (err) exit(1); break; case 'R': request = optarg; break; case 'f': cmd_file = optarg; break; default: com_err(argv[0], 0, "Usage: %s [-R request] " "[-f cmd_file]", subsystem_name); exit(1); } } sci_idx = ss_create_invocation(subsystem_name, version, (char *)NULL, &tst_bitmaps_cmds, &code); if (code) { ss_perror(sci_idx, code, "creating invocation"); exit(1); } (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code); if (code) { ss_perror(sci_idx, code, "adding standard requests"); exit (1); } printf("%s %s. Type '?' for a list of commands.\n\n", subsystem_name, version); setup_filesystem(argv[0], blocks, inodes, type, flags); if (request) { code = ss_execute_line(sci_idx, request); if (code) { ss_perror(sci_idx, code, request); exit_status++; } } else if (cmd_file) { exit_status = source_file(cmd_file, sci_idx); } else { ss_listen(sci_idx); } exit(exit_status); }
/* FIXME: This function does not handle LONG_LONG */ int _pSLang_sscanf (void) { int num; unsigned int num_refs; char *format; char *input_string, *input_string_max; SLFUTURE_CONST char *f, *s; unsigned char map8[256], map10[256], map16[256]; if (SLang_Num_Function_Args < 2) { _pSLang_verror (SL_INVALID_PARM, "Int_Type sscanf (str, format, ...)"); return -1; } num_refs = (unsigned int) SLang_Num_Function_Args; if (-1 == SLreverse_stack (num_refs)) return -1; num_refs -= 2; if (-1 == SLang_pop_slstring (&input_string)) return -1; if (-1 == SLang_pop_slstring (&format)) { SLang_free_slstring (input_string); return -1; } f = format; s = input_string; input_string_max = input_string + strlen (input_string); init_map (map8, 8); init_map (map10, 10); init_map (map16, 16); num = 0; while (num_refs != 0) { SLang_Object_Type obj; SLang_Ref_Type *ref; SLFUTURE_CONST char *smax; unsigned char *map; int base; int no_assign; int is_short; int is_long; int status; char chf; unsigned int width; int has_width; chf = *f++; if (chf == 0) { /* Hmmm.... what is the most useful thing to do?? */ #if 1 break; #else _pSLang_verror (SL_INVALID_PARM, "sscanf: format not big enough for output list"); goto return_error; #endif } if (isspace (chf)) { char *s1 = _pSLskip_whitespace (s); if (s1 == s) break; s = s1; continue; } if ((chf != '%') || ((chf = *f++) == '%')) { if (*s != chf) break; s++; continue; } no_assign = 0; is_short = 0; is_long = 0; width = 0; smax = input_string_max; /* Look for the flag character */ if (chf == '*') { no_assign = 1; chf = *f++; } /* Width */ has_width = isdigit (chf); if (has_width) { f--; (void) parse_uint (&f, f + strlen(f), &width, 10, map10); chf = *f++; } /* Now the type modifier */ switch (chf) { case 'h': is_short = 1; chf = *f++; break; case 'L': /* not implemented */ case 'l': is_long = 1; chf = *f++; break; } status = -1; if ((chf != 'c') && (chf != '[')) { s = _pSLskip_whitespace (s); if (*s == 0) break; } if (has_width) { if (width > (unsigned int) (input_string_max - s)) width = (unsigned int) (input_string_max - s); smax = s + width; } /* Now the format descriptor */ map = map10; base = 10; try_again: /* used by i, x, and o, conversions */ switch (chf) { case 0: _pSLang_verror (SL_INVALID_PARM, "sscanf: Unexpected end of format"); goto return_error; case 'D': is_long = 1; case 'd': if (is_short) { obj.o_data_type = SLANG_SHORT_TYPE; status = parse_short (&s, smax, &obj.v.short_val, base, map); } else if (is_long) { obj.o_data_type = SLANG_LONG_TYPE; status = parse_long (&s, smax, &obj.v.long_val, base, map); } else { obj.o_data_type = SLANG_INT_TYPE; status = parse_int (&s, smax, &obj.v.int_val, base, map); } break; case 'U': is_long = 1; case 'u': if (is_short) { obj.o_data_type = SLANG_USHORT_TYPE; status = parse_ushort (&s, smax, &obj.v.ushort_val, base, map); } else if (is_long) { obj.o_data_type = SLANG_ULONG_TYPE; status = parse_ulong (&s, smax, &obj.v.ulong_val, base, map); } else { obj.o_data_type = SLANG_INT_TYPE; status = parse_uint (&s, smax, &obj.v.uint_val, base, map); } break; case 'I': is_long = 1; case 'i': if ((s + 1 >= smax) || (*s != 0)) chf = 'd'; else if (((s[1] == 'x') || (s[1] == 'X')) && (s + 2 < smax)) { s += 2; chf = 'x'; } else chf = 'o'; goto try_again; case 'O': is_long = 1; case 'o': map = map8; base = 8; chf = 'd'; goto try_again; case 'X': is_long = 1; case 'x': base = 16; map = map16; chf = 'd'; goto try_again; case 'E': case 'F': is_long = 1; case 'e': case 'f': case 'g': #if SLANG_HAS_FLOAT if (is_long) { obj.o_data_type = SLANG_DOUBLE_TYPE; status = parse_double (&s, smax, &obj.v.double_val); } else { obj.o_data_type = SLANG_FLOAT_TYPE; status = parse_float (&s, smax, &obj.v.float_val); } #else _pSLang_verror (SL_NOT_IMPLEMENTED, "This version of the S-Lang does not support floating point"); status = -1; #endif break; case 's': obj.o_data_type = SLANG_STRING_TYPE; status = parse_string (&s, smax, &obj.v.s_val); break; case 'c': if (has_width == 0) { obj.o_data_type = SLANG_UCHAR_TYPE; obj.v.uchar_val = *s++; status = 1; break; } obj.o_data_type = SLANG_STRING_TYPE; status = parse_bstring (&s, smax, &obj.v.s_val); break; case '[': obj.o_data_type = SLANG_STRING_TYPE; status = parse_range (&s, smax, &f, &obj.v.s_val); break; case 'n': obj.o_data_type = SLANG_UINT_TYPE; obj.v.uint_val = (unsigned int) (s - input_string); status = 1; break; default: status = -1; _pSLang_verror (SL_NOT_IMPLEMENTED, "format specifier '%c' is not supported", chf); break; } if (status == 0) break; if (status == -1) goto return_error; if (no_assign) { SLang_free_object (&obj); continue; } if (-1 == SLang_pop_ref (&ref)) { SLang_free_object (&obj); goto return_error; } if (-1 == SLang_push (&obj)) { SLang_free_object (&obj); SLang_free_ref (ref); goto return_error; } if (-1 == _pSLang_deref_assign (ref)) { SLang_free_ref (ref); goto return_error; } SLang_free_ref (ref); num++; num_refs--; } if (-1 == SLdo_pop_n (num_refs)) goto return_error; SLang_free_slstring (format); SLang_free_slstring (input_string); return num; return_error: /* NULLS ok */ SLang_free_slstring (format); SLang_free_slstring (input_string); return -1; }
static int proc_args(int argc, char *argv[]) { unsigned long C, n; unsigned short *leds; int i; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "test_scan", strlen("test_scan")) == 0) { if( argc != 3 ) { printf("kbd: wrong no of arguments for test of kbd_test_scan \n"); return 1; } if( (C = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; if(C>1 || C < 0){ printf("kbd: invalid value for the parametrer\n"); return 1; } printf("kbd:: kbd_test_scan(%lu)\n", (unsigned)C); kbd_test_scan(C); return 0; } else if (strncmp(argv[1], "test_leds", strlen("test_leds")) == 0) { if( argc < 3) { printf("kbd: wrong no of arguments for test of kbd_test_leds \n"); return 1; } leds = malloc((argc - 2) * sizeof(unsigned short)); for (i = 0; i < argc - 2; i++){ leds[i] = parse_ulong(argv[2+i], 10); if(leds[i]<0 || leds[i]>2){ printf("kbd: there is no led with %s bit\n", leds[i]); return 1; } } kbd_test_leds(argc-2,leds); return 0; } else if (strncmp(argv[1], "test_timed_scan", strlen("test_timed_scan")) == 0) { if( argc != 3) { printf("kbd: wrong no of arguments for test of kbd_test_timed_scan \n"); return 1; } if( (n = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; if(n < 0){ printf("kbd: %lu is not a valid number for time\n", n); return 1; } printf("kbd:: kbd_test_timed_scan(%lu)\n", (unsigned)n); kbd_test_timed_scan(n); return 0; } else { printf("kbd: non valid function \"%s\" to test\n", argv[1]); return 1; } }