Permalink
Browse files

proper support for unmapping

  • Loading branch information...
1 parent d3ad933 commit 1c225dfa7b5cdc80a96524dfd6ee394983e2469b @bwalex committed Jul 12, 2011
Showing with 57 additions and 28 deletions.
  1. +9 −0 tcplay.3
  2. +27 −28 tcplay.c
  3. +1 −0 tcplay.h
  4. +1 −0 tcplay.map
  5. +15 −0 tcplay_api.c
  6. +1 −0 tcplay_api.h
  7. +3 −0 tcplay_api_test.c
View
9 tcplay.3
@@ -36,6 +36,7 @@
.Nm tc_api_uninit ,
.Nm tc_api_create_volume ,
.Nm tc_api_map_volume ,
+.Nm tc_api_unmap_volume ,
.Nm tc_api_check_cipher ,
.Nm tc_api_check_prf_hash ,
.Nm tc_api_get_error_msg ,
@@ -54,6 +55,8 @@
.Ft int
.Fn tc_api_map_volume "tc_api_opts *api_opts"
.Ft int
+.Fn tc_api_unmap_volume "tc_api_opts *api_opts"
+.Ft int
.Fn tc_api_check_cipher "tc_api_opts *api_opts"
.Ft int
.Fn tc_api_check_prf_hash "tc_api_opts *api_opts"
@@ -71,6 +74,7 @@ volumes.
The
.Fn tc_api_create_volume ,
.Fn tc_api_map_volume ,
+.Fn tc_api_unmap_volume ,
.Fn tc_api_check_cipher
and
.Fn tc_api_check_prf_hash
@@ -189,6 +193,11 @@ Depending on the passphrase/keyfiles used
either the outer or the hidden volume will be mapped.
.Pp
The
+.Fn tc_api_unmap_volume
+unmaps / closes the volume specified in
+.Fa tc_map_name .
+.Pp
+The
.Fn tc_api_check_cipher
function checks whether the cipher specified in the
.Fa api_opts
View
55 tcplay.c
@@ -780,6 +780,30 @@ map_volume(const char *map_name, const char *device, int sflag,
return 0;
}
+static
+int
+dm_remove_device(const char *name)
+{
+ struct dm_task *dmt = NULL;
+ int ret = EINVAL;
+
+ if ((dmt = dm_task_create(DM_DEVICE_REMOVE)) == NULL)
+ goto out;
+
+ if ((dm_task_set_name(dmt, name)) == 0)
+ goto out;
+
+ if ((dm_task_run(dmt)) == 0)
+ goto out;
+
+ ret = 0;
+out:
+ if (dmt)
+ dm_task_destroy(dmt);
+
+ return ret;
+}
+
int
dm_setup(const char *mapname, struct tcplay_info *info)
{
@@ -923,39 +947,14 @@ dm_setup(const char *mapname, struct tcplay_info *info)
return ret;
}
-/* XXX: move up */
-static
-int
-dm_remove_device(const char *name)
-{
- struct dm_task *dmt = NULL;
- int ret = EINVAL;
-
- if ((dmt = dm_task_create(DM_DEVICE_REMOVE)) == NULL)
- goto out;
-
- if ((dm_task_set_name(dmt, name)) == 0)
- goto out;
-
- if ((dm_task_run(dmt)) == 0)
- goto out;
-
- ret = 0;
-out:
- if (dmt)
- dm_task_destroy(dmt);
-
- return ret;
-}
-
int
dm_teardown(const char *mapname, const char *device __unused)
{
- struct dm_task *dmt = NULL;
#if 0
- struct dm_info dmi;
+ struct dm_task *dmt = NULL;
+ struct dm_info dmi;
#endif
- char map[PATH_MAX];
+ char map[PATH_MAX];
int i, error;
if ((error = dm_remove_device(mapname)) != 0) {
View
1 tcplay.h
@@ -186,6 +186,7 @@ int map_volume(const char *map_name, const char *device, int sflag,
char *passphrase, char *passphrase_hidden, int interactive, int retries,
time_t timeout);
int dm_setup(const char *mapname, struct tcplay_info *info);
+int dm_teardown(const char *mapname, const char *device);
typedef void(*summary_fn_t)(void);
View
1 tcplay.map
@@ -4,6 +4,7 @@ global:
tc_api_uninit;
tc_api_create_volume;
tc_api_map_volume;
+ tc_api_unmap_volume;
tc_api_check_cipher;
tc_api_check_prf_hash;
tc_api_get_error_msg;
View
15 tcplay_api.c
@@ -148,6 +148,21 @@ tc_api_map_volume(tc_api_opts *api_opts)
}
int
+tc_api_unmap_volume(tc_api_opts *api_opts)
+{
+ int err;
+
+ if ((api_opts == NULL) ||
+ (api_opts->tc_map_name == NULL)) {
+ errno = EFAULT;
+ return TC_ERR;
+ }
+
+ err = dm_teardown(api_opts->tc_map_name, api_opts->tc_device);
+ return (err) ? TC_ERR : TC_OK;
+}
+
+int
tc_api_check_cipher(tc_api_opts *api_opts)
{
struct tc_cipher_chain *chain;
View
1 tcplay_api.h
@@ -56,6 +56,7 @@ int tc_api_init(int verbose);
int tc_api_uninit(void);
int tc_api_create_volume(tc_api_opts *api_opts);
int tc_api_map_volume(tc_api_opts *api_opts);
+int tc_api_unmap_volume(tc_api_opts *api_opts);
int tc_api_check_cipher(tc_api_opts *api_opts);
int tc_api_check_prf_hash(tc_api_opts *api_opts);
const char *tc_api_get_error_msg(void);
View
3 tcplay_api_test.c
@@ -47,6 +47,9 @@ main(void)
printf("API MAP ERROR: %s\n", tc_api_get_error_msg());
assert(error == 0);
+ system("dmsetup ls");
+ tc_api_unmap_volume(&api_opts);
+
error = tc_api_uninit();
assert(error == 0);

0 comments on commit 1c225df

Please sign in to comment.