Exemple #1
0
int sys_openpty(int *master, int *slave, char *slavename, const struct termios *term,
		const struct winsize *win)
{
	int num = atomic_fetch_add(&__pty_next_num, 1);
	char mname[32];
	char sname[32];
	snprintf(mname, 32, "/dev/ptym%d", num);
	snprintf(sname, 32, "/dev/ptys%d", num);

	sys_mknod(mname, S_IFCHR | 0666, GETDEV(pty_major, num));
	sys_mknod(sname, S_IFCHR | 0666, GETDEV(pty_major, num));

	int mfd = sys_open(mname, O_RDWR, 0);
	int sfd = sys_open(sname, O_RDWR, 0);
	if(mfd < 0 || sfd < 0) {
		sys_unlink(mname);
		sys_unlink(sname);
		return -ENOENT;
	}

	struct file *mf = file_get(mfd);
	struct file *sf = file_get(sfd);
	vfs_inode_get(mf->inode);
	vfs_inode_get(sf->inode);
	
	pty_create(mf->inode);
	sf->inode->devdata = mf->inode->devdata;
	struct pty *pty = mf->inode->devdata;
	assert(pty);
	
	pty->master = mf->inode;
	pty->slave = sf->inode;
	pty->num = num;
	if(term)
		memcpy(&pty->term, term, sizeof(*term));
	if(win)
		memcpy(&pty->size, win, sizeof(*win));
	file_put(mf);
	file_put(sf);

	if(slavename)
		strncpy(slavename, sname, 32);
	if(master)
		*master = mfd;
	if(slave)
		*slave = sfd;
	return 0;
}
Exemple #2
0
status_t vfs_get_info (int16_t fd, file_info_t * p_info)

/*
 * ARGUMENTS
 * * fd : the file identifier
 * * p_info : a pointer to a file_info_t structure
 *
 * FUNCTION
 * Looks-up for the file corresponding to fd * If it exists, then calls the
 * file's get_info() function.
 *
 * RESULT
 * Fill-in the file_info_t structure.
 *
 * SOURCE
 */

{
  file_t file = NULL;
  status_t status = DNA_OK;

  watch (status_t)
  {
    ensure (fd >= 0 && fd < DNA_MAX_FILE, DNA_INVALID_FD);

    /*
     * Get the file associated to the fd.
     */

    status = file_get (fd, & file);
    ensure (status == DNA_OK, status);

    /*
     * Call ioctl on the file.
     */

    status = file -> vnode -> volume -> cmd -> get_info
      (file -> vnode -> volume -> data, file -> vnode -> data,
       file -> data, p_info);

    check (error, status == DNA_OK, status);

    /*
     * Release the file and return.
     */

    status = file_put (fd);
    panic (status != DNA_OK);

    return DNA_OK;
  }

  rescue (error)
  {
    status = file_put (fd);
    panic (status != DNA_OK);
    leave;
  }

}
Exemple #3
0
int						core(int r, char *buff)
{
	char				**param;

	ft_putstr(C_NONE);
	ft_putstr(C_GREEN);
	buff[r] = '\0';
	param = ft_split_whitespaces(buff);
	send(g_sock, buff, ft_strlen(buff), 0);
	if (ft_strcmp(buff, "quit\n") == 0)
		return (1);
	ft_bzero(buff, 1024);
	if (param[0] && ft_strcmp("get", param[0]) == 0)
		file_get(param[1]);
	else if (param[0] && ft_strcmp("put", param[0]) == 0)
	{
		if (param[1] && param[2] == NULL)
			put_file(param[1]);
		else
			write(1, "ERROR -> Need a file name as second parameter\n", 46);
	}
	else
		get_data();
	print_prompt();
	return (0);
}
struct file_descriptor *fd_open(struct path *path, int flags, bool is_tag)
{
    int fh = -1;
    if (!is_tag) {
        fh = open(path->realpath, flags);
        if (fh < 0) {
            print_debug("lulz %s\n", strerror(errno));
            return ERR_PTR(-errno);
        }
    }

