static int info_f(int argc, char **argv) { BlockDriverInfo bdi; char s1[64], s2[64]; int ret; if (bs->drv && bs->drv->format_name) { printf("format name: %s\n", bs->drv->format_name); } if (bs->drv && bs->drv->protocol_name) { printf("format name: %s\n", bs->drv->protocol_name); } ret = bdrv_get_info(bs, &bdi); if (ret) { return 0; } cvtstr(bdi.cluster_size, s1, sizeof(s1)); cvtstr(bdi.vm_state_offset, s2, sizeof(s2)); printf("cluster size: %s\n", s1); printf("vm state offset: %s\n", s2); return 0; }
static int map_f(int argc, char **argv) { int64_t offset; int64_t nb_sectors; char s1[64]; int num, num_checked; int ret; const char *retstr; offset = 0; nb_sectors = bs->total_sectors; do { num_checked = MIN(nb_sectors, INT_MAX); ret = bdrv_is_allocated(bs, offset, num_checked, &num); retstr = ret ? " allocated" : "not allocated"; cvtstr(offset << 9ULL, s1, sizeof(s1)); printf("[% 24" PRId64 "] % 8d/% 8d sectors %s at offset %s (%d)\n", offset << 9ULL, num, num_checked, retstr, s1, ret); offset += num; nb_sectors -= num; } while (offset < bs->total_sectors); return 0; }
static void print_report(const char *op, struct timeval *t, int64_t offset, int count, int total, int cnt, int Cflag) { char s1[64], s2[64], ts[64]; timestr(t, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0); if (!Cflag) { cvtstr((double)total, s1, sizeof(s1)); cvtstr(tdiv((double)total, *t), s2, sizeof(s2)); printf("%s %d/%d bytes at offset %" PRId64 "\n", op, total, count, offset); printf("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n", s1, cnt, ts, s2, tdiv((double)cnt, *t)); } else {/* bytes,ops,time,bytes/sec,ops/sec */ printf("%d,%d,%s,%.3f,%.3f\n", total, cnt, ts, tdiv((double)total, *t), tdiv((double)cnt, *t)); } }
static int alloc_f(int argc, char **argv) { int64_t offset, sector_num; int nb_sectors, remaining; char s1[64]; int num, sum_alloc; int ret; offset = cvtnum(argv[1]); if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); return 0; } if (argc == 3) { nb_sectors = cvtnum(argv[2]); } else { nb_sectors = 1; } remaining = nb_sectors; sum_alloc = 0; sector_num = offset >> 9; while (remaining) { ret = bdrv_is_allocated(bs, sector_num, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); return 0; } sector_num += num; remaining -= num; if (ret) { sum_alloc += num; } if (num == 0) { nb_sectors -= remaining; remaining = 0; } } cvtstr(offset, s1, sizeof(s1)); if (nb_sectors == 1) printf("sector allocated at offset %s\n", s1); else printf("%d/%d sectors allocated at offset %s\n", sum_alloc, nb_sectors, s1); return 0; }
static int length_f(int argc, char **argv) { int64_t size; char s1[64]; size = bdrv_getlength(bs); if (size < 0) { printf("getlength: %s\n", strerror(-size)); return 0; } cvtstr(size, s1, sizeof(s1)); printf("%s\n", s1); return 0; }
static int alloc_f(int argc, char **argv) { int64_t offset; int nb_sectors, remaining; char s1[64]; int num, sum_alloc; int ret; offset = cvtnum(argv[1]); if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n", (long long)offset); return 0; } if (argc == 3) nb_sectors = cvtnum(argv[2]); else nb_sectors = 1; remaining = nb_sectors; sum_alloc = 0; while (remaining) { ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); remaining -= num; if (ret) { sum_alloc += num; } } cvtstr(offset, s1, sizeof(s1)); if (nb_sectors == 1) printf("sector allocated at offset %s\n", s1); else printf("%d/%d sectors allocated at offset %s\n", sum_alloc, nb_sectors, s1); return 0; }
void GL::init() { static bool init = false; const GLubyte* str; if( init ) return; init = true; /* version check */ str = glGetString( GL_VERSION ); parseVersion( ( const char* ) str, &_glmajor, &_glminor ); str = glGetString( GL_SHADING_LANGUAGE_VERSION ); parseVersion( ( const char* ) str, &_glslmajor, &_glslminor ); if( _glmajor < 2 || ( _glmajor == 2 && _glminor == 0 ) ) { std::cerr << "GL Version too old, at least GL 2.1 is needed" << std::endl; std::exit( EXIT_FAILURE ); } if( _glslmajor == 1 && _glslminor < 20 ) { std::cerr << "GLSL Version too old, at least GLSL 1.20 is needed" << std::endl; std::exit( EXIT_FAILURE ); } /* extensions check */ if( _glmajor > 2 ) { int numext; glGetIntegerv( GL_NUM_EXTENSIONS, &numext ); for( int i = 0; i < numext; i++ ) { _extensions.push_back( ( const char* ) glGetStringi( GL_EXTENSIONS, i ) ); } } else { String cvtstr( ( const char* ) glGetString( GL_EXTENSIONS ) ); cvtstr.tokenize( _extensions, ' ' ); } if( existsExtension( "GL_ARB_vertex_array_object" ) || ( _glmajor > 2 || ( _glmajor == 2 && _glminor >= 1 ) ) ) { glGenVertexArrays = ( void (*)( GLsizei, GLuint* ) ) getProcAddress( "glGenVertexArrays" ); glDeleteVertexArrays = ( void (*)( GLsizei, const GLuint* ) ) getProcAddress( "glDeleteVertexArrays" ); glBindVertexArray = ( void (*)( GLuint ) ) getProcAddress( "glBindVertexArray" ); glIsVertexArray = ( GLboolean (*)( GLuint ) ) getProcAddress( "glIsVertexArray" ); } else if( existsExtension( "GL_APPLE_vertex_array_object" ) ) { glGenVertexArrays = ( void (*)( GLsizei, GLuint* ) ) getProcAddress( "glGenVertexArraysAPPLE" ); glDeleteVertexArrays = ( void (*)( GLsizei, const GLuint* ) ) getProcAddress( "glDeleteVertexArraysAPPLE" ); glBindVertexArray = ( void (*)( GLuint ) ) getProcAddress( "glBindVertexArrayAPPLE" ); glIsVertexArray = ( GLboolean (*)( GLuint ) ) getProcAddress( "glIsVertexArrayAPPLE" ); } else { std::cerr << "GL vertex array object extension missing" << std::endl; std::exit( EXIT_FAILURE ); } if( !existsExtension( "GL_ARB_texture_non_power_of_two" ) && _glmajor <= 2 ) { std::cerr << "GL texture non power of two extension missing" << std::endl; std::exit( EXIT_FAILURE ); } if( existsExtension( "GL_EXT_framebuffer_object" ) || existsExtension( "GL_ARB_framebuffer_object" ) || _glmajor > 2 ) { glBindRenderbuffer = ( void (*)( GLenum target, GLuint renderbuffer) ) getProcAddress( "glBindRenderbuffer" ); glDeleteRenderbuffers = ( void (*)( GLsizei n, const GLuint *renderbuffers) ) getProcAddress( "glDeleteRenderbuffers" ); glGenRenderbuffers = ( void (*)( GLsizei n, GLuint *renderbuffers) ) getProcAddress( "glGenRenderbuffers" ); glRenderbufferStorage = ( void (*)( GLenum target, GLenum internalformat, GLsizei width, GLsizei height) ) getProcAddress( "glRenderbufferStorage" ); glBindFramebuffer = ( void (*)( GLenum target, GLuint framebuffer ) ) getProcAddress( "glBindFramebuffer" ); glDeleteFramebuffers = ( void (*)( GLsizei n, const GLuint *framebuffers ) ) getProcAddress( "glDeleteFramebuffers" ); glGenFramebuffers = ( void (*)( GLsizei n, GLuint *framebuffers ) ) getProcAddress( "glGenFramebuffers" ); glFramebufferTexture1D = ( void (*)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level ) ) getProcAddress( "glFramebufferTexture1D" ); glFramebufferTexture2D = ( void (*)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level ) ) getProcAddress( "glFramebufferTexture2D" ); glFramebufferTexture3D = ( void (*)( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset ) ) getProcAddress( "glFramebufferTexture3D" ); glFramebufferRenderbuffer = ( void (*)( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) ) getProcAddress( "glFramebufferRenderbuffer" ); } else { std::cerr << "GL framebuffer extension missing" << std::endl; std::exit( EXIT_FAILURE ); } }
static int pread_f( int argc, char **argv) { size_t bsize; off64_t offset; unsigned int zeed = 0; long long count, total, tmp; size_t fsblocksize, fssectsize; struct timeval t1, t2; char s1[64], s2[64], ts[64]; char *sp; int Cflag, qflag, uflag, vflag; int eof = 0, direction = IO_FORWARD; int c; Cflag = qflag = uflag = vflag = 0; init_cvtnum(&fsblocksize, &fssectsize); bsize = fsblocksize; while ((c = getopt(argc, argv, "b:BCFRquvV:Z:")) != EOF) { switch (c) { case 'b': tmp = cvtnum(fsblocksize, fssectsize, optarg); if (tmp < 0) { printf(_("non-numeric bsize -- %s\n"), optarg); return 0; } bsize = tmp; break; case 'C': Cflag = 1; break; case 'F': direction = IO_FORWARD; break; case 'B': direction = IO_BACKWARD; break; case 'R': direction = IO_RANDOM; break; case 'q': qflag = 1; break; case 'u': uflag = 1; break; case 'v': vflag = 1; break; #ifdef HAVE_PREADV case 'V': vectors = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { printf(_("non-numeric vector count == %s\n"), optarg); return 0; } break; #endif case 'Z': zeed = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { printf(_("non-numeric seed -- %s\n"), optarg); return 0; } break; default: return command_usage(&pread_cmd); } } if (optind != argc - 2) return command_usage(&pread_cmd); offset = cvtnum(fsblocksize, fssectsize, argv[optind]); if (offset < 0 && (direction & (IO_RANDOM|IO_BACKWARD))) { eof = -1; /* read from EOF */ } else if (offset < 0) { printf(_("non-numeric length argument -- %s\n"), argv[optind]); return 0; } optind++; count = cvtnum(fsblocksize, fssectsize, argv[optind]); if (count < 0 && (direction & (IO_RANDOM|IO_FORWARD))) { eof = -1; /* read to EOF */ } else if (count < 0) { printf(_("non-numeric length argument -- %s\n"), argv[optind]); return 0; } if (alloc_buffer(bsize, uflag, 0xabababab) < 0) return 0; gettimeofday(&t1, NULL); switch (direction) { case IO_RANDOM: if (!zeed) /* srandom seed */ zeed = time(NULL); c = read_random(file->fd, offset, count, &total, zeed, eof); break; case IO_FORWARD: c = read_forward(file->fd, offset, count, &total, vflag, 0, eof); if (eof) count = total; break; case IO_BACKWARD: c = read_backward(file->fd, &offset, &count, &total, eof); break; default: ASSERT(0); } if (c < 0) return 0; if (qflag) return 0; gettimeofday(&t2, NULL); t2 = tsub(t2, t1); /* Finally, report back -- -C gives a parsable format */ timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0); if (!Cflag) { cvtstr((double)total, s1, sizeof(s1)); cvtstr(tdiv((double)total, t2), s2, sizeof(s2)); printf(_("read %lld/%lld bytes at offset %lld\n"), total, count, (long long)offset); printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"), s1, c, ts, s2, tdiv((double)c, t2)); } else {/* bytes,ops,time,bytes/sec,ops/sec */ printf("%lld,%d,%s,%.3f,%.3f\n", total, c, ts, tdiv((double)total, t2), tdiv((double)c, t2)); } return 0; }
static int reflink_f( int argc, char **argv) { off64_t soffset = 0, doffset = 0; long long count = 0, total; char s1[64], s2[64], ts[64]; char *infile = NULL; int Cflag, qflag, wflag, Wflag; struct xfs_ioctl_clone_range_args args; size_t fsblocksize, fssectsize; struct timeval t1, t2; int c, fd = -1; Cflag = qflag = wflag = Wflag = 0; init_cvtnum(&fsblocksize, &fssectsize); while ((c = getopt(argc, argv, "CqwW")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'w': wflag = 1; break; case 'W': Wflag = 1; break; default: return command_usage(&reflink_cmd); } } if (optind != argc - 4 && optind != argc - 1) return command_usage(&reflink_cmd); infile = argv[optind]; optind++; if (optind == argc) goto clone_all; soffset = cvtnum(fsblocksize, fssectsize, argv[optind]); if (soffset < 0) { printf(_("non-numeric src offset argument -- %s\n"), argv[optind]); return 0; } optind++; doffset = cvtnum(fsblocksize, fssectsize, argv[optind]); if (doffset < 0) { printf(_("non-numeric dest offset argument -- %s\n"), argv[optind]); return 0; } optind++; count = cvtnum(fsblocksize, fssectsize, argv[optind]); if (count < 1) { printf(_("non-positive length argument -- %s\n"), argv[optind]); return 0; } clone_all: c = IO_READONLY; fd = openfile(infile, NULL, c, 0); if (fd < 0) return 0; gettimeofday(&t1, NULL); if (count) { args.src_fd = fd; args.src_offset = soffset; args.src_length = count; args.dest_offset = doffset; c = ioctl(file->fd, XFS_IOC_CLONE_RANGE, &args); } else { c = ioctl(file->fd, XFS_IOC_CLONE, fd); } if (c < 0) { perror(_("reflink")); goto done; } total = count; c = 1; if (Wflag) fsync(file->fd); if (wflag) fdatasync(file->fd); if (qflag) goto done; gettimeofday(&t2, NULL); t2 = tsub(t2, t1); /* Finally, report back -- -C gives a parsable format */ timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0); if (!Cflag) { cvtstr((double)total, s1, sizeof(s1)); cvtstr(tdiv((double)total, t2), s2, sizeof(s2)); printf(_("linked %lld/%lld bytes at offset %lld\n"), total, count, (long long)doffset); printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"), s1, c, ts, s2, tdiv((double)c, t2)); } else {/* bytes,ops,time,bytes/sec,ops/sec */ printf("%lld,%d,%s,%.3f,%.3f\n", total, c, ts, tdiv((double)total, t2), tdiv((double)c, t2)); } done: close(fd); return 0; }
static int pwrite_f( int argc, char **argv) { size_t bsize; off64_t offset, skip = 0; long long count, total, tmp; unsigned int zeed = 0, seed = 0xcdcdcdcd; size_t fsblocksize, fssectsize; struct timeval t1, t2; char s1[64], s2[64], ts[64]; char *sp, *infile = NULL; int Cflag, qflag, uflag, dflag, wflag, Wflag; int direction = IO_FORWARD; int c, fd = -1; Cflag = qflag = uflag = dflag = wflag = Wflag = 0; init_cvtnum(&fsblocksize, &fssectsize); bsize = fsblocksize; while ((c = getopt(argc, argv, "b:Cdf:i:qs:S:uwWZ:")) != EOF) { switch (c) { case 'b': tmp = cvtnum(fsblocksize, fssectsize, optarg); if (tmp < 0) { printf(_("non-numeric bsize -- %s\n"), optarg); return 0; } bsize = tmp; break; case 'C': Cflag = 1; break; case 'F': direction = IO_FORWARD; break; case 'B': direction = IO_BACKWARD; break; case 'R': direction = IO_RANDOM; break; case 'd': dflag = 1; break; case 'f': case 'i': infile = optarg; break; case 's': skip = cvtnum(fsblocksize, fssectsize, optarg); if (skip < 0) { printf(_("non-numeric skip -- %s\n"), optarg); return 0; } break; case 'S': seed = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { printf(_("non-numeric seed -- %s\n"), optarg); return 0; } break; case 'q': qflag = 1; break; case 'u': uflag = 1; break; case 'w': wflag = 1; break; case 'W': Wflag = 1; break; case 'Z': zeed = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { printf(_("non-numeric seed -- %s\n"), optarg); return 0; } break; default: return command_usage(&pwrite_cmd); } } if (((skip || dflag) && !infile) || (optind != argc - 2)) return command_usage(&pwrite_cmd); if (infile && direction != IO_FORWARD) return command_usage(&pwrite_cmd); offset = cvtnum(fsblocksize, fssectsize, argv[optind]); if (offset < 0) { printf(_("non-numeric offset argument -- %s\n"), argv[optind]); return 0; } optind++; count = cvtnum(fsblocksize, fssectsize, argv[optind]); if (count < 0) { printf(_("non-numeric length argument -- %s\n"), argv[optind]); return 0; } if (alloc_buffer(bsize, uflag, seed) < 0) return 0; c = IO_READONLY | (dflag ? IO_DIRECT : 0); if (infile && ((fd = openfile(infile, NULL, c, 0)) < 0)) return 0; gettimeofday(&t1, NULL); switch (direction) { case IO_RANDOM: if (!zeed) /* srandom seed */ zeed = time(NULL); c = write_random(offset, count, zeed, &total); break; case IO_FORWARD: c = write_buffer(offset, count, bsize, fd, skip, &total); break; case IO_BACKWARD: c = write_backward(offset, &count, &total); break; default: total = 0; ASSERT(0); } if (c < 0) goto done; if (Wflag) fsync(file->fd); if (wflag) fdatasync(file->fd); if (qflag) goto done; gettimeofday(&t2, NULL); t2 = tsub(t2, t1); /* Finally, report back -- -C gives a parsable format */ timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0); if (!Cflag) { cvtstr((double)total, s1, sizeof(s1)); cvtstr(tdiv((double)total, t2), s2, sizeof(s2)); printf(_("wrote %lld/%lld bytes at offset %lld\n"), total, count, (long long)offset); printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"), s1, c, ts, s2, tdiv((double)c, t2)); } else {/* bytes,ops,time,bytes/sec,ops/sec */ printf("%lld,%d,%s,%.3f,%.3f\n", total, c, ts, tdiv((double)total, t2), tdiv((double)c, t2)); } done: if (infile) close(fd); return 0; }
static int sendfile_f( int argc, char **argv) { off64_t offset = 0; long long count, total; size_t blocksize, sectsize; struct timeval t1, t2; char s1[64], s2[64], ts[64]; char *infile = NULL; int Cflag, qflag; int c, fd = -1; Cflag = qflag = 0; init_cvtnum(&blocksize, §size); while ((c = getopt(argc, argv, "Cf:i:q")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; case 'f': fd = atoi(argv[1]); if (fd < 0 || fd >= filecount) { printf(_("value %d is out of range (0-%d)\n"), fd, filecount-1); return 0; } break; case 'i': infile = optarg; break; default: return command_usage(&sendfile_cmd); } } if (infile && fd != -1) return command_usage(&sendfile_cmd); if (!infile) fd = filetable[fd].fd; else if ((fd = openfile(infile, NULL, IO_READONLY, 0)) < 0) return 0; if (optind == argc - 2) { offset = cvtnum(blocksize, sectsize, argv[optind]); if (offset < 0) { printf(_("non-numeric offset argument -- %s\n"), argv[optind]); goto done; } optind++; count = cvtnum(blocksize, sectsize, argv[optind]); if (count < 0) { printf(_("non-numeric length argument -- %s\n"), argv[optind]); goto done; } } else { struct stat64 stat; if (fstat64(fd, &stat) < 0) { perror("fstat64"); goto done; } count = stat.st_size; } gettimeofday(&t1, NULL); c = send_buffer(offset, count, fd, &total); if (c < 0) goto done; if (qflag) goto done; gettimeofday(&t2, NULL); t2 = tsub(t2, t1); /* Finally, report back -- -C gives a parsable format */ timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0); if (!Cflag) { cvtstr((double)total, s1, sizeof(s1)); cvtstr(tdiv((double)total, t2), s2, sizeof(s2)); printf(_("sent %lld/%lld bytes from offset %lld\n"), total, count, (long long)offset); printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"), s1, c, ts, s2, tdiv((double)c, t2)); } else {/* bytes,ops,time,bytes/sec,ops/sec */ printf("%lld,%d,%s,%.3f,%.3f\n", total, c, ts, tdiv((double)total, t2), tdiv((double)c, t2)); } done: if (infile) close(fd); return 0; }