⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file system4.txt

📁 linux函数大全 linux函数大全 linux函数大全
💻 TXT
字号:
link

SYNOPSIS
int link(const char *src, const char *new); 


PARAMETERS
src: [in] points the the file we want to add a link to. 

new: [in] points to the path for the new link. 

DESCRIPTION
Creates a new (hard) link to a file. There is no way to distinguish the links. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EPERM: the file system does not support hard links or oldpath is the . or .. entry of a 
directory. 
EXDEV, EFAULT, EACCESS, ENAMETOOLONG, ENOENT, ENOTDIR, ENOMEM, EROFS, EEXIST, EMLINK, ELOOP
and ESPC.

****************************************************************************************
lseek

SYNOPSIS
off_t lseek(int fd, off_t offset, int whence); 


PARAMETERS
fd: [in] the file descriptor to manipulate. 

offset: [in] the offset modificator. 

whence: [in] indicates how to modify the offset. 


DESCRIPTION
Changes the read/write file offset of a file descriptor. The offset parameter is interpreted
according to the possible following values of whence: 


SEEK_SET 
the new file offset will be offset. 

SEEK_CUR 
the new file offset will be the current offset plus offset. 

SEEK_END 
the new file offset will be the end of the file plus offset. 
If we seek past the end of a file, the new file region contain 0. 


RETURN VALUE
On success, the call returns the new file offset. On errror, it returns -1 and sets errno 
to one of the following values: 


EINVAL: whence does not have a valid value. 
EBADF.


****************************************************************************************
mkdir

SYNOPSIS
int mkdir(const char *path, mode_t mode); 


PARAMETERS
path: [in] points to the path of the new directory. 

mode: [in] the access bits of the new directory. 

DESCRIPTION
Creates a new directory. The uid of the new directory is the same as the effective uid of 
the calling task. The gid of the new directory is the same as its parent directory. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EINVAL: the path contains a character not in the ASCII [0,127] range. 
ENOTDIR, ENAMETOOLONG, ENOENT, EACCESS, ELOOP, EPERM, EROFS, EEXIST, ENOSPC, EDQUOT, EIO and
EFAULT.


****************************************************************************************
mknod

SYNOPSIS
int mknod(const char *path, mode_t mode, dev_t dev); 


PARAMETERS
path: [in] points to the path of the new file. 

mode: [in] specifies the kind of special file to create. (Do not use it to specify the 
	access bits of the file.) 

dev: [in] the major and minor numbers of the new device. 


DESCRIPTION
Creates a special device file node. Only tasks with superuser privileges may use this call.
The access bits of the new file are the same as those of the umask of the current task. If 
mode does not specify a special device file, then dev is ignored. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EINVAL: the path contains a caracter that is outside the range [0,127]. 
EPERM: the calling process does not have superuser privileges. 
ENOTDIR, ENAMETOOLONG, ENOENT, EACCESS, ELOOP, EIO, ENOSPC, EDQUOT, EROFS, EEXIST and 
EFAULT.



****************************************************************************************
mount and umount

SYNOPSIS
int mount(const char *specialfile, const char *dir, const char *filesystemtype,unsigned long
rwflag, const void *data); 

int umount(const char *specialfile); 


PARAMETERS
specialfile: [in] points to the path of the file system to mount. 

dir: [in] points to the directory where to mount the file system. 

filesystemtype: [in] the type of file system. 

rwflag: [in] specifies read/write accesses to the file system. 

data: [in] fs dependent parameters. 


DESCRIPTION
mount mounts the file system and umount unmounts it. Only a task with superuser privileges 
may call those two syscalls. 

The rwflag parameter may take the one or more of following or'ed values: 


MS_RDONLY 
mount read-only. 

MS_NOSUID 
ignore suid and sgid bits. 

MS_NODEV 
disallow access to device special files. 

MS_NOEXEC 
disallow program execution. 

MS_SYNC 
writes are synced at once. 

MS_REMOUNT 
alter flags of a mounted FS. 

