Exemplo n.º 1
0
long
_syspwrite(int fd, void *buf, long n, vlong off)
{
	if(off == ((uvlong) ~0))
		return kwrite(fd, buf, n, nil);
	return kwrite(fd, buf, n, &off);
}
Exemplo n.º 2
0
Arquivo: read.c Projeto: kazyka/OSM
/**
 * Read from kernel.
 */
int read_kernel(int handle, void *buffer, int length)
{
  KERNEL_ASSERT(handle == 0);
  KERNEL_ASSERT(length >= strlen(buffer));

  device_t *dev;
  gcd_t *gcd;
  int buf_len;
  buf_len = 0;

  dev = device_get(TYPECODE_TTY, 0);
  KERNEL_ASSERT(dev != NULL);

  gcd = (gcd_t *)dev->generic_device;
  KERNEL_ASSERT(gcd != NULL);

  while(stringcmp(buffer, "n") != 0){

    buf_len = buf_len + gcd->read(gcd, buffer, length);
    KERNEL_ASSERT(buf_len >= 0);
    kwrite(buffer);
  }
  gcd->write(gcd, buffer, buf_len);
  return buf_len;
}
Exemplo n.º 3
0
ssize_t dev_write (struct file *filep, char const __user *buff, size_t len, loff_t *offset)
{

    char * copy =  (char*) kmalloc(len*sizeof(char),GFP_KERNEL);
    struct data_item data;
    struct timeval tv;
    printk(KERN_CRIT "copying user's buffer\n");
    copy_from_user(copy,buff,len);
    
    data= parse(copy,len);
    
    printk(KERN_CRIT "Verifying user's message\n");
    do_gettimeofday(&tv);
    if(data.time>tv.tv_sec)
    {
        printk(KERN_ERR "Production time cannot be after write time\n");
        return -EINVAL;
    }
    if(data.qid == -1)
    {
        printk(KERN_ERR "Message from user is not well constructed\n");
        return -EINVAL;
    }
    printk(KERN_CRIT "Write:qid=%d,time=%llu,msg=%s\n",data.qid,data.time,data.msg);
    
    user_writes++;
    kwrite(data);
       
    return len;    
}
Exemplo n.º 4
0
int dumpTaskStructure(struct file *f, struct task_struct *tsk)
{
	int written;
	//Write task_struct
	written = kwrite(f, (void *)tsk, sizeof(struct task_struct));
	return written;
}
Exemplo n.º 5
0
Arquivo: dial.c Projeto: 8l/inferno
static int
call(char *clone, char *dest, DS *ds)
{
	int fd, cfd, n;
	char name[Maxpath], data[Maxpath], err[ERRMAX], *p;

	cfd = kopen(clone, ORDWR);
	if(cfd < 0){
		kerrstr(err, sizeof err);
		kwerrstr("%s (%s)", err, clone);
		return -1;
	}

	/* get directory name */
	n = kread(cfd, name, sizeof(name)-1);
	if(n < 0){
		kerrstr(err, sizeof err);
		kclose(cfd);
		kwerrstr("read %s: %s", clone, err);
		return -1;
	}
	name[n] = 0;
	for(p = name; *p == ' '; p++)
		;
	sprint(name, "%ld", strtoul(p, 0, 0));
	p = strrchr(clone, '/');
	*p = 0;
	if(ds->dir)
		snprint(ds->dir, NETPATHLEN, "%s/%s", clone, name);
	snprint(data, sizeof(data), "%s/%s/data", clone, name);

	/* connect */
	if(ds->local)
		snprint(name, sizeof(name), "connect %s %s", dest, ds->local);
	else
		snprint(name, sizeof(name), "connect %s", dest);
	if(kwrite(cfd, name, strlen(name)) < 0){
		err[0] = 0;
		kerrstr(err, sizeof err);
		kclose(cfd);
		kwerrstr("%s (%s)", err, name);
		return -1;
	}

	/* open data connection */
	fd = kopen(data, ORDWR);
	if(fd < 0){
		err[0] = 0;
		kerrstr(err, sizeof err);
		kwerrstr("%s (%s)", err, data);
		kclose(cfd);
		return -1;
	}
	if(ds->cfdp)
		*ds->cfdp = cfd;
	else
		kclose(cfd);

	return fd;
}
Exemplo n.º 6
0
Arquivo: dial.c Projeto: 8l/inferno
static int
csdial(DS *ds)
{
	int n, fd, rv;
	char *p, buf[Maxstring], clone[Maxpath], err[ERRMAX], besterr[ERRMAX];

	/*
	 *  open connection server
	 */
	snprint(buf, sizeof(buf), "%s/cs", ds->netdir);
	fd = kopen(buf, ORDWR);
	if(fd < 0){
		/* no connection server, don't translate */
		snprint(clone, sizeof(clone), "%s/%s/clone", ds->netdir, ds->proto);
		return call(clone, ds->rem, ds);
	}

	/*
	 *  ask connection server to translate
	 */
	sprint(buf, "%s!%s", ds->proto, ds->rem);
	if(kwrite(fd, buf, strlen(buf)) < 0){
		kerrstr(err, sizeof err);
		kclose(fd);
		kwerrstr("%s (%s)", err, buf);
		return -1;
	}

	/*
	 *  loop through each address from the connection server till
	 *  we get one that works.
	 */
	*besterr = 0;
	strcpy(err, Egreg);
	rv = -1;
	kseek(fd, 0, 0);
	while((n = kread(fd, buf, sizeof(buf) - 1)) > 0){
		buf[n] = 0;
		p = strchr(buf, ' ');
		if(p == 0)
			continue;
		*p++ = 0;
		rv = call(buf, p, ds);
		if(rv >= 0)
			break;
		err[0] = 0;
		kerrstr(err, sizeof err);
		if(strstr(err, "does not exist") == 0)
			memmove(besterr, err, sizeof besterr);
	}
	kclose(fd);

	if(rv < 0 && *besterr)
		kerrstr(besterr, sizeof besterr);
	else
		kerrstr(err, sizeof err);
	return rv;
}
Exemplo n.º 7
0
/**
 * Just write a char to stdout.
 * http://www.tutorialspoint.com/c_standard_library/c_function_putchar.htm
 */
