简体   繁体   中英

Linux File Attribute Check

I was wondering at what stage the attributes on a file was checked by the kernel in Linux. An example of what I mean would be if I attempt to edit a file with the immutable attribute is created. At what point does the kernel return an error indicating the file cannot be changed. If I wanted to change how an attribute works, what would be the best way of accomplishing this process. I was thinking a kernel module that would redirect the read/write/append function to my own series of functions.

Thanks

EDIT :

What I am really interested in is adding a new file attribute through a kernel module.

It checkes permissions on open(); with immutable flag, eg, one can't open the file for writing, even if reading is also requested. For example:

$ python
>>> f = file('/tmp/11', 'r+')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: '/tmp/11'
>>> f = file('/tmp/11', 'r')
>>> print f
<open file '/tmp/11', mode 'r' at 0x7f87b9ba1660>

For checking the file attribute against open operation, see inode_permission() in fs/namei.c.

When you access (read, write..etc) a file, the very first thing is the OS does is to check if the the permission of the associated with the user/process is allowed has necessary permissions which is accomplished using fstat64 which returns a stat strcture containing information about inode, UID, GID etc. If the permissions are sufficient then the inode data structure is accessed to do whatever the action that was requested. Call to fstat64 is free ie there's no special privileges required for a process (which calls fstat64) to access the metadata about a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM