Beispiel #1
0
/* Get file details for a specified NFS File */
void
nfsfs_stat(pid_t pid, VNode self, const char *path, stat_t *buf) {
	dprintf(1, "*** nfsfs_stat: %p, %s, %p\n", self, path, buf);

	Process *p = process_lookup(pid);

	if (self != NULL) {
		NFS_File *nf = (NFS_File *) self->extra;
		if (nf == NULL) {
			dprintf(0, "!!! nfsfs_stat: Broken NFS file! No nfs struct! (file %s)\n",
					path);
			syscall_reply(process_get_tid(p), SOS_VFS_ERROR);
			return;
		}

		memcpy((void *) buf, (void *) &(self->vstat), sizeof(stat_t));
		syscall_reply(process_get_tid(p), SOS_VFS_OK);
	}
	
	// stat non open file
	else {
		dprintf(1, "*** nfsfs_stat: trying to stat non open file! (file %s)\n", path);

		NFS_StatRequest *rq = (NFS_StatRequest *) create_request(RT_STAT, self, pid);
		rq->stat = buf;
		rq->path = path;
		check_request((NFS_BaseRequest *) rq);
	}
}
Beispiel #2
0
/* NFS Callback for NFS_getdirent */
static
void
getdirent_cb(uintptr_t token, int status, int num_entries, struct nfs_filename *filenames,
		int next_cookie) {
	dprintf(1, "*** nfsfs_dirent_cb: %d, %d, %d, %d\n", token, status, num_entries, next_cookie);

	NFS_DirRequest *rq = (NFS_DirRequest *) get_request(token);
	if (rq == NULL) {
		dprintf(0, "!!! nfsfs: Corrupt dirent callback, no matching token: %d\n", token);
		return;
	}

	Process *p = process_lookup(rq->p.pid);

	if (status != NFS_OK) {
		syscall_reply(process_get_tid(p), status_nfs2vfs(status));
		remove_request((NFS_BaseRequest *) rq);
		return;
	}


	// got it
	if (rq->cpos + num_entries >= rq->pos + 1) {
		dprintf(2, "found file, getting now\n");
		int status = SOS_VFS_ERROR;
		struct nfs_filename *nfile = &filenames[rq->pos - rq->cpos];
		if (nfile->size + 1 <= rq->nbyte) {
			memcpy(rq->buf, nfile->file, nfile->size);
			rq->buf[nfile->size] = '\0';
			status = nfile->size;
		} else {
			dprintf(0, "!!! nfs_getdirent_cb: Filename too big for given buffer! (%d) (%d)\n",
					nfile->size, rq->nbyte);
			status = SOS_VFS_NOMEM;
		}
		syscall_reply(process_get_tid(p), status);
		remove_request((NFS_BaseRequest *) rq);
	}
	// need later directory entry
	else if (next_cookie > 0) {
		dprintf(2, "Need more dir entries to get file\n");
		rq->cpos += num_entries;
		nfs_readdir(&nfs_mnt, next_cookie, IO_MAX_BUFFER, getdirent_cb, rq->p.token);
	}
	// error case, just return SOS_VFS_OK to say nothing read, its not an error just eof
	else {
		dprintf(2, "nfsfs_getdirent: didnt find file (%d)\n", rq->pos);
		syscall_reply(process_get_tid(p), SOS_VFS_EOF);
		remove_request((NFS_BaseRequest *) rq);
	}
}
Beispiel #3
0
/* Remove a file */
void
nfsfs_remove(pid_t pid, VNode self, const char *path) {
	dprintf(1, "*** nfsfs_remove: %d %s ***\n", pid, path);

	if (self != NULL) {
		// cant remove open files
		syscall_reply(process_get_tid(process_lookup(pid)), SOS_VFS_OPEN);
	} else {
		// remove file
		NFS_RemoveRequest *rq = (NFS_RemoveRequest *)
			create_request(RT_REMOVE, self, pid);
		rq->path = path;
		check_request((NFS_BaseRequest *) rq);
	}
}
Beispiel #4
0
/* NFS Callback for NFS_Remove */
static
void
remove_cb(uintptr_t token, int status) {
	dprintf(1, "*** nfsfs: remove_cb %u %d *** \n", token, status);

	NFS_RemoveRequest *rq = (NFS_RemoveRequest *) get_request(token);
	if (rq == NULL) {
		dprintf(0, "!!! nfsfs: Corrupt remove callback, no matching token: %d\n", token);
		return;
	}

	syscall_reply(process_get_tid(process_lookup(rq->p.pid)),
			status_nfs2vfs(status));
	remove_request((NFS_BaseRequest *) rq);
}
Beispiel #5
0
gfarm_error_t
process_does_match(gfarm_pid_t pid,
	gfarm_int32_t keytype, size_t keylen, char *sharedkey,
	struct process **processp)
{
	struct process *process = process_lookup((gfarm_int32_t)pid);

