aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2022-10-13 21:13:45 +0200
committerMichael Albinus2022-10-13 21:13:45 +0200
commitcbd04ad3d572850775f18bde868c71abcde733ed (patch)
treecca60866632ff253cbc5062ab7483379e81a1376
parent10f55975d34dd7299f72fdf8d93fd8cbe2e41e25 (diff)
downloademacs-cbd04ad3d572850775f18bde868c71abcde733ed.tar.gz
emacs-cbd04ad3d572850775f18bde868c71abcde733ed.zip
Clarify structure of file-attribute's device number
* doc/lispref/buffers.texi (Buffer File Name): Fix description of buffer-file-number. * doc/lispref/files.texi (File Attributes): Clarify type of device number. Describe file-attribute-file-number. (Bug#58446) * etc/NEWS: Mention file-attribute-file-number. * lisp/files.el (buffer-file-number, file-attribute-device-number) (file-attribute-collect): Fix docstring. (file-attribute-file-number): New defsubst. (find-buffer-visiting, find-file-noselect) (set-visited-file-name, basic-save-buffer): * lisp/startup.el (normal-top-level-add-subdirs-to-load-path): * lisp/eshell/em-unix.el (eshell-shuffle-files): Use it. * src/dired.c (Ffile_attributes): Fix docstring.
-rw-r--r--doc/lispref/buffers.texi4
-rw-r--r--doc/lispref/files.texi13
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/eshell/em-unix.el6
-rw-r--r--lisp/files.el24
-rw-r--r--lisp/startup.el2
-rw-r--r--src/dired.c5
7 files changed, 38 insertions, 25 deletions
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi
index 6a1d125701c..b46b6c52d86 100644
--- a/doc/lispref/buffers.texi
+++ b/doc/lispref/buffers.texi
@@ -427,12 +427,12 @@ It is a permanent local, unaffected by
427@end defvar 427@end defvar
428 428
429@defvar buffer-file-number 429@defvar buffer-file-number
430This buffer-local variable holds the file number and directory device 430This buffer-local variable holds the inode number and directory device
431number of the file visited in the current buffer, or @code{nil} if no 431number of the file visited in the current buffer, or @code{nil} if no
432file or a nonexistent file is visited. It is a permanent local, 432file or a nonexistent file is visited. It is a permanent local,
433unaffected by @code{kill-all-local-variables}. 433unaffected by @code{kill-all-local-variables}.
434 434
435The value is normally a list of the form @code{(@var{filenum} 435The value is normally a list of the form @code{(@var{inodenum}
436@var{devnum})}. This pair of numbers uniquely identifies the file among 436@var{devnum})}. This pair of numbers uniquely identifies the file among
437all files accessible on the system. See the function 437all files accessible on the system. See the function
438@code{file-attributes}, in @ref{File Attributes}, for more information 438@code{file-attributes}, in @ref{File Attributes}, for more information
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 0e8efa3297c..b9d4e87dc73 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -1405,13 +1405,16 @@ a nonnegative integer.
1405 1405
1406@item 1406@item
1407The filesystem number of the device that the file is on 1407The filesystem number of the device that the file is on
1408@code{file-attribute-device-number}), an integer. 1408(@code{file-attribute-device-number}), an integer or a cons cell of
1409This element and the file's inode number 1409integers. The latter is sometimes used by remote files, in order to
1410together give enough information to distinguish any two files on the 1410distinguish the remote filesystems from the local ones.
1411system---no two files can have the same values for both of these
1412numbers.
1413@end enumerate 1411@end enumerate
1414 1412
1413The file's inode and device numbers together give enough information
1414to distinguish any two files on the system---no two files can have the
1415same values for both of these numbers. This tupel is returned by
1416@code{file-attribute-file-number}.
1417
1415For example, here are the file attributes for @file{files.texi}: 1418For example, here are the file attributes for @file{files.texi}:
1416 1419
1417@example 1420@example
diff --git a/etc/NEWS b/etc/NEWS
index ca857056fd8..7808c3beb20 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1872,7 +1872,7 @@ If non-nil, multiple revisions can be queried. This is done using
1872'completing-read-multiple'. 1872'completing-read-multiple'.
1873 1873
1874--- 1874---
1875*** New function 'vc-read-multiple-revisions' 1875*** New function 'vc-read-multiple-revisions'.
1876This function invokes 'vc-read-revision' with a non-nil value for 1876This function invokes 'vc-read-revision' with a non-nil value for
1877MULTIPLE. 1877MULTIPLE.
1878 1878
@@ -1880,7 +1880,7 @@ MULTIPLE.
1880*** New command 'vc-prepare-patch'. 1880*** New command 'vc-prepare-patch'.
1881Patches for any version control system can be prepared using VC. The 1881Patches for any version control system can be prepared using VC. The
1882command will query what commits to send and will compose messages for 1882command will query what commits to send and will compose messages for
1883your mail user agent. The behaviour of 'vc-prepare-patch' can be 1883your mail user agent. The behavior of 'vc-prepare-patch' can be
1884modified by the user options 'vc-prepare-patches-separately' and 1884modified by the user options 'vc-prepare-patches-separately' and
1885'vc-default-patch-addressee'. 1885'vc-default-patch-addressee'.
1886 1886
@@ -3148,6 +3148,11 @@ The following generalized variables have been made obsolete:
3148* Lisp Changes in Emacs 29.1 3148* Lisp Changes in Emacs 29.1
3149 3149
3150+++ 3150+++
3151** New accessor function 'file-attribute-file-number'.
3152It returns the list of the inode and device numbers retrieved by
3153'file-attributes'. This value can be used to identify a file uniquely.
3154
3155+++
3151** New macro 'while-let'. 3156** New macro 'while-let'.
3152This is like 'when-let', but repeats until a binding form is nil. 3157This is like 'when-let', but repeats until a binding form is nil.
3153 3158
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index 40b83010f94..378b0ceeeae 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -372,12 +372,10 @@ Remove the DIRECTORY(ies), if they are empty.")
372 (setq attr (eshell-file-attributes (car files))) 372 (setq attr (eshell-file-attributes (car files)))
373 (file-attribute-inode-number attr-target) 373 (file-attribute-inode-number attr-target)
374 (file-attribute-inode-number attr) 374 (file-attribute-inode-number attr)
375 (equal (file-attribute-inode-number attr-target)
376 (file-attribute-inode-number attr))
377 (file-attribute-device-number attr-target) 375 (file-attribute-device-number attr-target)
378 (file-attribute-device-number attr) 376 (file-attribute-device-number attr)
379 (equal (file-attribute-device-number attr-target) 377 (equal (file-attribute-file-number attr-target)
380 (file-attribute-device-number attr))) 378 (file-attribute-file-number attr)))
381 (eshell-error (format-message "%s: `%s' and `%s' are the same file\n" 379 (eshell-error (format-message "%s: `%s' and `%s' are the same file\n"
382 command (car files) target))) 380 command (car files) target)))
383 (t 381 (t
diff --git a/lisp/files.el b/lisp/files.el
index 94d110f0b7d..1a301485517 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -208,8 +208,8 @@ if the file has changed on disk and you have not edited the buffer."
208 :group 'find-file) 208 :group 'find-file)
209 209
210(defvar-local buffer-file-number nil 210(defvar-local buffer-file-number nil
211 "The device number and file number of the file visited in the current buffer. 211 "The inode and device numbers of the file visited in the current buffer.
212The value is a list of the form (FILENUM DEVNUM). 212The value is a list of the form (INODENUM DEVNUM).
213This pair of numbers uniquely identifies the file. 213This pair of numbers uniquely identifies the file.
214If the buffer is visiting a new file, the value is nil.") 214If the buffer is visiting a new file, the value is nil.")
215(put 'buffer-file-number 'permanent-local t) 215(put 'buffer-file-number 'permanent-local t)
@@ -2163,7 +2163,7 @@ If there is no such live buffer, return nil."
2163 (setq list (cdr list))) 2163 (setq list (cdr list)))
2164 found) 2164 found)
2165 (let* ((attributes (file-attributes truename)) 2165 (let* ((attributes (file-attributes truename))
2166 (number (nthcdr 10 attributes)) 2166 (number (file-attribute-file-number attributes))
2167 (list (buffer-list)) found) 2167 (list (buffer-list)) found)
2168 (and buffer-file-numbers-unique 2168 (and buffer-file-numbers-unique
2169 (car-safe number) ;Make sure the inode is not just nil. 2169 (car-safe number) ;Make sure the inode is not just nil.
@@ -2366,7 +2366,7 @@ the various files."
2366 (let* ((buf (get-file-buffer filename)) 2366 (let* ((buf (get-file-buffer filename))
2367 (truename (abbreviate-file-name (file-truename filename))) 2367 (truename (abbreviate-file-name (file-truename filename)))
2368 (attributes (file-attributes truename)) 2368 (attributes (file-attributes truename))
2369 (number (nthcdr 10 attributes)) 2369 (number (file-attribute-file-number attributes))
2370 ;; Find any buffer for a file that has same truename. 2370 ;; Find any buffer for a file that has same truename.
2371 (other (and (not buf) 2371 (other (and (not buf)
2372 (find-buffer-visiting 2372 (find-buffer-visiting
@@ -4744,7 +4744,7 @@ the old visited file has been renamed to the new name FILENAME."
4744 (setq buffer-file-name truename)))) 4744 (setq buffer-file-name truename))))
4745 (setq buffer-file-number 4745 (setq buffer-file-number
4746 (if filename 4746 (if filename
4747 (nthcdr 10 (file-attributes buffer-file-name)) 4747 (file-attribute-file-number (file-attributes buffer-file-name))
4748 nil)) 4748 nil))
4749 ;; write-file-functions is normally used for things like ftp-find-file 4749 ;; write-file-functions is normally used for things like ftp-find-file
4750 ;; that visit things that are not local files as if they were files. 4750 ;; that visit things that are not local files as if they were files.
@@ -5733,7 +5733,7 @@ Before and after saving the buffer, this function runs
5733 (setq save-buffer-coding-system last-coding-system-used) 5733 (setq save-buffer-coding-system last-coding-system-used)
5734 (setq buffer-file-coding-system last-coding-system-used)) 5734 (setq buffer-file-coding-system last-coding-system-used))
5735 (setq buffer-file-number 5735 (setq buffer-file-number
5736 (nthcdr 10 (file-attributes buffer-file-name))) 5736 (file-attribute-file-number (file-attributes buffer-file-name)))
5737 (if setmodes 5737 (if setmodes
5738 (condition-case () 5738 (condition-case ()
5739 (progn 5739 (progn
@@ -8658,19 +8658,25 @@ It is a nonnegative integer."
8658 8658
8659(defsubst file-attribute-device-number (attributes) 8659(defsubst file-attribute-device-number (attributes)
8660 "The file system device number in ATTRIBUTES returned by `file-attributes'. 8660 "The file system device number in ATTRIBUTES returned by `file-attributes'.
8661It is an integer." 8661It is an integer or a cons cell of integers."
8662 (nth 11 attributes)) 8662 (nth 11 attributes))
8663 8663
8664(defsubst file-attribute-file-number (attributes)
8665 "The inode and device numbers in ATTRIBUTES returned by `file-attributes'.
8666The value is a list of the form (INODENUM DEVNUM).
8667This pair of numbers uniquely identifies the file."
8668 (nthcdr 10 attributes))
8669
8664(defun file-attribute-collect (attributes &rest attr-names) 8670(defun file-attribute-collect (attributes &rest attr-names)
8665 "Return a sublist of ATTRIBUTES returned by `file-attributes'. 8671 "Return a sublist of ATTRIBUTES returned by `file-attributes'.
8666ATTR-NAMES are symbols with the selected attribute names. 8672ATTR-NAMES are symbols with the selected attribute names.
8667 8673
8668Valid attribute names are: type, link-number, user-id, group-id, 8674Valid attribute names are: type, link-number, user-id, group-id,
8669access-time, modification-time, status-change-time, size, modes, 8675access-time, modification-time, status-change-time, size, modes,
8670inode-number and device-number." 8676inode-number, device-number and file-number."
8671 (let ((all '(type link-number user-id group-id access-time 8677 (let ((all '(type link-number user-id group-id access-time
8672 modification-time status-change-time 8678 modification-time status-change-time
8673 size modes inode-number device-number)) 8679 size modes inode-number device-number file-number))
8674 result) 8680 result)
8675 (while attr-names 8681 (while attr-names
8676 (let ((attr (pop attr-names))) 8682 (let ((attr (pop attr-names)))
diff --git a/lisp/startup.el b/lisp/startup.el
index 04de7e42fea..c7faf4abc6f 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -458,7 +458,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
458 ;; The Windows version doesn't report meaningful inode numbers, so 458 ;; The Windows version doesn't report meaningful inode numbers, so
459 ;; use the canonicalized absolute file name of the directory instead. 459 ;; use the canonicalized absolute file name of the directory instead.
460 (setq attrs (or canonicalized 460 (setq attrs (or canonicalized
461 (nthcdr 10 (file-attributes this-dir)))) 461 (file-attribute-file-number (file-attributes this-dir))))
462 (unless (member attrs normal-top-level-add-subdirs-inode-list) 462 (unless (member attrs normal-top-level-add-subdirs-inode-list)
463 (push attrs normal-top-level-add-subdirs-inode-list) 463 (push attrs normal-top-level-add-subdirs-inode-list)
464 (dolist (file contents) 464 (dolist (file contents)
diff --git a/src/dired.c b/src/dired.c
index c2c099f0a5f..32c083ad7b0 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -923,11 +923,12 @@ Elements of the attribute list are:
923 8. File modes, as a string of ten letters or dashes as in ls -l. 923 8. File modes, as a string of ten letters or dashes as in ls -l.
924 9. An unspecified value, present only for backward compatibility. 924 9. An unspecified value, present only for backward compatibility.
92510. inode number, as a nonnegative integer. 92510. inode number, as a nonnegative integer.
92611. Filesystem device number, as an integer. 92611. Filesystem device number, as an integer or a cons cell of integers.
927 927
928Large integers are bignums, so `eq' might not work on them. 928Large integers are bignums, so `eq' might not work on them.
929On most filesystems, the combination of the inode and the device 929On most filesystems, the combination of the inode and the device
930number uniquely identifies the file. 930number uniquely identifies the file. This is provided by the access
931function `file-attribute-file-number'.
931 932
932On MS-Windows, performance depends on `w32-get-true-file-attributes', 933On MS-Windows, performance depends on `w32-get-true-file-attributes',
933which see. 934which see.