45
45
" are met (see pumount(1) for details). The mount point directory is removed\n"
48
" -l, --lazy : umount lazily, see umount(8)\n"
49
" --luks-force : luksClose devices pmount didn't open\n"
50
" -d, --debug : enable debug output (very verbose)\n"
51
" -h, --help : print help message and exit successfuly\n"
52
" --version : print version number and exit successfully\n"),
48
" -l, --lazy : umount lazily, see umount(8)\n"
49
" -d, --debug : enable debug output (very verbose)\n"
50
" -h, --help : print help message and exit successfuly\n"
51
" --version : print version number and exit successfully\n"),
53
52
exename, MEDIADIR );
63
62
check_umount_policy( const char* device, int do_lazy )
66
char mediadir[PATH_MAX];
68
66
devvalid = ( do_lazy || device_valid( device ) ) &&
69
67
device_mounted( device, 1, mntpt );
77
75
exit( E_INTERNAL );
80
/* MEDIADIR may be a symlink (for read-only root systems) */
81
if( NULL == realpath( MEDIADIR, mediadir ) ) {
82
fprintf( stderr, _("Error: could not find real path of %s\n"),
87
78
/* mount point must be below MEDIADIR */
88
if( strncmp( mntpt, mediadir, strlen( mediadir ) ) ) {
79
if( strncmp( mntpt, MEDIADIR, sizeof( MEDIADIR )-1 ) ) {
89
80
fprintf( stderr, _("Error: mount point %s is not below %s\n"), mntpt,
101
92
* @param lazy 0 for normal umount, 1 for lazy umount
104
do_umount_fstab( const char* device, int lazy, const char * fstab_mntpt )
95
do_umount_fstab( const char* device, int lazy )
106
97
/* drop all privileges */
113
104
debug( "device %s handled by fstab, calling umount\n", device );
114
if(! strncmp(device, "LABEL=", 6) || ! strncmp(device, "UUID=", 5)) {
115
debug( "'%s' is a label/uuid specification, using mount point %s to umount\n",
116
device, fstab_mntpt);
117
device = fstab_mntpt; /* device is now the mount point */
121
107
execl( UMOUNTPROG, UMOUNTPROG, "-l", device, NULL );
158
144
char device[PATH_MAX], mntptdev[PATH_MAX], path[PATH_MAX];
159
145
const char* fstab_device;
160
char fstab_mntpt[MEDIA_STRING_SIZE];
161
146
int is_real_path = 0;
166
150
static struct option long_opts[] = {
167
151
{ "help", 0, NULL, 'h'},
168
152
{ "debug", 0, NULL, 'd'},
169
153
{ "lazy", 0, NULL, 'l'},
170
{ "luks-force", 0, NULL, 'L'},
171
154
{ "version", 0, NULL, 'V' },
172
155
{ NULL, 0, NULL, 0}
241
222
/* is the device already handled by fstab? */
242
fstab_device = fstab_has_device( "/etc/fstab", device, fstab_mntpt, NULL );
223
fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL );
243
224
if( fstab_device ) {
244
do_umount_fstab( fstab_device, do_lazy, fstab_mntpt );
225
do_umount_fstab( fstab_device, do_lazy );
245
226
return E_EXECUMOUNT;
248
229
/* we cannot really check the real path when unmounting lazily since the
249
230
* device node might not exist any more */
250
231
if( !is_real_path && !do_lazy ) {
251
/* try to prepend '/dev' */
252
if( strncmp( device, DEVDIR, sizeof( DEVDIR )-1 ) ) {
254
snprintf( d, sizeof( d ), "%s%s", DEVDIR, device );
255
if ( !realpath( d, device ) ) {
256
perror( _("Error: could not determine real path of the device") );
259
debug( "trying to prepend '" DEVDIR
260
"' to device argument, now '%s'\n", device );
261
/* We need to lookup again in fstab: */
262
fstab_device = fstab_has_device( "/etc/fstab", device,
265
do_umount_fstab( fstab_device, do_lazy, fstab_mntpt );
232
perror( _("Error: could not determine real path of the device") );
271
236
/* does the device start with DEVDIR? */