
franta-hg@2: -- CREATE SCHEMA unix_sql_api;
franta-hg@2: 
franta-hg@2: SET search_path TO unix_sql_api;
franta-hg@2: 
franta-hg@2: DROP VIEW IF EXISTS fstab;
franta-hg@2: DROP FUNCTION IF EXISTS fstab();
franta-hg@2: DROP TYPE IF EXISTS unix_sql_api_fstab;
franta-hg@2: 
franta-hg@2: CREATE TYPE unix_sql_api_fstab AS (
franta-hg@2: 	device VARCHAR,
franta-hg@2: 	device_type VARCHAR,
franta-hg@2: 	device_value VARCHAR,
franta-hg@2: 	mount_point VARCHAR,
franta-hg@2: 	type VARCHAR,
franta-hg@2: 	types VARCHAR[],
franta-hg@2: 	options VARCHAR[],
franta-hg@2: 	dump INTEGER,
franta-hg@2: 	pass INTEGER
franta-hg@2: );
franta-hg@2: 
franta-hg@2: CREATE OR REPLACE FUNCTION fstab()
franta-hg@2: RETURNS SETOF unix_sql_api_fstab AS $$
franta-hg@2: 	use strict;
franta-hg@2: 	use warnings;
franta-hg@2: 	
franta-hg@2: 	open(FSTAB, "<", "/etc/fstab") or die $!;
franta-hg@2: 	
franta-hg@2: 	while (<FSTAB>) {
franta-hg@2: 		if (/^([^\s#]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(\d+)\s+(\d+)\s*$/) {
franta-hg@2: 			
franta-hg@2: 			my $device_spec_type;
franta-hg@2: 			my $device_spec_value;
franta-hg@2: 			{
franta-hg@2: 				if ($1 =~ /([^=]+)=(.*)/) {
franta-hg@2: 					($device_spec_type, $device_spec_value) = ($1, $2);
franta-hg@2: 				}
franta-hg@2: 			}
franta-hg@2: 			
franta-hg@2: 			return_next({
franta-hg@2: 				device => $1,
franta-hg@2: 				device_type => $device_spec_type,
franta-hg@2: 				device_value => $device_spec_value,
franta-hg@2: 				mount_point => $2,
franta-hg@2: 				type => $3,
franta-hg@2: 				types => [split(",", $3)],
franta-hg@2: 				options => [split(",", $4)],
franta-hg@2: 				dump => $5,
franta-hg@2: 				pass => $6
franta-hg@2: 			});
franta-hg@2: 		}
franta-hg@2: 	}
franta-hg@2: 	
franta-hg@2: 	return undef;
franta-hg@2: $$ LANGUAGE plperlu;
franta-hg@2: 
franta-hg@2: CREATE OR REPLACE VIEW fstab AS
franta-hg@2: 	SELECT * FROM fstab()
franta-hg@2: ; 




