Read system call for input

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Chpetrou
Posts: 17
Joined: Sun Aug 21, 2016 10:18 am
Libera.chat IRC: Chpetrou
Location: Cyprus, Greece
Contact:

Read system call for input

Post 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
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: Read system call for input

Post by lkurusa »

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

Lev
Chpetrou
Posts: 17
Joined: Sun Aug 21, 2016 10:18 am
Libera.chat IRC: Chpetrou
Location: Cyprus, Greece
Contact:

Re: Read system call for input

Post 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.
pragmatic
Posts: 15
Joined: Tue Jul 04, 2017 12:45 am

Re: Read system call for input

Post 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).
Chpetrou
Posts: 17
Joined: Sun Aug 21, 2016 10:18 am
Libera.chat IRC: Chpetrou
Location: Cyprus, Greece
Contact:

Re: Read system call for input

Post 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.
Post Reply