[PATCH] vi read-only mode bugfix and enhancement

Natanael Copa natanael.copa at gmail.com
Thu Jul 12 14:35:01 UTC 2007


Hi,

Attatched is a patch that will fix a bug in vi, enhance functionality a
bit, reduce size and make the code a bit more readable. Testcase
follows.

  echo "this file is readonly" > file1
  chmod 400 file1
  sudo chown root file

Before patch:

  ./busybox_old vi file1

File is empty (user has no read permissions) and statusline says:

  - file1 1/1 100%

Note that there is no indication of error or [Read-only]

After patch:

  ./busybox vi file1

File is still empty (user has no read permissions) but status line says:

  - file1 [Read-only] 1/1 100%

Original vim shows "permission denied" but "Read-only" is better than
nothing.

Try edit file and save as root. Old behaviour let user do this even if
file is write protected.

After patch file will be marked as [Read-only]. root will need to save
file with :wq!

Make bloatcheck:

function                                             old     new   delta
update_ro_status                                       -      86     +86
edit_file                                            921     919      -2
colon                                               3798    3778     -20
file_insert                                          336     260     -76
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 86/-98)            Total: -12
bytes
   text    data     bss     dec     hex filename
 706447    4728   14528  725703   b12c7 busybox_old
 706439    4728   14528  725695   b12bf busybox_unstripped


Natanael Copa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vi-readonly-fix.patch
Type: text/x-patch
Size: 4736 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070712/805f0afa/attachment-0002.bin 


More information about the busybox mailing list