Page 1 of 1

Read system call for input

Posted: Thu Jan 04, 2018 1:48 pm
by Chpetrou
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: Select all

ssize_t read(int fd, void *buf, size_t count) {
and inside i have just a

Code: Select all

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

Re: Read system call for input

Posted: Mon Jan 08, 2018 10:14 am
by lkurusa
Hint: What if the buffer passed in to read is not big enough?

Re: Read system call for input

Posted: Tue Jan 09, 2018 8:21 am
by Chpetrou
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.

Re: Read system call for input

Posted: Wed Jan 10, 2018 11:35 am
by pragmatic
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).

Re: Read system call for input

Posted: Thu Jan 11, 2018 9:08 am
by Chpetrou
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.