linux 学习笔记之 Files and Directories
来源:互联网 发布:盛科网络校园招聘 编辑:程序博客网 时间:2024/05/17 19:14
- file stat
int fstat(int fd, struct stat *info);
int lstat(const char *pathname, struct stat *info);
The fstat function obtains information about the file that is already open on the descriptor filedes. The lstat function is similar to stat, but when the named file is a symbolic link, lstat returns information about the symbolic link, not the file referenced by the symbolic link.
2. file access permissions
- The file rule is that whenever we want to open any type of file by name, we must have execute permission in each directory mentioned in the name, including the current directory, if it is implied. Read permission lets us read the directory(use ls command), write permission lets us create files below the directory and execute permission lets us pass through the directory when it is a component of a pathname what we are trying to access.
- We must have write permission for a file to specify the O_TRUNC flag in the open function.
- To delete an existing file, we need write permission and execute permission in the directory containing the file.
3. set-user-id, set-group-id, set-sticky-id
- set-user-id(S_ISUID) : used in some file like /etc/passwd and print queue, the S_ISUID tell kernel run program as file owner
- set-group-id(S_IGUID): tell kernel run program as file's group user
- set-sticky-id(S_ISVTX): if the bits is set for a directory, the file in the directory can be removed or renamed only if the user has the write permission for the directory and one of the fellowing: owns this file, owns the directory, is the superuser.
4. file truncation
int ftrruncate(int fd, off_t length);
- If the previous size of the file was greater than length, the data byond length is nolonger accessible.
- If the previous sizeof the file was less than length, the effect is system dependent , but XSI-confofrmation system will increase the file size. If the implementation does extend a file, data between the old end of file and the new end of file will read as 0.
5.
int symlink(const char *actualpath, const char * sympath);
int unlink(const char *pathname);
int remove(const char *pathname);
- Many system disallow hard link to directory to prevent loops in the file system.
- When a file is closed, kernel first checks the count of the number of process that have the file open, If this count has reached 0, the kernel then checks the link count; if it is 0, file's contents are delete. If the set-sticky-id is set in this directory we must have enough permission(see above).
- If the pathname is a symbolic link unlink removes the symbolic link, not the references by the link. There is no function to remove the file referenced by a symbolic link given the name of the link.
- We can also unlink a file or a directory with the remove function. For a file, remove is identical to unlink. For directory, remove is identical rmdir.
- It is not required that actualpath exist when the symbolic link is created.
6. chdir, fchdir
int fchdir(int fd);
Each program if run is a separate process, so the current working directory of the shell is unaffected by the call to chdir in the program.
7. device special files
Each file system on the same disk drive would usually have the same number, but a different minor number.
- linux 学习笔记之 Files and Directories
- List files and directories
- Files and Directories
- 4-Files and Directories
- Files and Directories
- 《APUE》Chapter 4 Files and directories (学习笔记加上自己的代码)
- 《APUE》Chapter 4 Files and directories (学习笔记加上自己的代码)
- Find The Largest Top 10 Files and Directories on Linux
- Linux - 操作文件与目录(manipulating files and directories)
- How to diff and merge files or directories on Linux
- cp - copy files and directories
- APUE-Chapter4. Files and Directories
- Ignore Files and Directories in Subversion
- Apache Tomcat 6.0 Directories and Files
- 170621 Linux and Windows directories
- BASIC ROOTKIT that hides files, directories, and processes
- BASIC ROOTKIT that hides files, directories, and processes
- BASIC ROOTKIT that hides files, directories, and processes
- 黑客与小白对话
- I am ATA
- 关于REBOL发邮件的研究
- log4j使用说明
- c/c++ 数字转成字符串, 字符串转成数字
- linux 学习笔记之 Files and Directories
- webrequest and webresponse(转载)
- windows"新建连接向导"大阅兵----第1集:建立VPN连接
- Leo谈谈写简历之秘籍篇
- jbpm白皮书
- log4j配制文件
- VS2005中如何去掉字符串操作函数的警告信息 _CRT_SECURE_NO_DEPRECATE
- 近期计划
- 动易网站管理系统删除任意文件漏洞