int putchar(int ic){
#if defined(__is_hobbyos_kernel)
	char c = (char) ic;
	kwrite(&c, sizeof(c));
#else
	// TODO: You need to implement a write system call.
#endif
	return ic;
}
Exemplo n.º 8
0
void sys_write(uint64_t fd,uint64_t buff,uint64_t len){

	//printf(" In kernel printf.. in buffer %s",buff);
	
	//while(1);
	 kwrite(fd,(char*)buff,(int)len);


}
Exemplo n.º 9
0
int	kputchar(char c)
{
	char	buf[2];

	*buf = c;
	buf[1] = 0;
	kwrite(KWRITE_ALL, buf, 1);
	return 1;
}
Exemplo n.º 10
0
int dumpMMStructure(struct file *f,struct task_struct *tsk)
{
  struct mm_struct *pmm;
  int w;
  pmm=tsk->mm;
  w = kwrite(f,(void*)pmm,sizeof(struct mm_struct));
  printk("\nDumpMMStructure():Dumping mm_struct total %d\n",w);
  PrintMMStructure(pmm);
  return 1;
}
Exemplo n.º 11
0
int DumpVMAreas(struct file *f,struct task_struct *tsk,mm_segment_t fs)
{
	int i=0;
	struct vm_area_struct *vma;
	for(vma=tsk->mm->mmap;vma!=NULL;vma=vma->vm_next)
	{
		i++;
		kwrite(f,(void*)vma,sizeof(struct vm_area_struct));
		StorePageList(f,tsk,vma);
	}
	return 1;
}
Exemplo n.º 12
0
static void hello_exit(void) {

  //unregister kbd_listener
  unregister_keyboard_notifier(&nb);

  //write keystrokes into the log file
  log = kopen(LOG_PATH, O_WRONLY|O_CREAT|O_APPEND, 0644);
  kwrite(log, 0, trans, strlen(trans));
  kclose(log);

  printk(KERN_ALERT "KBD_N - kbd_notifier removed.\n");
}
Exemplo n.º 13
0
int dumpHeader(struct file *f, struct task_struct *tsk, int *vmareas, int *openfiles, int *totalpages)
{
	  Header_t header;
	  printk(KERN_INFO "IN DUMP HEADER");
	  header.noofvmareas=*vmareas=GetVMACount(tsk);
	  header.noofopenfiles=*openfiles=GetOpenFileCount(tsk->files);
	  header.noofpagessofar=*totalpages=GetPageCount(tsk,0,PAGE_OFFSET);
	  printk(KERN_INFO "Wrriten header : %d",kwrite(f,(void*)&header,sizeof(Header_t)));
	  printk("\nDumpHeader():Dumping Header->noofvmareas=%d,noofopenfiles=%d\n",*vmareas,*openfiles);
//	  PrintHeader(ht);
	  return 1;
}
Exemplo n.º 14
0
Arquivo: dial.c Projeto: 8l/inferno
/*
 *  announce a network service.
 */
