1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/prototyp/prototyp.sql Mon Sep 01 15:36:16 2014 +0200
1.3 @@ -0,0 +1,58 @@
1.4 +-- CREATE SCHEMA unix_sql_api;
1.5 +
1.6 +SET search_path TO unix_sql_api;
1.7 +
1.8 +DROP VIEW IF EXISTS fstab;
1.9 +DROP FUNCTION IF EXISTS fstab();
1.10 +DROP TYPE IF EXISTS unix_sql_api_fstab;
1.11 +
1.12 +CREATE TYPE unix_sql_api_fstab AS (
1.13 + device VARCHAR,
1.14 + device_type VARCHAR,
1.15 + device_value VARCHAR,
1.16 + mount_point VARCHAR,
1.17 + type VARCHAR,
1.18 + types VARCHAR[],
1.19 + options VARCHAR[],
1.20 + dump INTEGER,
1.21 + pass INTEGER
1.22 +);
1.23 +
1.24 +CREATE OR REPLACE FUNCTION fstab()
1.25 +RETURNS SETOF unix_sql_api_fstab AS $$
1.26 + use strict;
1.27 + use warnings;
1.28 +
1.29 + open(FSTAB, "<", "/etc/fstab") or die $!;
1.30 +
1.31 + while (<FSTAB>) {
1.32 + if (/^([^\s#]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\d+)\s*$/) {
1.33 +
1.34 + my $device_spec_type;
1.35 + my $device_spec_value;
1.36 + {
1.37 + if ($1 =~ /([^=]+)=(.*)/) {
1.38 + ($device_spec_type, $device_spec_value) = ($1, $2);
1.39 + }
1.40 + }
1.41 +
1.42 + return_next({
1.43 + device => $1,
1.44 + device_type => $device_spec_type,
1.45 + device_value => $device_spec_value,
1.46 + mount_point => $2,
1.47 + type => $3,
1.48 + types => [split(",", $3)],
1.49 + options => [split(",", $4)],
1.50 + dump => $5,
1.51 + pass => $6
1.52 + });
1.53 + }
1.54 + }
1.55 +
1.56 + return undef;
1.57 +$$ LANGUAGE plperlu;
1.58 +
1.59 +CREATE OR REPLACE VIEW fstab AS
1.60 + SELECT * FROM fstab()
1.61 +;