forked from pool/psmisc
82 lines
2.2 KiB
Diff
82 lines
2.2 KiB
Diff
Use string comparision only if case of searching for NFS shares
|
|
|
|
---
|
|
src/fuser.c | 29 +++++++++++++++++++++--------
|
|
src/fuser.h | 2 +-
|
|
2 files changed, 22 insertions(+), 9 deletions(-)
|
|
|
|
--- src/fuser.c
|
|
+++ src/fuser.c 2017-06-20 14:30:08.176217649 +0000
|
|
@@ -2007,6 +2007,7 @@ static void clear_mntinfo(void)
|
|
|
|
static void init_mntinfo(void)
|
|
{
|
|
+ char type[256];
|
|
char mpoint[PATH_MAX*4 + 1]; // octal escaping takes 4 chars per 1 char
|
|
int mid, parid, max = 0;
|
|
uint maj, min;
|
|
@@ -2018,8 +2019,8 @@ static void init_mntinfo(void)
|
|
if ((mnt = fopen("/proc/self/mountinfo", "r")) == (FILE *) 0)
|
|
return;
|
|
while (fscanf
|
|
- (mnt, "%i %i %u:%u %*s %s %*[^\n]", &mid, &parid, &maj, &min,
|
|
- &mpoint[0]) == 5) {
|
|
+ (mnt, "%i %i %u:%u %*s %s %*s %*s - %s %*[^\n]",
|
|
+ &mid, &parid, &maj, &min, &mpoint[0], &type[0]) == 6) {
|
|
const size_t nlen = strlen(mpoint);
|
|
mntinfo_t *restrict mnt;
|
|
if (posix_memalign
|
|
@@ -2038,6 +2039,9 @@ static void init_mntinfo(void)
|
|
mnt->parid = parid;
|
|
mnt->dev = makedev(maj, min);
|
|
mnt->id = mid;
|
|
+ if (strncmp("nfs", type, 3) == 0)
|
|
+ mnt->nfs = 1;
|
|
+ else mnt->nfs = 0;
|
|
if (mid > max)
|
|
max = mid;
|
|
}
|
|
@@ -2105,16 +2109,25 @@ static int mntstat(const char *path, str
|
|
if (nlen < mnt->nlen)
|
|
continue;
|
|
if (mnt->nlen == 1) { /* root fs is the last entry */
|
|
- buf->st_dev = mnt->dev;
|
|
- buf->st_ino = 0;
|
|
- return 0;
|
|
+ if (mnt->nfs) {
|
|
+ fprintf(stderr, "NFS %s\n", use);
|
|
+ buf->st_dev = mnt->dev;
|
|
+ buf->st_ino = 0;
|
|
+ return 0;
|
|
+ }
|
|
+ errno = 0;
|
|
+ return stat(path, buf);
|
|
}
|
|
if (use[mnt->nlen] != '\0' && use[mnt->nlen] != '/')
|
|
continue;
|
|
if (strncmp(use, mnt->mpoint, mnt->nlen) == 0) {
|
|
- buf->st_dev = mnt->dev;
|
|
- buf->st_ino = 0;
|
|
- return 0;
|
|
+ if (mnt->nfs) {
|
|
+ buf->st_dev = mnt->dev;
|
|
+ buf->st_ino = 0;
|
|
+ return 0;
|
|
+ }
|
|
+ errno = 0;
|
|
+ return stat(path, buf);
|
|
}
|
|
}
|
|
errno = ENOENT;
|
|
--- src/fuser.h
|
|
+++ src/fuser.h 2017-06-20 14:28:48.013689702 +0000
|
|
@@ -91,7 +91,7 @@ struct mount_list {
|
|
# include "lists.h"
|
|
typedef struct mntinfo_s {
|
|
list_t this;
|
|
- int id, parid;
|
|
+ int id, parid, nfs:1;
|
|
dev_t dev;
|
|
size_t nlen;
|
|
char *mpoint;
|