1 #define _LARGEFILE64_SOURCE 1
3 #include "../../config/config.h"
14 #ifdef HAVE_SYS_TYPES_H
15 #include <sys/types.h>
17 #ifdef HAVE_SYS_STAT_H
24 #ifdef HAVE_LINUX_FS_H
27 #ifdef HAVE_SYS_IOCTL_H
28 #include <sys/ioctl.h>
31 static int istty2 = 0;
33 // Probably we should use autoconf or something and set HAVE_PY_GETARGCARGV...
34 #if __WIN32__ || __CYGWIN__
36 // There's no 'ps' on win32 anyway, and Py_GetArgcArgv() isn't available.
37 static void unpythonize_argv(void) { }
39 #else // not __WIN32__
41 // For some reason this isn't declared in Python.h
42 extern void Py_GetArgcArgv(int *argc, char ***argv);
44 static void unpythonize_argv(void)
49 Py_GetArgcArgv(&argc, &argv);
51 for (i = 0; i < argc-1; i++)
53 if (argv[i] + strlen(argv[i]) + 1 != argv[i+1])
55 // The argv block doesn't work the way we expected; it's unsafe
61 arge = argv[argc-1] + strlen(argv[argc-1]) + 1;
63 if (strstr(argv[0], "python") && argv[1] == argv[0] + strlen(argv[0]) + 1)
67 p = strrchr(argv[1], '/');
73 memmove(argv[0], p, len);
74 memset(arge - diff, 0, diff);
75 for (i = 0; i < argc; i++)
76 argv[i] = argv[i+1] ? argv[i+1]-diff : NULL;
81 #endif // not __WIN32__ or __CYGWIN__
84 static PyObject *selftest(PyObject *self, PyObject *args)
86 if (!PyArg_ParseTuple(args, ""))
89 return Py_BuildValue("i", !bupsplit_selftest());
93 static PyObject *blobbits(PyObject *self, PyObject *args)
95 if (!PyArg_ParseTuple(args, ""))
97 return Py_BuildValue("i", BUP_BLOBBITS);
101 static PyObject *splitbuf(PyObject *self, PyObject *args)
103 unsigned char *buf = NULL;
104 int len = 0, out = 0, bits = -1;
106 if (!PyArg_ParseTuple(args, "t#", &buf, &len))
108 out = bupsplit_find_ofs(buf, len, &bits);
109 if (out) assert(bits >= BUP_BLOBBITS);
110 return Py_BuildValue("ii", out, bits);
114 static PyObject *bitmatch(PyObject *self, PyObject *args)
116 unsigned char *buf1 = NULL, *buf2 = NULL;
117 int len1 = 0, len2 = 0;
120 if (!PyArg_ParseTuple(args, "t#t#", &buf1, &len1, &buf2, &len2))
124 for (byte = 0; byte < len1 && byte < len2; byte++)
126 int b1 = buf1[byte], b2 = buf2[byte];
129 for (bit = 0; bit < 8; bit++)
130 if ( (b1 & (0x80 >> bit)) != (b2 & (0x80 >> bit)) )
136 return Py_BuildValue("i", byte*8 + bit);
140 static PyObject *firstword(PyObject *self, PyObject *args)
142 unsigned char *buf = NULL;
146 if (!PyArg_ParseTuple(args, "t#", &buf, &len))
152 v = ntohl(*(uint32_t *)buf);
153 return PyLong_FromUnsignedLong(v);
157 #define BLOOM2_HEADERLEN 16
164 static void to_bloom_address_bitmask4(const bits40_t *buf,
165 const int nbits, uint64_t *v, unsigned char *bitmask)
170 mask = (1<<nbits) - 1;
171 raw = (((uint64_t)ntohl(buf->high)) << 8) | buf->low;
172 bit = (raw >> (37-nbits)) & 0x7;
173 *v = (raw >> (40-nbits)) & mask;
177 static void to_bloom_address_bitmask5(const uint32_t *buf,
178 const int nbits, uint32_t *v, unsigned char *bitmask)
183 mask = (1<<nbits) - 1;
185 bit = (raw >> (29-nbits)) & 0x7;
186 *v = (raw >> (32-nbits)) & mask;
190 #define BLOOM_SET_BIT(name, address, itype, otype) \
191 static void name(unsigned char *bloom, const void *buf, const int nbits)\
193 unsigned char bitmask;\
195 address((itype *)buf, nbits, &v, &bitmask);\
196 bloom[BLOOM2_HEADERLEN+v] |= bitmask;\
198 BLOOM_SET_BIT(bloom_set_bit4, to_bloom_address_bitmask4, bits40_t, uint64_t)
199 BLOOM_SET_BIT(bloom_set_bit5, to_bloom_address_bitmask5, uint32_t, uint32_t)
202 #define BLOOM_GET_BIT(name, address, itype, otype) \
203 static int name(const unsigned char *bloom, const void *buf, const int nbits)\
205 unsigned char bitmask;\
207 address((itype *)buf, nbits, &v, &bitmask);\
208 return bloom[BLOOM2_HEADERLEN+v] & bitmask;\
210 BLOOM_GET_BIT(bloom_get_bit4, to_bloom_address_bitmask4, bits40_t, uint64_t)
211 BLOOM_GET_BIT(bloom_get_bit5, to_bloom_address_bitmask5, uint32_t, uint32_t)
214 static PyObject *bloom_add(PyObject *self, PyObject *args)
216 unsigned char *sha = NULL, *bloom = NULL;
218 int len = 0, blen = 0, nbits = 0, k = 0;
220 if (!PyArg_ParseTuple(args, "w#s#ii", &bloom, &blen, &sha, &len, &nbits, &k))
223 if (blen < 16+(1<<nbits) || len % 20 != 0)
230 for (end = sha + len; sha < end; sha += 20/k)
231 bloom_set_bit5(bloom, sha, nbits);
237 for (end = sha + len; sha < end; sha += 20/k)
238 bloom_set_bit4(bloom, sha, nbits);
244 return Py_BuildValue("i", len/20);
247 static PyObject *bloom_contains(PyObject *self, PyObject *args)
249 unsigned char *sha = NULL, *bloom = NULL;
250 int len = 0, blen = 0, nbits = 0, k = 0;
254 if (!PyArg_ParseTuple(args, "t#s#ii", &bloom, &blen, &sha, &len, &nbits, &k))
264 for (steps = 1, end = sha + 20; sha < end; sha += 20/k, steps++)
265 if (!bloom_get_bit5(bloom, sha, nbits))
266 return Py_BuildValue("Oi", Py_None, steps);
272 for (steps = 1, end = sha + 20; sha < end; sha += 20/k, steps++)
273 if (!bloom_get_bit4(bloom, sha, nbits))
274 return Py_BuildValue("Oi", Py_None, steps);
279 return Py_BuildValue("ii", 1, k);
283 static uint32_t _extract_bits(unsigned char *buf, int nbits)
287 mask = (1<<nbits) - 1;
288 v = ntohl(*(uint32_t *)buf);
289 v = (v >> (32-nbits)) & mask;
292 static PyObject *extract_bits(PyObject *self, PyObject *args)
294 unsigned char *buf = NULL;
295 int len = 0, nbits = 0;
297 if (!PyArg_ParseTuple(args, "t#i", &buf, &len, &nbits))
303 return PyLong_FromUnsignedLong(_extract_bits(buf, nbits));
308 unsigned char bytes[20];
320 static int _cmp_sha(const struct sha *sha1, const struct sha *sha2)
323 for (i = 0; i < sizeof(struct sha); i++)
324 if (sha1->bytes[i] != sha2->bytes[i])
325 return sha1->bytes[i] - sha2->bytes[i];
330 static void _fix_idx_order(struct idx **idxs, int *last_i)
333 int low, mid, high, c = 0;
336 if (idxs[*last_i]->cur >= idxs[*last_i]->end)
338 idxs[*last_i] = NULL;
351 mid = (low + high) / 2;
352 c = _cmp_sha(idx->cur, idxs[mid]->cur);
364 memmove(&idxs[mid+1], &idxs[mid], (*last_i-mid)*sizeof(struct idx *));
369 static uint32_t _get_idx_i(struct idx *idx)
371 if (idx->cur_name == NULL)
372 return idx->name_base;
373 return ntohl(*idx->cur_name) + idx->name_base;
376 #define MIDX4_HEADERLEN 12
378 static PyObject *merge_into(PyObject *self, PyObject *args)
380 PyObject *ilist = NULL;
381 unsigned char *fmap = NULL;
382 struct sha *sha_ptr, *sha_start = NULL;
383 uint32_t *table_ptr, *name_ptr, *name_start;
384 struct idx **idxs = NULL;
385 int flen = 0, bits = 0, i;
386 uint32_t total, count, prefix;
390 if (!PyArg_ParseTuple(args, "w#iIO", &fmap, &flen, &bits, &total, &ilist))
393 num_i = PyList_Size(ilist);
394 idxs = (struct idx **)PyMem_Malloc(num_i * sizeof(struct idx *));
396 for (i = 0; i < num_i; i++)
398 long len, sha_ofs, name_map_ofs;
399 idxs[i] = (struct idx *)PyMem_Malloc(sizeof(struct idx));
400 PyObject *itup = PyList_GetItem(ilist, i);
401 if (!PyArg_ParseTuple(itup, "t#llli", &idxs[i]->map, &idxs[i]->bytes,
402 &len, &sha_ofs, &name_map_ofs, &idxs[i]->name_base))
404 idxs[i]->cur = (struct sha *)&idxs[i]->map[sha_ofs];
405 idxs[i]->end = &idxs[i]->cur[len];
407 idxs[i]->cur_name = (uint32_t *)&idxs[i]->map[name_map_ofs];
409 idxs[i]->cur_name = NULL;
411 table_ptr = (uint32_t *)&fmap[MIDX4_HEADERLEN];
412 sha_start = sha_ptr = (struct sha *)&table_ptr[1<<bits];
413 name_start = name_ptr = (uint32_t *)&sha_ptr[total];
422 if (count % 102424 == 0 && istty2)
423 fprintf(stderr, "midx: writing %.2f%% (%d/%d)\r",
424 count*100.0/total, count, total);
426 new_prefix = _extract_bits((unsigned char *)idx->cur, bits);
427 while (prefix < new_prefix)
428 table_ptr[prefix++] = htonl(count);
429 memcpy(sha_ptr++, idx->cur, sizeof(struct sha));
430 *name_ptr++ = htonl(_get_idx_i(idx));
432 if (idx->cur_name != NULL)
434 _fix_idx_order(idxs, &last_i);
437 while (prefix < (1<<bits))
438 table_ptr[prefix++] = htonl(count);
439 assert(count == total);
440 assert(prefix == (1<<bits));
441 assert(sha_ptr == sha_start+count);
442 assert(name_ptr == name_start+count);
445 return PyLong_FromUnsignedLong(count);
448 // This function should technically be macro'd out if it's going to be used
449 // more than ocasionally. As of this writing, it'll actually never be called
450 // in real world bup scenarios (because our packs are < MAX_INT bytes).
451 static uint64_t htonll(uint64_t value)
453 static const int endian_test = 42;
455 if (*(char *)&endian_test == endian_test) // LSB-MSB
456 return ((uint64_t)htonl(value & 0xFFFFFFFF) << 32) | htonl(value >> 32);
457 return value; // already in network byte order MSB-LSB
460 #define PACK_IDX_V2_HEADERLEN 8
461 #define FAN_ENTRIES 256
463 static PyObject *write_idx(PyObject *self, PyObject *args)
465 PyObject *pf = NULL, *idx = NULL;
468 unsigned char *fmap = NULL;
472 int i, j, ofs64_count;
473 uint32_t *fan_ptr, *crc_ptr, *ofs_ptr;
476 if (!PyArg_ParseTuple(args, "Ow#OI", &pf, &fmap, &flen, &idx, &total))
479 fan_ptr = (uint32_t *)&fmap[PACK_IDX_V2_HEADERLEN];
480 sha_ptr = (struct sha *)&fan_ptr[FAN_ENTRIES];
481 crc_ptr = (uint32_t *)&sha_ptr[total];
482 ofs_ptr = (uint32_t *)&crc_ptr[total];
483 f = PyFile_AsFile(pf);
487 for (i = 0; i < FAN_ENTRIES; ++i)
490 part = PyList_GET_ITEM(idx, i);
492 plen = PyList_GET_SIZE(part);
494 *fan_ptr++ = htonl(count);
495 for (j = 0; j < plen; ++j)
497 unsigned char *sha = NULL;
501 if (!PyArg_ParseTuple(PyList_GET_ITEM(part, j), "t#IK",
502 &sha, &sha_len, &crc, &ofs))
504 if (sha_len != sizeof(struct sha))
506 memcpy(sha_ptr++, sha, sizeof(struct sha));
507 *crc_ptr++ = htonl(crc);
508 if (ofs > 0x7fffffff)
510 uint64_t nofs = htonll(ofs);
511 if (fwrite(&nofs, sizeof(uint64_t), 1, f) != 1)
512 return PyErr_SetFromErrno(PyExc_OSError);
513 ofs = 0x80000000 | ofs64_count++;
515 *ofs_ptr++ = htonl((uint32_t)ofs);
518 return PyLong_FromUnsignedLong(count);
522 // I would have made this a lower-level function that just fills in a buffer
523 // with random values, and then written those values from python. But that's
524 // about 20% slower in my tests, and since we typically generate random
525 // numbers for benchmarking other parts of bup, any slowness in generating
526 // random bytes will make our benchmarks inaccurate. Plus nobody wants
527 // pseudorandom bytes much except for this anyway.
528 static PyObject *write_random(PyObject *self, PyObject *args)
530 uint32_t buf[1024/4];
531 int fd = -1, seed = 0, verbose = 0;
533 long long len = 0, kbytes = 0, written = 0;
535 if (!PyArg_ParseTuple(args, "iLii", &fd, &len, &seed, &verbose))
540 for (kbytes = 0; kbytes < len/1024; kbytes++)
543 for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
545 ret = write(fd, buf, sizeof(buf));
549 if (ret < (int)sizeof(buf))
551 if (verbose && kbytes/1024 > 0 && !(kbytes%1024))
552 fprintf(stderr, "Random: %lld Mbytes\r", kbytes/1024);
555 // handle non-multiples of 1024
559 for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
561 ret = write(fd, buf, len % 1024);
568 fprintf(stderr, "Random: %lld Mbytes, done.\n", kbytes/1024);
569 return Py_BuildValue("L", written);
573 static PyObject *random_sha(PyObject *self, PyObject *args)
575 static int seeded = 0;
576 uint32_t shabuf[20/4];
581 assert(sizeof(shabuf) == 20);
586 if (!PyArg_ParseTuple(args, ""))
589 memset(shabuf, 0, sizeof(shabuf));
590 for (i=0; i < 20/4; i++)
591 shabuf[i] = random();
592 return Py_BuildValue("s#", shabuf, 20);
596 static PyObject *open_noatime(PyObject *self, PyObject *args)
598 char *filename = NULL;
599 int attrs, attrs_noatime, fd;
600 if (!PyArg_ParseTuple(args, "s", &filename))
607 attrs |= O_LARGEFILE;
609 attrs_noatime = attrs;
611 attrs_noatime |= O_NOATIME;
613 fd = open(filename, attrs_noatime);
614 if (fd < 0 && errno == EPERM)
616 // older Linux kernels would return EPERM if you used O_NOATIME
617 // and weren't the file's owner. This pointless restriction was
618 // relaxed eventually, but we have to handle it anyway.
619 // (VERY old kernels didn't recognized O_NOATIME, but they would
620 // just harmlessly ignore it, so this branch won't trigger)
621 fd = open(filename, attrs);
624 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
625 return Py_BuildValue("i", fd);
629 static PyObject *fadvise_done(PyObject *self, PyObject *args)
633 if (!PyArg_ParseTuple(args, "iL", &fd, &ofs))
635 #ifdef POSIX_FADV_DONTNEED
636 posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED);
638 return Py_BuildValue("");
642 #ifdef FS_IOC_GETFLAGS
643 static PyObject *bup_get_linux_file_attr(PyObject *self, PyObject *args)
650 if (!PyArg_ParseTuple(args, "s", &path))
653 fd = open(path, O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_NOFOLLOW);
655 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
658 rc = ioctl(fd, FS_IOC_GETFLAGS, &attr);
662 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
666 return Py_BuildValue("k", attr);
668 #endif /* def FS_IOC_GETFLAGS */
671 #ifdef FS_IOC_SETFLAGS
672 static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
679 if (!PyArg_ParseTuple(args, "sk", &path, &attr))
682 fd = open(path, O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_NOFOLLOW);
684 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
686 rc = ioctl(fd, FS_IOC_SETFLAGS, &attr);
690 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
694 return Py_BuildValue("O", Py_None);
696 #endif /* def FS_IOC_SETFLAGS */
699 #ifdef HAVE_UTIMENSAT
700 #if defined(_ATFILE_SOURCE) \
701 || _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
702 #define HAVE_BUP_UTIMENSAT 1
704 static PyObject *bup_utimensat(PyObject *self, PyObject *args)
706 int rc, dirfd, flags;
708 long access, access_ns, modification, modification_ns;
709 struct timespec ts[2];
711 if (!PyArg_ParseTuple(args, "is((ll)(ll))i",
715 &modification, &modification_ns,
721 PyErr_SetString(PyExc_ValueError, "access time is NaN");
724 else if (isinf(access))
726 PyErr_SetString(PyExc_ValueError, "access time is infinite");
729 else if (isnan(modification))
731 PyErr_SetString(PyExc_ValueError, "modification time is NaN");
734 else if (isinf(modification))
736 PyErr_SetString(PyExc_ValueError, "modification time is infinite");
740 if (isnan(access_ns))
742 PyErr_SetString(PyExc_ValueError, "access time ns is NaN");
745 else if (isinf(access_ns))
747 PyErr_SetString(PyExc_ValueError, "access time ns is infinite");
750 else if (isnan(modification_ns))
752 PyErr_SetString(PyExc_ValueError, "modification time ns is NaN");
755 else if (isinf(modification_ns))
757 PyErr_SetString(PyExc_ValueError, "modification time ns is infinite");
761 ts[0].tv_sec = access;
762 ts[0].tv_nsec = access_ns;
763 ts[1].tv_sec = modification;
764 ts[1].tv_nsec = modification_ns;
766 rc = utimensat(dirfd, path, ts, flags);
768 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
770 return Py_BuildValue("O", Py_None);
773 #endif /* defined(_ATFILE_SOURCE)
774 || _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L */
775 #endif /* HAVE_UTIMENSAT */
778 #ifdef HAVE_STAT_ST_ATIM
779 # define BUP_STAT_ATIME_NS(st) (st)->st_atim.tv_nsec
780 # define BUP_STAT_MTIME_NS(st) (st)->st_mtim.tv_nsec
781 # define BUP_STAT_CTIME_NS(st) (st)->st_ctim.tv_nsec
782 #elif defined HAVE_STAT_ST_ATIMENSEC
783 # define BUP_STAT_ATIME_NS(st) (st)->st_atimespec.tv_nsec
784 # define BUP_STAT_MTIME_NS(st) (st)->st_mtimespec.tv_nsec
785 # define BUP_STAT_CTIME_NS(st) (st)->st_ctimespec.tv_nsec
787 # define BUP_STAT_ATIME_NS(st) 0
788 # define BUP_STAT_MTIME_NS(st) 0
789 # define BUP_STAT_CTIME_NS(st) 0
793 static PyObject *stat_struct_to_py(const struct stat *st)
795 long atime_ns = BUP_STAT_ATIME_NS(st);
796 long mtime_ns = BUP_STAT_MTIME_NS(st);
797 long ctime_ns = BUP_STAT_CTIME_NS(st);
799 /* Enforce the current timespec nanosecond range expectations. */
800 if (atime_ns < 0 || atime_ns > 999999999)
802 PyErr_SetString(PyExc_ValueError, "invalid atime timespec nanoseconds");
805 if (mtime_ns < 0 || mtime_ns > 999999999)
807 PyErr_SetString(PyExc_ValueError, "invalid mtime timespec nanoseconds");
810 if (ctime_ns < 0 || ctime_ns > 999999999)
812 PyErr_SetString(PyExc_ValueError, "invalid ctime timespec nanoseconds");
816 return Py_BuildValue("kkkkkkkk(Ll)(Ll)(Ll)",
817 (unsigned long) st->st_mode,
818 (unsigned long) st->st_ino,
819 (unsigned long) st->st_dev,
820 (unsigned long) st->st_nlink,
821 (unsigned long) st->st_uid,
822 (unsigned long) st->st_gid,
823 (unsigned long) st->st_rdev,
824 (unsigned long) st->st_size,
825 (long long) st->st_atime,
827 (long long) st->st_mtime,
829 (long long) st->st_ctime,
834 static PyObject *bup_stat(PyObject *self, PyObject *args)
839 if (!PyArg_ParseTuple(args, "s", &filename))
843 rc = stat(filename, &st);
845 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
846 return stat_struct_to_py(&st);
850 static PyObject *bup_lstat(PyObject *self, PyObject *args)
855 if (!PyArg_ParseTuple(args, "s", &filename))
859 rc = lstat(filename, &st);
861 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
862 return stat_struct_to_py(&st);
866 static PyObject *bup_fstat(PyObject *self, PyObject *args)
870 if (!PyArg_ParseTuple(args, "i", &fd))
876 return PyErr_SetFromErrno(PyExc_OSError);
877 return stat_struct_to_py(&st);
881 static PyMethodDef helper_methods[] = {
882 { "selftest", selftest, METH_VARARGS,
883 "Check that the rolling checksum rolls correctly (for unit tests)." },
884 { "blobbits", blobbits, METH_VARARGS,
885 "Return the number of bits in the rolling checksum." },
886 { "splitbuf", splitbuf, METH_VARARGS,
887 "Split a list of strings based on a rolling checksum." },
888 { "bitmatch", bitmatch, METH_VARARGS,
889 "Count the number of matching prefix bits between two strings." },
890 { "firstword", firstword, METH_VARARGS,
891 "Return an int corresponding to the first 32 bits of buf." },
892 { "bloom_contains", bloom_contains, METH_VARARGS,
893 "Check if a bloom filter of 2^nbits bytes contains an object" },
894 { "bloom_add", bloom_add, METH_VARARGS,
895 "Add an object to a bloom filter of 2^nbits bytes" },
896 { "extract_bits", extract_bits, METH_VARARGS,
897 "Take the first 'nbits' bits from 'buf' and return them as an int." },
898 { "merge_into", merge_into, METH_VARARGS,
899 "Merges a bunch of idx and midx files into a single midx." },
900 { "write_idx", write_idx, METH_VARARGS,
901 "Write a PackIdxV2 file from an idx list of lists of tuples" },
902 { "write_random", write_random, METH_VARARGS,
903 "Write random bytes to the given file descriptor" },
904 { "random_sha", random_sha, METH_VARARGS,
905 "Return a random 20-byte string" },
906 { "open_noatime", open_noatime, METH_VARARGS,
907 "open() the given filename for read with O_NOATIME if possible" },
908 { "fadvise_done", fadvise_done, METH_VARARGS,
909 "Inform the kernel that we're finished with earlier parts of a file" },
910 #ifdef FS_IOC_GETFLAGS
911 { "get_linux_file_attr", bup_get_linux_file_attr, METH_VARARGS,
912 "Return the Linux attributes for the given file." },
914 #ifdef FS_IOC_SETFLAGS
915 { "set_linux_file_attr", bup_set_linux_file_attr, METH_VARARGS,
916 "Set the Linux attributes for the given file." },
918 #ifdef HAVE_BUP_UTIMENSAT
919 { "utimensat", bup_utimensat, METH_VARARGS,
920 "Change file timestamps with nanosecond precision." },
922 { "stat", bup_stat, METH_VARARGS,
923 "Extended version of stat." },
924 { "lstat", bup_lstat, METH_VARARGS,
925 "Extended version of lstat." },
926 { "fstat", bup_fstat, METH_VARARGS,
927 "Extended version of fstat." },
928 { NULL, NULL, 0, NULL }, // sentinel
932 PyMODINIT_FUNC init_helpers(void)
935 PyObject *m = Py_InitModule("_helpers", helper_methods);
938 #ifdef HAVE_BUP_UTIMENSAT
939 PyModule_AddObject(m, "AT_FDCWD", Py_BuildValue("i", AT_FDCWD));
940 PyModule_AddObject(m, "AT_SYMLINK_NOFOLLOW",
941 Py_BuildValue("i", AT_SYMLINK_NOFOLLOW));
943 e = getenv("BUP_FORCE_TTY");
944 istty2 = isatty(2) || (atoi(e ? e : "0") & 2);