|
72 | 72 | #include<sys/xattr.h>
|
73 | 73 | #endif
|
74 | 74 |
|
| 75 | +#ifdef__LINUX__ |
| 76 | +#include<linux/fs.h>// For BLKGETSIZE64 |
| 77 | +#endif |
| 78 | + |
75 | 79 | #include<fuse.h>
|
76 | 80 | #include<fuse_opt.h>
|
77 | 81 |
|
@@ -164,6 +168,8 @@ static struct Settings {
|
164 | 168 | inthide_hard_links;
|
165 | 169 | intresolve_symlinks;
|
166 | 170 |
|
| 171 | +intblock_devices_as_files; |
| 172 | + |
167 | 173 | enumResolvedSymlinkDeletion {
|
168 | 174 | RESOLVED_SYMLINK_DELETION_DENY,
|
169 | 175 | RESOLVED_SYMLINK_DELETION_SYMLINK_ONLY,
|
@@ -365,8 +371,34 @@ static int getattr_common(const char *procpath, struct stat *stbuf)
|
365 | 371 | }
|
366 | 372 |
|
367 | 373 | /* Hide hard links */
|
368 |
| -if (settings.hide_hard_links) |
| 374 | +if (settings.hide_hard_links) { |
369 | 375 | 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 | + } |
370 | 402 |
|
371 | 403 | /* Then permission bits. Symlink permissions don't matter, though. */
|
372 | 404 | if ((stbuf->st_mode&S_IFLNK)!=S_IFLNK) {
|
@@ -1436,6 +1468,7 @@ static void print_usage(const char *progname)
|
1436 | 1468 | " --hide-hard-links Always report a hard link count of 1.\n"
|
1437 | 1469 | " --resolve-symlinks Resolve symbolic links.\n"
|
1438 | 1470 | " --resolved-symlink-deletion=... Decide how to delete resolved symlinks.\n"
|
| 1471 | +" --block-devices-as-files Show block devices as regular files.\n" |
1439 | 1472 | " --multithreaded Enable multithreaded mode. See man page\n"
|
1440 | 1473 | " for security issue with current implementation.\n"
|
1441 | 1474 | "\n"
|
@@ -1477,7 +1510,8 @@ enum OptionKey {
|
1477 | 1510 | OPTKEY_DISABLE_LOCK_FORWARDING,
|
1478 | 1511 | OPTKEY_ENABLE_IOCTL,
|
1479 | 1512 | OPTKEY_HIDE_HARD_LINKS,
|
1480 |
| -OPTKEY_RESOLVE_SYMLINKS |
| 1513 | +OPTKEY_RESOLVE_SYMLINKS, |
| 1514 | +OPTKEY_BLOCK_DEVICES_AS_FILES |
1481 | 1515 | };
|
1482 | 1516 |
|
1483 | 1517 | staticintprocess_option(void*data,constchar*arg,intkey,
|
@@ -1570,6 +1604,9 @@ static int process_option(void *data, const char *arg, int key,
|
1570 | 1604 | caseOPTKEY_RESOLVE_SYMLINKS:
|
1571 | 1605 | settings.resolve_symlinks=1;
|
1572 | 1606 | return0;
|
| 1607 | +caseOPTKEY_BLOCK_DEVICES_AS_FILES: |
| 1608 | +settings.block_devices_as_files=1; |
| 1609 | +return0; |
1573 | 1610 |
|
1574 | 1611 | caseOPTKEY_NONOPTION:
|
1575 | 1612 | if (!settings.mntsrc) {
|
@@ -1901,6 +1938,7 @@ int main(int argc, char *argv[])
|
1901 | 1938 | OPT2("--hide-hard-links","hide-hard-links",OPTKEY_HIDE_HARD_LINKS),
|
1902 | 1939 | OPT2("--resolve-symlinks","resolve-symlinks",OPTKEY_RESOLVE_SYMLINKS),
|
1903 | 1940 | 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), |
1904 | 1942 |
|
1905 | 1943 | OPT2("--realistic-permissions","realistic-permissions",OPTKEY_REALISTIC_PERMISSIONS),
|
1906 | 1944 | OPT2("--ctime-from-mtime","ctime-from-mtime",OPTKEY_CTIME_FROM_MTIME),
|
@@ -1949,6 +1987,7 @@ int main(int argc, char *argv[])
|
1949 | 1987 | settings.hide_hard_links=0;
|
1950 | 1988 | settings.resolve_symlinks=0;
|
1951 | 1989 | settings.resolved_symlink_deletion_policy=RESOLVED_SYMLINK_DELETION_SYMLINK_ONLY;
|
| 1990 | +settings.block_devices_as_files=0; |
1952 | 1991 | settings.realistic_permissions=0;
|
1953 | 1992 | settings.ctime_from_mtime=0;
|
1954 | 1993 | settings.enable_lock_forwarding=0;
|
|