File: test.pl

package info (click to toggle)
nbdkit 1.42.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,696 kB
  • sloc: ansic: 59,224; sh: 16,793; makefile: 6,463; python: 1,837; cpp: 1,116; ml: 504; perl: 502; tcl: 62
file content (94 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use strict;

my $disk = "\0" x (1024*1024);

BEGIN {
    # Call the debug function to check it works.
    Nbdkit::debug ("hello world!");

    # Check some expected constants are defined.  Since these constants
    # are defined by the nbdkit ABI, they should never change so checking
    # their absolute values here ought to be fine.
    die unless $Nbdkit::FLAG_MAY_TRIM == 1;
    die unless $Nbdkit::FLAG_FUA      == 2;
    die unless $Nbdkit::FLAG_REQ_ONE  == 4;
    die unless $Nbdkit::FUA_NATIVE    == 2;
    die unless $Nbdkit::CACHE_EMULATE == 1;
    die unless $Nbdkit::EXTENT_ZERO   == 2;
}

sub config_complete
{
}

sub open
{
    my $readonly = shift;
    Nbdkit::debug ("perl plugin opened, readonly=" . $readonly);
    my $h = { readonly => $readonly };
    return $h;
}

sub close
{
    my $h = shift;
}

sub get_size
{
    my $h = shift;
    return length ($disk);
}

sub can_write
{
    my $h = shift;
    return 1;
}

sub can_flush
{
    my $h = shift;
    return 1;
}

sub is_rotational
{
    my $h = shift;
    return 0;
}

sub can_trim
{
    my $h = shift;
    return 1;
}

sub pread
{
    my $h = shift;
    my $count = shift;
    my $offset = shift;
    return substr ($disk, $offset, $count);
}

sub pwrite
{
    my $h = shift;
    my $buf = shift;
    my $count = length ($buf);
    my $offset = shift;
    substr ($disk, $offset, $count) = $buf;
}

sub flush
{
    my $h = shift;
}

sub trim
{
    my $h = shift;
    my $count = shift;
    my $offset = shift;
}