From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5edee74b13d8e50a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: The "black magic" of ioctl Date: Thu, 21 Oct 2010 13:05:13 +0100 Organization: A noiseless patient Spider Message-ID: References: <74b46743-fb81-48cc-a478-ffd069db2fc6@k22g2000yqh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx03.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="15596"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dgFk8zybHd04wU7sDZIFBzsyMHrAabBw=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:mpIuIjKiLa5mQSpEs11RJQ/UGAA= sha1:K9x64VDjMywPAC648BPvGbwirqI= Xref: g2news2.google.com comp.lang.ada:15623 Date: 2010-10-21T13:05:13+01:00 List-Id: Francesco Piraneo Giuliano 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;