示例#1
0
void wm_container_buttonup(win *window, GR_EVENT_BUTTON *event)
{
	GR_RECT		r;
	GR_COORD	cxborder = 0, cyborder = 0;
	GR_WINDOW_INFO	info;

	Dprintf("wm_container_buttonup window %d\n", window->wid);

	GrGetWindowInfo(window->wid, &info);

	/* Check for close box press*/
	if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) ==
	    (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) {

		/* calc border sizes*/
		if (info.props & GR_WM_PROPS_BORDER) {
			cxborder = 1;
			cyborder = 1;
		}
		if (info.props & GR_WM_PROPS_APPFRAME) {
			cxborder = CXBORDER;
			cyborder = CYBORDER;
		}

		/* Get close box rect*/
		r.x = info.width - CXCLOSEBOX - cxborder - 2;
		r.y = cyborder + 2;
		r.width = CXCLOSEBOX;
		r.height = CYCLOSEBOX;

		/* Check mouseup in close box*/
		if (PtInRect(&r, event->x, event->y)) {
			if(window->close == GR_TRUE) {
				/*
				 * This sends a CLOSE_REQ event to the window.
				 * NXLIB clients catch this and convert it
				 * to an X11 ClientMessage with a WM_DELETE_WINDOW
				 * atom, causing the window to close.
				 */
				GrCloseWindow(window->clientid);
        		window->close = GR_FALSE;
        		return;
      		}
		}
	}
	window->close = GR_FALSE;

	if(window->active) {
#if OUTLINE_MOVE
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();

	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, pos->xorig, pos->yorig, pos->width, pos->height);
	  GrMoveWindow(window->wid, pos->xorig, pos->yorig);
#endif
	  free(window->data);
	  window->active = GR_FALSE;
	  window->data = 0;
	}
	
	if(window->sizing) {
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();
	  GR_WINDOW_INFO info;

	  GrGetWindowInfo(window->wid, &info);
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height);
	  GrResizeWindow(window->wid, event->rootx - info.x, event->rooty - info.y);
	  GrResizeWindow(window->clientid, event->rootx - info.x - pos->xoff, 
			 event->rooty - info.y - pos->yoff);
	  GrDestroyGC(gc);

	  free(window->data);
	  window->sizing = GR_FALSE;
	  window->data = 0;
	}
}
int main(int argc, char **argv)
{
	char *p;
	int c;
	int len = HPS;
	int inject = 0;
	int collapse = 0;
	int mremap_flag = 0;
	int pfn_get = 0;
	int split = 0;
	int verbose = 0;
	char buf[256];
	uint64_t pfn_buf[10];

	while ((c = getopt(argc, argv, "m:w:crpsiv")) != -1) {
		switch (c) {
		case 'm':
			len = strtol(optarg, NULL, 10) * HPS;
			break;
		case 'c':
			collapse = 1;
			break;
		case 'r':
			mremap_flag = 1;
			break;
		case 'p':
			pfn_get = 1;
			break;
		case 's':
			split = 1;
			break;
		case 'i':
			inject = 1;
			break;
		case 'v':
			verbose = 1;
			break;
		default:
			usage(argv[0]);
		}
	}

	signal(SIGUSR1, sighandler);

	p = mmap_check((void *)0x7f0000000000, len, PROTECTION,
		       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	Dprintf(verbose, "p = %p\n", p);
	madvise(p, len, MADV_HUGEPAGE);

	/* directly allocate thp in page fault. */
	write_bytes(p, len);
	pause();

	if (inject)
		madvise(p, 1, MADV_SOFT_OFFLINE);

	if (split) {
		mlock(p, 4096);
		munlock(p, 4096);
	}

	if (mremap_flag) {
		Dprintf(verbose, "mremap old p is %p!\n", p);
		p = mremap(p, len, len + HPS, 0, MREMAP_FIXED);
		/* p = mremap(p, len, len + HPS, 0, NULL); */
		if (p == (void *)-1)
			err("mremap");
		Dprintf(verbose, "mremap new p is %p!\n", p);
	}

	/* splitted thp will be collapsed again in the next khugepaged scan */
	if (split && collapse) {
		/* split thp */
		write_bytes(p, len);
	}
	pause();

	munmap(p, len);
	return 0;
}
示例#3
0
static void fire_update()
{
	int i = 0;
	int rowhit, colhit;
	while(i < me_firing) {
		myfire[i].posy += myfire[i].dir;
		/* test if hit something */
		if(get_rowcol(myfire[i].posx, myfire[i].posy,
					&rowhit, &colhit)) {
			if(alien_status[rowhit + colhit * aliens_rows] > 0) {
				/* when hit, fire out, destroy it
				 * (for now not animation) */
				myfire_delete(i);
				GrSetGCForeground(invaders_gc, GR_RGB(255,255,255));
				draw_alien(colhit,rowhit,itest);
				Dprintf("hit %d,%d,%d\n", colhit,rowhit,itest);
				Dprintf(" %d,%d\n",alien_maxx-alien_minx,
						cell_maxx - cell_minx);
				GrSetGCForeground(invaders_gc, GR_RGB(0,0,0));	
				alien_status[rowhit + colhit * aliens_rows] = 0;
				score += colhit * 2;
				update_score();
				aliens_left -= 1;
				if(aliens_left <= 0) {
					level++;
					invaders_create_board(level);
					draw_first();
					return;
				}
				continue;
			}
		}
		/* test if out board */
		if(myfire[i].posy < board_top) {
			myfire_delete(i);
			i--;
		}
		i++;
	}
	
	i = 0;
	while(i < alien_firing) {
		alienfire[i].posy += alienfire[i].dir;
		Dprintf("alienfire pos %d\n", alienfire[i].posy);
		/* test if hit me */
		if(alienfire[i].posy < (me_posy + ME_HEIGHT) &&
			alienfire[i].posy >= me_posy &&
			alienfire[i].posx >= me_posx &&
			alienfire[i].posx <= me_posx + ME_WIDTH) {
			/* End of game */
			game_status = GAME_STATUS_END;
			return;
		}
		/* test if out board */
		if(alienfire[i].posy >= board_bottom) {
			alienfire_delete(i);
			i--;
		}
		i++;
	}
}
示例#4
0
FTSENT *
fts_read (register FTS *sp)
{
	register FTSENT *p, *tmp;
	register unsigned short int instr;
	register char *t;

	/* If finished or unrecoverable error, return NULL. */
	if (sp->fts_cur == NULL || ISSET(FTS_STOP))
		return (NULL);

	/* Set current node pointer. */
	p = sp->fts_cur;

	/* Save and zero out user instructions. */
	instr = p->fts_instr;
	p->fts_instr = FTS_NOINSTR;

	/* Any type of file may be re-visited; re-stat and re-turn. */
	if (instr == FTS_AGAIN) {
		p->fts_info = fts_stat(sp, p, false);
		return (p);
	}
	Dprintf (("fts_read: p=%s\n",
		  p->fts_info == FTS_INIT ? "" : p->fts_path));

	/*
	 * Following a symlink -- SLNONE test allows application to see
	 * SLNONE and recover.  If indirecting through a symlink, have
	 * keep a pointer to current location.  If unable to get that
	 * pointer, follow fails.
	 */
	if (instr == FTS_FOLLOW &&
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
		p->fts_info = fts_stat(sp, p, true);
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
			if ((p->fts_symfd = diropen (sp, ".")) < 0) {
				p->fts_errno = errno;
				p->fts_info = FTS_ERR;
			} else
				p->fts_flags |= FTS_SYMFOLLOW;
		}
		goto check_for_dir;
	}

	/* Directory in pre-order. */
	if (p->fts_info == FTS_D) {
		/* If skipped or crossed mount point, do post-order visit. */
		if (instr == FTS_SKIP ||
		    (ISSET(FTS_XDEV) && p->fts_statp->st_dev != sp->fts_dev)) {
			if (p->fts_flags & FTS_SYMFOLLOW)
				(void)close(p->fts_symfd);
			if (sp->fts_child) {
				fts_lfree(sp->fts_child);
				sp->fts_child = NULL;
			}
			p->fts_info = FTS_DP;
			LEAVE_DIR (sp, p, "1");
			return (p);
		}

		/* Rebuild if only read the names and now traversing. */
		if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) {
			CLR(FTS_NAMEONLY);
			fts_lfree(sp->fts_child);
			sp->fts_child = NULL;
		}

		/*
		 * Cd to the subdirectory.
		 *
		 * If have already read and now fail to chdir, whack the list
		 * to make the names come out right, and set the parent errno
		 * so the application will eventually get an error condition.
		 * Set the FTS_DONTCHDIR flag so that when we logically change
		 * directories back to the parent we don't do a chdir.
		 *
		 * If haven't read do so.  If the read fails, fts_build sets
		 * FTS_STOP or the fts_info field of the node.
		 */
		if (sp->fts_child != NULL) {
			if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
				p->fts_errno = errno;
				p->fts_flags |= FTS_DONTCHDIR;
				for (p = sp->fts_child; p != NULL;
				     p = p->fts_link)
					p->fts_accpath =
					    p->fts_parent->fts_accpath;
			}
		} else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
			if (ISSET(FTS_STOP))
				return (NULL);
			/* If fts_build's call to fts_safe_changedir failed
			   because it was not able to fchdir into a
			   subdirectory, tell the caller.  */
			if (p->fts_errno && p->fts_info != FTS_DNR)
				p->fts_info = FTS_ERR;
			LEAVE_DIR (sp, p, "2");
			return (p);
		}
		p = sp->fts_child;
		sp->fts_child = NULL;
		goto name;
	}

	/* Move to the next node on this level. */
