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
701 static int bup_parse_xutime_args(char **path,
705 long *modification_ns,
706 PyObject *self, PyObject *args)
708 if (!PyArg_ParseTuple(args, "s((ll)(ll))",
711 modification, modification_ns))
716 PyErr_SetString(PyExc_ValueError, "access time is NaN");
719 else if (isinf(*access))
721 PyErr_SetString(PyExc_ValueError, "access time is infinite");
724 else if (isnan(*modification))
726 PyErr_SetString(PyExc_ValueError, "modification time is NaN");
729 else if (isinf(*modification))
731 PyErr_SetString(PyExc_ValueError, "modification time is infinite");
735 if (isnan(*access_ns))
737 PyErr_SetString(PyExc_ValueError, "access time ns is NaN");
740 else if (isinf(*access_ns))
742 PyErr_SetString(PyExc_ValueError, "access time ns is infinite");
745 else if (isnan(*modification_ns))
747 PyErr_SetString(PyExc_ValueError, "modification time ns is NaN");
750 else if (isinf(*modification_ns))
752 PyErr_SetString(PyExc_ValueError, "modification time ns is infinite");
759 #endif /* def HAVE_UTIMENSAT */
762 #ifdef HAVE_UTIMENSAT
764 static PyObject *bup_xutime_ns(PyObject *self, PyObject *args,
769 long access, access_ns, modification, modification_ns;
770 struct timespec ts[2];
772 if (!bup_parse_xutime_args(&path, &access, &access_ns,
773 &modification, &modification_ns,
777 ts[0].tv_sec = access;
778 ts[0].tv_nsec = access_ns;
779 ts[1].tv_sec = modification;
780 ts[1].tv_nsec = modification_ns;
781 rc = utimensat(AT_FDCWD, path, ts,
782 follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
784 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
786 return Py_BuildValue("O", Py_None);
790 #define BUP_HAVE_BUP_UTIME_NS 1
791 static PyObject *bup_utime_ns(PyObject *self, PyObject *args)
793 return bup_xutime_ns(self, args, 1);
797 #define BUP_HAVE_BUP_LUTIME_NS 1
798 static PyObject *bup_lutime_ns(PyObject *self, PyObject *args)
800 return bup_xutime_ns(self, args, 0);
803 #endif /* HAVE_UTIMENSAT */
806 #ifdef HAVE_STAT_ST_ATIM
807 # define BUP_STAT_ATIME_NS(st) (st)->st_atim.tv_nsec
808 # define BUP_STAT_MTIME_NS(st) (st)->st_mtim.tv_nsec
809 # define BUP_STAT_CTIME_NS(st) (st)->st_ctim.tv_nsec
810 #elif defined HAVE_STAT_ST_ATIMENSEC
811 # define BUP_STAT_ATIME_NS(st) (st)->st_atimespec.tv_nsec
812 # define BUP_STAT_MTIME_NS(st) (st)->st_mtimespec.tv_nsec
813 # define BUP_STAT_CTIME_NS(st) (st)->st_ctimespec.tv_nsec
815 # define BUP_STAT_ATIME_NS(st) 0
816 # define BUP_STAT_MTIME_NS(st) 0
817 # define BUP_STAT_CTIME_NS(st) 0
821 static PyObject *stat_struct_to_py(const struct stat *st)
823 long atime_ns = BUP_STAT_ATIME_NS(st);
824 long mtime_ns = BUP_STAT_MTIME_NS(st);
825 long ctime_ns = BUP_STAT_CTIME_NS(st);
827 /* Enforce the current timespec nanosecond range expectations. */
828 if (atime_ns < 0 || atime_ns > 999999999)
830 PyErr_SetString(PyExc_ValueError, "invalid atime timespec nanoseconds");
833 if (mtime_ns < 0 || mtime_ns > 999999999)
835 PyErr_SetString(PyExc_ValueError, "invalid mtime timespec nanoseconds");
838 if (ctime_ns < 0 || ctime_ns > 999999999)
840 PyErr_SetString(PyExc_ValueError, "invalid ctime timespec nanoseconds");
844 return Py_BuildValue("kkkkkkkk(Ll)(Ll)(Ll)",
845 (unsigned long) st->st_mode,
846 (unsigned long) st->st_ino,
847 (unsigned long) st->st_dev,
848 (unsigned long) st->st_nlink,
849 (unsigned long) st->st_uid,
850 (unsigned long) st->st_gid,
851 (unsigned long) st->st_rdev,
852 (unsigned long) st->st_size,
853 (long long) st->st_atime,
855 (long long) st->st_mtime,
857 (long long) st->st_ctime,
862 static PyObject *bup_stat(PyObject *self, PyObject *args)
867 if (!PyArg_ParseTuple(args, "s", &filename))
871 rc = stat(filename, &st);
873 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
874 return stat_struct_to_py(&st);
878 static PyObject *bup_lstat(PyObject *self, PyObject *args)
883 if (!PyArg_ParseTuple(args, "s", &filename))
887 rc = lstat(filename, &st);
889 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
890 return stat_struct_to_py(&st);
894 static PyObject *bup_fstat(PyObject *self, PyObject *args)
898 if (!PyArg_ParseTuple(args, "i", &fd))
904 return PyErr_SetFromErrno(PyExc_OSError);
905 return stat_struct_to_py(&st);
909 static PyMethodDef helper_methods[] = {
910 { "selftest", selftest, METH_VARARGS,
911 "Check that the rolling checksum rolls correctly (for unit tests)." },
912 { "blobbits", blobbits, METH_VARARGS,
913 "Return the number of bits in the rolling checksum." },
914 { "splitbuf", splitbuf, METH_VARARGS,
915 "Split a list of strings based on a rolling checksum." },
916 { "bitmatch", bitmatch, METH_VARARGS,
917 "Count the number of matching prefix bits between two strings." },
918 { "firstword", firstword, METH_VARARGS,
919 "Return an int corresponding to the first 32 bits of buf." },
920 { "bloom_contains", bloom_contains, METH_VARARGS,
921 "Check if a bloom filter of 2^nbits bytes contains an object" },
922 { "bloom_add", bloom_add, METH_VARARGS,
923 "Add an object to a bloom filter of 2^nbits bytes" },
924 { "extract_bits", extract_bits, METH_VARARGS,
925 "Take the first 'nbits' bits from 'buf' and return them as an int." },
926 { "merge_into", merge_into, METH_VARARGS,
927 "Merges a bunch of idx and midx files into a single midx." },
928 { "write_idx", write_idx, METH_VARARGS,
929 "Write a PackIdxV2 file from an idx list of lists of tuples" },
930 { "write_random", write_random, METH_VARARGS,
931 "Write random bytes to the given file descriptor" },
932 { "random_sha", random_sha, METH_VARARGS,
933 "Return a random 20-byte string" },
934 { "open_noatime", open_noatime, METH_VARARGS,
935 "open() the given filename for read with O_NOATIME if possible" },
936 { "fadvise_done", fadvise_done, METH_VARARGS,
937 "Inform the kernel that we're finished with earlier parts of a file" },
938 #ifdef FS_IOC_GETFLAGS
939 { "get_linux_file_attr", bup_get_linux_file_attr, METH_VARARGS,
940 "Return the Linux attributes for the given file." },
942 #ifdef FS_IOC_SETFLAGS
943 { "set_linux_file_attr", bup_set_linux_file_attr, METH_VARARGS,
944 "Set the Linux attributes for the given file." },
946 #ifdef BUP_HAVE_BUP_UTIME_NS
947 { "bup_utime_ns", bup_utime_ns, METH_VARARGS,
948 "Change path timestamps with up to nanosecond precision." },
950 #ifdef BUP_HAVE_BUP_LUTIME_NS
951 { "bup_lutime_ns", bup_lutime_ns, METH_VARARGS,
952 "Change path timestamps with up to nanosecond precision;"
953 " don't follow symlinks." },
955 { "stat", bup_stat, METH_VARARGS,
956 "Extended version of stat." },
957 { "lstat", bup_lstat, METH_VARARGS,
958 "Extended version of lstat." },
959 { "fstat", bup_fstat, METH_VARARGS,
960 "Extended version of fstat." },
961 { NULL, NULL, 0, NULL }, // sentinel
965 PyMODINIT_FUNC init_helpers(void)
968 PyObject *m = Py_InitModule("_helpers", helper_methods);
971 e = getenv("BUP_FORCE_TTY");
972 istty2 = isatty(2) || (atoi(e ? e : "0") & 2);