static int pcap_mmap_prepare_reading_pcap(int fd) { int ret; struct stat sb; set_ioprio_be(); spinlock_lock(&lock); ret = fstat(fd, &sb); if (ret < 0) panic("Cannot fstat pcap file!\n"); if (!S_ISREG (sb.st_mode)) panic("pcap dump file is not a regular file!\n"); map_size = sb.st_size; pstart = mmap(0, map_size, PROT_READ, MAP_SHARED | MAP_LOCKED /*| MAP_HUGETLB*/, fd, 0); if (pstart == MAP_FAILED) panic("mmap of file failed!"); ret = madvise(pstart, map_size, MADV_SEQUENTIAL); if (ret < 0) panic("Failed to give kernel mmap advise!\n"); pcurr = pstart + sizeof(struct pcap_filehdr); spinlock_unlock(&lock); return 0; }
static int pcap_mmap_prepare_writing_pcap(int fd) { int ret; off_t pos; struct stat sb; set_ioprio_be(); spinlock_lock(&lock); map_size = get_map_size(); ret = fstat(fd, &sb); if (ret < 0) panic("Cannot fstat pcap file!\n"); if (!S_ISREG (sb.st_mode)) panic("pcap dump file is not a regular file!\n"); pos = lseek(fd, map_size, SEEK_SET); if (pos < 0) panic("Cannot lseek pcap file!\n"); ret = write_or_die(fd, "", 1); if (ret != 1) panic("Cannot write file!\n"); pstart = mmap(0, map_size, PROT_WRITE, MAP_SHARED /*| MAP_HUGETLB*/, fd, 0); if (pstart == MAP_FAILED) panic("mmap of file failed!"); ret = madvise(pstart, map_size, MADV_SEQUENTIAL); if (ret < 0) panic("Failed to give kernel mmap advise!\n"); pcurr = pstart + sizeof(struct pcap_filehdr); spinlock_unlock(&lock); return 0; }
static void pcap_mm_init_once(bool enforce_prio) { if (enforce_prio) set_ioprio_be(); }