Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  R/W from/to partitions (on linux) (Silent Leaf)
   2. Re:  R/W from/to partitions (on linux) (Sylvain Henry)
   3. Re:  R/W from/to partitions (on linux) (Silent Leaf)
   4. Re:  which typefor this FFI call (Sylvain Henry)
   5. Re:  which typefor this FFI call (Sylvain Henry)


----------------------------------------------------------------------

Message: 1
Date: Mon, 26 Jun 2017 07:35:09 +0200
From: Silent Leaf <silent.le...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] R/W from/to partitions (on linux)
Message-ID:
        <cagfccjn9sx+1brbxba_a0a7+q3rfr8h6fcfxs5vzxdsi8zk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

I'd like to be able to read and write from/to partitions directly. I've had
trouble with the documentation (honestly i can't find anything, and any
mention of partitions leads to mathematical partitioning of lists or
whatever).

I obviously would need to be able to write or read from a specific position
in the partition. Mind you that would be good too for files (that is, being
able to read/write from a specific position in it) since i plan on making
disk images.

Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/23505dcf/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 26 Jun 2017 07:51:41 +0200
From: Sylvain Henry <sylv...@haskus.fr>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] R/W from/to partitions (on linux)
Message-ID: <d700a1db-44b1-4742-ece0-feeaff54b...@haskus.fr>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi,

It is not Haskell specific. You just have to read from the partition 
device special file (e.g., something like /dev/sdb2) as you would do 
with a normal file. You must have the permission to do so (e.g., be 
root). Be careful as you can destroy your system if you write something 
incorrect in your partitions.

Repositioning handles: 
https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/System-IO.html#g:13

Read/write: 
https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/System-IO.html#v:hPutBuf

Sylvain


On 26/06/2017 07:35, Silent Leaf wrote:
> Hi,
>
> I'd like to be able to read and write from/to partitions directly. 
> I've had trouble with the documentation (honestly i can't find 
> anything, and any mention of partitions leads to mathematical 
> partitioning of lists or whatever).
>
> I obviously would need to be able to write or read from a specific 
> position in the partition. Mind you that would be good too for files 
> (that is, being able to read/write from a specific position in it) 
> since i plan on making disk images.
>
> Thanks in advance!
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/3bb0b680/attachment-0001.html>

------------------------------

Message: 3
Date: Mon, 26 Jun 2017 07:57:01 +0200
From: Silent Leaf <silent.le...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] R/W from/to partitions (on linux)
Message-ID:
        <cagfccjoem9blhukfc9hpzo0nbuvb8pgycpgfuorfz67gn4l...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Darn quick answer! Thanks Sylvain, that may be all i need to start!

2017-06-26 7:51 GMT+02:00 Sylvain Henry <sylv...@haskus.fr>:

> Hi,
>
> It is not Haskell specific. You just have to read from the partition
> device special file (e.g., something like /dev/sdb2) as you would do with a
> normal file. You must have the permission to do so (e.g., be root). Be
> careful as you can destroy your system if you write something incorrect in
> your partitions.
>
> Repositioning handles: https://www.stackage.org/
> haddock/lts-8.20/base-4.9.1.0/System-IO.html#g:13
>
> Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/
> System-IO.html#v:hPutBuf
>
> Sylvain
>
> On 26/06/2017 07:35, Silent Leaf wrote:
>
> Hi,
>
> I'd like to be able to read and write from/to partitions directly. I've
> had trouble with the documentation (honestly i can't find anything, and any
> mention of partitions leads to mathematical partitioning of lists or
> whatever).
>
> I obviously would need to be able to write or read from a specific
> position in the partition. Mind you that would be good too for files (that
> is, being able to read/write from a specific position in it) since i plan
> on making disk images.
>
> Thanks in advance!
>
>
> _______________________________________________
> Beginners mailing 
> listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170626/a6409a3a/attachment-0001.html>

------------------------------

Message: 4
Date: Mon, 26 Jun 2017 08:18:08 +0200
From: Sylvain Henry <sylv...@haskus.fr>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] which typefor this FFI call
Message-ID: <830739f6-c249-fde2-a549-3b02bd2e2...@haskus.fr>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi,

I would use IORef and StablePtr:

import Foreign.StablePtr
import Foreign.Ptr
import Data.IORef

type H5Iterate = Hid -> CString -> Ptr () -> Ptr () -> IO ()

-- see https://wiki.haskell.org/Foreign_Function_Interface#Function_pointers
foreign import ccall "wrapper" mkOp :: H5Iterate -> FunPtr (H5Iterate)

foreign import ccall "H5Lvisit" h5iterate :: Hid -> Index -> Order -> 
FunPtr H5Iterate -> Ptr () -> IO ()

main = do
   state <- newIORef []
   statePtr <- newStablePtr state

   let
     callback :: H5Iterate
     callback hid name infoptr dataptr = do
         -- get the state
         stRef <- deRefStablePtr (castPtrToStablePtr dataptr)
         st <- readIORef stRef
         -- compute the new state
         newSt <- ...
         -- store the new state
         writeIORef stRef newSt

   h5iterate gid idttyp order (mkOp callback) (castStablePtrToPtr statePtr)

   -- retrieve the final state
   finalState <- readIORef state


- Sylvain


On 24/06/2017 15:47, PICCA Frederic-Emmanuel wrote:
> Hello
>
> I would like to create a binding for this function [1].
>
> herr_t H5Literate( hid_t group_id, H5_index_t index_type, H5_iter_order_t 
> order, hsize_t *idx, H5L_iterate_t op, void *op_data )
>
> My "only" problem is with the op and op_data part.
> Here the C op signature[2]
>
> op ->  herr_t (*H5L_iterate_t)( hid_t g_id, const char *name, const 
> H5L_info_t *info, void *op_data)
>
> What I would like to do is to create an Haskell function which allows to 
> return what is contained under the op_data.
> What I understand from this is that I give the H5Literate function an op 
> function which is executed for each group of my hdf5 file.
> So the op method is called with the releavant parameters.
> The op_data can be use to accumulate things during the traversal.
>
> H5Literate :: Hid -> Index  -> Order -> Maybe HSize -> H5Iterate -> _ -> _
>
> type H5Iterate = Hid -> ByteString -> Info -> _ -> _
>
> So it seems to me that I need to use a State inorder to do the accumulation.
>
> For exemple,I want to collect each group names and accumulate then in a list.
>
> Somy questioniswhat should be the signature of both function.
>
> I have also the fealing that the return type MUST have a Storableinstance.
>
>
> Thanks for your help
>
> Frederic
>
>
> [1] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate
> [2] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Visit
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



------------------------------

Message: 5
Date: Mon, 26 Jun 2017 08:33:44 +0200
From: Sylvain Henry <sylv...@haskus.fr>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] which typefor this FFI call
Message-ID: <46ecc981-a136-705b-48fc-93d512016...@haskus.fr>
Content-Type: text/plain; charset=utf-8; format=flowed

On 26/06/2017 08:18, Sylvain Henry wrote:
> Hi,
>
> I would use IORef and StablePtr:
>
> import Foreign.StablePtr
> import Foreign.Ptr
> import Data.IORef
>
> type H5Iterate = Hid -> CString -> Ptr () -> Ptr () -> IO ()
>
> -- see 
> https://wiki.haskell.org/Foreign_Function_Interface#Function_pointers
> foreign import ccall "wrapper" mkOp :: H5Iterate -> FunPtr (H5Iterate)
>
> foreign import ccall "H5Lvisit" h5iterate :: Hid -> Index -> Order -> 
> FunPtr H5Iterate -> Ptr () -> IO ()
>
> main = do
>   state <- newIORef []
>   statePtr <- newStablePtr state
>
>   let
>     callback :: H5Iterate
>     callback hid name infoptr dataptr = do
>         -- get the state
>         stRef <- deRefStablePtr (castPtrToStablePtr dataptr)
>         st <- readIORef stRef
>         -- compute the new state
>         newSt <- ...
>         -- store the new state
>         writeIORef stRef newSt
>
>   h5iterate gid idttyp order (mkOp callback) (castStablePtrToPtr 
> statePtr)
>
Don't forget to: freeStablePtr statePtr

>   -- retrieve the final state
>   finalState <- readIORef state
>
>
> - Sylvain
>
>
> On 24/06/2017 15:47, PICCA Frederic-Emmanuel wrote:
>> Hello
>>
>> I would like to create a binding for this function [1].
>>
>> herr_t H5Literate( hid_t group_id, H5_index_t index_type, 
>> H5_iter_order_t order, hsize_t *idx, H5L_iterate_t op, void *op_data )
>>
>> My "only" problem is with the op and op_data part.
>> Here the C op signature[2]
>>
>> op ->  herr_t (*H5L_iterate_t)( hid_t g_id, const char *name, const 
>> H5L_info_t *info, void *op_data)
>>
>> What I would like to do is to create an Haskell function which allows 
>> to return what is contained under the op_data.
>> What I understand from this is that I give the H5Literate function an 
>> op function which is executed for each group of my hdf5 file.
>> So the op method is called with the releavant parameters.
>> The op_data can be use to accumulate things during the traversal.
>>
>> H5Literate :: Hid -> Index  -> Order -> Maybe HSize -> H5Iterate -> _ 
>> -> _
>>
>> type H5Iterate = Hid -> ByteString -> Info -> _ -> _
>>
>> So it seems to me that I need to use a State inorder to do the 
>> accumulation.
>>
>> For exemple,I want to collect each group names and accumulate then in 
>> a list.
>>
>> Somy questioniswhat should be the signature of both function.
>>
>> I have also the fealing that the return type MUST have a 
>> Storableinstance.
>>
>>
>> Thanks for your help
>>
>> Frederic
>>
>>
>> [1] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate
>> [2] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Visit
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 108, Issue 14
******************************************

Reply via email to