OSDev.org
https://forum.osdev.org/

Read system call for input
https://forum.osdev.org/viewtopic.php?f=1&t=32662
Page 1 of 1

Author:  Chpetrou [ Thu Jan 04, 2018 1:48 pm ]
Post subject:  Read system call for input

Hello

I have my OS and i created an os specific toolkit with the newlib c library. I have some syscalls such as the write. I can write a program that uses printf and compile it and run it on user space on my os. Now i am trying to implement the read system call. I wrote the keyboard drivers, and also i wrote a kscanf and getchar functions and they work just fine on kernel space, but when i use scanf on user space through the read system call, it allow me to write and press enter but it doesn't save the value to show it when i printf the string. The read system call declaration is like the linux format,

Code:
ssize_t read(int fd, void *buf, size_t count) {


and inside i have just a
Code:
kscanf("%s", buf);
return 0;
}


in the write system call i have kprintf("%s", buf); and it works fine, but the read doesn't.

Can you help me?

Thanks in Advance

Author:  lkurusa [ Mon Jan 08, 2018 10:14 am ]
Post subject:  Re: Read system call for input

Hint: What if the buffer passed in to read is not big enough?

Author:  Chpetrou [ Tue Jan 09, 2018 8:21 am ]
Post subject:  Re: Read system call for input

Hello,

I checked it and it is big enough, i also tried to enlarge it but still almost the same. Just a symbol like @ appears which i guess means it is Null.

Author:  pragmatic [ Wed Jan 10, 2018 11:35 am ]
Post subject:  Re: Read system call for input

Chpetrou wrote:
Hello,

I checked it and it is big enough, i also tried to enlarge it but still almost the same. Just a symbol like @ appears which i guess means it is Null.


Try not to guess and do simple inspection. Rather than printing characters, try printing the hex value of what you receive. If you are printing '@' then the byte you received was 0x40, not 0. It might also be useful to print the return value of read (i.e. the number of characters read).

Author:  Chpetrou [ Thu Jan 11, 2018 9:08 am ]
Post subject:  Re: Read system call for input

Hello

I tried to print the buffer in hex but it prints this '0x80402fc6' which is probably just a random value in memory of an uninitialised buffer, so i think the buffer does not keep the value i am giving.

The problem is that i have the scanf function and in kernel mode it transfers it, so the problem is more likely with the read system call calling. That's what i don't know how to fix. The system calls with just printing work, this one which needs a value to be returned doesn't.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/