Subject: 24.4; Data lost when modifying file on filesystem with no space left on device / disc full

From: Matthew Blissett <[email-masked]>
Date: Sun, 17 May 2015 11:52:47 +0000

I attempted to edit a file on the filesystem containing $HOME, with no
space left (for non-root users).

Filesystem           1B-blocks            Used Available Use% Mounted on
/dev/sdb1      105,559,908,352 104,591,810,560         0 100% /home

When I saved the file (C-x C-s) Emacs gave the error "Write error: no
space left on device, /home", so I quit (C-x C-c), pressed "n" to not
save the file, and "yes" to exit with a modified buffer.  I expected the
original file to exist, but instead I have three zero-byte files:

-rwx------ 1 matt users     0 2015-05-17 11:57 script~
-rwxr-xr-x 1 matt users     0 2015-05-17 11:57 script
-rwxr-xr-x 1 matt users     0 2015-05-17 11:58 #script#

Example steps to reproduce:

dd if=/dev/zero of=small bs=1M count=10
mkfs.ext4 small
sudo mount -o loop small /mnt
sudo dd if=/dev/zero of=/mnt/85pc bs=1k count=8500
man man | sudo tee /mnt/man > /dev/null
sudo mkdir /mnt/.emacs.d
sudo chown -R $USER /mnt
HOME=/mnt emacs /mnt/man

(Edit the file, attempt to save, then exit discarding changes.)

ls -lAr /mnt

/mnt:
total 8,718,336
-rw-r--r-- 1 matt root  8,704,000 2015-05-17 11:31 85pc
drwxr-xr-x 2 matt root      1,024 2015-05-17 11:31 .emacs.d
drwx------ 2 matt root     12,288 2015-05-17 11:31 lost+found
-rw-r--r-- 1 matt root          0 2015-05-17 11:31 man
-rw-r--r-- 1 matt users         0 2015-05-17 11:31 #man#
-rw------- 1 matt users         0 2015-05-17 11:31 man~

/mnt/.emacs.d:
total 0
-rw------- 1 matt users 0 2015-05-17 11:31 %backup%~

I'd expect /mnt/man to be unchanged, or at minimum one of /mnt/man~ or
~/.emacs.d/%backup%~ to contain the original file's contents.

Cheers,

Matt

In GNU Emacs 24.4.1 (arm-unknown-linux-gnueabihf)
 of 2014-12-19 on henze, modified by Debian
System Description:	Debian GNU/Linux 8.0 (jessie)

Configured using:
 `configure --build arm-linux-gnueabihf --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --build arm-linux-gnueabihf --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --with-x=no --without-gconf --without-gsettings 'CFLAGS=-g -O2
 -fstack-protector-strong -Wformat -Werror=format-security -Wall'
 CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-z,relro'

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
ESC [ > 0 ; 1 1 5 ; 0 c C-x C-f DEL DEL / t m p / x 
DEL TAB TAB y RET C-x b RET RET C-x C-s C-x C-k RET 
n C-x k RET y e s RET ESC x r e p - e - b TAB RET

Recent messages:
Loading 00debian-vars...done
Loading /etc/emacs/site-start.d/50puppet-el.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...
Saving file /mnt/man...
Cannot write backup file; backing up in ~/.emacs.d/%backup%~
basic-save-buffer-2: Write error: no space left on device, /mnt/man
No keyboard macro defined.  Create one? (y or n) n
Quit

Load-path shadows:
/usr/share/emacs/24.4/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs/24.4/site-lisp/puppet-el/puppet-mode hides /usr/share/emacs/site-lisp/puppet-mode

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail regexp-opt rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils edmacro cl-loaddefs cl-lib kmacro
help-mode easymenu image xterm time-date tooltip electric uniquify
ediff-hook vc-hooks lisp-float-type tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify multi-tty emacs)

Memory information:
((conses 8 76608 7488)
 (symbols 24 17393 0)
 (miscs 20 35 135)
 (strings 16 10778 7177)
 (string-bytes 1 311082)
 (vectors 8 14096)
 (vector-slots 4 1145426 57182)
 (floats 8 65 408)
 (intervals 28 226 29)
 (buffers 512 13)
 (heap 1024 7950 543))