btfs: submission

This commit is contained in:
i0ntempest
2025-05-14 18:36:12 +10:00
parent d8841e1c08
commit b506fc6694
3 changed files with 298 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
PortSystem 1.0
PortGroup fuse 1.0
PortGroup github 1.0
PortGroup boost 1.0
PortGroup openssl 1.0
github.setup johang btfs 3.1 v
github.tarball_from archive
revision 0
categories fuse net
license GPL-3
maintainers {i0ntempest @i0ntempest} openmaintainer
description A bittorrent filesystem based on FUSE
long_description With ${name}, you can mount any .torrent file or magnet link and then use it\
as any read-only directory in your file tree. The contents of the files will\
be downloaded on-demand as they are read by applications.
checksums rmd160 f34ad8ce516fbb71966941bdb030116bb237d184 \
sha256 c363f04149f97baf1c5e10ac90677b8309724f2042ab045a45041cfb7b44649b \
size 24847
# Keep this in sync with boost version used for libtorrent-rasterbar
boost.version 1.81
boost.depends_type build
depends_lib-append port:curl \
port:libtorrent-rasterbar
patch.args -p1
# Revert upgrade to fuse 3
# Keep this for now for future reference
#patchfiles-append patch-revert-e0659b09a9e4f8c5f04382e33d0c2940940bb9dd.diff
patchfiles-append patch-83.diff
post-patch {
# Do not install btplay script - requires fusermount, unusable on macos
reinplace "s|scripts/Makefile ||" ${worksrcpath}/configure.ac
reinplace "s|scripts ||" ${worksrcpath}/Makefile.am
reinplace "s|-std=c++14|-std=gnu++14|" ${worksrcpath}/src/Makefile.am
reinplace "s|__APPLE__|__IGNORE__|" ${worksrcpath}/src/btfs.cc
}
use_autoreconf yes
configure.cppflags-append \
-DFUSE_DARWIN_ENABLE_EXTENSIONS=0
configure.args-append \
--disable-silent-rules
compiler.cxx_standard \
2014
variant fs_link description "Link ${name} to a .fs bundle in /Library/Filesystems" {
post-destroot {
set dir /Library/Filesystems/${name}.fs/Contents/Resources
xinstall -d ${destroot}${dir}
ln -s ${prefix}/bin/${name} ${destroot}${dir}/mount_${name}
}
destroot.violate_mtree \
yes
notes-append "
With +fs_link, you may use \'mount -t ${name}\' and use ${name} in /etc/fstab.
"
}
+96
View File
@@ -0,0 +1,96 @@
diff --git a/man/btfs.1 b/man/btfs.1
index 3dab66e..dcdb23a 100644
--- a/man/btfs.1
+++ b/man/btfs.1
@@ -45,6 +45,9 @@ maximum download rate (in kilobytes per second)
.TP
\fB\-\-max-upload-rate=\fIRATE\fR
maximum upload rate (in kilobytes per second)
+.TP
+\fB\-\-no\-prefetch\fR
+do not download files unless an application requests it
.SH EXAMPLES
mounting a torrent file:
btfs video.torrent ~/mnt
diff --git a/src/btfs.cc b/src/btfs.cc
index 4696bd1..67c39ac 100644
--- a/src/btfs.cc
+++ b/src/btfs.cc
@@ -106,7 +106,9 @@ jump(int piece, int size) {
static void
advance() {
- jump(cursor, 0);
+ if(!params.no_prefetch) {
+ jump(cursor, 0);
+ }
}
Read::Read(char *buf, int index, off_t offset, size_t size) {
@@ -118,6 +120,10 @@ Read::Read(char *buf, int index, off_t offset, size_t size) {
int64_t file_size = ti->files().file_size(index);
#endif
+ if(params.no_prefetch) {
+ handle.file_priority(index, 1);
+ }
+
while (size > 0 && offset < file_size) {
libtorrent::peer_request part = ti->map_file(index, offset,
(int) size);
@@ -182,8 +188,15 @@ int Read::read() {
// Trigger reads of finished pieces
trigger();
- // Move sliding window to first piece to serve this request
- jump(parts.front().part.piece, size());
+ if (params.no_prefetch) {
+ // Set priority of needed pieces
+ for (parts_iter i = parts.begin(); i != parts.end(); ++i) {
+ handle.piece_priority(i->part.piece, 7);
+ }
+ } else {
+ // Move sliding window to first piece to serve this request
+ jump(parts.front().part.piece, size());
+ }
while (!finished() && !failed)
// Wait for any piece to downloaded
@@ -206,6 +219,9 @@ setup() {
for (int i = 0; i < ti->num_files(); ++i) {
std::string parent("");
+ if(params.no_prefetch) {
+ handle.file_priority(i, 0);
+ }
#if LIBTORRENT_VERSION_NUM < 10100
char *p = strdup(ti->file_at(i).path.c_str());
@@ -935,6 +951,7 @@ static const struct fuse_opt btfs_opts[] = {
BTFS_OPT("--max-port=%lu", max_port, 4),
BTFS_OPT("--max-download-rate=%lu", max_download_rate, 4),
BTFS_OPT("--max-upload-rate=%lu", max_upload_rate, 4),
+ BTFS_OPT("--no-prefetch", no_prefetch, 1),
FUSE_OPT_END
};
@@ -973,6 +990,7 @@ print_help() {
printf(" --max-port=N end of listen port range\n");
printf(" --max-download-rate=N max download rate (in kB/s)\n");
printf(" --max-upload-rate=N max upload rate (in kB/s)\n");
+ printf(" --no-prefetch don't prefetch files in the background\n");
}
int
diff --git a/src/btfs.h b/src/btfs.h
index f16da78..ded0b01 100644
--- a/src/btfs.h
+++ b/src/btfs.h
@@ -131,6 +131,7 @@ struct btfs_params {
int max_download_rate;
int max_upload_rate;
const char *metadata;
+ int no_prefetch;
};
}
@@ -0,0 +1,134 @@
--- b/.github/workflows/ci.yml
+++ a/.github/workflows/ci.yml
@@ -33,7 +33,7 @@
DEBIAN_FRONTEND: noninteractive
run: |
apt-get update
+ apt-get -y install build-essential g++ autoconf autoconf-archive automake libtool libtorrent-rasterbar-dev libfuse-dev libcurl4-openssl-dev
- apt-get -y install build-essential g++ autoconf autoconf-archive automake libtool libtorrent-rasterbar-dev libfuse3-dev libcurl4-openssl-dev
- name: Build
run: |
autoreconf -i
--- b/README.md
+++ a/README.md
@@ -47,13 +47,13 @@
## Dependencies (on Linux)
+* fuse ("fuse" in Ubuntu 16.04)
+* libtorrent ("libtorrent-rasterbar8" in Ubuntu 16.04)
+* libcurl ("libcurl3" in Ubuntu 16.04)
-* fuse3 ("fuse3" in Ubuntu 22.04)
-* libtorrent ("libtorrent-rasterbar8" in Ubuntu 22.04)
-* libcurl ("libcurl4" in Ubuntu 22.04)
## Building from git on a recent Debian/Ubuntu
+ $ sudo apt-get install autoconf automake libfuse-dev libtorrent-rasterbar-dev libcurl4-openssl-dev g++
- $ sudo apt-get install autoconf automake libfuse3-dev libtorrent-rasterbar-dev libcurl4-openssl-dev g++
$ git clone https://github.com/johang/btfs.git btfs
$ cd btfs
$ autoreconf -i
@@ -68,7 +68,7 @@
Use [`brew`](https://brew.sh) to get the dependencies.
+ $ brew install Caskroom/cask/osxfuse libtorrent-rasterbar autoconf automake pkg-config
- $ brew install --cask macfuse libtorrent-rasterbar autoconf automake pkg-config
$ git clone https://github.com/johang/btfs.git btfs
$ cd btfs
$ autoreconf -i
--- b/configure.ac
+++ a/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
+AC_INIT(btfs, 3.1, johan.gunnarsson@gmail.com, btfs, https://github.com/johang/btfs)
-AC_INIT([btfs],[3.1],[johan.gunnarsson@gmail.com],[btfs],[https://github.com/johang/btfs])
AC_CONFIG_SRCDIR([src/btfs.cc])
AM_INIT_AUTOMAKE
@@ -8,7 +8,7 @@
AC_PROG_CXX
# Checks for libraries.
+PKG_CHECK_MODULES(FUSE, fuse >= 2.8.0)
-PKG_CHECK_MODULES(FUSE, fuse3 >= 3.0)
PKG_CHECK_MODULES(LIBTORRENT, libtorrent-rasterbar >= 1.0.0)
PKG_CHECK_MODULES(LIBCURL, libcurl >= 7.22.0)
@@ -25,5 +25,4 @@
# Check if -latomic is needed.
AC_SEARCH_LIBS(__atomic_load, atomic)
+AC_OUTPUT(Makefile src/Makefile scripts/Makefile man/Makefile)
-AC_CONFIG_FILES([Makefile src/Makefile scripts/Makefile man/Makefile])
-AC_OUTPUT
--- b/src/btfs.cc
+++ a/src/btfs.cc
@@ -17,7 +17,7 @@
along with BTFS. If not, see <http://www.gnu.org/licenses/>.
*/
+#define FUSE_USE_VERSION 26
-#define FUSE_USE_VERSION 31
#include <cstdlib>
#include <iostream>
@@ -27,8 +27,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <fuse.h>
-#include <fuse3/fuse.h>
-#include <fuse3/fuse_opt.h>
// The below pragma lines will silence lots of compiler warnings in the
// libtorrent headers file. Not btfs' fault.
@@ -421,9 +420,7 @@
}
static int
+btfs_getattr(const char *path, struct stat *stbuf) {
-btfs_getattr(const char *path, struct stat *stbuf,
- struct fuse_file_info *fi) {
- (void) fi;
if (!is_dir(path) && !is_file(path) && !is_root(path))
return -ENOENT;
@@ -468,9 +465,7 @@
static int
btfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi) {
- off_t offset, struct fuse_file_info *fi,
- enum fuse_readdir_flags flags) {
- (void)flags;
if (!is_dir(path) && !is_file(path) && !is_root(path))
return -ENOENT;
@@ -479,12 +474,12 @@
pthread_mutex_lock(&lock);
+ filler(buf, ".", NULL, 0);
+ filler(buf, "..", NULL, 0);
- filler(buf, ".", NULL, 0, (enum fuse_fill_dir_flags)0);
- filler(buf, "..", NULL, 0, (enum fuse_fill_dir_flags)0);
for (std::set<std::string>::iterator i = dirs[path].begin();
i != dirs[path].end(); ++i) {
+ filler(buf, i->c_str(), NULL, 0);
- filler(buf, i->c_str(), NULL, 0, (enum fuse_fill_dir_flags)0);
}
pthread_mutex_unlock(&lock);
@@ -560,8 +555,7 @@
}
static void *
+btfs_init(struct fuse_conn_info *conn) {
-btfs_init(struct fuse_conn_info *conn,
- struct fuse_config *cfg) {
pthread_mutex_lock(&lock);
time_of_mount = time(NULL);