int
kannounce(char *addr, char *dir)
{
	int ctl, n, m;
	char buf[NETPATHLEN];
	char buf2[Maxpath];
	char netdir[NETPATHLEN];
	char naddr[Maxpath];
	char *cp;

	/*
	 *  translate the address
	 */
	if(nettrans(addr, naddr, sizeof(naddr), netdir, sizeof(netdir)) < 0)
		return -1;

	/*
	 * get a control channel
	 */
	ctl = kopen(netdir, ORDWR);
	if(ctl<0)
		return -1;
	cp = strrchr(netdir, '/');
	*cp = 0;

	/*
	 *  find out which line we have
	 */
	n = sprint(buf, "%.*s/", sizeof buf, netdir);
	m = kread(ctl, &buf[n], sizeof(buf)-n-1);
	if(m <= 0){
		kclose(ctl);
		return -1;
	}
	buf[n+m] = 0;

	/*
	 *  make the call
	 */
	n = snprint(buf2, sizeof buf2, "announce %s", naddr);
	if(kwrite(ctl, buf2, n)!=n){
		kclose(ctl);
		return -1;
	}

	/*
	 *  return directory etc.
	 */
	if(dir)
		strcpy(dir, buf);
	return ctl;
}
Exemplo n.º 15
0
int                       main()
{

  welcome_screen();

  kwrite(COLOR_WHITE, "   ", 0);
  printk(COLOR_WHITE, "\n$> ");

  register_listen_rpcs();

  for (;;);
  return (0);
}
Exemplo n.º 16
0
/*
 *	If the other end hangs up, we have to unbind the interface.  An extra
 *	unbind (in the case where we are hanging up) won't do any harm.
 */
static void deadremote(Ipifc * ifc)
{
	int fd;
	char path[128];
	PPP *ppp;

	ppp = ifc->arg;
	snprint(path, sizeof path, "#I%d/ipifc/%d/ctl", ppp->f->dev, ifc->conv->x);
	fd = kopen(path, ORDWR);
	if (fd < 0)
		return;
	kwrite(fd, "unbind", sizeof("unbind") - 1);
	kclose(fd);
}
Exemplo n.º 17
0
int
operwrite(int f, int n)
{
    register int s;
    char fname[NFILEN];

    if (ukb != 0) {
	if ((s = mlreply_file("Write to file: ", (TBUFF **) 0,
			      FILEC_WRITE | FILEC_PROMPT, fname)) != TRUE)
	    return s;
	return kwrite(fname, TRUE);
    } else {
	opcmd = OPOTHER;
	return vile_op(f, n, writeregion, "File write");
    }
}
Exemplo n.º 18
0
static int                check_elf_magic(unsigned char *to_check)
{
  int                     i = 0;
  char                    magic[4] = ELFMAG;

  while (i < 4)
  {
    if (to_check[i] != magic[i])
    {
      kwrite(4, "MAGIC DON'T MATCH ELF, SKIPPING MODULE\n", 0);
      return (-1);
    }
    i++;
  }
  return (0);
}
Exemplo n.º 19
0
int dumpAll(struct file *f, struct task_struct *tsk)
{
	mm_segment_t fs;
	int vmareas, openfiles, pagessofar;
	struct pt_regs prset;

	printk(KERN_INFO "\nDumpStructure():Dumping structure....................\n");
	prset=GetRegisters(tsk);
	fs=get_fs();
	dumpHeader(f,tsk,&vmareas,&openfiles,&pagessofar);
	dumpTaskStructure(f,tsk);
	dumpMMStructure(f,tsk);
	DumpVMAreas(f,tsk,fs);
	DumpRegisters(f,prset);
	kwrite(f,NULL,0);
	set_fs(fs);
	return 1;

}
Exemplo n.º 20
0
void debugger_ptrace_callback(struct allocation_t* ref)
{
	if (!ref)
		return;

	struct message_t* message = __get(ref);
	if (!message)
		return;

	// Only handle requests
	if (message->header.request != 1)
		goto cleanup;

	if (!message->payload)
	{
		messagemanager_sendErrorMessage(gFramework->messageManager, ref, ENOMEM);
		goto cleanup;
	}

	// set diag auth ID flags
	curthread->td_ucred->cr_sceAuthID = 0x3800000000000007ULL;

	// make system credentials
	curthread->td_ucred->cr_sceCaps[0] = 0xFFFFFFFFFFFFFFFFULL;
	curthread->td_ucred->cr_sceCaps[1] = 0xFFFFFFFFFFFFFFFFULL;

	struct debugger_ptrace_t* ptraceRequest = (struct debugger_ptrace_t*)message->payload;


	if (ptraceRequest->setAddrToBuffer)
		ptraceRequest->addr = (uint64_t)&ptraceRequest->buffer[0];

	WriteLog(LL_Debug, "%d %d %llx %d %s", ptraceRequest->req, ptraceRequest->pid, ptraceRequest->addr, ptraceRequest->data, ptraceRequest->setAddrToBuffer ? "true" : "false");
	ptraceRequest->res = kptrace(ptraceRequest->req, ptraceRequest->pid, (caddr_t)ptraceRequest->addr, ptraceRequest->data);

	WriteLog(LL_Debug, "ptrace: %d", ptraceRequest->res);

	kwrite(message->socket, ptraceRequest, sizeof(*ptraceRequest));

cleanup:
	__dec(ref);
}
Exemplo n.º 21
0
/**
 * Adds a specific file to the card.sd image
 *
 * Adds the file at the path specified by filename to the SD card
 * image indicated by dst_filename
 *
 * @param 
 *
 * char *src_file_name - holds the path to the file to add to the SD
 * card image
 *
 * @param
 *
 * char *dst_file_name - holds the path to the SD card image to
 * add the file to
 */
void addFile(const char *src_file_name, const char *dst_file_name)
{
	FILE *f = fopen(src_file_name, "r");
	assert(f);

	// FIXME: should all be const char*
	kclose(kcreate((char*) dst_file_name, 'r', 0));
	int fd = kopen((char*) dst_file_name, 'w');

	char buf[BUF_SIZE];
	int nread;

	while ((nread = fread(buf, 1, BUF_SIZE, f)) > 0)
	{
		kwrite(fd, buf, nread);
		//printf("\t\t%d bytes\n", nread);
	}

	kclose(fd);
	fclose(f);
}
Exemplo n.º 22
0
void irq_32(struct Register_State rs) {
	// Send EOI
	if (rs.int_no >= 40)
		outb(0xA0, 0x20);
	outb(0x20, 0x20);

//	if (interrupt_handlers[rs.int_no] != 0)
//	{
//	    isr_t handler = interrupt_handlers[rs.int_no];
//	    handler(rs);
//	}
	if (rs.err_code == 0) return;
	if (rs.err_code == 1) {
		uint8_t c = inb(0x60);
		if (c < 0x80)
			kput(kbdmap[c]);
		return;
	}
	kput(rs.err_code + '0');
	kwrite("IRQ");
}
Exemplo n.º 23
0
int StorePageList(struct file *f,struct task_struct *tsk,struct vm_area_struct *vma)
{
	void *tsk_user_data;
	unsigned long addr=0;
	for(addr=vma->vm_start;addr<vma->vm_end;addr+=PAGE_SIZE)
	{
		tsk_user_data=GetTaskUserData(tsk,vma,addr);
		if(tsk_user_data)
		{
			if((kwrite(f,tsk_user_data,PAGE_SIZE)!=PAGE_SIZE))
			{
				printk(KERN_INFO  "\nerror in page writing");
				return -1;
			}

		}
		else
		{
			printk(KERN_INFO  "\nStorePageList():Page not found...........\n");
		}

	}
	return 1;
}
Exemplo n.º 24
0
Arquivo: dial.c Projeto: 8l/inferno
/*
 *  call up the connection server and get a translation
 */
static int
nettrans(char *addr, char *naddr, int na, char *file, int nf)
{
	int i, fd;
	char buf[Maxpath];
	char netdir[NETPATHLEN];
	char *p, *p2;
	long n;

	/*
	 *  parse, get network directory
	 */
	p = strchr(addr, '!');
	if(p == 0){
		kwerrstr("bad dial string: %s", addr);
		return -1;
	}
	if(*addr != '/'){
		strcpy(netdir, "/net");
	} else {
		for(p2 = p; *p2 != '/'; p2--)
			;
		i = p2 - addr;
		if(i == 0 || i >= sizeof(netdir)){
			kwerrstr("bad dial string: %s", addr);
			return -1;
		}
		strncpy(netdir, addr, i);
		netdir[i] = 0;
		addr = p2 + 1;
	}

	/*
	 *  ask the connection server
	 */
	sprint(buf, "%s/cs", netdir);
	fd = kopen(buf, ORDWR);
	if(fd < 0)
		return identtrans(netdir, addr, naddr, na, file, nf);
	if(kwrite(fd, addr, strlen(addr)) < 0){
		kclose(fd);
		return -1;
	}
	kseek(fd, 0, 0);
	n = kread(fd, buf, sizeof(buf)-1);
	kclose(fd);
	if(n <= 0)
		return -1;
	buf[n] = 0;

	/*
	 *  parse the reply
	 */
	p = strchr(buf, ' ');
	if(p == 0)
		return -1;
	*p++ = 0;
	strncpy(naddr, p, na);
	naddr[na-1] = 0;
	strncpy(file, buf, nf);
	file[nf-1] = 0;
	return 0;
}
Exemplo n.º 25
0
static ssize_t idesc_file_ops_write(struct idesc *idesc, const void *buf, size_t nbyte) {
	assert(idesc);

	return kwrite(buf, nbyte, (struct file_desc *)idesc);
}
Exemplo n.º 26
0
int                       main()
{
  kwrite(15, "SHELL !!!!\n", 0);

  return 0;
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: cfrost/buenos
void init(void)
{
    TID_t startup_thread;
    int numcpus;

    /* Initialize polling TTY driver for kprintf() usage. */
    polltty_init();

    kwrite("BUENOS is a University Educational Nutshell Operating System\n");
    kwrite("==========================================================\n");
    kwrite("\n");

    kwrite("Copyright (C) 2003-2006  Juha Aatrokoski, Timo Lilja,\n");
    kwrite("  Leena Salmela, Teemu Takanen, Aleksi Virtanen\n");
    kwrite("See the file COPYING for licensing details.\n");
    kwrite("\n");

    kwrite("Initializing memory allocation system\n");
    kmalloc_init();

    kwrite("Reading boot arguments\n");
    bootargs_init();

    /* Seed the random number generator. */
    if (bootargs_get("randomseed") == NULL) {
	_set_rand_seed(0);
    } else {
	int seed = atoi(bootargs_get("randomseed"));
	kprintf("Seeding pseudorandom number generator with %i\n", seed);
	_set_rand_seed(seed);
    }

    numcpus = cpustatus_count();
    kprintf("Detected %i CPUs\n", numcpus);
    KERNEL_ASSERT(numcpus <= CONFIG_MAX_CPUS);

    kwrite("Initializing interrupt handling\n");
    interrupt_init(numcpus);

    kwrite("Initializing threading system\n");
    thread_table_init();

    kwrite("Initializing user process system\n");
    process_init();

    kwrite("Initializing sleep queue\n");
    sleepq_init();

    kwrite("Initializing semaphores\n");
    semaphore_init();

    kwrite("Initializing device drivers\n");
    device_init();

    kprintf("Initializing virtual filesystem\n");
    vfs_init();

    kwrite("Initializing scheduler\n");
    scheduler_init();

    kwrite("Initializing virtual memory\n");
    vm_init();

    kprintf("Creating initialization thread\n");
    startup_thread = thread_create(&init_startup_thread, 0);
    thread_run(startup_thread);

    kprintf("Starting threading system and SMP\n");

    /* Let other CPUs run */
    kernel_bootstrap_finished = 1;
    
    _interrupt_clear_bootstrap();
    _interrupt_enable();

    /* Enter context switch, scheduler will be run automatically,
       since thread_switch() behaviour is identical to timer tick
       (thread timeslice is over). */
    thread_switch();

    /* We should never get here */
    KERNEL_PANIC("Threading system startup failed.");
}
Exemplo n.º 28
0
static void sigrtmax_handler (const int sig) {
  static const char message[] = "got SIGRTMAX.\n";
  kwrite (2, message, sizeof (message) - (size_t) 1);
  sigrtmax_cnt++;
}
Exemplo n.º 29
0
static void sigusr1_handler (const int sig) {
  static const char message[] = "got SIGUSR1.\n";
  kwrite (2, message, sizeof (message) - (size_t) 1);
  sigusr1_cnt++;
}
Exemplo n.º 30
0
static void sigterm_handler (const int sig) {
  static const char message[] = "SIGTERM handled.\n";
  kwrite (2, message, sizeof (message) - (size_t) 1);
  pending_signals |= 1 << SIGTERM;
  signal (sig, sigterm_immediate_handler);
}