stat

What's wrong with vfs_stat() call?

廉价感情. 提交于 2019-12-24 01:44:58
问题 I'm trying to do a stat on files, struct kstat stat; int error = vfs_stat ("/bin/ls", &stat); // /bin/ls exists if (error) { printk (KERN_INFO "error code %d\n", error); } else { printk (KERN_INFO "mode of ls: %o\n", stat.mode); printk (KERN_INFO "owner of ls: %o\n", stat.uid); } return error; But error was always set to 14 (Bad Address), what's wrong with the code? I'm running 3.9 kernel. 回答1: vfs_stat() is defined as: int vfs_stat(const char __user *name, struct kstat *stat); and __user is

C stat struct does not have st_ctime field but only st_ctim

半城伤御伤魂 提交于 2019-12-23 15:54:14
问题 I've now been googleing this for about two hours, yet I was unable to find any answers that helped. The definition of 'stat' as spcified in the manpage says that a st_ctime field exists. struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st

信息安全系统设计基础第九周学习总结

风流意气都作罢 提交于 2019-12-23 15:50:23
时间统计 预计时间(7小时或者5小时) 课本阅读 2小时 博客编写 3小时 (五笔输入法) 博客编写 1小时 验证代码 2小时 实际时间(8小时) 课本阅读 3小时 博客编写 3小时 (五笔输入法) 已放弃。。。 博客编写 3小时 验证代码 2小时 第十章 系统级I/O 输入/输出是在主存和外部设备之间拷贝数据的过程。输入操作是从I/O设备拷贝数据到主存,输出操作是从主存拷贝数据到I/O设备。 10.1 Unix I/O I/O设备:网络、磁盘和终端 Unix I/O :将设备映射为文件的方式,允许Unix内核引出一个简单、低级的应用接口。 描述符:打开文件时,内核返回一个小的非负整数。 Unix外壳创建的每个进程开始时都有三个打开的文件:标准输入(描述符为0)、标准输出(描述符为1)、标准错误(描述符为2)。 改变当前的文件位置:文件位置为k,初始为0。 seek操作:显式地设置文件的当前位置为k. EOF:是一个条件,而不是一个符号 关闭文件:内核释放文件打开时创建的数据结构,并将这个描述符恢复到可用的描述符池中。无论一个进程因为何种原因终止时,内核都会关闭所有打开的文件并释放它们的存储器资源。 10.2 打开和关闭文件 1、open函数:打开一个已存在的文件或者创建一个新文件 #include <sys/types.h> #include <sys/stat.h>

strace简单介绍

南楼画角 提交于 2019-12-22 05:22:39
1、strace是什么 strace是一个非常简单的工具,它可以跟踪系统调用的执行。最简单的方式,它可以从头到尾跟踪binary的执行,然后以一行文本输出系统调用的名字,参数和返回值。可用于诊断、调试和教学的Linux用户空间跟踪器。我们用它来监控用户空间进程和内核的交互,比如系统调用、信号传递、进程状态变更等。strace底层使用内核的ptrace特性来实现其功能。 2、怎么用 1)strace最简单的用法是执行一个指定的命令(过程中,starce会记录和解析命令进程的所有系统调用及这个进程的所有的信号值),在指定命令结束后立即退出 [root@VM_0_11_centos grub2]# strace cat /boot/grub2/grub.cfg execve("/usr/bin/cat", ["cat", "/boot/grub2/grub.cfg"], [/* 23 vars */]) = 0 brk(NULL) = 0x1741000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9eb4042000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open

Intercepting stat()

穿精又带淫゛_ 提交于 2019-12-21 06:06:10
问题 I have successfuly intercepted calls to read() , write() , open() , unlink() , rename() , creat() but somehow with exactly the same semantics intercepting stat() is not taking place. I have changed the execution environmnet using LD_PRELOAD. Am I missing something? The code is quite huge, which part of it will be most helpful to post so you can help? Thanks. Edit: I kept the interposed stat() wrapper simple to check if it works. int stat(const char *path,struct stat *buff) { printf("client

Get file attributes (hidden, readonly, system, archive) in Python

拈花ヽ惹草 提交于 2019-12-21 05:37:07
问题 Just started learning Python. How can i get a status of file's attributes in Python? I know that os.chmod(fullname, stat.S_IWRITE) delete readonly attribute, but how can i get status without changing it? I need to get all of the attributes of "hidden" , "system" , "readonly" , "archive" 回答1: You can use directly the Windows API like that import win32con import win32api attrs = win32api.GetFileAttributes(filepath) attrs & win32con.FILE_ATTRIBUTE_SYSTEM attrs & win32con.FILE_ATTRIBUTE_HIDDEN

Having trouble understanding how fs.stat() works

杀马特。学长 韩版系。学妹 提交于 2019-12-20 17:48:27
问题 I'm trying to write a function that tells me is a certain path is a directory. var fs = require('fs'); console.log("+++++++++++++++++++++++++++++++++++++++"); fs.statSync(pathname, function(err, stats) { console.log(stats.isDirectory()); }); console.log("+++++++++++++++++++++++++++++++++++++++"); However, it never prints the answer. If pathname exists - it doesn't call the function. If it doesn't exists, it generates an exception: ENOENT not a file or directory . I don't want to know it

Implementing the ls -al command in C

£可爱£侵袭症+ 提交于 2019-12-20 17:40:57
问题 As a part of an assignment from one of my classes, I have to write a program in C to duplicate the results of the ls -al command. I have read up on the necessary materials but I am still not getting the right output. Here is my code so far, its only supposed to print out the file size and the file name, but the file sizes its printing are not correct. Code: #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <dirent.h> int main(int

Implementing the ls -al command in C

自闭症网瘾萝莉.ら 提交于 2019-12-20 17:40:40
问题 As a part of an assignment from one of my classes, I have to write a program in C to duplicate the results of the ls -al command. I have read up on the necessary materials but I am still not getting the right output. Here is my code so far, its only supposed to print out the file size and the file name, but the file sizes its printing are not correct. Code: #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <dirent.h> int main(int

c and LD_PRELOAD. open and open64 calls intercepted, but not stat64

故事扮演 提交于 2019-12-20 10:41:56
问题 I've done a little shared library that tries to intercept open, open64, stat and stat64 sys calls. When I export LD_PRELOAD and run oracle's sqlplus, I can see the traces of the open and open64 calls, but no traces of the stat and stat64 calls. The shared library is a single c file with all the definitions of the sys calls in it. Why does it happen that some syscalls are intercepted and others don't? thanks for your help. 回答1: Because the GNU libc implements open() and open64() as you'd