7 Replies Latest reply on Mar 17, 2011 6:44 AM by Bill Robinson

    nsh mkdir with -m option does not work as documented

      When attempting to create a directory with the mkdir command and the -m option under NSH, the directory is created with default permissions minus the current umask.   As I understand it, the -m option should cause the umask value to be ignored and the directory created with the permissions specified.

       

      The following is an example of the difference in behavior between bash and nsh when using the -m option on a mkdir command:

       

      [root@osc-sacs-wks-01 test]# pwd

      /tmp/test

      [root@osc-sacs-wks-01 test]# umask

      0022

      [root@osc-sacs-wks-01 test]# mkdir -m 1777 bash_dir

      [root@osc-sacs-wks-01 test]# nsh

      osc-sacs-wks-01# umask

      022

      osc-sacs-wks-01# pwd

      /tmp/test

      osc-sacs-wks-01# mkdir -m 1777 nsh_dir

      osc-sacs-wks-01# ls -l

      total 16

      drwxrwxrwt  2 root    root        4096 Mar 16 11:29 bash_dir

      drwxr-xr-t  2 root    root        4096 Mar 16 11:29 nsh_dir

        • 1. Re: nsh mkdir with -m option does not work as documented

          The nsh mkdir command is based upon zsh, not bash. Is that the specified behavior for mkdir in zsh 4.2.4?

          • 2. Re: nsh mkdir with -m option does not work as documented

            My interpretation of the ZSH documentation is that it should explicitly set the permission based on the -m option and not apply the umask.

            http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#IDX1915

             

            "mkdir [ -p ] [ -m mode ] dir ... Creates directories. With the -p option, non-existing parent directories are first created if necessary, and there will be no complaint if the directory already exists. The -m option can be used to specify (in octal) a set of file permissions for the created directories, otherwise mode 777 modified by the current umask (see man page umask(2)) is used. "

            • 3. Re: nsh mkdir with -m option does not work as documented

              Might be a bug. File a support ticket

              • 4. Re: nsh mkdir with -m option does not work as documented
                Bill Robinson

                I’m seeing some inconsistent results:

                mkdir -m 0700 foo6

                drwx------   2 oozy     oozy         4096 Mar 16 15:59 foo6

                 

                mkdir -m 0770 foo7 && ls -la | grep foo7

                drwxrwx---   2 oozy     oozy         4096 Mar 16 16:00 foo7

                 

                mkdir -m 0777 foo8 && ls -la | grep foo8

                drwxrwxr-x   2 oozy     oozy         4096 Mar 16 16:00 foo8

                 

                mkdir -m 0007 foo12 && ls -la | grep foo12

                d------r-x   2 oozy     oozy         4096 Mar 16 16:02 foo12

                 

                mkdir -m 0077 foo13 && ls -la | grep foo13

                d---rwxr-x   2 oozy     oozy         4096 Mar 16 16:03 foo13

                 

                mkdir -m 0500 foo9 && ls -la | grep foo9

                dr-x------   2 oozy     oozy         4096 Mar 16 16:01 foo9

                 

                mkdir -m 0550 foo10 && ls -la | grep foo10

                dr-xr-x---   2 oozy     oozy        4096 Mar 16 16:02 foo10

                 

                mkdir -m 0555 foo11 && ls -la | grep foo11

                dr-xr-xr-x   2 oozy     oozy         4096 Mar 16 16:02 foo11

                 

                mkdir -m 0002 foo15 && ls -la | grep foo15

                d---------   2 oozy     oozy         4096 Mar 16 16:05 foo15

                 

                it seems like it’s having problems w/ the everyone write bit.

                • 5. Re: nsh mkdir with -m option does not work as documented
                  Bill Robinson

                  actually i take that back:

                   

                  OPTIONS
                         -m mode Set the file permissions of all created  directories  to  mode,
                                 where mode is an octal value.  By default the mode of the newly
                                 created directories is calculated to be:

                                        0777 minus <current umask of local host>

                   

                   

                  i take that to mean if my umask is 0002 and i run mkdir -m 0777 foo then foo will be 0775

                  • 6. Re: nsh mkdir with -m option does not work as documented

                    The way I interpret that documentation is - the mkdir without the -m option will use 0777 minus the umask as the default permissions of the file, otherwise you could use the -m option to explicit set the permissions.

                     

                    The wording of the man page is a bit unclear and confusing.  However, if you look at the documentation on from zsh regarding the -m option, it leads you to believe the permissions can be explicitly set.  Also it operates in this manner in when using a bash shell.

                    • 7. Re: nsh mkdir with -m option does not work as documented
                      Bill Robinson

                      i was going to post last night – I think you are right – I re-read that, and the linux mkdir man page and the –m should override the umask.  It appears the nsh one is not.  our manpage is confusing though – it should say something like “the default behavior of mkdir is to subtract the umask, w/ the –m option the default umask will be overridden”