next:	tmp = p;
	if ((p = p->fts_link) != NULL) {
		sp->fts_cur = p;
		free(tmp);

		/*
		 * If reached the top, return to the original directory (or
		 * the root of the tree), and load the file names for the next
		 * root.
		 */
		if (p->fts_level == FTS_ROOTLEVEL) {
			if (RESTORE_INITIAL_CWD(sp)) {
				SET(FTS_STOP);
				return (NULL);
			}
			fts_load(sp, p);
			goto check_for_dir;
		}

		/*
		 * User may have called fts_set on the node.  If skipped,
		 * ignore.  If followed, get a file descriptor so we can
		 * get back if necessary.
		 */
		if (p->fts_instr == FTS_SKIP)
			goto next;
		if (p->fts_instr == FTS_FOLLOW) {
			p->fts_info = fts_stat(sp, p, true);
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
				if ((p->fts_symfd = diropen (sp, ".")) < 0) {
					p->fts_errno = errno;
					p->fts_info = FTS_ERR;
				} else
					p->fts_flags |= FTS_SYMFOLLOW;
			}
			p->fts_instr = FTS_NOINSTR;
		}

name:		t = sp->fts_path + NAPPEND(p->fts_parent);
		*t++ = '/';
		memmove(t, p->fts_name, p->fts_namelen + 1);