RETURN VALUE

EPERM, ENODEV, ENOTBLK, ENXIO, EMFILE, EFAULT, ENOMEM, EINVAL, EBUSY, ENOTDIR, ENOENT, 
ENAMETOOLONG, ELOOP, EROFS.


****************************************************************************************
pipe

SYNOPSIS
int pipe(int filedes[2]); 

PARAMETERS
filedes: [out] the array containing the end points. 

DESCRIPTION
Creates a pair of pipe end points. The flow is from filedes[1] to filedes[0]. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EMFILE, ENFILE and EFAULT.


****************************************************************************************
read

SYNOPSIS
int read(int fd, char *buf, size_t count); 


PARAMETERS
fd: [in] the file descriptor to read from. 

buf: [out] the buffer that will contain information read. 

count: [in] the maximal size of buf. 


DESCRIPTION
Reads up to count bytes into buf from fd. 


RETURN VALUE
On success zero is returned. On error, -1 is returned and errno is set to one of the 
following values: 


EINVAL: fd cannot be read. 
EINTR, EAGAIN, EISDIR, EBADF and EFAULT. 



****************************************************************************************
readdir

SYNOPSIS
struct dirent *readdir(DIR *dir); 


PARAMETERS
dir: [in] the file descriptor of a directory. 


DESCRIPTION
This call returns in a dirent structure the next entry of a directory or NULL if the end is
reached or an error occurs. The area where the pointer returned by readdir points to is a 
static space that is overwritten by subsequent calls to readdir. 

(It there no way to implement that call in user space???) 


RETURN VALUE
On success, returns a pointer to the dirent structure. On error, returns -1 and sets errno 
to the following value: EBADF.


****************************************************************************************
readlink

SYNOPSIS
int readlink(const char *path, char *buf, size_t bufsiz); 


PARAMETERS
path: [in] points to the symlink to read. 

buf: [out] points to the buffer where to put the information. 

bufsiz: [in] the maximum size of the buffer. 


DESCRIPTION
Reads the content of a symlink. 


RETURN VALUE
On success, returns the number of bytes read. On error, returns -1 and sets errno to one of
the following value: 


EINVAL: the path contains a character outside the [0,127] range or the file is not a 
symlink. 
ENOTDIR, ENAMETOOLONG, ENOENT, EACCESS, ELOOP, EIO or EFAULT.


****************************************************************************************
rename

SYNOPSIS
int rename(const char *src, const char *dest); 


PARAMETERS
src: [in] the file to more/rename. 

dest: [in] the new name or place for the file. 


DESCRIPTION
Renames and move files. The destination is overwriten if it already exists. 


RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EISDIR: newpath is an existing directory, but src is not. 
EPERM: the directory containing src and the task's effective uid is not equal to the uid of
	 the file or the directory containing it, or the file system does not support 
	renaming. 
EXDEV, ENOTEMPTY, EMLINK, ENOTDIR, EFAULT, EACCESS, ENAMETOOLONG, ENOENT, ENOMEM, EROFS, 
ELOOP or ENOSPC.

****************************************************************************************
rmdir

SYNOPSIS
int rmdir(const char *path); 

PARAMETERS
path: [in] points to path of directory to remove. 


DESCRIPTION
Removes a directory. The directory to be removed must be empty. 


RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EPERM: the file system does not support directory removal, or the directory containing path
and the task's effective uid is not equal to the uid of the file or the directory containing
it. 
EFAULT, EACCESS, ENAMETOOLONG, ENOENT, ENOTDIR, ENOTEMPTY, EBUSY, ENOMEM, EROFS or ELOOP.



****************************************************************************************
select

SYNOPSIS
int select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval 
		*timeout); 

Macro utilities: 

FD_CLR(int fd, fd_set *set); 

FD_ISSET(int fd, fd_set *set); 

FD_SET(int fd, fd_set *set); 

FD_ZERO(fd_set *set); 