	if (process == NULL)
		return (GFARM_ERR_NO_SUCH_PROCESS);
	if (keytype != GFM_PROTO_PROCESS_KEY_TYPE_SHAREDSECRET ||
	    keylen != GFM_PROTO_PROCESS_KEY_LEN_SHAREDSECRET ||
	    memcmp(sharedkey, process->sharedkey,
	    GFM_PROTO_PROCESS_KEY_LEN_SHAREDSECRET) != 0)
		return (GFARM_ERR_AUTHENTICATION);
	*processp = process;
	return (GFARM_ERR_NO_ERROR);
}
Beispiel #6
0
void tcp_inspect(struct ip *iph, struct tcphdr *tcp)
{
    if (tcp->th_flags == TH_SYN) {
        struct pfl0w_process *p = malloc (sizeof *p);
        fprintf(stderr, "TCP [%d] (%s:%d - ", tcp->th_flags, inet_ntoa(iph->ip_src), ntohs(tcp->th_sport));
        fprintf(stderr, "%s:%d)\n", inet_ntoa(iph->ip_dst), ntohs(tcp->th_dport));

        p->src = iph->ip_src.s_addr;
        p->dst = iph->ip_dst.s_addr;
        p->src_port = ntohs(tcp->th_sport);
        p->dst_port = ntohs(tcp->th_dport);

        int r = process_lookup(p);
        fprintf(stderr, "Process pid: %d\n", r);
        free(p);
    }
}
Beispiel #7
0
/* NFS Callback for NFS_Stat */
static
void 
stat_cb(uintptr_t token, int status, struct cookie *fh, fattr_t *attr) {
	dprintf(1, "*** nfsfs_stat_cb: %d, %d, %p, %p\n", token, status, fh, attr);

	NFS_StatRequest *rq = (NFS_StatRequest *) get_request(token);
	if (rq == NULL) {
		dprintf(0, "!!! nfsfs: Corrupt stat callback, no matching token: %d\n", token);
		return;
	}

	if (status == NFS_OK) {
		cp_stats(rq->stat, attr);
	}

	syscall_reply(process_get_tid(process_lookup(rq->p.pid)),
			status_nfs2vfs(status));
	remove_request((NFS_BaseRequest *) rq);
}
Beispiel #8
0
int
sys_getsid(struct thread *td, struct sys_getsid_args *ap)
{
	struct process *p;

	mutex_slock(&processtopo);
	if (ap->pid == 0) {
		p = td->td_process;
	} else {
		p = process_lookup(ap->pid);
		if (p == NULL) {
			mutex_sunlock(&processtopo);
			return (ESRCH);
		}
	}
	ap->retval = p->p_group->pg_session->s_id;
	mutex_sunlock(&processtopo);
	return (0);
}
Beispiel #9
0
int32_t waitpid(int32_t pid, int32_t *wstatus, int32_t options) {

	struct process_control_block_type *proc;

	proc=process_lookup(pid);

	if (debug) printk("Waiting on pid %d\n",pid);

	while (proc->status!=PROCESS_STATUS_EXITED) {

		schedule();
	}

	if (wstatus!=NULL) *wstatus=proc->exit_value;

	/* Kill the zombie now? */

	/* Reschedule? */
	return pid;
}
Beispiel #10
0
/* Flush the given nfs file to disk. (UNSUPPORTED) (no buffering used) */
void
nfsfs_flush(pid_t pid, VNode self, fildes_t file) {
	dprintf(1, "*** nfsfs_flush: %d, %p, %d\n", pid, self, file);
	dprintf(1, "!!! nfsfs_flush: Not implemented for nfs fs\n");
	syscall_reply(process_get_tid(process_lookup(pid)), SOS_VFS_NOTIMP);
}