    struct file_descriptor *fd = calloc(sizeof*fd, 1);
    if (!fd)
        return ERR_PTR(-ENOMEM);

    if (!strcmp(path->filename, TAG_FILENAME))
        fd->is_tag_file = true;

    if (is_tag)
        fd->tag = tag_get(path->filename);
    else
        fd->file = file_get(path->filename);

    fd->is_tag = is_tag;
    fd->path = path;
    fd->fh = fh;
    return fd;
}
Exemple #5
0
/**
 * close the file given by the descriptor
 */
int
file_close_descriptor( struct proc *p, int fd ) {
	struct file 	*f = NULL;
	int 		err = 0;

	err = file_get( p, fd, &f );
	if( err )
		return err;
	
	//make sure there are programs using it
	KASSERT( f->f_refcount > 0 );

	//detach from the file descriptor table
	fd_detach( p->p_fd, fd );
	
	//decrease both refcounts
	f->f_refcount--;
	VOP_DECREF( f->f_vnode );

	//destroy if we are the only ones using it
	if( f->f_refcount == 0 ) {
		F_UNLOCK( f );
		file_destroy( f );
		return 0;
	}

	//unlock the file
	F_UNLOCK( f );
	return 0;
}
Exemple #6
0
int		ft_command(char *data, t_uenv *user, char *pwd)
{
	int			wt;
	char		**param;

	if (data[0] == '\0')
	{
		send(user->cs, "Wrong command\n", 14, 0);
		send(user->cs, "ERROR\n", 6, 0);
		return (1);
	}
	param = ft_split_whitespaces(data);
	wt = 300;
	(void)pwd;
	if (ft_strcmp(param[0], "ls") == 0)
	{
		user = core(user, data);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "cd") == 0)
	{
		ft_cd(&user, ft_strsplit(data, ' '));
		//send(user->cs, ft_strjoin(user->pwd, "\n"), ft_strlen(user->pwd) + 1, 0);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "get") == 0)
	{
		file_get(user, data);
		//send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "put") == 0)
	{
		file_put(user, param[1]);
		//send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "pwd") == 0 && param[1] == NULL)
	{
		send(user->cs, ft_strjoin(user->pwd, "\n"), ft_strlen(user->pwd) + 1, 0);
		send(user->cs, "SUCCES\n", 7, 0);
		return (1);
	}
	else if (ft_strcmp(param[0], "quit") == 0 && param[1] == NULL)
	{
		send(user->cs, "Exit\n", 5, 0);
		close(user->cs);
		return (0);
	}
	else
	{
		send(user->cs, "Wrong command\n", 14, 0);
		send(user->cs, "ERROR\n", 6, 0);
	}
	return (1);
}
Exemple #7
0
int sys_posix_fsstat(int fd, struct posix_statfs *sb)
{
	struct file *f = file_get(fd);
	if(!f) return -EBADF;
	struct inode *i = f->inode;
	int r = fs_callback_fs_stat(i->filesystem, sb);
	file_put(f);
	return r;
}
Exemple #8
0
static int at_kfd(int dirfd)
{
  if (dirfd == AT_FDCWD)
    return AT_FDCWD;
  file_t* dir = file_get(dirfd);
  if (dir == NULL)
    return -1;
  return dir->kfd;
}
Exemple #9
0
int sys_isatty(int f)
{
	struct file *file = file_get(f);
	if(!file)
		return -EBADF;
	int ret = MAJOR(file->inode->phys_dev) == pty_major;
	file_put(file);
	return ret;
}
Exemple #10
0
int sys_fstat(int fp, struct stat *sb)
{
	if(!sb)
		return -EINVAL;
	struct file *f = file_get(fp);
	if(!f) return -EBADF;
	do_stat(f->inode, sb);
	file_put(f);
	return 0;
}
Exemple #11
0
static int path_unlink(struct path *fd)
{
    struct file *f;

    f = file_get(fd->filename);
    if (NULL == f) {
        return -ENOENT;
    }
    void remove_tag(const char *filename, void *tag, void *file)
    {
        untag_file(tag, file);
    }
Exemple #12
0
int sys_faccessat(int dirfd, const char *name, int mode, int flags){
  if(name[0] == '/'){
    return sys_access(name, mode);
  }
  file_t* dir = file_get(dirfd);
  if(dir)
  {
    size_t name_size = strlen(name)+1;
    return frontend_syscall(SYS_access, dir->kfd, (uintptr_t)name, name_size, mode, flags);
  }
  return -EBADF;
}
Exemple #13
0
int sys_fcntl(int fd, int cmd, int arg)
{
  int r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = frontend_syscall(SYS_fcntl, f->kfd, cmd, arg, 0, 0, 0, 0);
    file_decref(f);
  }

  return r;
}
Exemple #14
0
int sys_dup(int fd)
{
  int r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_dup(f);
    file_decref(f);
  }

  return r;
}
Exemple #15
0
ssize_t sys_pread(int fd, char* buf, size_t n, off_t offset)
{
  ssize_t r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_pread(f, buf, n, offset);
    file_decref(f);
  }

  return r;
}
Exemple #16
0
int sys_ftruncate(int fd, off_t len)
{
  int r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_truncate(f, len);
    file_decref(f);
  }

  return r;
}
Exemple #17
0
int sys_fstat(int fd, void* st)
{
  int r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_stat(f, st);
    file_decref(f);
  }

  return r;
}
Exemple #18
0
sysret_t sys_fstat(int fd, void* st)
{
  sysret_t r = {-1,EBADF};
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_stat(f, st);
    file_decref(f);
  }

  return r;
}
Exemple #19
0
ssize_t sys_write(int fd, const char* buf, size_t n)
{
  ssize_t r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_write(f, buf, n);
    file_decref(f);
  }

  return r;
}
Exemple #20
0
ssize_t sys_read(int fd, char* buf, size_t n)
{
  ssize_t r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_read(f, buf, n);
    file_decref(f);
  }

  return r;
}
Exemple #21
0
ssize_t sys_lseek(int fd, size_t ptr, int dir)
{
  ssize_t r = -EBADF;
  file_t* f = file_get(fd);

  if (f)
  {
    r = file_lseek(f, ptr, dir);
    file_decref(f);
  }

  return r;
}
Exemple #22
0
long sys_fstatat(int dirfd, const char* name, void* st, int flags)
{
  if(name[0] == '/'){
    return sys_stat(name, st);
  }
  file_t* dir = file_get(dirfd);
  if(dir)
  {
    size_t name_size = strlen(name)+1;
    populate_mapping(st, sizeof(struct stat), PROT_WRITE);
    return frontend_syscall(SYS_fstatat, dir->kfd, (uintptr_t)name, name_size, (uintptr_t)st, flags);
  }
  return -EBADF;
}
Exemple #23
0
int sys_attach_pty(int fd)
{
	struct file *mf = file_get(fd);
	if(!mf) {
		return -EBADF;
	}
	if(MAJOR(mf->inode->phys_dev) != pty_major) {
		file_put(mf);
		return -EINVAL;
	}
	__pty_open(mf);
	file_put(mf);
	return 0;
}
Exemple #24
0
int sys_read(int fp, off_t pos, unsigned char *buf, size_t count)
{
	if(!buf)
		return -EINVAL;
	struct file *f = file_get(fp);
	if(!f)
		return -EBADF;
	if(!(f->flags & _FREAD)) {
		file_put(f);
		return -EACCES;
	}
	int ret = fs_file_pread(f, pos, buf, count);
	file_put(f);
	return ret;
}
Exemple #25
0
static int gpio_read(int gpio, int *value)
{
	int ret;
	char tmp[256];

	if ((ret = check_exported(gpio)))
		return ret;

	sprintf(tmp, "/sys/class/gpio%d/value", gpio);
	if (0 < file_get(tmp, tmp, 256))
		return 0;

	*value = atoi(tmp);

	return -EIO;
}
Exemple #26
0
int main()
{
	Cmix_file::enable_ft_support();
	xcc_dirs::load_from_registry();
	string dir = xcc_dirs::get_dir(game_dune2);

	Cxd2_files files;
	if (files.load(dir))
		return 1;
	file_put(xcc_dirs::get_data_dir() + "xd2 files.xif", files.save().vdata());
	shared_data exe = file_get(dir + "dune2.exe");
	if (!exe.size())
		return 1;
	const char* e = reinterpret_cast<const char*>(exe.data());
	auto bt = reinterpret_cast<const t_building_type*>(&exe[194010]);
	for (auto& i : boost::make_iterator_range(bt, bt + 19))
	{
		ofstream("../xd2 be/dune/objects/" + to_lower_copy(string(e + 229504 + i.name)) + ".ini")
			<< "cameo = " << i.cameo_shp_index << endl
			<< "class = structure" << endl
			<< "cost = " << i.cost << endl
			<< "cx = " << (i.size == 0 || i.size == 2 ? 1 : i.size == 1 || i.size == 3 || i.size == 4 ? 2 : 3) << endl
			<< "cy = " << (i.size == 0 || i.size == 1 ? 1 : i.size == 2 || i.size == 3 || i.size == 5 ? 2 : 3) << endl
			<< "icon = " << i.icon_index << endl
			<< "power = " << i.power_in << endl
			<< "sight = " << i.sight << endl
			<< "strength = " << i.strength << endl
			<< "techlevel = " << i.techlevel << endl
			<< "wsa = " << e + 229504 + i.wsa << endl
			;
	}
	auto ut = reinterpret_cast<const t_unit_type*>(&exe[195840]);
	for (auto& i : boost::make_iterator_range(ut, ut + 27))
	{
		ofstream("../xd2 be/dune/objects/" + to_lower_copy(string(e + 229504 + i.name)) + ".ini")
			<< "body = " << i.body_shp_index << endl
			<< "cameo = " << i.cameo_shp_index << endl
			<< "cost = " << i.cost << endl
			<< "sight = " << i.sight << endl
			<< "speed = " << i.speed << endl
			<< "strength = " << i.strength << endl
			<< "turret = " << i.turret_shp_index << endl
			<< "wsa = " << e + 229504 + i.wsa << endl
			;
	}
	return 0;
}
Exemple #27
0
int sys_write(int fp, off_t pos, unsigned char *buf, size_t count)
{
	struct file *f = file_get(fp);
	if(!f)
		return -EBADF;
	if(!count || !buf) {
		file_put(f);
		return -EINVAL;
	}
	if(!(f->flags & _FWRITE)) {
		file_put(f);
		return -EACCES;
	}
	int ret = fs_file_pwrite(f, pos, buf, count);
	file_put(f);
	return ret;
}
Exemple #28
0
    // Close interface
  static void ven_cleanup (void) {
    logd ("ven_cleanup");
    server_thread_stop ();

    if (veno_cleanup)
      veno_cleanup ();

    bt_ven_cbacks = NULL;

    shim_stop ();

    if (file_get (g2_audio_done_file))
      file_delete (g2_audio_done_file);

    logd ("ven_cleanup done");
    return;
  }
Exemple #29
0
int sys_getdents(int fd, struct dirent_posix *dirs, unsigned int count)
{
	struct file *f = file_get(fd);
	if(!f) return -EBADF;

	unsigned nex;
	if(!vfs_inode_check_permissions(f->inode, MAY_READ, 0)) {
		file_put(f);
		return -EACCES;
	}
	rwlock_acquire(&f->inode->lock, RWL_READER);
	int r = fs_callback_inode_getdents(f->inode, f->pos, dirs, count, &nex);
	rwlock_release(&f->inode->lock, RWL_READER);
	f->pos = nex;

	file_put(f);
	return r;
}
Exemple #30
0
int sys_writepos(int fp, unsigned char *buf, size_t count)
{
	struct file *f = file_get(fp);
	if(!f)
		return -EBADF;
	if(!count || !buf) {
		file_put(f);
		return -EINVAL;
	}
	if(!(f->flags & _FWRITE)) {
		file_put(f);
		return -EACCES;
	}
	if(f->flags & _FAPPEND)
		f->pos = f->inode->length;
	int ret = fs_file_write(f, buf, count);
	file_put(f);
	return ret;
}