-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfsview_down.cpp
56 lines (48 loc) · 1.5 KB
/
fsview_down.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2022 Light Labs Inc.
* All Rights Reserved
* Licensed under the MIT license.
*/
#include "conf/config.h"
#include "allsys.h"
int main( int argc, char ** argv )
{
CtrlConf cfg;
cfg.parse( argc, argv );
int control_fd = open( cfg.dmControl, O_RDWR );
if( control_fd < 0 )
{
perror( cfg.dmControl );
exit( 2 );
}
struct dm_ioctl header;
for( int i = 0; i < argc; ++i )
{
memset( &header, 0, sizeof( header ) );
header.version[0] = DM_VERSION_MAJOR;
header.version[1] = 0; // MINOR too high
header.version[2] = 0; // omit PATCHLEVEL
strncpy( header.name, argv[i], DM_NAME_LEN );
// if the device exists, tear it down:
// - allow pending I/O complete;
header.data_start = 0;
header.data_size = sizeof( header );
header.flags = 0;
header.dev = 0;
if( ioctl( control_fd, DM_DEV_SUSPEND, &header ) < 0 )
{ perror( "Can't flush i/o on device" ); }
// - suspend the device mapping;
header.data_start = 0;
header.data_size = sizeof( header );
header.flags = DM_SUSPEND_FLAG;
header.dev = 0;
if( ioctl( control_fd, DM_DEV_SUSPEND, &header ) < 0 )
{ perror( "Can't suspend device" ); }
// - destroy the device mapping.
header.dev = 0;
if( ioctl( control_fd, DM_DEV_REMOVE, &header ) < 0 )
{ perror( "Can't destroy device" ); }
}
close( control_fd );
return 0;
}