int zuluCrypRemoveEntryFromMtab( const char * m_point ) { #if USE_NEW_LIBMOUNT_API struct libmnt_lock * lock ; #else mnt_lock * lock ; #endif struct mntent * mt ; FILE * f ; FILE * g ; size_t dir_len = strlen( m_point ) ; int h ; lock = mnt_new_lock( "/etc/mtab~",getpid() ) ; f = setmntent( "/etc/mtab","r" ) ; if( mnt_lock_file( lock ) != 0 ){ h = 4 ; }else{ g = setmntent( "/etc/mtab-zuluCrypt","w" ) ; while( ( mt = getmntent( f ) ) != NULL ){ if( StringPrefixMatch( mt->mnt_dir,m_point,dir_len ) ){ /* * an entry we want to delete,skip it */ ; }else{ addmntent( g,mt ) ; } } endmntent( g ) ; rename( "/etc/mtab-zuluCrypt","/etc/mtab" ) ; chown( "/etc/mtab",0,0 ) ; chmod( "/etc/mtab",S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH ) ; mnt_unlock_file( lock ) ; h = 0 ; } endmntent( f ) ; mnt_free_lock( lock ) ; return h ; }
/** * mnt_update_table: * @upd: update * @lc: lock or NULL * * High-level API to update /etc/mtab (or private /run/mount/utab file). * * The @lc lock is optional and will be created if necessary. Note that * the automatically created lock blocks all signals. * * See also mnt_lock_block_signals() and mnt_context_get_lock(). * * Returns: 0 on success, negative number on error. */ int mnt_update_table(struct libmnt_update *upd, struct libmnt_lock *lc) { struct libmnt_lock *lc0 = lc; int rc = -EINVAL; assert(upd); if (!upd->filename || !upd) return -EINVAL; if (!upd->ready) return 0; DBG(UPDATE, mnt_debug_h(upd, "%s: update tab", upd->filename)); if (upd->fs) { DBG(UPDATE, mnt_fs_print_debug(upd->fs, stderr)); } if (!lc) { lc = mnt_new_lock(upd->filename, 0); if (lc) mnt_lock_block_signals(lc, TRUE); } if (lc && upd->userspace_only) mnt_lock_use_simplelock(lc, TRUE); /* use flock */ if (!upd->fs && upd->target) rc = update_remove_entry(upd, lc); /* umount */ else if (upd->mountflags & MS_MOVE) rc = update_modify_target(upd, lc); /* move */ else if (upd->mountflags & MS_REMOUNT) rc = update_modify_options(upd, lc); /* remount */ else if (upd->fs) rc = update_add_entry(upd, lc); /* mount */ upd->ready = FALSE; DBG(UPDATE, mnt_debug_h(upd, "%s: update tab: done [rc=%d]", upd->filename, rc)); if (lc != lc0) mnt_free_lock(lc); return rc; }