PARAMETERS
numfds: [in] the number of file descriptors to watch. 

readfds: [in out] on entry, the file descriptor to watch for readability. On exit, the file
	descriptors that are readable. 

writefds: [in out] on entry, the file descriptors to watch for writability. On exit, the 
	file descriptors that are writable. 

exceptfds: [in out] on entry, the file descriptor to watch exceptions. On exit, the file 
	descriptors have exceptions raised. 

timeout: [in out] on entry, the timeout value. On return, contains the remaining time. 


DESCRIPTION
Makes the calling task sleep until some conditions on the file descriptors become true or 
until a timeout value expires. There are three conditions for which files may be tested: 


with readfds: Can the file be read? 
with writefds: Can the file be written? 
with exceptfds: Is there any exception pending on the file? 
Whenever one of the conditions on one the specified files is true, the call returns. 

There are four utilities provided for manipulation of the file descriptor sets: 


FD_SET 
sets the specified file descriptor flag. 

FD_CLR 
clears the specified file descriptor flag. 

FD_ZERO 
clears the set. 

FD_ISSET 
returns true if the file descriptor flag is set. 

RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EBADF, EINTR, EINVAL or ENOMEM



****************************************************************************************
symlink

SYNOPSIS
int symlink(const char *src, const char *dest); 

PARAMETERS
src: [in] the new link. 

dest: [in] the file to point to. 


DESCRIPTION
Creates a symlink form src to dest. The destination does not need to exist at the time of 
the creation of the link. 


RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EPERM: the file system does not support symlinks. 
EFAULT, EACCESS, ENAMETOOLONG, ENOENT, ENOTDIR, ENOMEM, EROFS, EEXIST, ELOOP, ENOSPC.

****************************************************************************************
sync

SYNOPSIS
int sync(void); 


DESCRIPTION
Brings the hard disk state of the file system in sync with the internal state of the file 
system. 


RETURN VALUE
Always zero. 


****************************************************************************************
umask

SYNOPSIS
int umask(int mask); 

PARAMETERS
mask: [in] the new mask. 


DESCRIPTION
Sets the umask value to mask&0777. 


RETURN VALUE
The previous value of the mask.


****************************************************************************************
unlink

SYNOPSIS
int unlink(const char *path); 

PARAMETERS
path: [in] points to the path of the file to unlink. 


DESCRIPTION
Deletes a link to a file. If the file is not used and it was the last link, the file is also
deleted. 


RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EPERM: the directory has the stiky bit on but the calling taks uid does not match the file 
uid or the directory uid. 
EFAULT, EACCESS, ENAMETOOLONG, ENOENT, ENOTDIR, EISDIR, ENOMEM, EROFS.


****************************************************************************************
utime

SYNOPSIS
int utime(const char *filename, struct utimbuf *buf); 


PARAMETERS
filename: [in] points to the path of the file to change. 

buf: [in] points to the new times. 


DESCRIPTION
Changes the access and modification times of a inode. The utimbuf structure has the 
following layout: 


struct utimbuf {
        time_t actime;  /* access time */
        time_t modtime; /* modification time */
};

If buf is NULL the times are set to the current time. 


RETURN VALUE
On success, returns zero. On error, returns -1 and sets errno to one of the following value: 


EROFS, ENOTDIR, ENOENT, EFAULT, ENAMETOOLONG, ELOOP, EACCESS, EPERM.


****************************************************************************************
write

SYNOPSIS
size_t write(int fd, const char *buf, size_t count); 

PARAMETERS
fd: [in] the file descriptor to read from. 

buf: [out] the buffer where to store the data read. 

count: [in] the maximum count of bytes to read. 


DESCRIPTION
Read up to count bytes form fd. 


RETURN VALUE
On success, the number of bytes read. On error, returns -1 and sets errno to one of the 
following values: 


EINVAL: the kind of object attached to fd cannot be written to. 
EBADF, EFAULT, EPIPE, EINTR, EAGAIN, ENOSPC. 
****************************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -