mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Haskell bindings: Fix integer arguments.
This commit is contained in:
@@ -40,6 +40,7 @@ module Guestfs (
|
||||
mount,
|
||||
sync,
|
||||
touch,
|
||||
aug_init,
|
||||
aug_close,
|
||||
aug_set,
|
||||
aug_mv,
|
||||
@@ -50,14 +51,20 @@ module Guestfs (
|
||||
rm_rf,
|
||||
mkdir,
|
||||
mkdir_p,
|
||||
chmod,
|
||||
chown,
|
||||
pvcreate,
|
||||
vgcreate,
|
||||
lvcreate,
|
||||
mkfs,
|
||||
sfdisk,
|
||||
write_file,
|
||||
umount,
|
||||
umount_all,
|
||||
lvm_remove_all,
|
||||
blockdev_setro,
|
||||
blockdev_setrw,
|
||||
blockdev_setbsz,
|
||||
blockdev_flushbufs,
|
||||
blockdev_rereadpt,
|
||||
upload,
|
||||
@@ -79,17 +86,22 @@ module Guestfs (
|
||||
cp,
|
||||
cp_a,
|
||||
mv,
|
||||
drop_caches,
|
||||
ping_daemon,
|
||||
zerofree,
|
||||
pvresize,
|
||||
sfdisk_N,
|
||||
lvresize,
|
||||
resize2fs,
|
||||
e2fsck_f,
|
||||
sleep,
|
||||
scrub_device,
|
||||
scrub_file,
|
||||
scrub_freespace
|
||||
) where
|
||||
import Foreign
|
||||
import Foreign.C
|
||||
import Foreign.C.Types
|
||||
import IO
|
||||
import Control.Exception
|
||||
import Data.Typeable
|
||||
@@ -328,6 +340,18 @@ touch h path = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_aug_init" c_aug_init
|
||||
:: GuestfsP -> CString -> CInt -> IO (CInt)
|
||||
|
||||
aug_init :: GuestfsH -> String -> Int -> IO ()
|
||||
aug_init h root flags = do
|
||||
r <- withCString root $ \root -> withForeignPtr h (\p -> c_aug_init p root (fromIntegral flags))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_aug_close" c_aug_close
|
||||
:: GuestfsP -> IO (CInt)
|
||||
|
||||
@@ -448,6 +472,30 @@ mkdir_p h path = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_chmod" c_chmod
|
||||
:: GuestfsP -> CInt -> CString -> IO (CInt)
|
||||
|
||||
chmod :: GuestfsH -> Int -> String -> IO ()
|
||||
chmod h mode path = do
|
||||
r <- withCString path $ \path -> withForeignPtr h (\p -> c_chmod p (fromIntegral mode) path)
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_chown" c_chown
|
||||
:: GuestfsP -> CInt -> CInt -> CString -> IO (CInt)
|
||||
|
||||
chown :: GuestfsH -> Int -> Int -> String -> IO ()
|
||||
chown h owner group path = do
|
||||
r <- withCString path $ \path -> withForeignPtr h (\p -> c_chown p (fromIntegral owner) (fromIntegral group) path)
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_pvcreate" c_pvcreate
|
||||
:: GuestfsP -> CString -> IO (CInt)
|
||||
|
||||
@@ -472,6 +520,18 @@ vgcreate h volgroup physvols = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_lvcreate" c_lvcreate
|
||||
:: GuestfsP -> CString -> CString -> CInt -> IO (CInt)
|
||||
|
||||
lvcreate :: GuestfsH -> String -> String -> Int -> IO ()
|
||||
lvcreate h logvol volgroup mbytes = do
|
||||
r <- withCString logvol $ \logvol -> withCString volgroup $ \volgroup -> withForeignPtr h (\p -> c_lvcreate p logvol volgroup (fromIntegral mbytes))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_mkfs" c_mkfs
|
||||
:: GuestfsP -> CString -> CString -> IO (CInt)
|
||||
|
||||
@@ -484,6 +544,30 @@ mkfs h fstype device = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_sfdisk" c_sfdisk
|
||||
:: GuestfsP -> CString -> CInt -> CInt -> CInt -> Ptr CString -> IO (CInt)
|
||||
|
||||
sfdisk :: GuestfsH -> String -> Int -> Int -> Int -> [String] -> IO ()
|
||||
sfdisk h device cyls heads sectors lines = do
|
||||
r <- withCString device $ \device -> withMany withCString lines $ \lines -> withArray0 nullPtr lines $ \lines -> withForeignPtr h (\p -> c_sfdisk p device (fromIntegral cyls) (fromIntegral heads) (fromIntegral sectors) lines)
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_write_file" c_write_file
|
||||
:: GuestfsP -> CString -> CString -> CInt -> IO (CInt)
|
||||
|
||||
write_file :: GuestfsH -> String -> String -> Int -> IO ()
|
||||
write_file h path content size = do
|
||||
r <- withCString path $ \path -> withCString content $ \content -> withForeignPtr h (\p -> c_write_file p path content (fromIntegral size))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_umount" c_umount
|
||||
:: GuestfsP -> CString -> IO (CInt)
|
||||
|
||||
@@ -544,6 +628,18 @@ blockdev_setrw h device = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_blockdev_setbsz" c_blockdev_setbsz
|
||||
:: GuestfsP -> CString -> CInt -> IO (CInt)
|
||||
|
||||
blockdev_setbsz :: GuestfsH -> String -> Int -> IO ()
|
||||
blockdev_setbsz h device blocksize = do
|
||||
r <- withCString device $ \device -> withForeignPtr h (\p -> c_blockdev_setbsz p device (fromIntegral blocksize))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_blockdev_flushbufs" c_blockdev_flushbufs
|
||||
:: GuestfsP -> CString -> IO (CInt)
|
||||
|
||||
@@ -796,6 +892,18 @@ mv h src dest = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_drop_caches" c_drop_caches
|
||||
:: GuestfsP -> CInt -> IO (CInt)
|
||||
|
||||
drop_caches :: GuestfsH -> Int -> IO ()
|
||||
drop_caches h whattodrop = do
|
||||
r <- withForeignPtr h (\p -> c_drop_caches p (fromIntegral whattodrop))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_ping_daemon" c_ping_daemon
|
||||
:: GuestfsP -> IO (CInt)
|
||||
|
||||
@@ -832,6 +940,30 @@ pvresize h device = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_sfdisk_N" c_sfdisk_N
|
||||
:: GuestfsP -> CString -> CInt -> CInt -> CInt -> CInt -> CString -> IO (CInt)
|
||||
|
||||
sfdisk_N :: GuestfsH -> String -> Int -> Int -> Int -> Int -> String -> IO ()
|
||||
sfdisk_N h device n cyls heads sectors line = do
|
||||
r <- withCString device $ \device -> withCString line $ \line -> withForeignPtr h (\p -> c_sfdisk_N p device (fromIntegral n) (fromIntegral cyls) (fromIntegral heads) (fromIntegral sectors) line)
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_lvresize" c_lvresize
|
||||
:: GuestfsP -> CString -> CInt -> IO (CInt)
|
||||
|
||||
lvresize :: GuestfsH -> String -> Int -> IO ()
|
||||
lvresize h device mbytes = do
|
||||
r <- withCString device $ \device -> withForeignPtr h (\p -> c_lvresize p device (fromIntegral mbytes))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_resize2fs" c_resize2fs
|
||||
:: GuestfsP -> CString -> IO (CInt)
|
||||
|
||||
@@ -856,6 +988,18 @@ e2fsck_f h device = do
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_sleep" c_sleep
|
||||
:: GuestfsP -> CInt -> IO (CInt)
|
||||
|
||||
sleep :: GuestfsH -> Int -> IO ()
|
||||
sleep h secs = do
|
||||
r <- withForeignPtr h (\p -> c_sleep p (fromIntegral secs))
|
||||
if (r == -1)
|
||||
then do
|
||||
err <- last_error h
|
||||
fail err
|
||||
else return ()
|
||||
|
||||
foreign import ccall unsafe "guestfs_scrub_device" c_scrub_device
|
||||
:: GuestfsP -> CString -> IO (CInt)
|
||||
|
||||
|
||||
@@ -7265,7 +7265,7 @@ and generate_haskell_hs () =
|
||||
*)
|
||||
let can_generate style =
|
||||
let check_no_bad_args =
|
||||
List.for_all (function Bool _ | Int _ -> false | _ -> true)
|
||||
List.for_all (function Bool _ -> false | _ -> true)
|
||||
in
|
||||
match style with
|
||||
| RErr, args -> check_no_bad_args args
|
||||
@@ -7300,6 +7300,7 @@ module Guestfs (
|
||||
) where
|
||||
import Foreign
|
||||
import Foreign.C
|
||||
import Foreign.C.Types
|
||||
import IO
|
||||
import Control.Exception
|
||||
import Data.Typeable
|
||||
@@ -7363,6 +7364,7 @@ last_error h = do
|
||||
pr "%s %s = do\n" name
|
||||
(String.concat " " ("h" :: List.map name_of_argt (snd style)));
|
||||
pr " r <- ";
|
||||
(* Convert pointer arguments using with* functions. *)
|
||||
List.iter (
|
||||
function
|
||||
| FileIn n
|
||||
@@ -7370,17 +7372,18 @@ last_error h = do
|
||||
| String n -> pr "withCString %s $ \\%s -> " n n
|
||||
| OptString n -> pr "maybeWith withCString %s $ \\%s -> " n n
|
||||
| StringList n -> pr "withMany withCString %s $ \\%s -> withArray0 nullPtr %s $ \\%s -> " n n n n
|
||||
| Bool n ->
|
||||
(* XXX this doesn't work *)
|
||||
pr " let\n";
|
||||
pr " %s = case %s of\n" n n;
|
||||
pr " False -> 0\n";
|
||||
pr " True -> 1\n";
|
||||
pr " in fromIntegral %s $ \\%s ->\n" n n
|
||||
| Int n -> pr "fromIntegral %s $ \\%s -> " n n
|
||||
| Bool _ | Int _ -> ()
|
||||
) (snd style);
|
||||
(* Convert integer arguments. *)
|
||||
let args =
|
||||
List.map (
|
||||
function
|
||||
| Bool n -> sprintf "(fromIntegral %s)" n
|
||||
| Int n -> sprintf "(fromIntegral %s)" n
|
||||
| FileIn n | FileOut n | String n | OptString n | StringList n -> n
|
||||
) (snd style) in
|
||||
pr "withForeignPtr h (\\p -> c_%s %s)\n" name
|
||||
(String.concat " " ("p" :: List.map name_of_argt (snd style)));
|
||||
(String.concat " " ("p" :: args));
|
||||
(match fst style with
|
||||
| RErr | RInt _ | RInt64 _ | RBool _ ->
|
||||
pr " if (r == -1)\n";
|
||||
|
||||
Reference in New Issue
Block a user