umount.c revision e3478379751fda30316204c68112b5a2b9ffd5a7
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 ProFUSION embedded systems
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <libudev.h>
#include "list.h"
#include "mount-setup.h"
#include "umount.h"
#include "util.h"
typedef struct MountPoint {
char *path;
bool read_only;
} MountPoint;
MountPoint *mp;
return NULL;
return mp;
}
static void mount_point_remove_and_free(MountPoint *mount_point, MountPoint **mount_point_list_head) {
}
while (*mount_point_list_head)
}
char *path, *p;
unsigned int i;
int r;
return -errno;
for (i = 1;; i++) {
int k;
MountPoint *mp;
if ((k = fscanf(proc_self_mountinfo,
"%*s " /* (1) mount id */
"%*s " /* (2) parent id */
"%*s " /* (3) major:minor */
"%*s " /* (4) root */
"%ms " /* (5) mount point */
"%*s" /* (6) mount options */
"%*[^-]" /* (7) optional fields */
"- " /* (8) separator */
"%*s " /* (9) file system type */
"%*s" /* (10) mount source */
"%*s" /* (11) mount options 2 */
"%*[^\n]", /* some rubbish at the end */
&path)) != 1) {
if (k == EOF)
break;
log_warning("Failed to parse /proc/self/mountinfo:%u.", i);
continue;
}
if (mount_point_is_api(path)) {
continue;
}
r = -ENOMEM;
goto finish;
}
if (!(mp = mount_point_alloc(p))) {
r = -ENOMEM;
goto finish;
}
}
r = 0;
return r;
}
unsigned int i;
int r;
return -errno;
for (i = 2;; i++) {
int k;
if ((k = fscanf(proc_swaps,
"%*s " /* type of swap */
"%*s " /* swap size */
"%*s " /* used */
"%*s\n", /* priority */
&dev)) != 1) {
if (k == EOF)
break;
log_warning("Failed to parse /proc/swaps:%u.", i);
continue;
}
continue;
}
if (!d) {
r = -ENOMEM;
goto finish;
}
swap = mount_point_alloc(d);
if (!swap) {
free(d);
r = -ENOMEM;
goto finish;
}
}
r = 0;
return r;
}
int r;
struct udev_enumerate *e = NULL;
r = -ENOMEM;
goto finish;
}
if (!(e = udev_enumerate_new(udev))) {
r = -ENOMEM;
goto finish;
}
if (udev_enumerate_add_match_subsystem(e, "block") < 0) {
r = -EIO;
goto finish;
}
if (udev_enumerate_add_match_sysname(e, "loop*") < 0) {
r = -EIO;
goto finish;
}
if (udev_enumerate_scan_devices(e) < 0) {
r = -EIO;
goto finish;
}
MountPoint *lb;
char *loop;
if (!loop) {
r = -ENOMEM;
goto finish;
}
if (!lb) {
r = -ENOMEM;
goto finish;
}
}
r = 0;
if (e)
return r;
}
static int delete_loopback(const char *device) {
int fd, r;
errno = 0;
return 0;
}
return -errno;
}
r = errno;
if (r == ENXIO) /* not bound, so no error */
r = 0;
errno = r;
return -errno;
}
int failed = 0;
continue;
/* Trying to umount. Forcing to umount if busy (only for NFS mounts) */
else {
failed++;
}
}
return failed;
}
int failed = 0;
continue;
/* Trying to remount read-only */
} else {
failed++;
}
}
return failed;
}
int failed = 0;
else {
failed++;
}
}
return failed;
}
int failed = 0;
else {
failed++;
}
}
return failed;
}
int umount_all(void) {
int r;
if (r < 0)
goto end;
if (r <= 0)
goto end;
end:
return r;
}
int swapoff_all(void) {
int r;
r = swap_list_get(&swap_list_head);
if (r < 0)
goto end;
end:
return r;
}
int loopback_detach_all(void) {
int r;
if (r < 0)
goto end;
end:
return r;
}