Previous | Table of Contents | Next

Page 869

SEE ALSO

link(2), unlink(2), rename(2), open(2), lstat(2), ln(1), link(8)

Linux, 24 July 1993

sync

sync—Commits buffer cache to disk

SYPNOSIS

#include <unistd.h>
int sync(void);

DESCRIPTION

sync first commits inodes to buffers, and then buffers to disk.

RETURN VALUE

sync always returns 0.

CONFORMS TO

SVID, AT&T, X/OPEN, BSD 4.3

BUGS

According to the standard specification (for example, SVID), sync() schedules the writes, but it might return before the actual writing is done. However, since version 1.3.20, Linux does actually wait. (This still does not guarantee data integrity; modern disks have large caches.)

SEE ALSO

bdflush(2), fsync(2), fdatasync(2), update(8), sync(8)

Linux 1.3.88, 15 April 1995

sysctl

sysctl—Reads/writes system parameters

SYPNOSIS

#include <unistd.h>
#include <linux/unistd.h>
#include <linux/sysctl.h>
_syscall1(int_sysctl, struct __sysctl_args *args);
int sysctl(struct __sysctl_args *args);

DESCRIPTION

The sysctl call reads and/or writes kernel parameters—for example, the hostname or the maximum number of open files. The argument has the form

struct __sysctl__args {
    int *name; /* integer vector describing variable */
    int nlen; /* length of this vector */
    void *oldval; /* 0 or address where to store old value */
    size_t *oldlenp; /* available room for old value,

Page 870

        overwritten by actual size of old value */
    void *newval; /* 0 or address of new value */
    size_t newlen; /* size of new value */
};

This call does a search in a tree structure, possibly resembling a directory tree under /proc/sys, and, if the requested item is found, calls some appropriate routine to read or modify the value.

Example

#include <linux/unistd.h>
#include <linux/types.h>
#include <linux/sysctl.h>

_syscall1(int, _sysctl, struct __sysctl args *, args);
int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
        void *newval, size_t newlen)
{
    struct __sysctl__args args={name,nlen,oldval,oldlenp,newval,newlen};
    return _sysctl(&args);
}

#define SIZE(x) sizeof(x)/sizeof(x[0])
#define OSNAMESZ 100

char osname[OSNAMESZ];
int osnamelth;
int name[] = { CTL_KERN, KERN_OSTYPE };

main(){
    osnamelth = SIZE(osname);
    if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
        perror("sysctl");
    else
        printf("This machine is running %*s\n", osnamelth, osname);
    return 0;
}

RETURN VALUES

Upon successful completion, sysctl returns 0. Otherwise, a value of _1 is returned, and errno is set to indicate the error.

ERRORS

ENOTDIR name was not found.
EPERM No search permission for one of the encountered directories, or no read permission where oldval was nonzero, or no write permission where newval was nonzero.
EFAULT The invocation asked for the previous value by setting oldval non-NULL, but allowed zero room in oldlenp.

CONFORMS TO

This call is Linux specific.

HISTORY

A sysctl call has been present in Linux since version 1.3.57. It originated in BSD-4.4. Only Linux has the /proc/sys mirror, and the object-naming schemes differ between Linux and BSD 4.4, but the declaration of the sysctl(2) function is the same in both.

Page 871

BUGS

Not all available objects are properly documented.

It is not yet possible to change operating system by writing to /proc/sys/kernel/ostype.

SEE ALSO

proc(5)

Linux 1.3.85, 11 April 1996

sysfs

sysfs—Gets filesystem type information

SYPNOSIS

int sysfs(int option, const char * fsname);
int sysfs(int option, unsigned int fs_index, char * buf);
int sysfs(int option);

DESCRIPTION

sysfs returns information about the filesystem types currently present in the kernel. The specific form of the sysfs call and the information returned depend on the option in effect. You can

  • Translate the filesystem identifier string fsname into a filesystem type index.
  • Translate the filesystem type index fs_index into a null-terminated filesystem identifier string. This string will be written to the buffer pointed to by buf. Make sure that buf has enough space to accept the string.
  • Return the total number of filesystem types currently present in the kernel.

The numbering of the filesystem type indexes begins with 0.

RETURN VALUE

On success, sysfs returns the filesystem index for the first option, 0 for the second option, and the number of currently configured filesystems for the third option. On error, _1 is returned, and errno is set appropriately.

ERRORS

EINVAL fsname is not a valid filesystem type identifier; fs_index is out of bounds; option is invalid.
EFAULT Either fsname or buf is outside your accessible address space.

CONFORMS TO

System V

Linux 1.3.16, 9 August 1995

sysinfo

sysinfo—Returns information on overall system statistics

SYPNOSIS

As of Linux 0.99.10 and image release 4.4,

#include <linux/kernel.h>
#include <linux/sys.h>
int sysinfo(struct sysinfo *info);

Page 872

DESCRIPTION

sysinfo returns information in the following structure:

struct sysinfo {
     long uptime;              /* Seconds since boot */
     unsigned long loads[3];   /* 1, 5, and 15 minute load averages */
     unsigned long totalram;   /* Total usable main memory size */
     unsigned long freeram;    /* Available memory size */
     unsigned long sharedram;  /* Amount of shared memory */
     unsigned long bufferram;  /* Memory used by buffers */
     unsigned long totalswap;  /* Total swap space size */
     unsigned long freeswap;   /* swap space still available */
     unsigned short procs;     /* Number of current processes */
     char _f[22];              /* Pads structure to 64 bytes */
};

sysinfo provides a simple way of getting overall system statistics. This is more portable than reading /dev/kmem.

RETURN VALUE

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

ERRORS

EFAULT The pointer to struct sysinfo is invalid.

CONFORMS TO

This function is Linux specific.

BUGS

The Linux DLL 4.4.1 libraries do not contain a proper prototype for this function.

Linux 0.99.10, 24 July 1993

syslog

syslog—Reads and/or clears kernel message ring buffer; sets console_loglevel

SYPNOSIS

#include <unistd.h>
#include <linux/unistd.h>
_syscall3(int syslog, int type, char *bufp, int len);
int syslog(int type, char *bufp, int len);

DESCRIPTION

This is probably not the function you are interested in. Look at syslog(3) for the C library interface. This page only documents the bare kernel system call interface.

The type argument determines the action taken by syslog.

From kernel/printk.c:/*

Valid commands to syslog are

0—Close the log. Currently a NOP.

1—Open the log. Currently a NOP.

2—Read from the log.

Previous | Table of Contents | Next

1