On 16/02/15 21:08, Bob Pack wrote:
> On Mon, 16 Feb 2015 22:53:38 +0100, mrr wrote:
>
>> If you were a developer you would know that a file is opened for example by:
>> int open(const char *pathname, int flags);
>> And afaik never using the inode number on user application level.
>> If you were doing kernel development, there you could (as far as file
>> system is an OS abstraction).
>
> I'm *not* a developer, so I'm confused as all hell why the "inode"
> option worked to keep the file from being overwritten by KDE/Nautilus
The inode number is not used to access files at the user level, but it
can be used at the user level to find different directory entries that
point to the same data eg:
$ touch file_1
$ ls -li file_[12]
364462 -rw-r--r-- 1 user group 0 20-02-16 21:49 file_1
$ ln file_1 file_2
$ cat file_2
$ cat > file_1
Hello world
^D
$ ls -l file_[12]
364462 -rw-r--r-- 2 user group 12 20-02-16 21:50 file_1
364462 -rw-r--r-- 2 user group 12 20-02-16 21:50 file_2
$ cat file_2
Hello world
$
file_1 and file_2 are exactly the same file (they both have the same
inode number - 364462)! They are two different filenames that point to
the same data (in this case in the same directory, but they could be in
different directories [that are in the same file system of a mount
point]). Further:
$ rm file_1
$ cat file_2
Hello world
$ cat file_1
cat: file_1: No such file or directory
$ ls -li file_[12]
364462 -rw-r--r-- 1 user group 12 20-02-16 21:50 file_2
$
The file into which the data was put (file_1) is removed (or more
accurately the directory entry which points to the data is removed), but
the data is still accessible by the entry file_2.
The way *nix [native] files systems work is to have a giant array of
pointers (nodes) which contain all the information (except one piece -
the actual filename) about the files (access permissions, dates of
access, size, etc). The index into this array is the index-node or
inode for short.
To access the data of a file, special files (called directories) are
used which contain a mapping between the filename and the inode. When
accessing the data the system traces through the directory structure to
find the filename which then gives it the inode of the data. This is
then copied into the kernel data tables when the file is opened - the
name is no longer used, and can even be deleted (unlinked/removed) from
the directory structure and still the data in the file will be
accessible (to the program which opened it).
> I had never seen that "i" before, in any "ls" listing, so, the
> entire concept is new to me.
It doesn't appear there as it isn't the normal *nix permissions. It is
accessible via the lsattr (list attributes) command instead.
> Here's what worked though, but which I don't really understand
> with respect to the "i" in the middle of the long line of dashes:
>
> Prevent the Nautilus "Recent" option from remembering files:
> $ lsattr ~/.local/share/recently-used.xbel # check immutable attribute
> -------------e-- /home/foo/.local/share/recently-used.xbel
> $ rm ~/.local/share/recently-used.xbel # clear current file history
> $ touch ~/.local/share/recently-used.xbel # create a 0-byte history file
> $ sudo chattr +i ~/.local/share/recently-used.xbel # make it readonly
> $ lsattr ~/.local/share/recently-used.xbel # check immutable attribute
> ----i--------e-- /home/foo/.local/share/recently-used.xbel
the 'i' in the middle of the dashes tells you that the i[mmutable]
attribute is set. With this attribute set, no change whatsoever can be
made to the file - it has become read-only and undeleteable to
*EVERYONE* including root.
For details see: man chattr
> Somehow, this "i" in the middle of the dashes, prevents Nautilus
> from remembering Recent files because it prevents Nautilus from
> adding anything to the xbel file (whatever an xbel is).
That's what immutable means: it CANNOT be changed by ANYTHING.