Open system call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rengaraj
    New Member
    • Jan 2007
    • 168

    Open system call

    Dear Friends,
    In open system call we have three arguments.
    First: file descriptor
    Second: flag
    Third: Mode

    for example we use
    open (fd, O_RDWR | O_CREAT , 0764)

    Here i used 764 only but it doesn't work fine. If i use 0764 it worked fine.
    I know
    7 (File owner 4-Read 2-Write 1-Execute)
    6 (File owner 4-Read 2-Write )
    4 (File owner 4-Read 2-Write 1-Execute)

    But what is that 0 before the 764 ??
    Advance Thanks
    Rengaraj.R
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    The zero is in the position of the "sticky bit". If it's zero, the user has normal permissions but if it's set to 1, then the user can only delete or rename files they own and have write permission for the directory. This bit can only be set on directories.

    Comment

    • rengaraj
      New Member
      • Jan 2007
      • 168

      #3
      Originally posted by drhowarddrfine
      The zero is in the position of the "sticky bit". If it's zero, the user has normal permissions but if it's set to 1, then the user can only delete or rename files they own and have write permission for the directory. This bit can only be set on directories.
      Thank You Sir

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        Originally posted by rengaraj
        Dear Friends,
        In open system call we have three arguments.
        First: file descriptor
        Second: flag
        Third: Mode

        for example we use
        open (fd, O_RDWR | O_CREAT , 0764)

        Here i used 764 only but it doesn't work fine. If i use 0764 it worked fine.
        I know
        7 (File owner 4-Read 2-Write 1-Execute)
        6 (File owner 4-Read 2-Write )
        4 (File owner 4-Read 2-Write 1-Execute)

        But what is that 0 before the 764 ??
        Advance Thanks
        Rengaraj.R
        I thought the leading 0 indicated an octal numeric constant with 0764 represents rwxrw-r---, see

        the constant 764 would be a decimal numeric value

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          That's true but when setting the system you refer to the first bit as 0 or 1. A C coder has to adjust for that.

          Comment

          • ValHolla
            New Member
            • Sep 2006
            • 8

            #6
            The '0' in 0764 is for the use of "sticky bit", "setuid", "setgid" etc...

            here is how that bit is set
            4 - setuid
            2 - setgid
            1 - sticky bit

            setuid will yield a file that will be executed as the "owner" regardless of the user that executes the file

            setgid will yield the same as setuid but with "group" instead of owner.

            you can typically see the use of sticky bit on /tmp
            drwxrwxrwt .... /tmp
            this allows for only the "owner" of the file to manipulate a file in a world writable directory... among other things.

            example 4755 would yeald an ls -l that looks like

            -rwsr-xr-x ..... filename

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Horace1 is, in fact, correct.
              This is due both to the way that permissions are specified in Linux as well as the way numbers are handled in C. In linux, file permissions are set using an octal notation. When you see the number 755, the internal representation is not actually the value seven hundred fifty-five decimal, rather, it is 493 decimal.
              Incorporating the leading zero, allows a programmer to maintain a numbering schema consistent with the way a user would set permissions on the command line - octal.

              Comment

              Working...