diff --git a/.gitignore b/.gitignore index c6127b3..95f24b0 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ modules.order Module.symvers Mkfile.old dkms.conf +*.swp +*.swo diff --git a/4/fileDirectory/.dirent.c.swp b/4/fileDirectory/.dirent.c.swp deleted file mode 100644 index 65e0b12..0000000 Binary files a/4/fileDirectory/.dirent.c.swp and /dev/null differ diff --git a/4/fileDirectory/.filetime.c.swp b/4/fileDirectory/.filetime.c.swp deleted file mode 100644 index d1733e3..0000000 Binary files a/4/fileDirectory/.filetime.c.swp and /dev/null differ diff --git a/4/fileDirectory/.mkdir.c.swp b/4/fileDirectory/.mkdir.c.swp deleted file mode 100644 index 37480d0..0000000 Binary files a/4/fileDirectory/.mkdir.c.swp and /dev/null differ diff --git a/4/fileDirectory/chdir.c b/4/fileDirectory/chdir.c index 0eeaf73..3e13ea7 100644 --- a/4/fileDirectory/chdir.c +++ b/4/fileDirectory/chdir.c @@ -1,6 +1,15 @@ #include +#include int main(void) { - // TODO + if(chdir("/home/eric") < 0) { + printf("chdir error\n"); + return -1; + } + + char buf[1024]; + + char *pbuf = getcwd(buf, 1024); + printf("CWD: %s\n", pbuf); return 0; } diff --git a/4/fileDirectory/dev.c b/4/fileDirectory/dev.c new file mode 100644 index 0000000..214558f --- /dev/null +++ b/4/fileDirectory/dev.c @@ -0,0 +1,26 @@ +#include +#include +#include + +int main(void) { + struct stat buf; + + if(stat("/dev/sda", &buf) < 0){ + printf("stat error for /dev/sda\n"); + return -1; + } + + printf("dev = %ld\nrdev = %ld\n", buf.st_dev, buf.st_rdev); + + if(S_ISCHR(buf.st_mode)){ + printf("character device\n"); + } + else if (S_ISBLK(buf.st_mode)){ + printf("block device\n"); + } + else { + printf("unkonwn device\n"); + } + + return 0; +} diff --git a/README.md b/README.md index fc153e5..f002ccb 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ``` 2. 已加载的内核模块 ``` - Module Size Used by + Module Size Used by ipt_MASQUERADE 16384 1 nf_conntrack_netlink 49152 0 xfrm_user 40960 1