aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2017-10-01 22:31:39 -0700
committerPaul Eggert2017-10-01 22:33:20 -0700
commit135bca574c31b7bf6df6c63d28f180956928dde7 (patch)
tree1259c514b5304e7b1dbb8a9098f0a6dd63e00003 /src
parent4829a3b033b119b088947d14b73efc197b2547fa (diff)
downloademacs-135bca574c31b7bf6df6c63d28f180956928dde7.tar.gz
emacs-135bca574c31b7bf6df6c63d28f180956928dde7.zip
Port file-system-info to non-Microsoft
* admin/merge-gnulib (GNULIB_MODULES): Add fsusage. * doc/emacs/files.texi (Directories): Remove documentation of now-obsolete directory-free-space-program and directory-free-space-args. * etc/NEWS: Mention change. * etc/PROBLEMS: Slow df is no longer a problem. * lib/fsusage.c, lib/fsusage.h, m4/fsusage.m4: New files, copied from Gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lisp/dired.el (dired-free-space-program) (dired-free-space-args): These aliases are now obsolete. * lisp/files.el (directory-free-space-program) (directory-free-space-args): Now obsolete. (get-free-disk-space): Just call file-system-info instead of the now-obsolete directory-free-space-program. * nt/gnulib-cfg.mk (OMIT_GNULIB_MODULE_fsusage): New macro. * src/fileio.c: Include fsusage.h. (blocks_to_bytes, Ffile_system_info) [!DOS_NT]: New functions. (syms_of_fileio) [!DOS_NT]: Defsubr file-system-info.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/fileio.c b/src/fileio.c
index adb3534532c..11370279d1b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -96,6 +96,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
96#include <acl.h> 96#include <acl.h>
97#include <allocator.h> 97#include <allocator.h>
98#include <careadlinkat.h> 98#include <careadlinkat.h>
99#include <fsusage.h>
99#include <stat-time.h> 100#include <stat-time.h>
100#include <tempname.h> 101#include <tempname.h>
101 102
@@ -5765,6 +5766,40 @@ effect except for flushing STREAM's data. */)
5765 return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; 5766 return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil;
5766} 5767}
5767 5768
5769#ifndef DOS_NT
5770
5771/* Yield a Lisp float as close as possible to BLOCKSIZE * BLOCKS, with
5772 the result negated if NEGATE. */
5773static Lisp_Object
5774blocks_to_bytes (uintmax_t blocksize, uintmax_t blocks, bool negate)
5775{
5776 /* On typical platforms the following code is accurate to 53 bits,
5777 which is close enough. BLOCKSIZE is invariably a power of 2, so
5778 converting it to double does not lose information. */
5779 double bs = blocksize;
5780 return make_float (negate ? -bs * -blocks : bs * blocks);
5781}
5782
5783DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
5784 doc: /* Return storage information about the file system FILENAME is on.
5785Value is a list of numbers (TOTAL FREE AVAIL), where TOTAL is the total
5786storage of the file system, FREE is the free storage, and AVAIL is the
5787storage available to a non-superuser. All 3 numbers are in bytes.
5788If the underlying system call fails, value is nil. */)
5789 (Lisp_Object filename)
5790{
5791 Lisp_Object encoded = ENCODE_FILE (Fexpand_file_name (filename, Qnil));
5792 struct fs_usage u;
5793 if (get_fs_usage (SSDATA (encoded), NULL, &u) != 0)
5794 return Qnil;
5795 return list3 (blocks_to_bytes (u.fsu_blocksize, u.fsu_blocks, false),
5796 blocks_to_bytes (u.fsu_blocksize, u.fsu_bfree, false),
5797 blocks_to_bytes (u.fsu_blocksize, u.fsu_bavail,
5798 u.fsu_bavail_top_bit_set));
5799}
5800
5801#endif /* !DOS_NT */
5802
5768void 5803void
5769init_fileio (void) 5804init_fileio (void)
5770{ 5805{
@@ -6115,6 +6150,10 @@ This includes interactive calls to `delete-file' and
6115 6150
6116 defsubr (&Sset_binary_mode); 6151 defsubr (&Sset_binary_mode);
6117 6152
6153#ifndef DOS_NT
6154 defsubr (&Sfile_system_info);
6155#endif
6156
6118#ifdef HAVE_SYNC 6157#ifdef HAVE_SYNC
6119 defsubr (&Sunix_sync); 6158 defsubr (&Sunix_sync);
6120#endif 6159#endif