franta-hg@2
|
1 |
-- CREATE SCHEMA unix_sql_api;
|
franta-hg@2
|
2 |
|
franta-hg@2
|
3 |
SET search_path TO unix_sql_api;
|
franta-hg@2
|
4 |
|
franta-hg@2
|
5 |
DROP VIEW IF EXISTS fstab;
|
franta-hg@2
|
6 |
DROP FUNCTION IF EXISTS fstab();
|
franta-hg@2
|
7 |
DROP TYPE IF EXISTS unix_sql_api_fstab;
|
franta-hg@2
|
8 |
|
franta-hg@2
|
9 |
CREATE TYPE unix_sql_api_fstab AS (
|
franta-hg@2
|
10 |
device VARCHAR,
|
franta-hg@2
|
11 |
device_type VARCHAR,
|
franta-hg@2
|
12 |
device_value VARCHAR,
|
franta-hg@2
|
13 |
mount_point VARCHAR,
|
franta-hg@2
|
14 |
type VARCHAR,
|
franta-hg@2
|
15 |
types VARCHAR[],
|
franta-hg@2
|
16 |
options VARCHAR[],
|
franta-hg@2
|
17 |
dump INTEGER,
|
franta-hg@2
|
18 |
pass INTEGER
|
franta-hg@2
|
19 |
);
|
franta-hg@2
|
20 |
|
franta-hg@2
|
21 |
CREATE OR REPLACE FUNCTION fstab()
|
franta-hg@2
|
22 |
RETURNS SETOF unix_sql_api_fstab AS $$
|
franta-hg@2
|
23 |
use strict;
|
franta-hg@2
|
24 |
use warnings;
|
franta-hg@2
|
25 |
|
franta-hg@2
|
26 |
open(FSTAB, "<", "/etc/fstab") or die $!;
|
franta-hg@2
|
27 |
|
franta-hg@2
|
28 |
while (<FSTAB>) {
|
franta-hg@2
|
29 |
if (/^([^\s#]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\d+)\s*$/) {
|
franta-hg@2
|
30 |
|
franta-hg@2
|
31 |
my $device_spec_type;
|
franta-hg@2
|
32 |
my $device_spec_value;
|
franta-hg@2
|
33 |
{
|
franta-hg@2
|
34 |
if ($1 =~ /([^=]+)=(.*)/) {
|
franta-hg@2
|
35 |
($device_spec_type, $device_spec_value) = ($1, $2);
|
franta-hg@2
|
36 |
}
|
franta-hg@2
|
37 |
}
|
franta-hg@2
|
38 |
|
franta-hg@2
|
39 |
return_next({
|
franta-hg@2
|
40 |
device => $1,
|
franta-hg@2
|
41 |
device_type => $device_spec_type,
|
franta-hg@2
|
42 |
device_value => $device_spec_value,
|
franta-hg@2
|
43 |
mount_point => $2,
|
franta-hg@2
|
44 |
type => $3,
|
franta-hg@2
|
45 |
types => [split(",", $3)],
|
franta-hg@2
|
46 |
options => [split(",", $4)],
|
franta-hg@2
|
47 |
dump => $5,
|
franta-hg@2
|
48 |
pass => $6
|
franta-hg@2
|
49 |
});
|
franta-hg@2
|
50 |
}
|
franta-hg@2
|
51 |
}
|
franta-hg@2
|
52 |
|
franta-hg@2
|
53 |
return undef;
|
franta-hg@2
|
54 |
$$ LANGUAGE plperlu;
|
franta-hg@2
|
55 |
|
franta-hg@2
|
56 |
CREATE OR REPLACE VIEW fstab AS
|
franta-hg@2
|
57 |
SELECT * FROM fstab()
|
franta-hg@2
|
58 |
;
|