From 6a62053893b3fe56ec4d564e282ed168a683f3fe Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 20 Dec 2000 03:39:08 +0000 Subject: [PATCH] fuser doesnt use losetup --- ChangeLog | 3 ++- README | 4 ++++ src/fuser.c | 25 +++++++++++-------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 581db79..c6b14a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,8 @@ Changes from 19 to 20 (14-DEC-2000) - License changed to GPL - signames.h generated better (suggested by Grant Erickson) - uses getopt() for better command line stuff - - makes less assumptions about pcess name, closes Debian Bug #53337 + - makes less assumptions about process name, closes Debian Bug #53337 + - Doesn't use losetup for loop deivces in fuser. Changes from version 18 to 19 (25-OCT-1999) ============================= diff --git a/README b/README index 34a6f82..7ae8370 100644 --- a/README +++ b/README @@ -12,3 +12,7 @@ This package contains four little utilities that use the proc FS: They should work with most recent kernels. Man pages are included. - Werner Almesberger + +src/loop.h was stolen from util-linux package which in turn stole it from +the Linux kernel. + diff --git a/src/fuser.c b/src/fuser.c index a5ddf8f..8834a3c 100644 --- a/src/fuser.c +++ b/src/fuser.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include /* for LOOP_MAJOR */ #include "comm.h" +#include "loop.h" /* for loop_info */ #include "signals.h" @@ -418,7 +420,6 @@ scan_mounts (void) FILE *file; struct stat st_dev, st_parent, st_mounted; char line[MAX_LINE + 1], path[PATH_MAX + 1], mounted[PATH_MAX + 3]; - char tmp[MAX_LINE + 1]; char *end; if (!(file = fopen (PROC_BASE "/mounts", "r"))) @@ -432,19 +433,15 @@ scan_mounts (void) continue; /* might be NFS or such */ if (S_ISBLK (st_dev.st_mode) && MAJOR (st_dev.st_rdev) == LOOP_MAJOR) { - FILE *pipe; - - sprintf (tmp, "losetup %s", path); - if (!(pipe = popen (tmp, "r"))) - fprintf (stderr, "popen(%s) failed\n", tmp); - else - { - int dev, ino; - - if (fscanf (pipe, "%*s [%x]:%d", &dev, &ino) == 2) - add_other (it_loop, dev, dev, ino, path); - (void) fclose (pipe); - } + struct loop_info loopinfo; + int fd; + + if ((fd = open(path, O_RDWR)) > 0) { + if (ioctl(fd, LOOP_GET_STATUS, &loopinfo) >= 0) { + add_other(it_loop,loopinfo.lo_device,loopinfo.lo_device,loopinfo.lo_inode,path); + } + (void) close(fd); + } } if (stat (mounted, &st_mounted) < 0) { -- 2.40.0