Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

fuser(2)  —  System Calls

NAME

fuser − Reports PIDs and UIDs for files, file systems and/or the devices attached to them. 

SYNOPSIS

#include <sys/fuser.h>

int fuser (
     char ∗file,
     long flag,
     struct f_user fuser_array[],
     long sizeof_fuser_array );

PARAMETERS

fileSpecifies the file name. 

flagSpecifies one of the following values.  If none of the following are values are specified, the default is to match open files. 

F_FILE_ONLY
Matches only file ids.

F_CONTAINED
Provides mount point matching.

fuser_array
Specifies the array.

sizeof_fuser_array
Specifies the size of the fuser array. 

DESCRIPTION

The fuser function reports a list of PIDs and UIDs that are associated with a specified file, file system, and/or the devices that are attached to them. 

The fuser function can report back additional information about "matches" by ORing one of the following constants that can be passed back in the member fu_flags:

F_CDIRCurrent directory

F_RDIRCurrent directory

F_PDIRParent of the current directory

F_OPENAt least one file open, but the number open is not known. 

F_TTYControlling terminal

F_TRACETrace

EXAMPLES

Open regular files and special files are matched using the flag parameter set at 0L. Thus, if process 127 and 3220 open the /home/try file simultaneously and the fuser function is active, the PIDs and UIDs associated with the home/try file are reported as in the following example:

fuser("/home/try", 0L, fuser_array, (long) sizeof (fuser_array));

Similarly, if the special device file /dev/ttyp2 is open by process 32, then that PID and its associated UID are reported as in the following example:

fuser("/dev/ttyp2", 0L, fuser_array, (long) sizeof (fuser_array));

RETURN VALUES

On success, the fuser function returns the number of fuser_array elements that were found. The contents of the structure are as follows: typedef struct  f_user {
        pid_t   fu_pid;
        int     fu_flags;
        uid_t   fu_uid;
} f_user_t;

If an error is encountered, the fuser function returns -1 if the file parameter specified does not exist or if the fuser_array structure can not be filled. The fuser function stops trying if the array is not large enough to hold the next match return information. 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026