OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:34 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Read system call for input
PostPosted: Thu Jan 04, 2018 1:48 pm 
Offline

Joined: Sun Aug 21, 2016 10:18 am
Posts: 17
Location: Cyprus, Greece
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


Top
 Profile  
 
 Post subject: Re: Read system call for input
PostPosted: Mon Jan 08, 2018 10:14 am 
Offline
Member
Member
User avatar

Joined: Wed Aug 08, 2012 6:39 am
Posts: 42
Location: New York, NY
Hint: What if the buffer passed in to read is not big enough?

_________________
Cheers,

Lev


Top
 Profile  
 
 Post subject: Re: Read system call for input
PostPosted: Tue Jan 09, 2018 8:21 am 
Offline

Joined: Sun Aug 21, 2016 10:18 am
Posts: 17
Location: Cyprus, Greece
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.


Top
 Profile  
 
 Post subject: Re: Read system call for input
PostPosted: Wed Jan 10, 2018 11:35 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: Read system call for input
PostPosted: Thu Jan 11, 2018 9:08 am 
Offline

Joined: Sun Aug 21, 2016 10:18 am
Posts: 17
Location: Cyprus, Greece
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 76 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group