| 1 | #include <sys/types.h> |
| 2 | #include <sys/stat.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <sys/mman.h> |
| 5 | #include <stdio.h> |
| 6 | #include <stdint.h> |
| 7 | #include <unistd.h> |
| 8 | #include <errno.h> |
| 9 | #include <uuid/uuid.h> |
| 10 | #include <string.h> |
| 11 | |
| 12 | #define FILE_LEN (4 * 4096) |
| 13 | |
| 14 | int main(int argc, char **argv) |
| 15 | { |
| 16 | char *base, *pos; |
| 17 | int fd, ret; |
| 18 | off_t off; |
| 19 | uuid_t uuid; |
| 20 | |
| 21 | fd = open("dummystream", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); |
| 22 | if (fd < 0) { |
| 23 | perror("open"); |
| 24 | return -1; |
| 25 | } |
| 26 | off = posix_fallocate(fd, 0, FILE_LEN); |
| 27 | if (off < 0) { |
| 28 | printf("Error in fallocate\n"); |
| 29 | return -1; |
| 30 | } |
| 31 | #if 0 |
| 32 | { |
| 33 | ssize_t len; |
| 34 | |
| 35 | off = lseek(fd, FILE_LEN - 1, SEEK_CUR); |
| 36 | if (off < 0) { |
| 37 | perror("lseek"); |
| 38 | return -1; |
| 39 | } |
| 40 | len = write(fd, "", 1); |
| 41 | if (len < 0) { |
| 42 | perror("write"); |
| 43 | return -1; |
| 44 | } |
| 45 | } |
| 46 | #endif |
| 47 | base = mmap(NULL, FILE_LEN, PROT_READ|PROT_WRITE, |
| 48 | MAP_SHARED, fd, 0); |
| 49 | if (!base) { |
| 50 | perror("mmap"); |
| 51 | return -1; |
| 52 | } |
| 53 | pos = base; |
| 54 | |
| 55 | /* magic */ |
| 56 | *(uint32_t *) pos = 0xC1FC1FC1; |
| 57 | pos += sizeof(uint32_t); |
| 58 | |
| 59 | /* trace_uuid */ |
| 60 | ret = uuid_parse("2a6422d0-6cee-11e0-8c08-cb07d7b3a564", uuid); |
| 61 | if (ret) { |
| 62 | printf("uuid parse error\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | memcpy(pos, uuid, 16); |
| 66 | pos += 16; |
| 67 | |
| 68 | /* stream_id */ |
| 69 | *(uint32_t *) pos = 0; |
| 70 | pos += sizeof(uint32_t); |
| 71 | |
| 72 | ret = munmap(base, FILE_LEN); |
| 73 | if (ret) { |
| 74 | perror("munmap"); |
| 75 | return -1; |
| 76 | } |
| 77 | close(fd); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | |