Skip to content

Commit 56965dd

Browse files
committed
Christoph Biedl <[email protected]> adds the feature of
offset and size command-line options. In the quote below are his stated motivations: Hello, the patch below implements a new option -o for vbladed, denoting the number of sectors that should be skipped at the beginning of the exported file. Default is 0 (no offset, export from beginning, current behaviour). Rationale: If the exported files are actually raw block devices on the target, something that might happen when using logical volumes for exports, several tools running on the target that assume block devices are for exclusive local access only might create confusion or even havoc. Most prominently: * os-prober of grub (might be disabled, though) Might mount any block device found that contain a file system. * (Linux) logical volume management Will report any physical volume if the export is used as such. * (Linux) blkid Reports any block device (minor impact, mostly information leakage) The overall problem is applications are not aware some block devices might be used from a remote client while there's no locking and that might be hard to implement Solutions tried but not considered helpful: * Filter out exported block devices Problems: The tools need the ability to filter; new tools might come into existance, requiring new action. Filter languages might be hard to use (Linux LVM is quite a nightmare here). * Optionally open block devices with O_EXCL Had no effect. Still exposes block devices where no vbladed is running yet. So the goal was to hide the actual content from these tools. One approach was to obscure the data using XOR, however it seemed easier to sacrifice one or more sectors (8 recommended for 4k sector hard drives) for a simple workaround. This is based on vblade-20, tests on Debian Linux included a simple write of each sector with a unique ID and later re-read in order to detect any re-ordering bugs, however everything worked as expected. Christoph
1 parent c743d5a commit 56965dd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

aoe.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,13 @@ int
462462
main(int argc, char **argv)
463463
{
464464
int ch, omode = 0, readonly = 0;
465+
vlong length = 0;
465466

466467
bufcnt = Bufcount;
468+
offset = 0;
467469
setbuf(stdin, NULL);
468470
progname = *argv;
469-
while ((ch = getopt(argc, argv, "b:dsrm:")) != -1) {
471+
while ((ch = getopt(argc, argv, "b:dsrm:o:l:")) != -1) {
470472
switch (ch) {
471473
case 'b':
472474
bufcnt = atoi(optarg);
@@ -485,6 +487,12 @@ main(int argc, char **argv)
485487
case 'm':
486488
setmask(optarg);
487489
break;
490+
case 'o':
491+
offset = atoi(optarg);
492+
break;
493+
case 'l':
494+
length = atoi(optarg);
495+
break;
488496
case '?':
489497
default:
490498
usage();
@@ -505,6 +513,18 @@ main(int argc, char **argv)
505513
setserial(argv[3], shelf, slot);
506514
size = getsize(bfd);
507515
size /= 512;
516+
if (size < offset) {
517+
fprintf(stderr, "Offset %llu too big - remaining size is negative!\n", offset);
518+
exit(1);
519+
}
520+
size -= offset;
521+
if (length) {
522+
if (length > size) {
523+
fprintf(stderr, "Length %llu too big - exceeds size of file!\n", offset);
524+
exit(1);
525+
}
526+
size = length;
527+
}
508528
ifname = argv[2];
509529
sfd = dial(ifname, bufcnt);
510530
getea(sfd, ifname, mac);

ata.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ atacmd(Ataregs *p, uchar *dp, int ndp, int payload) // do the ata cmd
164164
return 0;
165165
}
166166
if (p->cmd == 0x20 || p->cmd == 0x24)
167-
n = getsec(bfd, dp, lba, p->sectors);
167+
n = getsec(bfd, dp, lba+offset, p->sectors);
168168
else {
169169
// packet should be big enough to contain the data
170170
if (payload < 512 * p->sectors)
171171
return -1;
172-
n = putsec(bfd, dp, lba, p->sectors);
172+
n = putsec(bfd, dp, lba+offset, p->sectors);
173173
}
174174
n /= 512;
175175
if (n != p->sectors) {

dat.h

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ uchar mac[6];
169169
int bfd; // block file descriptor
170170
int sfd; // socket file descriptor
171171
vlong size; // size of vblade
172+
vlong offset;
172173
char *progname;
173174
char serial[Nserial+1];
174175

vblade.8

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ The -r flag restricts the export of the device to be read-only.
5555
The -m flag takes an argument, a comma separated list of MAC addresses
5656
permitted access to the vblade. A MAC address can be specified in upper
5757
or lower case, with or without colons.
58+
.TP
59+
\fB-o\fP
60+
The -o flag takes an argument, the number of sectors that should be
61+
skipped at the beginning of filename.
62+
.TP
63+
\fB-l\fP
64+
The -l flag takes an argument, the number of sectors to exports.
65+
Defaults to the end of file.
5866
.SH EXAMPLE
5967
In this example, the root user on a host named
6068
.I nai

0 commit comments

Comments
 (0)