Rename format.{cc,h} -> util.{cc,h}.
[cumulus.git] / scandir.cc
index 980d843..d398eee 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 #include <string>
 #include <vector>
 
-#include "format.h"
 #include "localdb.h"
 #include "store.h"
 #include "sha1.h"
 #include "statcache.h"
+#include "util.h"
 
 using std::list;
 using std::string;
 using std::vector;
 using std::ostream;
 
+/* Version information.  This will be filled in by the Makefile. */
+#ifndef LBS_VERSION
+#define LBS_VERSION Unknown
+#endif
+#define LBS_STRINGIFY(s) LBS_STRINGIFY2(s)
+#define LBS_STRINGIFY2(s) #s
+static const char lbs_version[] = LBS_STRINGIFY(LBS_VERSION);
+
 static TarSegmentStore *tss = NULL;
 
 /* Buffer for holding a single block of data read from a file. */
@@ -340,11 +349,11 @@ void scanfile(const string& path, bool include)
     case S_IFSOCK:
         inode_type = 's';
         break;
-    case S_IFCHR:
-        inode_type = 'c';
-        break;
     case S_IFBLK:
-        inode_type = 'b';
+    case S_IFCHR:
+        inode_type = ((stat_buf.st_mode & S_IFMT) == S_IFBLK) ? 'b' : 'c';
+        file_info["device"] = encode_int(major(stat_buf.st_rdev))
+            + "/" + encode_int(minor(stat_buf.st_rdev));
         break;
     case S_IFLNK:
         inode_type = 'l';
@@ -616,6 +625,8 @@ int main(int argc, char *argv[])
     {
         list<string>::const_iterator i;
 
+        printf("LBS Version: %s\n", lbs_version);
+
         printf("--dest=%s\n--localdb=%s\n\n",
                backup_dest.c_str(), localdb_dir.c_str());
 
@@ -686,6 +697,7 @@ int main(int argc, char *argv[])
     std::ofstream descriptor(desc_filename.c_str());
 
     descriptor << "Format: LBS Snapshot v0.1\n";
+    descriptor << "Producer: " << lbs_version << "\n";
     strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf);
     descriptor << "Date: " << desc_buf << "\n";
     descriptor << "Root: " << backup_root << "\n";