From edad8fa9c588be3f698dc029ded9b2c5cf4a99dd Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 8 Aug 2007 10:00:00 -0700 Subject: [PATCH] Include link counts and inode numbers in metadata dumps. When the link count on a file is greater than one, include the link count and a representation of the inode number (actually, inode number and device). This will provide all information which should be needed for detecting hard links at restore time. The backup program itself does not identify hard-linked files and treat them any differently--since storage for identical files can be shared, the storing a hard-linked file multiple times should still be relatively efficient. --- format.txt | 14 ++++++++++++++ scandir.cc | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/format.txt b/format.txt index 590116d..54d9f8c 100644 --- a/format.txt +++ b/format.txt @@ -186,6 +186,20 @@ Common fields (required in all stanzas): s socket mtime [integer]: Modification time of the file. +Optional common fields: + links [integer]: Number of hard links to this file, generally only + reported if greater than 1. + inode [string]: String specifying the inode number of this file when + it was dumped. If "links" is greater than 1, then searching for + other files that have an identical "inode" value can be used to + determine which files should be hard-linked together when + restoring. The inode field should be treated as an opaque + string and compared for equality as such; an implementation may + choose whatever representation is convenient. The format + produced by the standard tool is // (where + and specify the device of the containing + filesystem and is the inode number of the file). + Special fields used for regular files: checksum [string]: Checksum of the file contents. size [integer]: Size of the file, in bytes. diff --git a/scandir.cc b/scandir.cc index 841dc91..1b3032d 100644 --- a/scandir.cc +++ b/scandir.cc @@ -305,6 +305,13 @@ void dump_inode(const string& path, // Path within snapshot file_info["group"] += " (" + uri_encode(grp->gr_name) + ")"; } + if (stat_buf.st_nlink > 1) { + file_info["links"] = encode_int(stat_buf.st_nlink); + file_info["inode"] = encode_int(major(stat_buf.st_dev)) + + "/" + encode_int(minor(stat_buf.st_dev)) + + "/" + encode_int(stat_buf.st_ino); + } + char inode_type; switch (stat_buf.st_mode & S_IFMT) { -- 2.20.1