linux-sys_文件系统
来源:互联网 发布:mssql 查询语句 编辑:程序博客网 时间:2024/06/05 04:02
一、文件系统
1.window文件系统 ntfs U盘 FAT32
linux文件系统 ext2、ext3、ext4
2.stat
stat里面的时间辨析
atime(最近访问时间):
mtime(最近更改时间):指最近修改文件内容的时间。
ctime(最近改动时间):指最近改动Inode的时间。
3.access 检查一个文件是否有访问权限
#include <unistd.h>
int access(const char *pathname, int mode);
R_OK 是否有读权限
W_OK 是否有写权限
X_OK 是否有执行权限
F_OK 文件是否存在
4.chmod
#include <sys/stat.h>
int chmod(const char *path, mode_t mode);
int fchomod(int fd, mode_t mode);
5. chown
#include <unistd.h>
int chown(const char *path, uid_t owner, gid_t group);
int fchown(int fd, uid_t owner, gid_t group);
int lchown(const char *path, uid_t owner, gid_t group);
##utime
##truncate
## link
创建一个硬链接
当rm删除文件时,只是删除了目录下的记录项和把inode硬链接计数减1,当硬链接计数减为0时,才会真正删除文件
#include <unistd.h>
int link(const char *oldpath, const char *newpath);
1.硬链接通常要求位于同一文件系统中,POSIX允许跨文件系统
2.符号链接没有文件系统限制
3.通常不允许创建目录的硬链接,某些unix系统下超级用户可以创建目录的硬链接
4.创建目录项以及增加硬链接计数应当是一个原子操作
int syslink(const char *oldpath, const char *newpath);
ssize_t readlink(const char *path, char *buf, size_t bufsiz);
int unlink(const char *pathname)
##rename
文件重命名
#include <stdio.h>
int rename(const char *oldpath, const char *newpath);
##chdir
改变当前进程的工作目录
#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);
##getcwd
获取当前工作目录
#include <unistd.h>
char *getcwd(char *buf, size_t size);
char *getwd(char *buf); //基本不用了 不安全 容易溢出
char *get_current_dir_name(void); //基本不用了 不安全
##pathconf
获取系统文件名可以定义的最大文件名、io缓冲区多大等系统的资源限制值
#include <unistd.h>
long fpathconf(int fd, int name);
long pathconf(char *path, int name);
二、目录操作
1. mkdir
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
2.rmdir
#include <unistd.h>
int rmdir(const char *pathname);
3.opendir
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DIR *fdopendir(int fd);
4.readdir
readdir每次返回一条记录项,DIR*指针指向吓一跳记录项
#include <dirent.h>
struct dirent *readdir(DIR *dirp);
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* not an offset; see NOTES */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all filesystem types */
char d_name[256]; /* filename */
};
5.rewinddir
把目录指针恢复到初始位置
#include <sys/types.h>
#include <dirent.h>
void rewinddir(DIR *dirp);
##seekdir //不太常用
##telldir //不太常用
6.closedir
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dirp);
递归遍历目录的实现:
/* 归遍历目录的实现 */#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <dirent.h>#include <stdio.h>#include <string.h>#define MAX_PATH 1024/* dirwalk: apply fcn to all files in dir */void dirwalk(char *dir, void(*fcn)(char *)){ char name[MAX_PATH]; struct dirent *dp; DIR *dfd; if((dfd = opendir(dir)) == NULL) { fprintf(stderr, "dirwalk: can't open %s\n",dir); return; } while((dp = readdir(dfd)) != NULL) { if(strcmp(dp->d_name, ".") == 0 ||strcmp(dp->d_name, "..") ==0) continue; /* skip self and parent */ if(strlen(dir)+strlen(dp->d_name)+2 > sizeof(name)) fprintf(stderr, "dirwalk: name %s %s too long\n", dir,dp->d_name); else { sprintf(name, "%s/%s", dir, dp->d_name); (*fcn)(name); } } closedir(dfd);}/* fsize: print the size and name of file "name" */void fsize(char *name){ struct stat stbuf; if(stat(name, &stbuf) == -1) { fprintf(stderr, "fsize: can't access %s\n", name); return; } if((stbuf.st_mode & S_IFMT) == S_IFDIR) dirwalk(name,fsize); printf("%8ld %s\n",stbuf.st_size, name);}int main(int argc, char **argv){ if (argc == 1) fsize("."); else while(--argc > 0) fsize(*++argv); return 0;}
##虚拟文件系统 VFS
dup、dup2 实现多个文件描述符指向一个file结构体
- linux-sys_文件系统
- linux-sys_文件IO
- linux-sys_进程
- linux-sys_信号
- linux-sys_进程间通信(IPC)
- Linux文件系统
- linux文件系统
- Linux文件系统
- Linux文件系统
- linux 文件系统
- LINUX 文件系统
- Linux文件系统
- linux文件系统
- Linux文件系统
- Linux 文件系统
- Linux 文件系统
- linux 文件系统
- linux 文件系统
- Android环境搭建
- Java设计模式_(行为型)_策略模式
- @Controller和@RestController的区别?
- 电商图片轮播效果
- 欢迎使用CSDN-markdown编辑器
- linux-sys_文件系统
- c++学习:多态(一)
- JQ中bind绑定多个事件类型
- centos 安装jdk 所遇问题
- 机器学习技法课程学习笔记15 -- Matrix Factorization
- 基于ionic2 的移动app开发过程《4》
- iOS11关于隐藏导航栏后带有scrollView界面出现,下移问题
- ubuntu14.04 nuttx开发环境的搭建
- 手动卸载删除ActiveX控件。