From: Simon Wright <simon@pushface.org>
Subject: Re: The "black magic" of ioctl
Date: Thu, 21 Oct 2010 13:05:13 +0100
Date: 2010-10-21T13:05:13+01:00 [thread overview]
Message-ID: <m2sjzz3g5i.fsf@pushface.org> (raw)
In-Reply-To: cbc04455-d43b-4cca-ab56-51b6273fdc08@j18g2000yqd.googlegroups.com
Francesco Piraneo Giuliano <fpiraneo@gmail.com> writes:
> So, please don't use ioctl -> black magic -> forbidden! :-)
>
> But my application still need to be written and has to run under linux
> so to collect some data about linux' framebuffer I have to use ioctl;
> the only solution is to write all low level interfacing (open the
> device, get informations about, map it into memory) in C then write
> the upper level in Ada?
I've never had to do this. But, for example..
Googling linux ioctl framebuffer led to a piece of code:
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
...
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Error reading fixed information.\n");
exit(2);
}
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Error reading variable information.\n");
exit(3);
}
and an Ada way (there are several alternatives) would be to create a
package Framebuffer:
with Interfaces.C;
package Framebuffer is
type Fixed_Screeninfo is record
--
end record;
pragma Convention (C, Fixed_Screeninfo);
-- probably a good idea to lay out the structure precisely
type Variable_Screeninfo is record
--
end record;
pragma Convention (C, Variable_Screeninfo);
Read_Error : exception;
function Get_Fixed_Screeninfo
(Fd : Interfaces.C.int) return Fixed_Screeninfo;
-- etc
end Framebuffer;
package body Framebuffer is
function Get_Fixed_Screeninfo
(Fd : Interfaces.C.int) return Fixed_Screeninfo
is
function ioctl (fildes : Interfaces.C.int;
request : Interfaces.C.unsigned_long;
finfo : access Fixed_Screeninfo) return Interfaces.C.int;
pragma Import (C, ioctl, "ioctl");
FBIOGET_FSCREENINFO : constant Interfaces.C.unsigned_long := ???;
-- get the appropriate value from the system headers; maybe
-- write a tiny C program to print the value for you.
finfo : aliased Fixed_Screeninfo;
use type Interfaces.C.int;
begin
if ioctl (Fd, FBIOGET_FSCREENINFO, finfo'Access) /= 0 then
raise Read_Error;
end if;
return finfo;
end Get_Fixed_Screeninfo;
-- etc
end Framebuffer;
next prev parent reply other threads:[~2010-10-21 12:05 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-21 9:13 The "black magic" of ioctl Francesco Piraneo Giuliano
2010-10-21 10:20 ` Ludovic Brenta
2010-10-21 11:31 ` Francesco Piraneo Giuliano
2010-10-21 11:50 ` Mark Lorenzen
2010-10-21 12:04 ` Ludovic Brenta
2010-10-22 16:46 ` Francesco Piraneo Giuliano
2010-10-22 16:47 ` Francesco Piraneo Giuliano
2010-10-21 12:05 ` Simon Wright [this message]
2010-10-22 20:16 ` michael bode
2010-10-23 12:13 ` Simon Wright
2010-10-23 13:27 ` michael bode
2010-10-23 16:25 ` Simon Wright
2010-10-23 18:12 ` michael bode
2010-10-23 20:26 ` Florian Weimer
2010-10-24 11:08 ` Simon Wright
2010-10-24 17:58 ` Florian Weimer
2010-10-24 12:41 ` Frank J. Lhota
2010-10-24 17:56 ` Florian Weimer
2010-10-24 18:36 ` Simon Wright
2010-10-25 0:45 ` Frank J. Lhota
2010-10-25 1:13 ` Frank J. Lhota
2010-10-25 18:56 ` Florian Weimer
2010-10-21 11:46 ` Colin Paul Gloster
2010-10-25 7:08 ` Yannick Duchêne (Hibou57)
2010-10-21 13:40 ` Julian Leyh
2010-10-21 13:58 ` Simon Wright
2010-10-21 20:45 ` Randy Brukardt
2010-10-22 16:40 ` Francesco Piraneo Giuliano
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox