Beispiel #1
0
cube cube::operator + (const cube &h) const
{
    cube H = {x+h.x,y+h.y,z+h.z};
    if (distance(H) > get_map_size())
    {
        int S = get_map_size();
        if (distance(H,cube{2*S+1, -S, -S-1}) <= S)
        {
            H = cube_subtract(H,cube{2*S+1, -S, -S-1});
        }
        else if (distance(H,cube{S+1, -2*S-1, S}) <= S)
        {
            H = cube_subtract(H,cube{S+1, -2*S-1, S});
        }
        else if (distance(H,cube{-S, -S-1, 2*S+1}) <= S)
        {
            H = cube_subtract(H,cube{-S, -S-1, 2*S+1});
        }
        else if (distance(H,cube{-2*S-1, S, S+1}) <= S)
        {
            H = cube_subtract(H,cube{-2*S-1, S, S+1});
        }
        else if (distance(H,cube{-S-1, 2*S+1, -S}) <= S)
        {
            H = cube_subtract(H,cube{-S-1, 2*S+1, -S});
        }
        else if (distance(H,cube{S, S+1, -2*S-1}) <= S)
        {
            H = cube_subtract(H,cube{S, S+1, -2*S-1});
        }
    }
    return H;
}
Beispiel #2
0
static int pcap_mmap_prepare_writing_pcap(int fd)
{
	int ret;
	struct stat sb;

	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");
	/* Expand file buffer, so that mmap can be done. */
	ret = lseek(fd, map_size, SEEK_SET);
	if (ret < 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)
		puke_and_die(EXIT_FAILURE, "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 gboolean
invalidate_canvas (ChamplainPathLayer *layer)
{
  ChamplainPathLayerPrivate *priv = layer->priv;
  gfloat view_width, view_height;
  gint map_width, map_height;
  gint viewport_x, viewport_y;
  gint anchor_x, anchor_y;
  gfloat right_actor_width, right_actor_height;
  gfloat left_actor_width, left_actor_height;

  right_actor_width = 256;
  right_actor_height = 256;
  left_actor_width = 0;
  left_actor_height = 0;
  map_width = 256;
  map_height = 256;

  if (priv->view != NULL)
    {
      get_map_size (priv->view, &map_width, &map_height);
      clutter_actor_get_size (CLUTTER_ACTOR (priv->view), &view_width, &view_height);
      champlain_view_get_viewport_origin (priv->view, &viewport_x, &viewport_y);
      champlain_view_get_viewport_anchor (priv->view, &anchor_x, &anchor_y);

      right_actor_width = MIN (map_width - (viewport_x + anchor_x), (gint)view_width);
      right_actor_height = MIN (map_height - (viewport_y + anchor_y), (gint)view_height);
      left_actor_width = MIN (view_width - right_actor_width, map_width - right_actor_width);
      left_actor_height = right_actor_height;

      /* Ensure sizes are positive  */
      right_actor_width = MAX (0, right_actor_width);
      right_actor_height = MAX (0, right_actor_height);
      left_actor_width = MAX (0, left_actor_width);
      left_actor_height = MAX (0, left_actor_height);
    }

  clutter_actor_set_size (priv->path_actor, map_width, map_height);

  clutter_actor_set_size (priv->right_actor, right_actor_width, right_actor_height);
  clutter_canvas_set_size (CLUTTER_CANVAS (priv->right_canvas), right_actor_width, right_actor_height);
  clutter_content_invalidate (priv->right_canvas);

  if (left_actor_width != 0)
    {
      clutter_actor_set_size (priv->left_actor, left_actor_width, left_actor_height);
      clutter_canvas_set_size (CLUTTER_CANVAS (priv->left_canvas), left_actor_width, left_actor_height);
      clutter_content_invalidate (priv->left_canvas);
    }

  priv->redraw_scheduled = FALSE;

  return FALSE;
}
Beispiel #4
0
int			main(void)
{
	t_env	env;

	get_map_size(&env, "map");
	makeparams(&env);
	wolf(&env);
	mlx_hook(env.win, 2, (1L << 0), get_key_event, &env);
	mlx_loop(env.mlx);
	return (0);
}
Beispiel #5
0
static int fusecow_truncate(const char *path, off64_t size)
{
    (void) size;

    if(strcmp(path, "/") != 0)
        return -ENOENT;
    

    st_size = size;
    munmap(mem_write_map, mem_write_map_size);
    mem_write_map_size = get_map_size();
    ftruncate(fd_write_map, mem_write_map_size);

    pwrite64(fd_write_map, &st_size, sizeof st_size, 8);
    
    mem_write_map = mmap(NULL, mem_write_map_size , PROT_READ|PROT_WRITE, MAP_SHARED, fd_write_map, 0);

    if(ftruncate(fd_write, size)==-1) {
	return -errno;
    }

    return 0;

}
Beispiel #6
0
int main(int argc, char *argv[])
{
    int ret,i;
    char* argv2[argc-1+2];  // File name removed, "-o nonempty,direct_io" added
    int our_arguments_count=5; /* argv[0], source file, storage file and mount point */

    block_size=8192;
    fd=0;
    fd_write=0;
    fd_write_map=0;
    mem_write_map=MAP_FAILED;
    fd_read=0;
    fd_read_map=0;
    mem_read_map=MAP_FAILED;
    read_only = 0;

    int block_size_overridden=0;

    if(argc<4){
	fprintf(stderr,"fusecoraw alpha version. Copy-on-read-and-write block device using FUSE and sparse files. Fusecow originally created by _Vi, altered to fusecoraw by EvdH.\n");
    fprintf(stderr,"Usage: %s read_file mountpoint_file write_file read_file [-RM read_file.map] [-WM write_file.map] [-B blocksize] [-RO (read-only, for remounting)] [FUSE_options]\n",argv[0]);
	fprintf(stderr,"Examples:\n");
	fprintf(stderr,"    fusecoraw source mountpoint copy-on-write-fle copy-on-read-file\n");
	fprintf(stderr,"Remember to \"touch\" your mountpoints, not \"mkdir\" them.\n");
	return 1;
    }

    {
    char write_mapfile_buff[4096];
    sprintf(write_mapfile_buff, "%s.map", argv[3]);
    const char *write_mapfile = write_mapfile_buff;
    char read_mapfile_buff[4096];
    sprintf(read_mapfile_buff, "%s.map", argv[4]);
    const char *read_mapfile = read_mapfile_buff;
    for(;argv[our_arguments_count];) {
        if(!strcmp(argv[our_arguments_count], "-B")) {
        ++our_arguments_count;
        sscanf(argv[our_arguments_count], "%i", &block_size);
        block_size_overridden = 1;
        ++our_arguments_count;
        } else
        if(!strcmp(argv[our_arguments_count], "-WM")) {
        ++our_arguments_count;
        write_mapfile = argv[our_arguments_count];
        ++our_arguments_count;
        } else
        if(!strcmp(argv[our_arguments_count], "-RM")) {
        ++our_arguments_count;
        read_mapfile = argv[our_arguments_count];
        ++our_arguments_count;
        } else
        if(!strcmp(argv[our_arguments_count], "-RO")) {
        ++our_arguments_count;
        read_only = 1;
        } else {
        break;
        }
    }

    fd=open64(argv[1],O_RDONLY);
    if(fd<0){
        fprintf(stderr, "Unable to open read file \"%s\"\n", argv[1]);
        perror("open");
        return 1;
    }
    fd_write=open64(argv[3], O_RDWR|O_CREAT, 0777);
    if(fd_write<0){
        fprintf(stderr, "Unable to open write file \"%s\"\n", argv[3]);
        perror("open");
        return 1;
    }
    fd_write_map=open(write_mapfile, O_RDWR|O_CREAT, 0777);
    if(fd_write_map<0){
        fprintf(stderr, "Unable to open map file \"%s\"\n", write_mapfile);
        perror("open");
        return 1;
    }

    if(read_only)
        fd_read=open64(argv[4], O_RDONLY, 0777);
    else
        fd_read=open64(argv[4], O_RDWR|O_CREAT, 0777);
    if(fd_read<0){
        fprintf(stderr, "Unable to open read file \"%s\"\n", argv[4]);
        perror("open");
        return 1;
    }


    if(read_only)
        fd_read_map=open(read_mapfile, O_RDONLY, 0777);
    else
        fd_read_map=open(read_mapfile, O_RDWR|O_CREAT, 0777);
    if(fd_read_map<0){
        fprintf(stderr, "Unable to open read map file \"%s\"\n", read_mapfile);
        perror("open");
        return 1;
    }


    char write_signature[8];
    write_signature[0]=0;
    pread64(fd_write_map, &write_signature, sizeof write_signature, 0);
    write_signature[7]=0;
    if (strcmp(write_signature, "fusecow")) {
        // No signature:
        struct stat stbuf;
        fstat(fd, &stbuf);
        stbuf.st_size = st_size = (off64_t)lseek64(fd, (off64_t)0, SEEK_END);
        pwrite64(fd_write_map, "fusecow\n", 8, 0);
        pwrite64(fd_write_map, &st_size, sizeof st_size, 8);
        pwrite64(fd_write_map, &block_size, sizeof block_size, 16);
        // Actual data begins at offset 32
    } else {
        pread64(fd_write_map, &st_size, sizeof st_size, 8);
        int blocksize;
        pread64(fd_write_map, &blocksize, sizeof block_size, 16);
        if(block_size_overridden && blocksize!=block_size) {
        fprintf(stderr, "Your block size %d and block size %d saved in \"%s\" is not the same\nI will use saved block size anyway\n",
            block_size, blocksize, write_mapfile);
        // return 1;
        }
        block_size = blocksize;
    }

    char read_signature[8];
    read_signature[0]=0;
    pread64(fd_read_map, &read_signature, sizeof read_signature, 0);
    read_signature[7]=0;
    if (strcmp(read_signature, "fusecow")) {
        // No signature:
        struct stat stbuf;
        fstat(fd, &stbuf);
        stbuf.st_size = st_size = (off64_t)lseek64(fd, (off64_t)0, SEEK_END);
        pwrite64(fd_read_map, "fusecow\n", 8, 0);
        pwrite64(fd_read_map, &st_size, sizeof st_size, 8);
        pwrite64(fd_read_map, &block_size, sizeof block_size, 16);
        // Actual data begins at offset 32
    } else {
        pread64(fd_read_map, &st_size, sizeof st_size, 8);
        int blocksize;
        pread64(fd_read_map, &blocksize, sizeof block_size, 16);
        if(block_size_overridden && blocksize!=block_size) {
        fprintf(stderr, "Your block size %d and block size %d saved in \"%s\" is not the same\nI will use saved block size anyway\n",
            block_size, blocksize, read_mapfile);
        // return 1;
        }
        block_size = blocksize;
    }

    mem_write_map_size = get_map_size();
    ftruncate(fd_write_map, mem_write_map_size);
    mem_write_map = mmap(NULL, mem_write_map_size , PROT_READ|PROT_WRITE, MAP_SHARED, fd_write_map, 0);
    if(mem_write_map==MAP_FAILED) {
        perror("mmap");
        fprintf(stderr, "Unable to open memory mapping. Using simplified mode.\n");
    }


    mem_read_map_size = get_map_size();
    ftruncate(fd_read_map, mem_read_map_size);
    if(!read_only){
        mem_read_map = mmap(NULL, mem_read_map_size , PROT_READ|PROT_WRITE, MAP_SHARED, fd_read_map, 0);
        if(mem_read_map==MAP_FAILED) {
            perror("mmap");
            fprintf(stderr, "Unable to open memory mapping. Using simplified mode.\n");
        }
        }
    }

    copyup_buffer = (char*) malloc(block_size);

    int argc2=0;
    argv2[argc2++]=argv[0];
    argv2[argc2++]=argv[2]; // mount point file
    for(i=our_arguments_count;i<argc;++i)argv2[argc2++]=argv[i];
    argv2[argc2++]="-o";
    argv2[argc2++]="nonempty,direct_io";
    argv2[argc2]=0;

    ret=fuse_main(argc2, argv2, &fusecow_oper, NULL);

    close(fd);
    close(fd_write);
    close(fd_write_map);
    close(fd_read);
    close(fd_read_map);
    munmap(mem_write_map, mem_write_map_size);
    munmap(mem_read_map, mem_read_map_size);
    free(copyup_buffer);

    return ret;
}
Beispiel #7
0
/* Fonction exécutée par un thread. */
void *watch_sockets(void *useless) {
    u_int i,size, i_fd ;
    int nb_readable = 0 ;
    struct pollfd *socket_set;
    int timeout = 1000;   /* timeout (1s) pour poll, afin de régulièrement remettre les sockets dans l'ensemble */
    useless=useless;
    /* Initialisation. */
    socket_set = (struct pollfd*) malloc(sizeof(struct pollfd)*N_SOCK) ;
    size = get_map_size(socket_map) ;
    for(i = 0 ; i < N_SOCK ; i++) {
        socket_set[i].events = POLLIN ;
        socket_set[i].revents = 0 ;
    }
    for(i = 0 ; i < size ; i++)
        socket_set[i].fd = (int) get_id(socket_map,i) ;
    for(i = size ; i < N_SOCK ; i++)
        socket_set[i].fd = -1 ; /* pas de socket pour l'instant */
    /* Boucle d'écoute */
    while(!quit_program) {
        if((nb_readable=poll(socket_set,size,timeout))<0) {
            perror("poll");
            exit(errno) ;
        }
        /* On réactive les sockets de handled_request */
        pthread_mutex_lock(&handled_request->lock) ;

        while(handled_request->first != handled_request->last) {
            i_fd = get_name(socket_map,(u_int)handled_request->queue[handled_request->first]) ;
            size = get_map_size(socket_map) ; /* peut être de nouvelles sockets */
            assert(socket_set[i_fd].fd < 0) ;
            socket_set[i_fd].fd = handled_request->queue[handled_request->first] ;
            handled_request->first ++ ;
        }
        pthread_mutex_unlock(&handled_request->lock) ;
        /* On place dans request toutes les sockets avec un message en attente. */
        if(nb_readable == 0) continue ;
        if(VERBOSE) {
            pthread_mutex_lock(&print_lock) ;
            green();
            printf("[Watching thread]\t");
            blue();
            printf("There is %d additional readable socket(s).\n",nb_readable) ;
            normal();
            pthread_mutex_unlock(&print_lock) ;
        }
        pthread_mutex_lock(&request->lock) ;
        for(i = 0 ; i < size ; i++) {
            if(socket_set[i].revents != 0) { /* un événement ! */
                assert(socket_set[i].fd > 0) ;
                request->queue[request->last] = socket_set[i].fd ;
                request->last = (request->last+1)%N_SOCK ;
                if(sem_post(&request->full) < 0) { /* signal sur la semaphore */
                    perror("sem_post");
                    exit(errno) ;
                }
                socket_set[i].fd = -1 ; /* desactive la surveillance sur cette socket */
            }
        }
        pthread_mutex_unlock(&request->lock) ;
    }
    pthread_mutex_lock(&print_lock) ;
    green();
    printf("[Watching thread]\t");
    normal();
    printf("will quit.\n") ;
    pthread_mutex_unlock(&print_lock) ;
    for(i = 0 ; i < N_THREAD ; i++) {
        if(sem_post(&request->full) < 0) { /* signal sur la semaphore */
            perror("sem_post");
            exit(errno) ;
        }
    }
    free(socket_set);
    pthread_exit(useless);
}