Previous | Table of Contents | Next

Page 862

socketcall

socketcall—Socket system calls

SYPNOSIS

int socketcall(int call, unsigned long *args);

DESCRIPTION

socketcall is a common kernel entry point for the socket system calls. call determines which socket function to invoke. args points to a block containing the actual arguments, which are passed through to the appropriate call.

User programs should call the appropriate functions by their usual names. Only standard library implementors and kernel hackers need to know about socketcall.

SEE ALSO

accept(2), bind(2), connect(2), getpeername(2), getsockname(2), getsockopt(2), listen(2), recv(2), recvfrom(2), send(2), sendto(2), setsockopt(2), shutdown(2), socket(2), socketpair(2)

Linux 1.2.4, 15 April 1995

socketpair

socketpair—Creates a pair of connected sockets

SYPNOSIS

#include <sys/types.h>
#include <sys/socket.h>
int socketpair(int d, int type, int protocol, int sv[2]);

DESCRIPTION

The call creates an unnamed pair of connected sockets in the specified domain d, of the specified type, and using the optionally specified protocol. The descriptors used in referencing the new sockets are returned in sv[0] and sv[1]. The two sockets are indistinguishable.

RETURN VALUE

On success, 0 is returned. On error, _1 is returned, and errno is set appropriately.

ERRORS

EMFILE Too many descriptors are in use by this process.
EAFNOSUPPORT The specified address family is not supported on this machine.
EPROTONOSUPPORT The specified protocol is not supported on this machine.
EOPNOSUPPORT The specified protocol does not support creation of socket pairs.
EFAULT The address sv does not specify a valid part of the process's address space.

HISTORY

The socketpair function call appeared in BSD 4.2.

BUGS

This call is currently implemented only for the UNIX domain.

Page 863

SEE ALSO

read(2), write(2), pipe(2)

BSD Man Page, 24 July 1993

stat, fstat, lstat

stat, fstat, lstat—Get file status

SYPNOSIS

#include <sys/stat.h>
#include <unistd.h>
int stat(const char *file_name,struct stat *buf);
int fstat(int filedes,struct stat *buf);
int lstat(const char *file_name, struct stat *buf);

DESCRIPTION

These functions return information about the specified file. You do not need any access rights to the file to get this information, but you need search rights to all directories named in the path leading to the file.

stat stats the file pointed to by file_name and fills in buf.

lstat is identical to stat, except that the link itself is stated, not the file that is obtained by tracing the links.

fstat is identical to stat, except that the open file pointed to by filedes (as returned by open(2)) is stated in place of file_name.

They all return a stat structure, which is declared as follows:

struct stat
{
    dev_t             st_dev;         /* device */
    ino_t             st_ino;         /* inode */
    umode_t           st_mode;        /*protection */
    nlink_t           st_nlink;       /* number of hard links */
    uid_t             st_uid;         /* user ID of owner */
    gid_t             st_gid;         /* group ID of owner */
    dev_t             st_rdev;        /* device type (if inode device) */
    off_t             st_size;        /* total size, in bytes */
    unsigned long     st_blksize;     /* blocksize for filesystem I/O */
    unsigned long     st_blocks;      /* number of blocks allocated */
    time_t            st_atime;       /* time of last access */
    time_t            st_mtime;       /* time of last modification */
    time_t            st_ctime;       /* time of last change */
};

Note that st_blocks may not always be in terms of blocks of size st_blksize, and that st_blksize may instead provide a notion of the "preferred" block size for efficient filesystem I/O.

Not all the Linux filesystems implement all the time fields. Traditionally, st_atime is changed by mknod(2), utime(2), read(2), write(2), and truncate(2).

Traditionally, st_mtime is changed by mknod(2), utime(2), and write(2). st_mtime is not changed for changes in owner, group, hard link count, or mode.

Traditionally, st_ctime is changed by writing or by setting inode information (that is, owner, group, link count, mode, and so on).

Page 864

The following macros are defined to check the file type:

S_ISLNK(m) Is it a symbolic link?
S_ISREG(m) Is it a regular file?
S_ISDIR(m) Is it a directory?
S_ISCHR(m) Is it a character device?
S_ISBLK(m) Is it a block device?
S_ISFIFO(m) Is it fifo?
S_ISSOCK(m) Is it a socket?

