From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 981C0BC48 for ; Mon, 11 Apr 2005 09:51:11 +0200 (CEST) Received: from smtp5.wanadoo.fr (smtp5.wanadoo.fr [193.252.22.26]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j3B7pBt3007491 for ; Mon, 11 Apr 2005 09:51:11 +0200 Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf0506.wanadoo.fr (SMTP Server) with ESMTP id 291661C00254 for ; Mon, 11 Apr 2005 09:51:11 +0200 (CEST) Received: from pegasos (AStrasbourg-251-1-52-2.w82-126.abo.wanadoo.fr [82.126.142.2]) by mwinf0506.wanadoo.fr (SMTP Server) with ESMTP id BF31D1C00242; Mon, 11 Apr 2005 09:51:10 +0200 (CEST) X-ME-UUID: 20050411075110783.BF31D1C00242@mwinf0506.wanadoo.fr Received: from luther by pegasos with local (Exim 4.50) id 1DKtci-0003Te-De; Mon, 11 Apr 2005 09:46:20 +0200 Date: Mon, 11 Apr 2005 09:46:19 +0200 To: caml-list@yquem.inria.fr, sven.luther@wanadoo.fr Subject: ocaml, int32/64, bigarray and unsigned values ... Message-ID: <20050411074619.GA26797@pegasos> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline User-Agent: Mutt/1.5.6+20040907i From: Sven Luther X-Miltered: at nez-perce with ID 425A2C6F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 bigarray:01 sven:01 luther:01 sven:01 luther:01 ocaml:01 byte:01 corresponds:01 bigarray:01 arrays:01 bindings:01 byte:01 plateform:01 bytecode:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Hello, I had plans to do a rewrite of GNU parted, a project which i am involved with, in ocaml, and am being blocked by a few issues. I know i can read disk sectors easily with the large-file support, which would mean that i could support all underlying files that the ocaml standard library supports, as opposed to parted which has some special code for linux, hurd, and a couple of others. This would probably mean that if i did it right, i could even use said library on windows, haven't investigated though. Now to my problems, which are basically two. 1) most disk partition tables and filesystem have a mapping from a given disk 512 byte sector to a descriptive structure. In C you simply define the structure which corresponds to it, and you cast the sector to it, and then test if some magic numbers and checksums are or not enough to identify the sector as of the given type. The nearest to that would be either trying to use the bigarray infrastructure and mmap capability, but it only makes provision for mapping arrays and not structures. The other possibilities is to either have some C bindings which do the proper cast, or to have access functions which transform parts of a byte array into values. The first one is ugly, as i was aiming for a purely ocaml solution (so i can build and arch/plateform independent bytecode tool), and the second would probably be a disaster speed wise, and also somewhat ugly unless properly encapsulated in an abstract module. Which brings me to the second problem. 2) Disk descriptors like partition table and filesystems, need to have exact values, and the values are mostly unsigned 8, 16, 32 or 64 bit integers, strings and bit fields. The int64 and int32 offer these kind of values, but only the signed version. Is it save to make calculation on a signed number and ignoring the sign bit ? Does this not cause risk of overflow ? I am not particularly knowledgeable of the different signed/unsigned implementations on the different architectures and plateform that i would need to support. Also, i believe that bit fields are not easily available, altough there is some support in the Int32 and int64 bit-wise operators, but again we have the signed vs unsigned problem, altough it is maybe ignored for bit operations ? These two questions also are of importance if you want to write chip drivers in ocaml, since you have to mmap the mmio registers of the chips, and have a similar exact access to the registers used, altough the registers should fall better in the bigarray mapping, since you mostly access those as 8, 16, 32, 64 or even 128 bit values. But maybe ocaml 3.09 could have direct support for these kind of operations, opening a new field of usage for ocaml ? Friendly, Sven Luther