check_for_dir:
		sp->fts_cur = p;
		if (p->fts_info == FTS_NSOK)
		  {
		    if (p->fts_statp->st_size == FTS_STAT_REQUIRED)
		      p->fts_info = fts_stat(sp, p, false);
		    else
		      fts_assert (p->fts_statp->st_size == FTS_NO_STAT_REQUIRED);
		  }

		if (p->fts_info == FTS_D)
		  {
		    /* Now that P->fts_statp is guaranteed to be valid,
		       if this is a command-line directory, record its
		       device number, to be used for FTS_XDEV.  */
		    if (p->fts_level == FTS_ROOTLEVEL)
		      sp->fts_dev = p->fts_statp->st_dev;
		    Dprintf (("  entering: %s\n", p->fts_path));
		    if (! enter_dir (sp, p))
		      {
			__set_errno (ENOMEM);
			return NULL;
		      }
		  }
		return p;
	}

	/* Move up to the parent node. */
	p = tmp->fts_parent;
	sp->fts_cur = p;
	free(tmp);

	if (p->fts_level == FTS_ROOTPARENTLEVEL) {
		/*
		 * Done; free everything up and set errno to 0 so the user
		 * can distinguish between error and EOF.
		 */
		free(p);
		__set_errno (0);
		return (sp->fts_cur = NULL);
	}

	fts_assert (p->fts_info != FTS_NSOK);

	/* NUL terminate the file name.  */
	sp->fts_path[p->fts_pathlen] = '\0';

	/*
	 * Return to the parent directory.  If at a root node, restore
	 * the initial working directory.  If we came through a symlink,
	 * go back through the file descriptor.  Otherwise, move up
	 * one level, via "..".
	 */
	if (p->fts_level == FTS_ROOTLEVEL) {
		if (RESTORE_INITIAL_CWD(sp)) {
			p->fts_errno = errno;
			SET(FTS_STOP);
		}
	} else if (p->fts_flags & FTS_SYMFOLLOW) {
		if (FCHDIR(sp, p->fts_symfd)) {
			int saved_errno = errno;
			(void)close(p->fts_symfd);
			__set_errno (saved_errno);
			p->fts_errno = errno;
			SET(FTS_STOP);
		}
		(void)close(p->fts_symfd);
	} else if (!(p->fts_flags & FTS_DONTCHDIR) &&
		   fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
		p->fts_errno = errno;
		SET(FTS_STOP);
	}
	p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
	if (p->fts_errno == 0)
		LEAVE_DIR (sp, p, "3");
	return ISSET(FTS_STOP) ? NULL : p;
}
int SSerialInterface::serial_main( )
{
	Dprintf("Linux Loadcell serial app\n");
	if (!_cl_port) { 
		printf("serial_main() - ERROR: Port argument required\n");
	}

	// Specify with the "-p" option.  Should refer to "/dev/ttyUSB0" or other.
	if (_cl_port==NULL)
		return -1;

	// WRITE 1 or 2 BYTES (stored in _cl_single_byte & _cl_another_byte) :
	if (_cl_single_byte >= 0) {
		unsigned char data[2];
		data[0] = (unsigned char)_cl_single_byte;
		if (_cl_another_byte < 0) {
			write(_fd, &data, 1);
		} else {
			data[1] = _cl_another_byte;
			write(_fd, &data, 2);
		}
		return 0;
	}

	// while either User option: "-r" and "-t"
	printf("Entering serial_main while () loop\n");
	while (!(_cl_no_rx && _cl_no_tx)) 
	{
		int retval = poll( &serial_poll, 1, 1000 );
		if (retval == -1) {
			perror("poll()");
		} else if (retval) {
			// Received Data : 
			if (serial_poll.revents & POLLIN) { /* Recieve */
				printf("Poll received\n");
				// 
				if (_cl_rx_delay) { 
					// only read if it has been rx-delay ms
					// since the last read
					struct timespec current;
					clock_gettime(CLOCK_MONOTONIC, &current);
					if (diff_ms(&current, &last_read) > _cl_rx_delay) {
						process_read_data();
						last_read = current;
					}
				} else {
					process_read_data();
				}
			}

			// Transmit Buffer Empty : 
			if (serial_poll.revents & POLLOUT) {

				if (_cl_tx_delay) {
					// only write if it has been tx-delay ms
					// since the last write
					struct timespec current;
					clock_gettime(CLOCK_MONOTONIC, &current);
					if (diff_ms(&current, &last_write) > _cl_tx_delay) {
						process_write_data();
						last_write = current;
					}
				} else {
					//printf(".");
					process_write_data();
				}
			}
		} else if (!(_cl_no_tx && _write_count != 0 && _write_count == _read_count)) {
			// No data. We report this unless we are no longer
			// transmitting and the receive count equals the
			// transmit count, suggesting a loopback test that has
			// finished.
			printf("No data within one second. %s\n", _cl_port);
		}

		if (_cl_stats || _cl_tx_time || _cl_rx_time) {
			struct timespec current;
			clock_gettime(CLOCK_MONOTONIC, &current);

			if (_cl_stats) {
				if (current.tv_sec - last_stat.tv_sec > 5) {
					dump_serial_port_stats();
					last_stat = current;
				}
			}
			if (_cl_tx_time) {
				if (current.tv_sec - start_time.tv_sec >= _cl_tx_time) {
					_cl_tx_time = 0;
					_cl_no_tx = 1;
					serial_poll.events &= ~POLLOUT;
					printf("Stopped transmitting.\n");
				}
			}
			if (_cl_rx_time) {
				if (current.tv_sec - start_time.tv_sec >= _cl_rx_time) {
					_cl_rx_time = 0;
					_cl_no_rx = 1;
					serial_poll.events &= ~POLLIN;
					printf("Stopped receiving.\n");
				}
			}
		}
	}

	tcdrain(_fd);
	dump_serial_port_stats();
	tcflush(_fd, TCIOFLUSH);
	free(_cl_port);

	printf("serial_main()  Thread Terminated.\n");
	int result = abs(_write_count - _read_count) + _error_count;
	return (result > 255) ? 255 : result;
}
示例#6
0
static void serve_forget(fuse_req_t req, fuse_ino_t ino, unsigned long nlookup)
{
	Dprintf("%s(ino = %lu, nlookup = %lu)\n", __FUNCTION__, ino, nlookup);
	(void) hash_map_erase(reqmount(req)->parents, (void *) ino);
	fuse_reply_none(req);
}
示例#7
0
static void serve_fsyncdir(fuse_req_t req, fuse_ino_t fuse_ino, int datasync,
                           struct fuse_file_info * fi)
{
	Dprintf("%s(ino = %lu, datasync = %d)\n", __FUNCTION__, fuse_ino, datasync);
	ssync(req, fuse_ino, datasync, fi);	
}
示例#8
0
static int fill_stat(mount_t * mount, inode_t cfs_ino, fuse_ino_t fuse_ino, struct stat * stbuf)
{
	Dprintf("%s(fuse_ino = %lu, cfs_ino = %u)\n", __FUNCTION__, fuse_ino, cfs_ino);
	int r;
	CFS_t * cfs = mount->cfs;
	uint32_t type;
	bool nlinks_supported = feature_supported(cfs, FSTITCH_FEATURE_NLINKS);
	bool uid_supported = feature_supported(cfs, FSTITCH_FEATURE_UID);
	bool gid_supported = feature_supported(cfs, FSTITCH_FEATURE_GID);
	bool perms_supported = feature_supported(cfs, FSTITCH_FEATURE_UNIX_PERM);
	bool mtime_supported = feature_supported(cfs, FSTITCH_FEATURE_MTIME);
	bool atime_supported = feature_supported(cfs, FSTITCH_FEATURE_ATIME);
	uint32_t nlinks = 0;
	uint16_t perms;
	time_t mtime = time(NULL);
	time_t atime = mtime;

	r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_FILETYPE, sizeof(type), &type);
	if (r < 0)
	{
		Dprintf("%d:cfs->get_metadata() = %d\n", __LINE__, r);
		return r;
	}

	if (nlinks_supported)
	{
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_NLINKS, sizeof(nlinks), &nlinks);
		if (r < 0)
			fprintf(stderr, "%s: get_metadata for nlinks failed, manually counting links for directories and assuming files have 1 link\n", __FUNCTION__);
		else
			assert(r == sizeof(nlinks));
	}

	if (type == TYPE_DIR)
	{
		if (!nlinks)
		{
			dirent_t dirent;
			uint32_t basep = 0;
			fdesc_t * fdesc;

			r = CALL(cfs, open, cfs_ino, 0, &fdesc);
			assert(r >= 0);
			fdesc->common->parent = (inode_t) hash_map_find_val(mount->parents, (void *) cfs_ino);
			assert(fdesc->common->parent != INODE_NONE);

			while ((r = CALL(cfs, get_dirent, fdesc, &dirent, sizeof(dirent), &basep)) >= 0)
				if (dirent.d_type == TYPE_DIR)
					nlinks++;

			r = CALL(cfs, close, fdesc);
			assert(r >= 0);
		}

		stbuf->st_mode = S_IFDIR;
		perms = 0777; // default, in case permissions are not supported
	}
	else if (type == TYPE_FILE || type == TYPE_SYMLINK || type == TYPE_DEVICE)
	{
		int32_t filesize;

		if (!nlinks)
			nlinks = 1;

		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_SIZE, sizeof(filesize), &filesize);
		if (r < 0)
		{
			Dprintf("%d:cfs->get_metadata() = %d\n", __LINE__, r);
			goto err;
		}

		if (type == TYPE_SYMLINK)
			stbuf->st_mode = S_IFLNK;
		else
			stbuf->st_mode = S_IFREG;
		perms = 0666; // default, in case permissions are not supported
		stbuf->st_size = (off_t) filesize;
	}
	else if (type == TYPE_INVAL)
	{
		fprintf(stderr, "%s:%s(fuse_ino = %lu, cfs_ino = %u): file type is invalid\n", __FILE__, __FUNCTION__, fuse_ino, cfs_ino);
		r = -1;
		goto err;
	}
	else
	{
		fprintf(stderr, "%s:%s(fuse_ino = %lu, cfs_ino = %u): unsupported file type %u\n", __FILE__, __FUNCTION__, fuse_ino, cfs_ino, type);
		r = -1;
		goto err;
	}

	if (uid_supported)
	{
		uint32_t cfs_uid;
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_UID, sizeof(cfs_uid), &cfs_uid);
		if (r >= 0)
		{
			assert(r == sizeof(cfs_uid));
			stbuf->st_uid = cfs_uid;
			if (stbuf->st_uid != cfs_uid)
				fprintf(stderr, "%s: UID not large enough to hold CFS UID %u\n", __FUNCTION__, cfs_uid);
		}
		else
			fprintf(stderr, "%s: file system at \"%s\" claimed uid but get_metadata returned %i\n", __FUNCTION__, modman_name_cfs(cfs), r);
	}
	else
		stbuf->st_uid = 0;

	if (gid_supported)
	{
		uint32_t cfs_gid;
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_GID, sizeof(cfs_gid), &cfs_gid);
		if (r >= 0)
		{
			assert(r == sizeof(cfs_gid));
			stbuf->st_gid = cfs_gid;
			if (stbuf->st_gid != cfs_gid)
				fprintf(stderr, "%s: GID not large enough to hold CFS GID %u\n", __FUNCTION__, cfs_gid);
		}
		else
			fprintf(stderr, "%s: file system at \"%s\" claimed gid but get_metadata returned %i\n", __FUNCTION__, modman_name_cfs(cfs), r);
	}
	else
		stbuf->st_gid = 0;

	if (perms_supported)
	{
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_UNIX_PERM, sizeof(perms), &perms);
		if (r < 0)
			fprintf(stderr, "%s: file system at \"%s\" claimed unix permissions but get_metadata returned %i\n", __FUNCTION__, modman_name_cfs(cfs), r);
		else
			assert(r == sizeof(perms));
	}

	if (mtime_supported)
	{
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_MTIME, sizeof(mtime), &mtime);
		if (r < 0)
			fprintf(stderr, "%s: file system at \"%s\" claimed mtime but get_metadata returned %i\n", __FUNCTION__, modman_name_cfs(cfs), r);
		else
			assert(r == sizeof(time_t));
	}

	if (atime_supported)
	{
		r = CALL(cfs, get_metadata, cfs_ino, FSTITCH_FEATURE_ATIME, sizeof(atime), &atime);
		if (r < 0)
			fprintf(stderr, "%s: file system at \"%s\" claimed atime but get_metadata returned %i\n", __FUNCTION__, modman_name_cfs(cfs), r);
		else
			assert(r == sizeof(time_t));
	}

	stbuf->st_mode |= perms;
	stbuf->st_mtime = mtime;
	stbuf->st_atime = atime;
	stbuf->st_ino = fuse_ino;
	stbuf->st_nlink = nlinks;

	return 0;

  err:
	return r;
}
示例#9
0
static void serve_setattr(fuse_req_t req, fuse_ino_t fuse_ino, struct stat * attr,
                          int to_set, struct fuse_file_info * fi)
{
	inode_t cfs_ino = fusecfsino(req, fuse_ino);
	int supported = FUSE_SET_ATTR_SIZE;
	bool uid_supported   = feature_supported(reqcfs(req), FSTITCH_FEATURE_UID);
	bool gid_supported   = feature_supported(reqcfs(req), FSTITCH_FEATURE_GID);
	bool perms_supported = feature_supported(reqcfs(req), FSTITCH_FEATURE_UNIX_PERM);
	bool mtime_supported = feature_supported(reqcfs(req), FSTITCH_FEATURE_MTIME);
	bool atime_supported = feature_supported(reqcfs(req), FSTITCH_FEATURE_MTIME);
	struct stat stbuf;
	int r;
	Dprintf("%s(ino = %lu, to_set = %d)\n", __FUNCTION__, fuse_ino, to_set);

	if (uid_supported)
		supported |= FUSE_SET_ATTR_UID;
	if (gid_supported)
		supported |= FUSE_SET_ATTR_GID;
	if (perms_supported)
		supported |= FUSE_SET_ATTR_MODE;
	if (mtime_supported)
		supported |= FUSE_SET_ATTR_MTIME;
	if (atime_supported)
		supported |= FUSE_SET_ATTR_ATIME;

	if (to_set != (to_set & supported))
	{
		r = fuse_reply_err(req, ENOSYS);
		fuse_reply_assert(!r);
		return;
	}

	if (to_set & FUSE_SET_ATTR_SIZE)
	{
		fdesc_t * fdesc;
		uint32_t size;

		size = (uint32_t) attr->st_size;
		assert(size == attr->st_size);
		Dprintf("\tsize = %u\n", size);

		if (fi)
			fdesc = fi_get_fdesc(fi);
		else
		{
			r = CALL(reqcfs(req), open, cfs_ino, 0, &fdesc);
			if (r < 0)
			{
				r = fuse_reply_err(req, -r);
				fuse_reply_assert(!r);
				return;
			}
			fdesc->common->parent = (inode_t) hash_map_find_val(reqmount(req)->parents, (void *) cfs_ino);
			assert(fdesc->common->parent != INODE_NONE);
		}

		r = CALL(reqcfs(req), truncate, fdesc, size);

		if (!fi)
		{
			r = CALL(reqcfs(req), close, fdesc);
			if (r < 0)
			{
				r = fuse_reply_err(req, -r);
				fuse_reply_assert(!r);
				return;
			}
		}

		if (r < 0)
		{
			r = fuse_reply_err(req, -r);
			fuse_reply_assert(!r);
			return;
		}
	}

	fsmetadata_t fsm[5];
	uint32_t nfsm = 0;
	
	if (to_set & FUSE_SET_ATTR_UID)
	{
		fsm[nfsm].fsm_feature = FSTITCH_FEATURE_UID;
		fsm[nfsm].fsm_value.u = attr->st_uid;
		nfsm++;
	}

	if (to_set & FUSE_SET_ATTR_GID)
	{
		fsm[nfsm].fsm_feature = FSTITCH_FEATURE_GID;
		fsm[nfsm].fsm_value.u = attr->st_gid;
		nfsm++;
	}

	if (to_set & FUSE_SET_ATTR_MODE)
	{
		fsm[nfsm].fsm_feature = FSTITCH_FEATURE_UNIX_PERM;
		fsm[nfsm].fsm_value.u = attr->st_mode;
		nfsm++;
	}

	if (to_set & FUSE_SET_ATTR_MTIME)
	{
		fsm[nfsm].fsm_feature = FSTITCH_FEATURE_MTIME;
		fsm[nfsm].fsm_value.u = attr->st_mtime;
		nfsm++;
	}
	
	if (to_set & FUSE_SET_ATTR_ATIME)
	{
		// XXX Why did we use attr->st_mtime here?
		fsm[nfsm].fsm_feature = FSTITCH_FEATURE_ATIME;
		fsm[nfsm].fsm_value.u = attr->st_atime;
		nfsm++;
	}

	if (nfsm > 0) {
		r = CALL(reqcfs(req), set_metadata2, cfs_ino, fsm, nfsm);
		if (r < 0)
		{
			r = fuse_reply_err(req, -r);
			fuse_reply_assert(!r);
			return;
		}
	}

	memset(&stbuf, 0, sizeof(stbuf));
	r = fill_stat(reqmount(req), cfs_ino, fuse_ino, &stbuf);
	if (r < 0)
		r = fuse_reply_err(req, -r);
	else
		r = fuse_reply_attr(req, &stbuf, STDTIMEOUT);
	fuse_reply_assert(!r);
}
示例#10
0
// Return the amount of time to wait between sched_run_callbacks() calls
static struct timeval fuse_serve_timeout(void)
{
	struct timeval tv = { .tv_sec = 0, .tv_usec = 1000000/HZ };
	return tv;
}

