Skip to content
Advertisement

What are the correct permissions while “sys_open”ing a file?

I am trying to read the contents of a file using x86 assembly on Linux. The question is, what we should put into edx – the “permissions” register for sys_open.

I’ve used open() of C before; but there wasn’t any “permissions” field. I am trying to read a file belongs to the same owner of the executable. The file’s permissions are set to 0400 (-r--------). I’ve tried opening the file with edx: empty (0), 0666 and 0400. All of them returns “-13” to eax which seems to be EACCES.

Sample code:

JavaScript

What should edx to be to open a file, in general (or in this read-only case)? File’s current permissions, an empty, an arbitrary?

Thanks!

Advertisement

Answer

man 2 open:

if neither O_CREAT nor O_TMPFILE is specified, then mode is ignored.

As such it doesn’t matter what you put in edx if you are opening an existing file for reading. The cause of your problems is something else.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement