#include #include #include #include /* * Usage: cp-catalog * * Read the catalog from beginning to end. Read 'read_size' bytes * on each read. * * To ensure that a bug in catalog_read() in the kernel code is fixed. * cp-catalog 5 > /tmp/catalog-5 * cp-catalog > /tmp/catalog-4096 * diff /tmp/catalog-5 /tmp/catalog-4096 * * If both files are identical and size is about 256K, the bug is fixed. */ #define CATALOG "/sys/bus/event_source/devices/hv_24x7/interface/catalog" #define TMP_CATALOG "/tmp/catalog" main(int argc, char *argv[]) { int read_size, rfd, wfd, rc; struct stat stat_buf; char *input_file; char buf[4096]; char output_file[256]; read_size = 4096; if (argc > 1) read_size = atoi(argv[1]); if (read_size > sizeof(buf)) read_size = sizeof(buf); input_file = CATALOG; sprintf(output_file, "%s-%d", TMP_CATALOG, read_size); rfd = open(input_file, O_RDONLY); if (rfd < 0) { perror(input_file); _Exit(1); } wfd = open(output_file, O_WRONLY|O_CREAT|O_TRUNC); if (wfd < 0) { perror(output_file); _Exit(1); } while(1) { memset(buf, 0, sizeof(buf)); rc = read(rfd, buf, read_size); if (rc <= 0) break; if (write(wfd, buf, rc) != rc) { perror("write()"); break; } } if (fstat(wfd, &stat_buf) < 0) { perror("fstat()"); _Exit(1); } printf("catalog size %zd\n", stat_buf.st_size); }