common/parse-utils.o \
common/path-utils.o \
common/rbtree-utils.o \
+ common/reproducible.o \
common/send-stream.o \
common/send-utils.o \
common/sort-utils.o \
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include "kerncompat.h"
+#include <limits.h>
+#include <stdlib.h>
+#include <time.h>
+#include "common/messages.h"
+#include "common/parse-utils.h"
+#include "common/reproducible.h"
+
+time_t reproducible_now(void)
+{
+ const char *sde = getenv("SOURCE_DATE_EPOCH");
+ u64 val;
+
+ if (!sde || !*sde)
+ return time(NULL);
+
+ if (parse_u64(sde, &val) < 0 || val > (u64)LONG_MAX) {
+ error("invalid SOURCE_DATE_EPOCH: '%s' is not a non-negative integer fitting in time_t",
+ sde);
+ exit(1);
+ }
+ return (time_t)val;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef __BTRFS_REPRODUCIBLE_H__
+#define __BTRFS_REPRODUCIBLE_H__
+
+#include <time.h>
+
+/*
+ * Return SOURCE_DATE_EPOCH as a time_t, or time(NULL) when it is unset
+ * or empty. Errors out if it is set to something other than a
+ * non-negative integer that fits in time_t.
+ */
+time_t reproducible_now(void);
+
+#endif
#include "kernel-shared/disk-io.h"
#include "kernel-shared/uuid-tree.h"
#include "kernel-shared/transaction.h"
-#include "common/root-tree-utils.h"
#include "common/messages.h"
+#include "common/reproducible.h"
+#include "common/root-tree-utils.h"
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid)
{
int ret;
struct btrfs_inode_item inode_item;
- time_t now = time(NULL);
+ time_t now = reproducible_now();
memset(&inode_item, 0, sizeof(inode_item));
btrfs_set_stack_inode_generation(&inode_item, trans->transid);
#include "common/messages.h"
#include "common/device-utils.h"
#include "common/open-utils.h"
+#include "common/reproducible.h"
#include "common/string-utils.h"
#include "mkfs/common.h"
btrfs_set_item_offset(buf, nritems, itemoff);
btrfs_set_item_size(buf, nritems, sizeof(root_item));
if (blk == MKFS_FS_TREE) {
- time_t now = time(NULL);
+ time_t now = reproducible_now();
uuid_generate(uuid);
memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);