struct callback_list {
	unlock_callback_t callback;
	void * data;
	int count;
	struct callback_list * next;
};
static struct callback_list * callbacks;

int fstitchd_unlock_callback(unlock_callback_t callback, void * data)
{
	if(callbacks && callbacks->callback == callback && callbacks->data == data)
		callbacks->count++;
	else
	{
		struct callback_list * list = malloc(sizeof(*list));
		if(!list)
			return -ENOMEM;
		list->callback = callback;
		list->data = data;
		list->count = 1;
		list->next = callbacks;
		callbacks = list;
	}
	return 0;
}

// Adapted from FUSE's lib/fuse_loop.c to support sched callbacks and multiple mounts
int fuse_serve_loop(void)
{
	struct timeval tv;
	mount_t ** mp;
	int r;
	Dprintf("%s()\n", __FUNCTION__);

	if (!root_cfs)
	{
		fprintf(stderr, "%s(): no root cfs was specified; not running.\n", __FUNCTION__);
		return -1;
	}

	if ((r = fuse_serve_mount_load_mounts()) < 0)
	{
		fprintf(stderr, "%s(): fuse_serve_load_mounts: %d\n", __FUNCTION__, r);
		return r;
	}

	serving = 1;
	tv = fuse_serve_timeout();

	while ((mp = fuse_serve_mounts()) && mp && mp[0])
	{
		fd_set rfds;
		int max_fd = 0;
		struct timeval it_start, it_end;

		FD_ZERO(&rfds);

		if (shutdown_pipe[0] != -1)
		{
			FD_SET(shutdown_pipe[0], &rfds);
			if (shutdown_pipe[0] > max_fd)
				max_fd = shutdown_pipe[0];
		}

		FD_SET(remove_activity, &rfds);
		if (remove_activity > max_fd)
			max_fd = remove_activity;

		for (mp = fuse_serve_mounts(); mp && *mp; mp++)
		{
			if ((*mp)->mounted && !fuse_session_exited((*mp)->session))
			{
				//printf("[\"%s\"]", mount->fstitch_path); fflush(stdout); // debug
				int mount_fd = fuse_chan_fd((*mp)->channel);
				FD_SET(mount_fd, &rfds);
				if (mount_fd > max_fd)
					max_fd = mount_fd;
			}
		}

		r = select(max_fd+1, &rfds, NULL, NULL, &tv);

		if (r == 0)
		{
			//printf("."); fflush(stdout); // debugging output
			sched_run_callbacks();
			tv = fuse_serve_timeout();
		}
		else if (r < 0)
		{
			if (errno != EINTR)
				perror("select");
			//printf("!\n"); fflush(stdout); // debugging output
			tv = fuse_serve_timeout(); // tv may have become undefined
		}
		else
		{
			if (gettimeofday(&it_start, NULL) == -1)
			{
				perror("gettimeofday");
				break;
			}

			for (mp = fuse_serve_mounts(); mp && *mp; mp++)
			{
				if ((*mp)->mounted && FD_ISSET((*mp)->channel_fd, &rfds))
				{
					r = fuse_chan_receive((*mp)->channel, channel_buf, channel_buf_len);
					if(r <= 0)
						fprintf(stderr, "fuse_chan_receive() returned %d, ignoring!\n", r);
					//assert(r > 0); // this happens during shutdown on MacFUSE...

					Dprintf("fuse_serve: request for mount \"%s\"\n", (*mp)->fstitch_path);
					fuse_session_process((*mp)->session, channel_buf, r, (*mp)->channel);
					sched_run_cleanup();
				}
			}

			if (shutdown_pipe[0] != -1 && FD_ISSET(shutdown_pipe[0], &rfds))
			{
				// Start unmounting all filesystems
				// Looping will stop once all filesystems are unmounted
				ignore_shutdown_signals();
				if (fuse_serve_mount_start_shutdown() < 0)
				{
					fprintf(stderr, "fuse_serve_mount_start_shutdown() failed, exiting fuse_serve_loop()\n");
					return -1;
				}
			}

			if (FD_ISSET(remove_activity, &rfds))
			{
				if (fuse_serve_mount_step_remove() < 0)
				{
					fprintf(stderr, "fuse_serve_mount_step_remove() failed, exiting fuse_serve_loop()\n");
					return -1;
				}
			}


			if (gettimeofday(&it_end, NULL) == -1)
			{
				perror("gettimeofday");
				break;
			}
			tv = time_subtract(tv, time_elapsed(it_start, it_end));
		}

		while(callbacks)
		{
			struct callback_list * first = callbacks;
			callbacks = first->next;
			first->callback(first->data, first->count);
			free(first);
		}
	}

	serving = 0;

	return 0;
}
示例#11
0
void
NX_InitOSKeymap(_THIS)
{
    int i;

    Dprintf("enter NX_InitOSKeymap\n");

    // Map the nanox scancodes to SDL keysyms
    for (i = 0; i < SDL_arraysize(NX_NONASCII_keymap); ++i)
        NX_NONASCII_keymap[i] = SDLK_UNKNOWN;

    NX_NONASCII_keymap[MWKEY_LEFT & 0xFF] = SDLK_LEFT;
    NX_NONASCII_keymap[MWKEY_RIGHT & 0xFF] = SDLK_RIGHT;
    NX_NONASCII_keymap[MWKEY_UP & 0xFF] = SDLK_UP;
    NX_NONASCII_keymap[MWKEY_DOWN & 0xFF] = SDLK_DOWN;
    NX_NONASCII_keymap[MWKEY_INSERT & 0xFF] = SDLK_INSERT;
    NX_NONASCII_keymap[MWKEY_DELETE & 0xFF] = SDLK_DELETE;
    NX_NONASCII_keymap[MWKEY_HOME & 0xFF] = SDLK_HOME;
    NX_NONASCII_keymap[MWKEY_END & 0xFF] = SDLK_END;
    NX_NONASCII_keymap[MWKEY_PAGEUP & 0xFF] = SDLK_PAGEUP;
    NX_NONASCII_keymap[MWKEY_PAGEDOWN & 0xFF] = SDLK_PAGEDOWN;

    NX_NONASCII_keymap[MWKEY_KP0 & 0xFF] = SDLK_KP0;
    NX_NONASCII_keymap[MWKEY_KP1 & 0xFF] = SDLK_KP1;
    NX_NONASCII_keymap[MWKEY_KP2 & 0xFF] = SDLK_KP2;
    NX_NONASCII_keymap[MWKEY_KP3 & 0xFF] = SDLK_KP3;
    NX_NONASCII_keymap[MWKEY_KP4 & 0xFF] = SDLK_KP4;
    NX_NONASCII_keymap[MWKEY_KP5 & 0xFF] = SDLK_KP5;
    NX_NONASCII_keymap[MWKEY_KP6 & 0xFF] = SDLK_KP6;
    NX_NONASCII_keymap[MWKEY_KP7 & 0xFF] = SDLK_KP7;
    NX_NONASCII_keymap[MWKEY_KP8 & 0xFF] = SDLK_KP8;
    NX_NONASCII_keymap[MWKEY_KP9 & 0xFF] = SDLK_KP9;
    NX_NONASCII_keymap[MWKEY_KP_PERIOD & 0xFF] = SDLK_KP_PERIOD;
    NX_NONASCII_keymap[MWKEY_KP_DIVIDE & 0xFF] = SDLK_KP_DIVIDE;
    NX_NONASCII_keymap[MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY;
    NX_NONASCII_keymap[MWKEY_KP_MINUS & 0xFF] = SDLK_KP_MINUS;
    NX_NONASCII_keymap[MWKEY_KP_PLUS & 0xFF] = SDLK_KP_PLUS;
    NX_NONASCII_keymap[MWKEY_KP_ENTER & 0xFF] = SDLK_KP_ENTER;
    NX_NONASCII_keymap[MWKEY_KP_EQUALS & 0xFF] = SDLK_KP_EQUALS;

    NX_NONASCII_keymap[MWKEY_F1 & 0xFF] = SDLK_F1;
    NX_NONASCII_keymap[MWKEY_F2 & 0xFF] = SDLK_F2;
    NX_NONASCII_keymap[MWKEY_F3 & 0xFF] = SDLK_F3;
    NX_NONASCII_keymap[MWKEY_F4 & 0xFF] = SDLK_F4;
    NX_NONASCII_keymap[MWKEY_F5 & 0xFF] = SDLK_F5;
    NX_NONASCII_keymap[MWKEY_F6 & 0xFF] = SDLK_F6;
    NX_NONASCII_keymap[MWKEY_F7 & 0xFF] = SDLK_F7;
    NX_NONASCII_keymap[MWKEY_F8 & 0xFF] = SDLK_F8;
    NX_NONASCII_keymap[MWKEY_F9 & 0xFF] = SDLK_F9;
    NX_NONASCII_keymap[MWKEY_F10 & 0xFF] = SDLK_F10;
    NX_NONASCII_keymap[MWKEY_F11 & 0xFF] = SDLK_F11;
    NX_NONASCII_keymap[MWKEY_F12 & 0xFF] = SDLK_F12;

    NX_NONASCII_keymap[MWKEY_NUMLOCK & 0xFF] = SDLK_NUMLOCK;
    NX_NONASCII_keymap[MWKEY_CAPSLOCK & 0xFF] = SDLK_CAPSLOCK;
    NX_NONASCII_keymap[MWKEY_SCROLLOCK & 0xFF] = SDLK_SCROLLOCK;
    NX_NONASCII_keymap[MWKEY_LSHIFT & 0xFF] = SDLK_LSHIFT;
    NX_NONASCII_keymap[MWKEY_RSHIFT & 0xFF] = SDLK_RSHIFT;
    NX_NONASCII_keymap[MWKEY_LCTRL & 0xFF] = SDLK_LCTRL;
    NX_NONASCII_keymap[MWKEY_RCTRL & 0xFF] = SDLK_RCTRL;
    NX_NONASCII_keymap[MWKEY_LALT & 0xFF] = SDLK_LALT;
    NX_NONASCII_keymap[MWKEY_RALT & 0xFF] = SDLK_RALT;
    NX_NONASCII_keymap[MWKEY_LMETA & 0xFF] = SDLK_LMETA;
    NX_NONASCII_keymap[MWKEY_RMETA & 0xFF] = SDLK_RMETA;
    NX_NONASCII_keymap[MWKEY_ALTGR & 0xFF] = SDLK_MODE;

    NX_NONASCII_keymap[MWKEY_PRINT & 0xFF] = SDLK_PRINT;
    NX_NONASCII_keymap[MWKEY_SYSREQ & 0xFF] = SDLK_SYSREQ;
    NX_NONASCII_keymap[MWKEY_PAUSE & 0xFF] = SDLK_PAUSE;
    NX_NONASCII_keymap[MWKEY_BREAK & 0xFF] = SDLK_BREAK;
    NX_NONASCII_keymap[MWKEY_MENU & 0xFF] = SDLK_MENU;

    Dprintf("leave NX_InitOSKeymap\n");
}
示例#12
0
void
NX_PumpEvents(_THIS)
{
    GR_EVENT event;
    static GR_BUTTON last_button_down = 0;

    GrCheckNextEvent(&event);
    while (event.type != GR_EVENT_TYPE_NONE) {

        // dispatch event
        switch (event.type) {
        case GR_EVENT_TYPE_MOUSE_ENTER:
            {
                Dprintf("mouse enter\n");
                SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
                break;
            }

        case GR_EVENT_TYPE_MOUSE_EXIT:
            {
                Dprintf("mouse exit\n");
                SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
                break;
            }

        case GR_EVENT_TYPE_FOCUS_IN:
            {
                Dprintf("focus in\n");
                SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
                break;
            }

        case GR_EVENT_TYPE_FOCUS_OUT:
            {
                Dprintf("focus out\n");
                SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
                break;
            }

        case GR_EVENT_TYPE_MOUSE_MOTION:
            {
                Dprintf("mouse motion\n");

                if (SDL_VideoSurface) {
                    if (currently_fullscreen) {
                        if (check_boundary
                            (this, event.button.x, event.button.y)) {
                            SDL_PrivateMouseMotion(0, 0,
                                                   event.button.x -
                                                   OffsetX,
                                                   event.button.y - OffsetY);
                        }
                    } else {
                        SDL_PrivateMouseMotion(0, 0, event.button.x,
                                               event.button.y);
                    }
                }
                break;
            }

        case GR_EVENT_TYPE_BUTTON_DOWN:
            {
                int button = event.button.buttons;

                Dprintf("button down\n");

                switch (button) {
                case MWBUTTON_L:
                    button = 1;
                    break;
                case MWBUTTON_M:
                    button = 2;
                    break;
                case MWBUTTON_R:
                    button = 3;
                    break;
                default:
                    button = 0;
                }
                last_button_down = button;

                if (currently_fullscreen) {
                    if (check_boundary(this, event.button.x, event.button.y)) {
                        SDL_PrivateMouseButton(SDL_PRESSED, button,
                                               event.button.x -
                                               OffsetX,
                                               event.button.y - OffsetY);
                    }
                } else {
                    SDL_PrivateMouseButton(SDL_PRESSED, button,
                                           event.button.x, event.button.y);
                }
                break;
            }

            // do not konw which button is released
        case GR_EVENT_TYPE_BUTTON_UP:
            {
                Dprintf("button up\n");

                if (currently_fullscreen) {
                    if (check_boundary(this, event.button.x, event.button.y)) {
                        SDL_PrivateMouseButton(SDL_RELEASED,
                                               last_button_down,
                                               event.button.x -
                                               OffsetX,
                                               event.button.y - OffsetY);
                    }
                } else {
                    SDL_PrivateMouseButton(SDL_RELEASED,
                                           last_button_down,
                                           event.button.x, event.button.y);
                }
                last_button_down = 0;
                break;
            }

        case GR_EVENT_TYPE_KEY_DOWN:
            {
                SDL_keysym keysym;

                Dprintf("key down\n");
                SDL_PrivateKeyboard(SDL_PRESSED,
                                    NX_TranslateKey(&event.keystroke,
                                                    &keysym));
                break;
            }

        case GR_EVENT_TYPE_KEY_UP:
            {
                SDL_keysym keysym;

                Dprintf("key up\n");
                SDL_PrivateKeyboard(SDL_RELEASED,
                                    NX_TranslateKey(&event.keystroke,
                                                    &keysym));
                break;
            }

        case GR_EVENT_TYPE_CLOSE_REQ:
            {
                Dprintf("close require\n");
                SDL_PrivateQuit();
                break;
            }

        case GR_EVENT_TYPE_EXPOSURE:
            {
                Dprintf("event_type_exposure\n");
                if (SDL_VideoSurface) {
                    NX_RefreshDisplay(this);    //, & event.exposure) ;
                }
                break;
            }

        case GR_EVENT_TYPE_UPDATE:
            {
                switch (event.update.utype) {
                case GR_UPDATE_MAP:
                    {
                        Dprintf("GR_UPDATE_MAP\n");
                        // If we're not active, make ourselves active
                        if (!(SDL_GetAppState() & SDL_APPACTIVE)) {
                            // Send an internal activate event
                            SDL_PrivateAppActive(1, SDL_APPACTIVE);
                        }
                        if (SDL_VideoSurface) {
                            NX_RefreshDisplay(this);
                        }
                        break;
                    }

                case GR_UPDATE_UNMAP:
                case GR_UPDATE_UNMAPTEMP:
                    {
                        Dprintf("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n");
                        // If we're active, make ourselves inactive
                        if (SDL_GetAppState() & SDL_APPACTIVE) {
                            // Send an internal deactivate event
                            SDL_PrivateAppActive(0,
                                                 SDL_APPACTIVE |
                                                 SDL_APPINPUTFOCUS);
                        }
                        break;
                    }

                case GR_UPDATE_SIZE:
                    {
                        Dprintf("GR_UPDATE_SIZE\n");
                        SDL_PrivateResize(event.update.width,
                                          event.update.height);
                        break;
                    }

                case GR_UPDATE_MOVE:
                case GR_UPDATE_REPARENT:
                    {
                        Dprintf("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n");
#ifdef ENABLE_NANOX_DIRECT_FB
                        if (Clientfb) {
                            /* Get current window position and fb pointer */
                            if (currently_fullscreen)
                                GrGetWindowFBInfo(FSwindow, &fbinfo);
                            else
                                GrGetWindowFBInfo(SDL_Window, &fbinfo);
                        }
#endif
                        break;
                    }

                default:
                    Dprintf("unknown GR_EVENT_TYPE_UPDATE\n");
                    break;
                }
                break;
            }

        default:
            {
                Dprintf("pump event default\n");
            }
        }

        GrCheckNextEvent(&event);
    }
}
示例#13
0
文件: SDL_nxmouse.c 项目: bohwaz/ozex
int NX_ShowWMCursor (_THIS, WMcursor * cursor)
{
    Dprintf ("NX_ShowWMCursor\n") ;
    return 1 ;
}
示例#14
0
文件: SDL_nxmouse.c 项目: bohwaz/ozex
void NX_FreeWMCursor (_THIS, WMcursor * cursor)
{
    Dprintf ("NX_FreeWMCursor\n") ;
    free (cursor) ;
    return ;
}