static int fs_stateMapFile(struct fs_dump_state * state, int preserve_flag ) { int ret = 0, flags; switch(state->mode) { case FS_STATE_LOAD_MODE: flags = PROT_READ | PROT_WRITE; /* loading involves a header invalidation */ break; case FS_STATE_DUMP_MODE: flags = PROT_WRITE; break; default: ViceLog(0, ("fs_stateMapFile: invalid dump state mode\n")); return 1; } state->mmap.map = afs_mmap(NULL, state->file_len, flags, MAP_SHARED, state->fd, 0); if (state->mmap.map == MAP_FAILED) { state->mmap.size = 0; state->mmap.map = NULL; ViceLog(0, ("fs_stateMapFile: failed to memory map file '%s'\n", state->fn)); ret = 1; goto done; } state->mmap.size = state->file_len; state->mmap.cursor = state->mmap.map; if (preserve_flag) { /* don't lose track of where we are during a file resize */ afs_foff_t curr_offset = state->mmap.offset; state->mmap.offset = 0; fs_stateIncCursor(state, curr_offset); } else { /* reset offset */ state->mmap.offset = 0; } /* for state loading, accesses will be sequential, so let's give * the VM subsystem a heads up */ if (state->mode == FS_STATE_LOAD_MODE) { /* XXX madvise may not exist on all platforms, so * we may need to add some ifdefs at some point... */ flags = MADV_SEQUENTIAL | MADV_WILLNEED; #ifdef AFS_SUN510_ENV flags |= MADV_ACCESS_LWP; /* added in solaris 9 12/02 */ #endif madvise(state->mmap.map, state->mmap.size, flags); } done: return ret; }
static int openFile(char * path) { int ret = 0; struct afs_stat status; dump_fd = afs_open(path, O_RDWR); if (dump_fd == -1) { fprintf(stderr, "dump file '%s' failed to open\n", path); ret = 1; goto done; } printf("opened dump file '%s'\n", path); if (afs_fstat(dump_fd, &status) == -1) { fprintf(stderr, "failed to stat file\n"); ret = 1; goto done; } map_len = status.st_size; map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0); if (map == MAP_FAILED) { fprintf(stderr, "failed to mmap file\n"); ret = 1; goto done; } printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map); done: if (ret) { if (map) { munmap(map, map_len); map = NULL; } if (dump_fd != -1) { close(dump_fd); dump_fd = -1; } } return ret; }