/* Load a new ghost image */ static vm_ghost_image_t *vm_ghost_image_load(char *filename) { vm_ghost_image_t *img; if (!(img = calloc(1,sizeof(*img)))) return NULL; img->fd = -1; if (!(img->filename = strdup(filename))) { vm_ghost_image_free(img); return NULL; } img->fd = memzone_open_file(img->filename,&img->area_ptr,&img->file_size); if (img->fd == -1) { vm_ghost_image_free(img); return NULL; } m_log("GHOST","loaded ghost image %s (fd=%d) at addr=%p (size=0x%llx)\n", img->filename,img->fd,img->area_ptr,(long long)img->file_size); return img; }
/* Open a VM file and map it in memory */ int vm_mmap_open_file(vm_instance_t *vm,char *name, u_char **ptr,off_t *fsize) { char *filename; int fd; if (!(filename = vm_build_filename(vm,name))) { fprintf(stderr,"vm_mmap_open_file: unable to create filename (%s)\n", name); return(-1); } if ((fd = memzone_open_file(filename,ptr,fsize)) == -1) fprintf(stderr,"vm_mmap_open_file: unable to open file '%s' (%s)\n", filename,strerror(errno)); free(filename); return(fd); }