caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* ocaml, int32/64, bigarray and unsigned values ...
@ 2005-04-11  7:46 Sven Luther
  2005-04-11 12:57 ` [Caml-list] " Eric Cooper
  0 siblings, 1 reply; 9+ messages in thread
From: Sven Luther @ 2005-04-11  7:46 UTC (permalink / raw)
  To: caml-list, sven.luther

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-05-25  9:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-11  7:46 ocaml, int32/64, bigarray and unsigned values Sven Luther
2005-04-11 12:57 ` [Caml-list] " Eric Cooper
2005-04-11 15:35   ` Sven Luther
2005-04-11 16:13     ` Eric Cooper
2005-04-13  6:54     ` Florian Hars
2005-04-13 18:28     ` Ken Rose
2005-05-25  6:06     ` partition tables and ocaml Taras
2005-05-25  9:09       ` Sven Luther
2005-04-12 17:19   ` [Caml-list] ocaml, int32/64, bigarray and unsigned values Paul Snively

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).