Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial code for reporting fake fs size as suggested in #32 #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ Minor:
- Look at capabilities instead of uid==0 when checking for special privileges.
Do this in a portable way and fall back to uid==0 if not available.

- add real diskspace limiting (quota) besides of ability to report fake size.
Maybe there can be even different limit for different paths? dunno.
I think it's good idea to have sepparate code for faking reported size and
limiting size, so user can decide if he wants both or only one of them.
9 changes: 9 additions & 0 deletions src/bindfs.1
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ only if deleting the target succeeded). The default is \fBsymlink-only\fP.
Note that deleting files inside symlinked directories is always possible with
all settings, including \fBdeny\fP, unless something else protects those files.

.SH SIZE LIMITS AND FAKE SIZE REPORTING

.TP
.B \-\-size=\fI...\fPM, \-o size=\fI...\fPM
Report fake FS size of \fB...\fP Megabytes. Note this does not actually limit anything.
It's experimental feature and it may cause your \fBdf\fP go nuts.
Currently only \fBM\fP suffix is supported.
Actual limiting is planned in future.

.SH MISCELLANEOUS OPTIONS

Expand Down Expand Up @@ -477,6 +485,7 @@ for consistency.
.SH AUTHOR
Martin P\[:a]rtel <martin dot partel at gmail dot com>

Contributors: Tomas 'Harvie' Mudrunka (2016 - concept of size limiting and initial code for reporting fake fs size)

.SH SEE ALSO
\fBchmod\fP(1), \fBfusermount\fP(1), \fBhttp://bindfs.org/\fP
Expand Down
39 changes: 39 additions & 0 deletions src/bindfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ static struct Settings {
uid_t uid_offset;
gid_t gid_offset;

long bindfs_size; //Maybe it should be unsigned in future, however right now i use -1 to signal it's not used
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

off_t is probably appropriate here. It's signed, and since we compile with -D_FILE_OFFSET_BITS=64 it's also 64 bits.


} settings;


Expand Down Expand Up @@ -1100,6 +1102,24 @@ static int bindfs_statfs(const char *path, struct statvfs *stbuf)
return -errno;

res = statvfs(real_path, stbuf);

if(settings.bindfs_size >= 0) {
//see: man 3 statvfs
//stbuf->f_frsize //block size (used for block to size conversion)

stbuf->f_blocks = settings.bindfs_size/stbuf->f_frsize; //total size in blocks
//We cannot have more free blocks than there are blocks in total:
stbuf->f_bfree = stbuf->f_bfree < stbuf->f_blocks ? stbuf->f_bfree : stbuf->f_blocks ; //free blocks
stbuf->f_bavail = stbuf->f_bavail < stbuf->f_blocks ? stbuf->f_bavail : stbuf->f_blocks ; //free blocks for unprivileged

/*
//TODO: same for inodes in future (when size limiting will be done)
stbuf->f_file = 0; //total size in inodes
stbuf->f_ffree = 0; //free inodes
stbuf->f_favail = 0; //free inodes for unprivileged
*/
}

free(real_path);
if (res == -1)
return -errno;
Expand Down Expand Up @@ -1404,6 +1424,14 @@ static void print_usage(const char *progname)
"Rate limits:\n"
" --read-rate=... Limit to bytes/sec that can be read.\n"
" --write-rate=... Limit to bytes/sec that can be written.\n"
"\n"
"Size limits:\n"
" --size=...M Report fake FS size of ... Megabytes\n"
" Note this does not actually limit anything\n"
" and it may cause your df go nuts.\n"
// " --size-limit=...M Limit usable FS size to ... Megabytes\n"
// " this defaults to --size, unless you want it to\n"
// " be different from value reported to df.\n"
"\n"
"Miscellaneous:\n"
" -n --no-allow-other Do not add -o allow_other to fuse options.\n"
Expand Down Expand Up @@ -1809,6 +1837,7 @@ int main(int argc, char *argv[])
int multithreaded;
char *uid_offset;
char *gid_offset;
char *bindfs_size;
} od;

#define OPT2(one, two, key) \
Expand Down Expand Up @@ -1874,6 +1903,8 @@ int main(int argc, char *argv[])

OPT_OFFSET2("--uid-offset=%s", "uid-offset=%s", uid_offset, 0),
OPT_OFFSET2("--gid-offset=%s", "gid-offset=%s", gid_offset, 0),

OPT_OFFSET2("--size=%s", "size=%s", bindfs_size, 0),
FUSE_OPT_END
};

Expand Down Expand Up @@ -1916,6 +1947,7 @@ int main(int argc, char *argv[])
settings.ctime_from_mtime = 0;
settings.uid_offset = 0;
settings.gid_offset = 0;
settings.bindfs_size = -1;

atexit(&atexit_func);

Expand Down Expand Up @@ -2101,6 +2133,13 @@ int main(int argc, char *argv[])
}
}

/* parse size */
if (od.bindfs_size) {
char* bindfs_size_ptr = od.bindfs_size;
settings.bindfs_size = strtoul(od.bindfs_size, &bindfs_size_ptr, 10);
//fprintf(stderr, "Activated experimental fake size: %ldM\n", settings.bindfs_size); //Debug
settings.bindfs_size *= (1024*1024); //Currently only Megabytes are supported
}

/* Single-threaded mode by default */
if (!od.multithreaded) {
Expand Down