Loading ...
Sorry, an error occurred while loading the content.

Can't write to ntfs file system

Expand Messages
  • Graham Lawrence
    I have an external hard drive that is in ntfs file format. Vim will neither create a file, nor write to existing files, on this file system. It returns E212,
    Message 1 of 22 , Jan 1, 2012
    • 0 Attachment
      I have an external hard drive that is in ntfs file format. Vim will
      neither create a file, nor write to existing files, on this file
      system. It returns E212, saying I do not have permission.

      The drive mounts automatically from my fstab entry when I start the system

      /dev/sdb1 /media/500gb ntfs-3g rw,user,auto 0 0

      and mount shows it as

      /dev/sdb1 on /media/500gb type fuseblk
      (rw,noexec,nosuid,nodev,allow_other,blksize=4096)

      so its permissions and ownerships are universally, e.g.

      /media/500gb/Films/Mouchette (1967) (French with English Subtitles) $ls -l
      total 4
      drwxrwxrwx 1 root root 4096 Jan 1 08:50 VIDEO_TS/
      -rwxrwxrwx 1 root root 0 Jan 1 10:40 mplog*

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tony Mechelynck
      ... Not all Linux kernels support overwriting NTFS files, and even fewer support file creation. See http://en.wikipedia.org/wiki/NTFS#Linux for details. Best
      Message 2 of 22 , Jan 1, 2012
      • 0 Attachment
        On 01/01/12 19:09, Graham Lawrence wrote:
        > I have an external hard drive that is in ntfs file format. Vim will
        > neither create a file, nor write to existing files, on this file
        > system. It returns E212, saying I do not have permission.
        >
        > The drive mounts automatically from my fstab entry when I start the system
        >
        > /dev/sdb1 /media/500gb ntfs-3g rw,user,auto 0 0
        >
        > and mount shows it as
        >
        > /dev/sdb1 on /media/500gb type fuseblk
        > (rw,noexec,nosuid,nodev,allow_other,blksize=4096)
        >
        > so its permissions and ownerships are universally, e.g.
        >
        > /media/500gb/Films/Mouchette (1967) (French with English Subtitles) $ls -l
        > total 4
        > drwxrwxrwx 1 root root 4096 Jan 1 08:50 VIDEO_TS/
        > -rwxrwxrwx 1 root root 0 Jan 1 10:40 mplog*
        >

        Not all Linux kernels support overwriting NTFS files, and even fewer
        support file creation. See http://en.wikipedia.org/wiki/NTFS#Linux for
        details.


        Best regards,
        Tony.
        --
        "This is a job for BOB VIOLENCE and SCUM, the INCREDIBLY STUPID MUTANT
        DOG."
        -- Bob Violence

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Marty Fried
        ... I m not an expert, but I ve always managed to get things like this working. I had some problems originally with my NTFS partitions, although I don t
        Message 3 of 22 , Jan 1, 2012
        • 0 Attachment
          On Sun, Jan 1, 2012 at 10:09 AM, Graham Lawrence <gl00637@...> wrote:
          I have an external hard drive that is in ntfs file format.  Vim will
          neither create a file, nor write to existing files, on this file
          system.  It returns E212, saying I do not have permission.

          The drive mounts automatically from my fstab entry when I start the system

             /dev/sdb1        /media/500gb     ntfs-3g     rw,user,auto     0   0

          and mount shows it as

             /dev/sdb1 on /media/500gb type fuseblk
          (rw,noexec,nosuid,nodev,allow_other,blksize=4096)

          so its permissions and ownerships are universally, e.g.

             /media/500gb/Films/Mouchette (1967) (French with English Subtitles) $ls -l
             total 4
             drwxrwxrwx 1 root root 4096 Jan  1 08:50 VIDEO_TS/
             -rwxrwxrwx 1 root root    0 Jan  1 10:40 mplog*

          I'm not an expert, but I've always managed to get things like this working.  I had some problems originally with my NTFS partitions, although I don't remember the details.  I think it may have had to do with the owner, rather than the permissions, but there must be more to it, since it appears that everyone should be able to write to it. But things aren't always what they appear to be.  :)

          I had to change my mount to something much more complex than the default.  Mine now looks like this on my Ubuntu system; I'm using UUIDs instead of device names.

          UUID=##big number##    /media/subdirectory   ntfs  auto,users,uid=username,gid=username,utf8,dmask=027,fmask=137  0   0

          Pardon me if this is too elementary, but I'd recommend unmounting the device, editing fstab (and saving, of course), then entering "mount -a" in a terminal to test.  Modify if needed, then repeat until it works or you give up.  At least, that's my usual procedure.

          Hope this helps, and hope nobody minds the off-topic discussion.

          Good luck...
          --
          Marty Fried

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Graham Lawrence
          Sorry, should have been more emphatic, I have the ntfs-3g driver. Vim is the *only* app that has a problem writing to this device, all others do so freely. I
          Message 4 of 22 , Jan 2, 2012
          • 0 Attachment
            Sorry, should have been more emphatic, I have the ntfs-3g driver. Vim
            is the *only* app that has a problem writing to this device, all
            others do so freely. I have to keep windows to run my printer and tv,
            but virtually all the files on this ntfs drive are created in linux.

            So the problem is specific to vim. The help has no reference for ntfs
            or fat32, but as vim can be used on windows it must be able to write
            to these file systems. Or is that a feature only available with the
            windows version?

            I would much prefer a solution within vim itself, rather than tinker
            with my fstab. It took a lot of false starts to get this device to
            automount on system start-up, without activating linux's excessive
            deference to the pathetic OS, and thus trying to boot from the ntfs
            drive.

            What I do at the moment is use a mapping that writes such files to my
            linux hd, then copies it to the ntfs drive, but I often forget to use
            it as I rely on another mapping to close vim down that also saves all
            open buffers.

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Joan Miquel Torres Rigo
            ... This cannot be vim-ntfs issue because vim hasn t access to ntfs (or any other) filesystem except than VFS (Virtual FileSystem) abstraction. The only things
            Message 5 of 22 , Jan 2, 2012
            • 0 Attachment
              2012/1/2 Graham Lawrence <gl00637@...>:
              > Sorry, should have been more emphatic, I have the ntfs-3g driver.  Vim
              > is the *only* app that has a problem writing to this device, all
              > others do so freely.  I have to keep windows to run my printer and tv,
              > but virtually all the files on this ntfs drive are created in linux.
              >
              > So the problem is specific to vim.

              This cannot be vim-ntfs issue because vim hasn't access to ntfs (or
              any other) filesystem except than VFS (Virtual FileSystem)
              abstraction.

              The only things that changes are the filesystem cababilities and how
              VFS handles the missing ones.

              For example, NTFS hasn't support for file's user / group ownership.

              As you said, you have read and write pemissions for these files but,
              if you see at your own report, you can discover that YOU ARE NOT the
              owner of those files because ntfs doesn't support such thing and the
              user who mounted the filesystem was root.

              Then, you have read and write permissions, but you cannot change this
              permissions or ownership. Which is probably what vim is trying to do.

              Why vim is trying to that is a vim issue (also maybe related with your
              .vimrc and/or the plugins yo are using). If you discover that,
              probably you can change this behaviour (sure loosing some --maybe
              unwanted-- feature).

              Why you aren't the owner IS operating system and fstab setup issue.

              It could be interesting to know what and why is trying to do vim that
              only the file owner can do. But I thing is more interesting to become
              the file owner to be able to do that. Regardless if wi finally decide
              that we want or not.




              > The help has no reference for ntfs
              > or fat32, but as vim can be used on windows it must be able to write
              > to these file systems.  Or is that a feature only available with the
              > windows version?

              No. Vim has no access to phisical filesystems in linux. And in windows
              maybe, but it is definitively a bad idea to do that in any way.



              PD: Is not a solution, but while you are searching for that, you can
              overwrite the file with:

              :w ! cat > %
              (notice the space between 'w' and '!')


              Regards.

              --
              Joan Miquel Torres__________________________________
              Linux Registered User #164872
              http://www.mallorcaweb.net/joanmiquel
              BULMA: http://bulma.net http://breu.bulma.net/?l2301

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Marty Fried
              ... Vim can definitely edit files on an NTFS partition - I do it, and rechecked. Maybe there is still something to do with the owner, that only Vim cares
              Message 6 of 22 , Jan 2, 2012
              • 0 Attachment
                On Mon, Jan 2, 2012 at 7:17 AM, Graham Lawrence <gl00637@...> wrote:
                Sorry, should have been more emphatic, I have the ntfs-3g driver.  Vim
                is the *only* app that has a problem writing to this device, all
                others do so freely.  I have to keep windows to run my printer and tv,
                but virtually all the files on this ntfs drive are created in linux.

                Sorry, I didn't really know what ntfs-3g meant at the time.

                Vim can definitely edit files on an NTFS partition - I do it, and rechecked.  Maybe there is still something to do with the owner, that only Vim cares about.  Can you set yourself as the owner of the directory?  I had problems doing that; I would make myself the owner of the directory, but mounting would change that, so I made those changes to the mount command, and finally got it working.

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • Graham Lawrence
                I thank you all for your help, but I really can t use your recommendations without screwing up something else on my system. I have a script which runs
                Message 7 of 22 , Jan 3, 2012
                • 0 Attachment
                  I thank you all for your help, but I really can't use your
                  recommendations without screwing up something else on my system. I
                  have a script which runs automatically on system startup which
                  immediately references this ntfs drive, so I must have this drive
                  automount on startup like my internal HD, or the script will fail. It
                  runs for several hours, during which I can't unmount and remount the
                  drive.

                  The initial mount command assigns the drive to ROOT:ROOT with rwx
                  permissions for all users. These cannot be changed with chown, chmod,
                  chgrp as explained at
                  http://ubuntu.swerdna.org/ubuntfs.html
                  As this is an ubuntu site this behavior is not specific to my distro,
                  slackware. I assume it is standard behavior for the kernel, ntfs-3g
                  and the core utilities.

                  I appreciate that one can get vim to write to this drive by having it
                  use a different linux command to do so, and am already doing that.
                  But I often forget to use it because my vim shutdown script
                  automatically writes out any altered buffers; but then it fails if it
                  tries to write to this ntfs drive. The only feasible solution for me
                  is to elaborate my shutdown script to choose the appropriate write
                  procedure for each buffer.

                  I think this is a bug in vim. The ownership of the file should not be
                  an issue, only the permissions, which are as they should be. This is
                  the standard adhered to by all other apps except, as far as I know,
                  only vim.

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Marty Fried
                  ... Vim that comes with it. It looked exactly like your setup... example: $ ls -l total 56 drwxrwxrwx 10 root root 4096 2011-12-31 21:23 ./ drwxr-xr-x 24
                  Message 8 of 22 , Jan 3, 2012
                  • 0 Attachment
                    On Tue, Jan 3, 2012 at 7:45 AM, Graham Lawrence <gl00637@...> wrote:
                    I thank you all for your help, but I really can't use your
                    recommendations without screwing up something else on my system.  I
                    have a script which runs automatically on system startup which
                    immediately references this ntfs drive, so I must have this drive
                    automount on startup like my internal HD, or the script will fail.  It
                    runs for several hours, during which I can't unmount and remount the
                    drive.

                    The initial mount command assigns the drive to ROOT:ROOT with rwx
                    permissions for all users.  These cannot be changed with chown, chmod,
                    chgrp as explained at
                       http://ubuntu.swerdna.org/ubuntfs.html
                    As this is an ubuntu site this behavior is not specific to my distro,
                    slackware.  I assume it is standard behavior for the kernel, ntfs-3g
                    and the core utilities.

                    I appreciate that one can get vim to write to this drive by having it
                    use a different linux command to do so, and am already doing that.
                    But I often forget to use it because my vim shutdown script
                    automatically writes out any altered buffers; but then it fails if it
                    tries to write to this ntfs drive.  The only feasible solution for me
                    is to elaborate my shutdown script to choose the appropriate write
                    procedure for each buffer.

                    I think this is a bug in vim.  The ownership of the file should not be
                    an issue, only the permissions, which are as they should be.  This is
                    the standard adhered to by all other apps except, as far as I know,
                    only vim.

                    I checked this on my Ubuntu 11.10 system with the default version of
                    Vim that comes with it.  It looked exactly like your setup... example:
                    $ ls -l
                    total 56
                    drwxrwxrwx 10 root  root   4096 2011-12-31 21:23 ./
                    drwxr-xr-x 24 root  root   4096 2011-12-31 12:26 ../
                    . . .
                    drwxrwxrwx  1 root  root   8192 2012-01-02 12:00 xp-c/
                    $ cd xp-c
                    $ ls -l
                    drwxrwxrwx  1 root root       4096 2012-01-03 08:56 Temp/
                    $ cd Temp
                    $ ls -l
                    -rwxrwxrwx 2 root root    21 2012-01-03 08:51 BoiseNetWiz.txt*

                    I was able to edit this file with vim/gvim with no problem, 
                    either with editing nor with creating the temp file.

                    I guess the reason I changed the permissions on my system were not
                    to give me access, but to make the files not writable to all.  If
                    nothing else, I don't like having all the file coloring as shown
                    on my system with these settings.

                    I never meant that you need to unmount/remount the drive just to use Vim,
                    at least not normally.  I only said to do that for debugging to get the right
                    mount command, then you would leave whatever works in your fstab file for
                    startup.  But if you are convinced that this is a Vim problem, then I guess
                    you don't want to bother.  Sorry nobody has been able to tell you the answer.




                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • Joan Miquel Torres Rigo
                    ... Nobody said nothing about mount or umount nothing manually. You just need to change the mount options in your /etc/fstab file. Try something like this:
                    Message 9 of 22 , Jan 3, 2012
                    • 0 Attachment
                      2012/1/3 Graham Lawrence <gl00637@...>:
                      > I thank you all for your help, but I really can't use your
                      > recommendations without screwing up something else on my system.  I
                      > have a script which runs automatically on system startup which
                      > immediately references this ntfs drive, so I must have this drive
                      > automount on startup like my internal HD, or the script will fail.  It
                      > runs for several hours, during which I can't unmount and remount the
                      > drive.

                      Nobody said nothing about mount or umount nothing manually. You just
                      need to change the mount options in your /etc/fstab file.


                      Try something like this:

                      /dev/sdb1 /media/500gb ntfs-3g
                      rw,user,auto,uid=<username>,gid=<groupname> 0 0

                      ...changing <username> and <groupname> with your user and primary
                      group names (primary group name is tipically the same as username --in
                      fact, in Ubuntu, Debian and many other distros this is the default--).

                      Umounting and remounting (with 'mount -a') is only to make changes to
                      take effect without rebooting.

                      But, in fact, them will take effect next time you reboot regardless
                      you manually umount/remount or not.



                      >
                      > The initial mount command assigns the drive to ROOT:ROOT with rwx
                      > permissions for all users.  These cannot be changed with chown, chmod,
                      > chgrp as explained at
                      >    http://ubuntu.swerdna.org/ubuntfs.html
                      [...]

                      This is **exactly** what I said in my first email in this thread:

                      «Ownership and permissions are set only in the mount command.»

                      ...they are set only in the mount command, but THEY ARE SET anyway.

                      They defaults to root:root because root is the user who executes the
                      mount command and no other thing is specified in fstab. Then root is a
                      reasonable default option, but you can change this acording to your
                      needings.



                      > I appreciate that one can get vim to write to this drive by having it
                      > use a different linux command to do so, and am already doing that.
                      > But I often forget to use it because my vim shutdown script
                      > automatically writes out any altered buffers; but then it fails if it
                      > tries to write to this ntfs drive.  The only feasible solution for me
                      > is to elaborate my shutdown script to choose the appropriate write
                      > procedure for each buffer.

                      ...or discover what is causing this problem and fix it ;-)


                      > I think this is a bug in vim.  The ownership of the file should not be
                      > an issue, only the permissions, which are as they should be.

                      I suspect not.

                      Execute vim with '-u /dev/null' (I think there is better way, but I
                      don't remember it now) to avoid processing your .vimrc and try to edit
                      and save some file in your NTFS filesystem.

                      If it fail again, try to temporary remove all your plugins (If you
                      have any) by renaming plugins directory.

                      If I'm in truth, then you only need to play enabling/disabling
                      settings in your .vimrc or plugins to determine which is causing the
                      problem.

                      If it continues failing, then it will seem a vim issue, but I think
                      this will not occour because, as you said, vim doesn't need to change
                      ownership or permissions to save a file. But some plugins or mappings
                      may need it.


                      > This is
                      > the standard adhered to by all other apps except, as far as I know,
                      > only vim.

                      Vim must use operating system services to write files (there is no
                      other way to do it for non privileged users in linux --and
                      definitively there is no other right way to do it--).

                      This services are the same for all programs. SURE your vim is trying
                      to do something else. The questions are WHAT and WHY.



                      Regards.

                      --
                      Joan Miquel Torres__________________________________
                      Linux Registered User #164872
                      http://www.mallorcaweb.net/joanmiquel
                      BULMA: http://bulma.net http://breu.bulma.net/?l2301

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Charles Campbell
                      ... May I assume you ve verified that you can create a file on the ntfs drive: ex. echo junk /media/500gb/junk append to a file on the ntfs drive: ex.
                      Message 10 of 22 , Jan 3, 2012
                      • 0 Attachment
                        Graham Lawrence wrote:
                        > I thank you all for your help, but I really can't use your
                        > recommendations without screwing up something else on my system. I
                        > have a script which runs automatically on system startup which
                        > immediately references this ntfs drive, so I must have this drive
                        > automount on startup like my internal HD, or the script will fail. It
                        > runs for several hours, during which I can't unmount and remount the
                        > drive.
                        >
                        > The initial mount command assigns the drive to ROOT:ROOT with rwx
                        > permissions for all users. These cannot be changed with chown, chmod,
                        > chgrp as explained at
                        > http://ubuntu.swerdna.org/ubuntfs.html
                        > As this is an ubuntu site this behavior is not specific to my distro,
                        > slackware. I assume it is standard behavior for the kernel, ntfs-3g
                        > and the core utilities.
                        >
                        > I appreciate that one can get vim to write to this drive by having it
                        > use a different linux command to do so, and am already doing that.
                        > But I often forget to use it because my vim shutdown script
                        > automatically writes out any altered buffers; but then it fails if it
                        > tries to write to this ntfs drive. The only feasible solution for me
                        > is to elaborate my shutdown script to choose the appropriate write
                        > procedure for each buffer.
                        >
                        > I think this is a bug in vim. The ownership of the file should not be
                        > an issue, only the permissions, which are as they should be. This is
                        > the standard adhered to by all other apps except, as far as I know,
                        > only vim.
                        >
                        >
                        May I assume you've verified that you can create a file on the ntfs drive:

                        ex. echo "junk"> /media/500gb/junk

                        append to a file on the ntfs drive:

                        ex. echo "more junk">> /media/500gb/junk

                        and that you can delete a file on the ntfs drive:

                        ex. /bin/rm /media/500gb/junk

                        from your Ubuntu system?

                        After creating a file /media/500gb/junk, what does

                        /bin/ls -lsa /media/500gb/junk

                        show?

                        Regards,
                        Chip Campbell


                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • Joan Miquel Torres Rigo
                        ... [...] ... I just missed this detail checking your answer while writting my last email ;-) ...But I could figure out that is very improbable that no other
                        Message 11 of 22 , Jan 3, 2012
                        • 0 Attachment
                          2012/1/3 Marty Fried <marty@...>:

                          > I checked this on my Ubuntu 11.10 system with the default version of
                          > Vim that comes with it.  It looked exactly like your setup...

                          [...]

                          > I was able to edit this file with vim/gvim with no problem,
                          > either with editing nor with creating the temp file.
                          >
                          > I guess the reason I changed the permissions on my system were not
                          > to give me access, but to make the files not writable to all.

                          I just missed this detail checking your answer while writting my last
                          email ;-) ...But I could figure out that is very improbable that no
                          other users had the same problem before if it were result to be vim
                          issue. But I have'nt any ntfs filesystem to check that. :-O

                          Now is clear that the problem is in his vim setup and the only way to
                          find the exact cause of it is to try disabling setting by setting.

                          >  If
                          > nothing else, I don't like having all the file coloring as shown
                          > on my system with these settings.
                          >
                          > I never meant that you need to unmount/remount the drive just to use Vim,
                          > at least not normally.  I only said to do that for debugging to get the
                          > right
                          > mount command, then you would leave whatever works in your fstab file for
                          > startup.

                          Of course ;-)

                          > But if you are convinced that this is a Vim problem, then I guess
                          > you don't want to bother.  Sorry nobody has been able to tell you the
                          > answer.

                          :-D


                          --
                          Joan Miquel Torres__________________________________
                          Linux Registered User #164872
                          http://www.mallorcaweb.net/joanmiquel
                          BULMA: http://bulma.net http://breu.bulma.net/?l2301

                          --
                          You received this message from the "vim_use" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        • Marty Fried
                          Further thoughts: ... you should. ... experimenting with your fstab settings instead. ... possible solution. Did you know there is a Vim command that will
                          Message 12 of 22 , Jan 3, 2012
                          • 0 Attachment
                            Further thoughts:
                            On Tue, Jan 3, 2012 at 9:19 AM, Marty Fried <marty@...> wrote:
                            On Tue, Jan 3, 2012 at 7:45 AM, Graham Lawrence <gl00637@...> wrote:
                            I thank you all for your help, but I really can't use your
                            recommendations without screwing up something else on my system.  I
                            have a script which runs automatically on system startup which
                            immediately references this ntfs drive, so I must have this drive
                            automount on startup like my internal HD, or the script will fail.  It
                            runs for several hours, during which I can't unmount and remount the
                            drive.
                            There is no reason you should have to do this anyway.  Nobody suggested you should.
                             

                            The initial mount command assigns the drive to ROOT:ROOT with rwx
                            permissions for all users.  These cannot be changed with chown, chmod,
                            chgrp as explained at
                               http://ubuntu.swerdna.org/ubuntfs.html
                            As this is an ubuntu site this behavior is not specific to my distro,
                            slackware.  I assume it is standard behavior for the kernel, ntfs-3g
                            and the core utilities.
                            Yes, and I am very aware of this, which is exactly why I suggested experimenting with
                            your fstab settings instead. 

                            I appreciate that one can get vim to write to this drive by having it
                            use a different linux command to do so, and am already doing that. 
                            But I often forget to use it because my vim shutdown script
                            automatically writes out any altered buffers; but then it fails if it
                            tries to write to this ntfs drive.  The only feasible solution for me
                            is to elaborate my shutdown script to choose the appropriate write
                            procedure for each buffer.
                            I wouldn't say it's the *only feasible* solution, only that it's a possible solution.

                            Did you know there is a Vim command that will automatically write any named, unsaved
                            buffers anytime Vim loses focus?  You can add this to your .vimrc:
                            au FocusLost * :wa

                            The Vim FAQ addresses this, and another that might be useful:
                            23.5. How do I automatically save all the changed buffers whenever Vim
                                  loses focus?
                            
                            You can define an autocommand for the FocusLost event which will save all
                            the modified buffers whenever Vim loses focus:
                                :autocmd FocusLost * wall
                            
                            For more information, read
                                :help FocusLost
                                :help :wall
                            
                            
                            23.6. How do I execute/run a function when Vim exits to do some cleanup?
                            
                            You can use VimLeave autocmd event to execute a function just before Vim
                            exists. For example,
                                :autocmd VimLeave * call MyCleanupFunction()
                            
                            For more information, read
                                :help VimLeave

                            --
                            You received this message from the "vim_use" maillist.
                            Do not top-post! Type your reply below the text you are replying to.
                            For more information, visit http://www.vim.org/maillist.php
                          • Bram Moolenaar
                            ... One suggestion I haven t heard yet: Try changing the backupcopy setting. Vim has some protection against doing bad things with root permission, that
                            Message 13 of 22 , Jan 4, 2012
                            • 0 Attachment
                              Graham Lawrence wrote:

                              > I thank you all for your help, but I really can't use your
                              > recommendations without screwing up something else on my system. I
                              > have a script which runs automatically on system startup which
                              > immediately references this ntfs drive, so I must have this drive
                              > automount on startup like my internal HD, or the script will fail. It
                              > runs for several hours, during which I can't unmount and remount the
                              > drive.
                              >
                              > The initial mount command assigns the drive to ROOT:ROOT with rwx
                              > permissions for all users. These cannot be changed with chown, chmod,
                              > chgrp as explained at
                              > http://ubuntu.swerdna.org/ubuntfs.html
                              > As this is an ubuntu site this behavior is not specific to my distro,
                              > slackware. I assume it is standard behavior for the kernel, ntfs-3g
                              > and the core utilities.
                              >
                              > I appreciate that one can get vim to write to this drive by having it
                              > use a different linux command to do so, and am already doing that.
                              > But I often forget to use it because my vim shutdown script
                              > automatically writes out any altered buffers; but then it fails if it
                              > tries to write to this ntfs drive. The only feasible solution for me
                              > is to elaborate my shutdown script to choose the appropriate write
                              > procedure for each buffer.
                              >
                              > I think this is a bug in vim. The ownership of the file should not be
                              > an issue, only the permissions, which are as they should be. This is
                              > the standard adhered to by all other apps except, as far as I know,
                              > only vim.

                              One suggestion I haven't heard yet: Try changing the 'backupcopy'
                              setting.

                              Vim has some protection against doing bad things with root permission,
                              that might interfere with what you are doing.

                              --
                              Why isn't there mouse-flavored cat food?

                              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                              /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                              \\\ an exciting new programming language -- http://www.Zimbu.org ///
                              \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                              --
                              You received this message from the "vim_use" maillist.
                              Do not top-post! Type your reply below the text you are replying to.
                              For more information, visit http://www.vim.org/maillist.php
                            • Joan Miquel Torres Rigo
                              ... If I understood well, vim is executed as non privileged user, not root. But the permissions of all files (inexistent in ntfs) are set according to a
                              Message 14 of 22 , Jan 4, 2012
                              • 0 Attachment
                                2012/1/4 Bram Moolenaar <Bram@...>:

                                >
                                > One suggestion I haven't heard yet: Try changing the 'backupcopy'
                                > setting.
                                >
                                > Vim has some protection against doing bad things with root permission,
                                > that might interfere with what you are doing.

                                If I understood well, vim is executed as non privileged user, not root.

                                But the permissions of all files (inexistent in ntfs) are set
                                according to a predefined mask which, in this case, includes execution
                                privilege for user, goup and other which, of course, can be a relative
                                security risk if the owner is root. Maybe that is what you would
                                mean...

                                NOTE: The write permission in the mask cannot be removed because, for
                                directorys, this means the "enter" permission (read and write
                                permissions in directorys always belongs to its contents). Then, the
                                only way to remove execution permission for root in a ntfs files is
                                setting the ownership of the whole filesystem to other user..



                                Regards.

                                --
                                Joan Miquel Torres__________________________________
                                Linux Registered User #164872
                                http://www.mallorcaweb.net/joanmiquel
                                BULMA: http://bulma.net http://breu.bulma.net/?l2301

                                --
                                You received this message from the "vim_use" maillist.
                                Do not top-post! Type your reply below the text you are replying to.
                                For more information, visit http://www.vim.org/maillist.php
                              • Marty Fried
                                ... someone with root permission should know what they are doing, and is working without protection on purpose. Also, I m surprised that Vim would even know.
                                Message 15 of 22 , Jan 4, 2012
                                • 0 Attachment
                                  On Wed, Jan 4, 2012 at 4:37 AM, Bram Moolenaar <Bram@...> wrote:

                                  Vim has some protection against doing bad things with root permission,
                                  that might interfere with what you are doing.

                                  I'm surprised to hear this - it seems to go against the philosophy that someone with root permission should know what they are doing, and is working  without protection on purpose.  Also, I'm surprised that Vim would even know.

                                  I'm curious now about what sort of protection there is.

                                  -- 
                                  Marty Fried
                                   

                                  --
                                  You received this message from the "vim_use" maillist.
                                  Do not top-post! Type your reply below the text you are replying to.
                                  For more information, visit http://www.vim.org/maillist.php
                                • Graham Lawrence
                                  My apologies to all. It is something in my vimrc. Without that, vim creates and edits on ntfs without complaint. My thanks to Joan Miquel Torres Rigo for
                                  Message 16 of 22 , Jan 4, 2012
                                  • 0 Attachment
                                    My apologies to all. It is something in my vimrc. Without that, vim
                                    creates and edits on ntfs without complaint. My thanks to Joan Miquel
                                    Torres Rigo for the suggestion.

                                    --
                                    You received this message from the "vim_use" maillist.
                                    Do not top-post! Type your reply below the text you are replying to.
                                    For more information, visit http://www.vim.org/maillist.php
                                  • Joan Miquel Torres Rigo
                                    ... That s not exact: Root account should NEVER been used in production environments. You should use sudo instead. Apart of that, a welder also should know
                                    Message 17 of 22 , Jan 4, 2012
                                    • 0 Attachment
                                      2012/1/4 Marty Fried <marty@...>:
                                      >>
                                      > I'm surprised to hear this - it seems to go against the philosophy that
                                      > someone with root permission should know what they are doing, and is working
                                      >  without protection on purpose.

                                      That's not exact:

                                      Root account should NEVER been used in production environments. You
                                      should use sudo instead.

                                      Apart of that, a welder also should know what he are doing while
                                      managing soldering iron. But leaving things disordered in its
                                      workspace is always a bad idea. Even when you know exactly what you
                                      are doing.

                                      Similarly, having execution permission for file, like plain text or
                                      html, which is not designed to be executied, is a bad idea:

                                      First because you probably took less care about write access to that
                                      file because you didn't planed to execute it.

                                      And, second because, anytime you can, for example, forgive to type
                                      'vim' before the file name when trying to edit it.

                                      ...And I didn't talk about suid permission (which lets any user with
                                      execution permission to execute the file as if he were the owner
                                      --temporary "becoming him"--) ...but this permission is never set in
                                      usual umasks like when mounting not permission-enabled filesystems.



                                      Regards.

                                      --
                                      Joan Miquel Torres__________________________________
                                      Linux Registered User #164872
                                      http://www.mallorcaweb.net/joanmiquel
                                      BULMA: http://bulma.net http://breu.bulma.net/?l2301

                                      --
                                      You received this message from the "vim_use" maillist.
                                      Do not top-post! Type your reply below the text you are replying to.
                                      For more information, visit http://www.vim.org/maillist.php
                                    • Marty Fried
                                      On Wed, Jan 4, 2012 at 12:17 PM, Joan Miquel Torres Rigo
                                      Message 18 of 22 , Jan 4, 2012
                                      • 0 Attachment
                                        On Wed, Jan 4, 2012 at 12:17 PM, Joan Miquel Torres Rigo <joanmiquel@...> wrote:
                                        2012/1/4 Marty Fried <marty@...>:
                                        >>
                                        > I'm surprised to hear this - it seems to go against the philosophy that
                                        > someone with root permission should know what they are doing, and is working
                                        >  without protection on purpose.

                                        That's not exact:

                                        Root account should NEVER been used in production environments. You
                                        should use sudo instead.
                                        I agree.  That is why I believe that if someone is using root account for something, it is probably for maintenance, or to fix a problem.  It may be that the person has root access for maintenance, but is not in the sudo users file, and doesn't have time to set it up for a one-time use.  


                                        Apart of that, a welder also should know what he are doing while
                                        managing soldering iron. But leaving things disordered in its
                                        workspace is always a bad idea. Even when you know exactly what you
                                        are doing.
                                        I think the welder is the normal user.  It's more like root is a repair person, who is repairing the welder's equipment.  A welder shouldn't take the equipment apart, normally, but a repair person may need to, and knows what they are doing.  You don't want to disable the equipment in some way when he's working on it, as he may need it to be functioning normally to fix it.

                                         -- 
                                        Marty Fried

                                        --
                                        You received this message from the "vim_use" maillist.
                                        Do not top-post! Type your reply below the text you are replying to.
                                        For more information, visit http://www.vim.org/maillist.php
                                      • Christian Brabandt
                                        Hi Graham! ... What is the culprit? regards, Christian -- Ist mein Fleisch willig, kann Dein Geist noch so schwach sein. -- You received this message from the
                                        Message 19 of 22 , Jan 4, 2012
                                        • 0 Attachment
                                          Hi Graham!

                                          On Mi, 04 Jan 2012, Graham Lawrence wrote:

                                          > My apologies to all. It is something in my vimrc. Without that, vim
                                          > creates and edits on ntfs without complaint. My thanks to Joan Miquel
                                          > Torres Rigo for the suggestion.

                                          What is the culprit?

                                          regards,
                                          Christian
                                          --
                                          Ist mein Fleisch willig, kann Dein Geist noch so schwach sein.

                                          --
                                          You received this message from the "vim_use" maillist.
                                          Do not top-post! Type your reply below the text you are replying to.
                                          For more information, visit http://www.vim.org/maillist.php
                                        • Charles Campbell
                                          ... Nice philosophy, but: I suspect that due to the free nature of the various linux distros, there are quite a few root users who only barely know what
                                          Message 20 of 22 , Jan 4, 2012
                                          • 0 Attachment
                                            Marty Fried wrote:
                                            > On Wed, Jan 4, 2012 at 12:17 PM, Joan Miquel Torres Rigo
                                            > <joanmiquel@... <mailto:joanmiquel@...>> wrote:
                                            >
                                            > 2012/1/4 Marty Fried <marty@...
                                            > <mailto:marty@...>>:
                                            > >>
                                            > > I'm surprised to hear this - it seems to go against the
                                            > philosophy that
                                            > > someone with root permission should know what they are doing,
                                            > and is working
                                            > > without protection on purpose.
                                            >
                                            > That's not exact:
                                            >
                                            > Root account should NEVER been used in production environments. You
                                            > should use sudo instead.
                                            >
                                            > I agree. That is why I believe that if someone is using root account
                                            > for something, it is probably for maintenance, or to fix a problem.
                                            > It may be that the person has root access for maintenance, but is not
                                            > in the sudo users file, and doesn't have time to set it up for a
                                            > one-time use.
                                            >
                                            >
                                            > Apart of that, a welder also should know what he are doing while
                                            > managing soldering iron. But leaving things disordered in its
                                            > workspace is always a bad idea. Even when you know exactly what you
                                            > are doing.
                                            >
                                            > I think the welder is the normal user. It's more like root is a
                                            > repair person, who is repairing the welder's equipment. A welder
                                            > shouldn't take the equipment apart, normally, but a repair person may
                                            > need to, and knows what they are doing. You don't want to disable the
                                            > equipment in some way when he's working on it, as he may need it to be
                                            > functioning normally to fix it.
                                            >
                                            Nice philosophy, but: I suspect that due to the free nature of the
                                            various linux distros, there are quite a few "root" users who only
                                            barely know what they're doing. Having a complex editor like Vim doing
                                            things (such as backups, changing permissions, changing ownership) isn't
                                            a good idea imho. Such things should be done explicitly (ie.
                                            chmod,chgrp, chown, or by menu); requiring all the barely to somewhat
                                            competent root administrators to have mastered all the nuances of vim is
                                            naive.
                                            Admittedly, I didn't go over all 83 hits I got with helpgrep in detail.

                                            Regards,
                                            Chip Campbell

                                            --
                                            You received this message from the "vim_use" maillist.
                                            Do not top-post! Type your reply below the text you are replying to.
                                            For more information, visit http://www.vim.org/maillist.php
                                          • Marty Fried
                                            On Wed, Jan 4, 2012 at 2:25 PM, Charles Campbell
                                            Message 21 of 22 , Jan 4, 2012
                                            • 0 Attachment
                                              On Wed, Jan 4, 2012 at 2:25 PM, Charles Campbell <Charles.E.Campbell@...> wrote:
                                              Marty Fried wrote:

                                              I agree.  That is why I believe that if someone is using root account for something, it is probably for maintenance, or to fix a problem.  It may be that the person has root access for maintenance, but is not in the sudo users file, and doesn't have time to set it up for a one-time use.


                                              Nice philosophy, but: I suspect that due to the free nature of the various linux distros, there are quite a few "root" users who only barely know what they're doing.  Having a complex editor like Vim doing things (such as backups, changing permissions, changing ownership) isn't a good idea imho.  Such things should be done explicitly (ie. chmod,chgrp, chown, or by menu); requiring all the barely to somewhat competent root administrators to have mastered all the nuances of vim is naive.
                                              Admittedly, I didn't go over all 83 hits I got with helpgrep in detail.
                                              I guess I spoke somewhat out of ignorance; I wasn't aware that Vim did those things.  I don't even know how, and I'm not sure if I want to know.  :)

                                              I use the explicit methods you mentioned. I'm a simple kind of guy, and I like things to be pretty modular, so I know what will happen.  When I use an editor, I only expect it to change the contents of the file.  It's nice that it allows me, after prompting, to save to a read-only file, and I appreciate it sometimes, but I wouldn't mind if it didn't.

                                               I'll admit that I'm somewhat torn in my opinions about protecting barely competent users from themselves.  Throughout my long experience with computers, that's mostly the way I learned, by destroying things.  I learned things like backing up, not assuming things when the consequences matter, etc.

                                              Now, if it were Windows, maybe I would expect the handholding.  But I've messed up Windows in the past, too.  :)

                                              Regards,

                                              Marty Fried

                                              --
                                              You received this message from the "vim_use" maillist.
                                              Do not top-post! Type your reply below the text you are replying to.
                                              For more information, visit http://www.vim.org/maillist.php
                                            • porphyry5
                                              ... Apparently there is no culprit. After creating the file as I described, I returned vimrc to its place, preparatory to testing each individual entry.
                                              Message 22 of 22 , Jan 5, 2012
                                              • 0 Attachment
                                                On Jan 4, 1:28 pm, Christian Brabandt <cbli...@...> wrote:
                                                > Hi Graham!
                                                >
                                                > On Mi, 04 Jan 2012, Graham Lawrence wrote:
                                                >
                                                > > My apologies to all.  It is something in my vimrc.  Without that, vim
                                                > > creates and edits on ntfs without complaint.  My thanks to Joan Miquel
                                                > > Torres Rigo for the suggestion.
                                                >
                                                > What is the culprit?

                                                Apparently there is no culprit. After creating the file as I
                                                described, I returned vimrc to its place, preparatory to testing each
                                                individual entry. Repetitive drudgery is not to my taste, so rather
                                                than get down to it I decided to do a little clutching at straws.
                                                Went back to the buffer of the file created on the ntfs drive, added
                                                an "a" to it and issued a write command, which executed without
                                                incident. Similarly I created another new file on the drive.

                                                I have no explanation, and I'm not about to look for one.
                                                >
                                                > regards,
                                                > Christian
                                                > --
                                                > Ist mein Fleisch willig, kann Dein Geist noch so schwach sein.

                                                --
                                                You received this message from the "vim_use" maillist.
                                                Do not top-post! Type your reply below the text you are replying to.
                                                For more information, visit http://www.vim.org/maillist.php
                                              Your message has been successfully submitted and would be delivered to recipients shortly.