The following flags are defined for the st_mode field:

S_IFMT 00170000 Bitmask for the file type bitfields
S_IFSOCK 0140000 Socket
S_IFLNK 0120000 Symbolic link
S_IFREG 0100000 Regular file
S_IFBLK 0060000 Block device
S_IFDIR 0040000 Directory
S_IFCHR 0020000 Character device
S_IFIFO 0010000 Fifo
S_ISUID 0004000 Set UID bit
S_ISGID 0002000 Set GID bit
S_ISVTX 0001000 Sticky bit
S_IRWXU 00700 User (file owner) has read, write, and execute permission
S_IRUSR (S_IREAD) 00400 User has read permission
S_IWUSR (S_IWRITE) 00200 User has write permission
S_IXUSR (S_IEXEC) 00100 User has execute permission
S_IRWXG 00070 Group has read, write, and execute permission
S_IRGRP 00040 Group has read permission
S_IWGRP 00020 Group has write permission
S_IXGRP 00010 Group has execute permission
S_IRWXO 00007 others have read, write, and execute permission
S_IROTH 00004 Others have read permission
S_IWOTH 00002 Others have write permission
S_IXOTH 00001 Others have execute permission

RETURN VALUE

On success, 0 is returned. On error, _1 is returned, and errno is set appropriately.

ERRORS

EBADF filedes is bad.
ENOENT File does not exist.

CONFORMS TO

SVID (not lstat()), AT&T (not lstat()), POSIX (not lstat()), X/OPEN (not lstat()), BSD 4.3

SEE ALSO

chmod(2), chown(2), readlink(2), utime(2)

Linux 1.1.75, 1 January 1995

Page 865

statfs, fstatfs

statfs, fstatfs—Get filesystem statistics

SYPNOSIS

#include <sys/vfs.h>
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);

DESCRIPTION

statfs returns information about a mounted filesystem. path is the pathname of any file within the mounted filesystem. buf is a pointer to a statfs structure defined as follows:

struct statfs {
    long     f_type;        /* type of filesystem (see below) */
    long     f_bsize;       /* optimal transfer block size */
    long     f_blocks;      /* total data blocks in filesystem */
    long     f_bfree;       /* free blocks in fs */
    long     f_bavail;      /* free blocks avail to non-superuser */
    long     f_files;       /* total file nodes in filesystem */
    long     f_ffree;       /* free file nodes in fs */
    fsid_t   f_fsid;        /* filesystem id */
    long     f_namelen;     /* maximum length of filenames */
    long     f_spare[6];    /* spare for later */
};

Filesystem types:

linux/ext2_fs.h:   EXT2_OLD_SUPER_MAGIC  0xEF51
linux/ext2_fs.h:   EXT2_SUPER_MAGIC      0xEF53
linux/ext_fs.h:    EXT_SUPER_MAGIC       0x137D
linux/iso_fs.h:    ISOFS_SUPER_MAGIC     0x9660
linux/minix_fs.h:  MINIX_SUPER_MAGIC     0x137F /* orig. minix */
linux/minix_fs.h:  MINIX_SUPER_MAGIC2    0x138F /* 30 char minix */
linux/minix_fs.h:  NEW_MINIX_SUPER_MAGIC 0x2468 /* minix V2 */
linux/msdos_fs.h:  MSDOS_SUPER_MAGIC     0x4d44
linux/nfs_fs.h:    NFS_SUPER_MAGIC       0x6969
linux/proc_fs.h:   PROC_SUPER_MAGIC      0x9fa0
linux/xia_fs.h:    XIAFS_SUPER_MAGIC     0x012FD16D

Fields that are undefined for a particular filesystem are set to _1. fstatfs returns the same information about an open file referenced by descriptor fd.

RETURN VALUE

On success, 0 is returned. On error, _1 is returned, and errno is set appropriately.

ERRORS

For statfs:
ENOTDIR A component of the path prefix of path is not a directory.
EINVAL path contains a character with the high-order bit set.
ENAMETOOLONG The length of a component of path exceeds 255 characters, or the length of path exceeds 1,023 characters.
ENOENT The file referred to by path does not exist.
EACCES Search permission is denied for a component of the path prefix of path.
ELOOP Too many symbolic links were encountered in translating path.

Previous | Table of Contents | Next

1