M
M
Mika Slepinin2016-10-26 23:18:56
linux
Mika Slepinin, 2016-10-26 23:18:56

What happens "under the hood" when a chmod is executed?

Good evening!
What happens when e.g. is executed
$ chmod +x myfile?
It is clear that the file is given the right to execute, now it can be executed, and in ls -la we will now see something like this:

-rwxrwxr-x  1 username usergroup 42 Oct 26 23:25 myfile

But what happened "under the hood"?
Is the file itself affected, or are changes made somewhere (I wonder where), in the file system, or something else?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
1
15432, 2016-10-26
@mikalaikaia

На уровне файловой системы у каждого файла есть свойства - имя, владелец, время создания / изменения, права доступа. Вот права доступа и изменяются. Происходит модификация записи файла в структуре файловой системы ext3 (или какая у вас там)

S
Saboteur, 2016-10-26
@saboteur_kiev Куратор тега Linux

В файловой системе стандарта POSIX (стандарт для всех *nix), есть аттрибуты файла в виде rwxrwxrwx, плюс еще два-три специальных бита.
Собственно этот аттрибут и правится. Внутри файла ничего не меняется.
Можете нагуглить права доступа в POSIX системах.
Этот флаг говорит системе, что файл - исполняемый. Но как его исполнят, система смотрит по заголовку файла.
Для скриптовых файлов, там обычно указан путь к интерпретатору. Для бинарных - соответствующий заголовок.
В отличие от Windows, расширение в *nix не значит ничего.

S
sim3x, 2016-10-26
@sim3x

git.savannah.gnu.org/cgit/coreutils.git/tree/src/c...

M
Max, 2016-10-27
@MaxDukov

there is such a wonderful thing - inodes . Information about rights/owners/access times/modifications/etc.

A
abcd0x00, 2016-10-27
@abcd0x00

Is the file itself affected, or can changes be made somewhere (I wonder where) in the file system

The file itself is not affected. A file is managed through its inode. An inode is a structure in the file system that describes a file. When you run ls, it doesn't go into files, but iterates through their inodes, reading information from them. And the contents of the file are written to the inode as the address of the first block. This inode determines what can be done with the contents of the file.

M
Maxim Moseychuk, 2016-10-27
@fshp

In addition to all the answers, I will clarify that permissions are an attribute of a file.
In addition to rights, the attributes are also the file name, owner, group, access timestamps. The attributes do not affect the content of the file. For example, when renaming the contents of a file, the contents are preserved.
Attributes are not something universal, their support depends on the file system. For example, FAT32 does not support standard POSIX access attributes. In turn, EXT4 does not support the stealth attribute (hidden files and folders in Windows).
When copying a file from one file system to another, the OS tries to keep the same attributes.
The tar archiver can save the attributes of archived files and restore them when unpacking.
When sending a file, for example, via mail, all attributes, except for the name, will be lost.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question