Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa3cc55

Browse files
committed
Added option: --block-devices-as-files
Fixesmpartel#53.
1 parentd63afe5 commitfa3cc55

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

‎ChangeLog‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2017-04-19 Martin Pärtel <martin dot partel at gmail dot com>
2+
3+
* Added --block-devices-as-files (issue #53).
4+
15
2017-03-14 Martin Pärtel <martin dot partel at gmail dot com>
26

37
* Added Vagrantfile for FreeBSD 10.3 and fixed build and test suite to

‎src/bindfs.1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ only if deleting the target succeeded). The default is \fBsymlink-only\fP.
277277
Note that deleting files inside symlinked directories is always possible with
278278
all settings, including\fBdeny\fP, unless something else protects those files.
279279

280+
.TP
281+
.B\-\-block\-devices\-as\-files,\-oblock\-devices\-as\-files
282+
Shows block devices as regular files.
283+
280284

281285
.SH MISCELLANEOUS OPTIONS
282286

‎src/bindfs.c‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
#include<sys/xattr.h>
7373
#endif
7474

75+
#ifdef__LINUX__
76+
#include<linux/fs.h>// For BLKGETSIZE64
77+
#endif
78+
7579
#include<fuse.h>
7680
#include<fuse_opt.h>
7781

@@ -164,6 +168,8 @@ static struct Settings {
164168
inthide_hard_links;
165169
intresolve_symlinks;
166170

171+
intblock_devices_as_files;
172+
167173
enumResolvedSymlinkDeletion {
168174
RESOLVED_SYMLINK_DELETION_DENY,
169175
RESOLVED_SYMLINK_DELETION_SYMLINK_ONLY,
@@ -365,8 +371,34 @@ static int getattr_common(const char *procpath, struct stat *stbuf)
365371
}
366372

367373
/* Hide hard links */
368-
if (settings.hide_hard_links)
374+
if (settings.hide_hard_links) {
369375
stbuf->st_nlink=1;
376+
}
377+
378+
/* Block files as regular files. */
379+
if (settings.block_devices_as_files&&S_ISBLK(stbuf->st_mode)) {
380+
stbuf->st_mode ^=S_IFBLK |S_IFREG;// Flip both bits
381+
#ifdef__LINUX__
382+
uint64_tsize;
383+
ioctl(file,BLKGETSIZE64,&size);
384+
stbuf->st_size= (off_t)size;
385+
if (stbuf->st_size<0) {// Underflow
386+
return-EOVERFLOW;
387+
}
388+
#else
389+
intfd=open(procpath,O_RDONLY);
390+
if (fd==-1) {
391+
return-errno;
392+
}
393+
off_tsize=lseek(fd,0,SEEK_END);
394+
if (size== (off_t)-1) {
395+
close(fd);
396+
return-errno;
397+
}
398+
stbuf->st_size=size;
399+
close(fd);
400+
#endif
401+
}
370402

371403
/* Then permission bits. Symlink permissions don't matter, though. */
372404
if ((stbuf->st_mode&S_IFLNK)!=S_IFLNK) {
@@ -1436,6 +1468,7 @@ static void print_usage(const char *progname)
14361468
" --hide-hard-links Always report a hard link count of 1.\n"
14371469
" --resolve-symlinks Resolve symbolic links.\n"
14381470
" --resolved-symlink-deletion=... Decide how to delete resolved symlinks.\n"
1471+
" --block-devices-as-files Show block devices as regular files.\n"
14391472
" --multithreaded Enable multithreaded mode. See man page\n"
14401473
" for security issue with current implementation.\n"
14411474
"\n"
@@ -1477,7 +1510,8 @@ enum OptionKey {
14771510
OPTKEY_DISABLE_LOCK_FORWARDING,
14781511
OPTKEY_ENABLE_IOCTL,
14791512
OPTKEY_HIDE_HARD_LINKS,
1480-
OPTKEY_RESOLVE_SYMLINKS
1513+
OPTKEY_RESOLVE_SYMLINKS,
1514+
OPTKEY_BLOCK_DEVICES_AS_FILES
14811515
};
14821516

14831517
staticintprocess_option(void*data,constchar*arg,intkey,
@@ -1570,6 +1604,9 @@ static int process_option(void *data, const char *arg, int key,
15701604
caseOPTKEY_RESOLVE_SYMLINKS:
15711605
settings.resolve_symlinks=1;
15721606
return0;
1607+
caseOPTKEY_BLOCK_DEVICES_AS_FILES:
1608+
settings.block_devices_as_files=1;
1609+
return0;
15731610

15741611
caseOPTKEY_NONOPTION:
15751612
if (!settings.mntsrc) {
@@ -1901,6 +1938,7 @@ int main(int argc, char *argv[])
19011938
OPT2("--hide-hard-links","hide-hard-links",OPTKEY_HIDE_HARD_LINKS),
19021939
OPT2("--resolve-symlinks","resolve-symlinks",OPTKEY_RESOLVE_SYMLINKS),
19031940
OPT_OFFSET2("--resolved-symlink-deletion=%s","resolved-symlink-deletion=%s",resolved_symlink_deletion,-1),
1941+
OPT2("--block-devices-as-files","block-devices-as-files",OPTKEY_BLOCK_DEVICES_AS_FILES),
19041942

19051943
OPT2("--realistic-permissions","realistic-permissions",OPTKEY_REALISTIC_PERMISSIONS),
19061944
OPT2("--ctime-from-mtime","ctime-from-mtime",OPTKEY_CTIME_FROM_MTIME),
@@ -1949,6 +1987,7 @@ int main(int argc, char *argv[])
19491987
settings.hide_hard_links=0;
19501988
settings.resolve_symlinks=0;
19511989
settings.resolved_symlink_deletion_policy=RESOLVED_SYMLINK_DELETION_SYMLINK_ONLY;
1990+
settings.block_devices_as_files=0;
19521991
settings.realistic_permissions=0;
19531992
settings.ctime_from_mtime=0;
19541993
settings.enable_lock_forwarding=0;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Copyright 2006,2007,2008,2009,2010 Martin Pärtel <martin.partel@gmail.com>
4+
#
5+
# This file is part of bindfs.
6+
#
7+
# bindfs is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# bindfs is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with bindfs. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
21+
# if we are being run by make check it will set srcdir and we should use it
22+
$LOAD_PATH <<(ENV['srcdir'] ||'.')
23+
require'common.rb'
24+
25+
raise"Please run this as root"unlessProcess.uid ==0
26+
27+
ifARGV.include?("-h") ||ARGV.include?("--help") ||ARGV.length !=1
28+
puts
29+
puts"Usage:#{$0} /dev/some-block-device"
30+
puts
31+
puts"This test will attempt to read the block device through bindfs."
32+
puts"This is a separate test file because it's nontrivial to set up a"
33+
puts"block device for testing in a non-intrusive and portable way."
34+
puts
35+
exit(1)
36+
end
37+
38+
device=ARGV[0]
39+
40+
root_testenv("--block-devices-as-files --resolve-symlinks")do
41+
symlink(device,'src/devicelink')
42+
43+
size_through_bindfs=File.size('mnt/devicelink')
44+
measured_size=File.open(device,"r")do |f|
45+
f.seek(0,IO::SEEK_END)
46+
f.tell
47+
end
48+
assert{size_through_bindfs ==measured_size}
49+
assert{measured_size >=512}
50+
puts"Device size:#{size_through_bindfs}"
51+
52+
data_read_through_bindfs=File.read('mnt/devicelink',512)
53+
data_read_directly=File.read(device,512)
54+
assert{data_read_through_bindfs ==data_read_directly}
55+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp