~awstools-dev/ubuntu/maverick/ec2-ami-tools/maverick

« back to all changes in this revision

Viewing changes to lib/ec2/platform/linux/mtab.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-10-14 08:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20081014083525-c0n69wr7r7aqfb8w
Tags: 1.3-26357-0ubuntu2
* New upstream version.
* Update the debian copyright file.
* Added quilt patch system to make it easier to maintain. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008 Amazon.com, Inc. or its affiliates.  All Rights
 
2
# Reserved.  Licensed under the Amazon Software License (the
 
3
# "License").  You may not use this file except in compliance with the
 
4
# License. A copy of the License is located at
 
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
 
6
# file.  This file is distributed on an "AS IS" BASIS, WITHOUT
 
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 
8
# the License for the specific language governing permissions and
 
9
# limitations under the License.
 
10
 
 
11
module EC2
 
12
  module Platform
 
13
    module Linux
 
14
      LOCAL_FS_TYPES = ['ext2', 'ext3', 'xfs', 'jfs', 'reiserfs', 'tmpfs']
 
15
      class Mtab
 
16
        class Entry
 
17
          REGEX = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$/
 
18
          attr_reader :device   # mounted device.
 
19
          attr_reader :mpoint   # mount point.
 
20
          attr_reader :fstype   # file system type.
 
21
          attr_reader :options  # options
 
22
          attr_reader :value    # entire line
 
23
          
 
24
          
 
25
          def initialize(dev, mnt_point, fs_type, opts, line)
 
26
            @device = dev
 
27
            @mpoint = mnt_point
 
28
            @fstype = fs_type
 
29
            @options= opts
 
30
            @value  = line
 
31
          end
 
32
          
 
33
          def self.parse(line)
 
34
            return nil if line[0,1] == '#'
 
35
            if (m = REGEX.match(line))
 
36
              parts = m.captures
 
37
              return Entry.new(parts[0], parts[1], parts[2], parts[3], line.strip)
 
38
            else
 
39
              return nil
 
40
            end
 
41
          end
 
42
          
 
43
          def to_s
 
44
            value
 
45
          end
 
46
          
 
47
          def print
 
48
            puts(to_s)
 
49
          end
 
50
        end
 
51
        
 
52
        attr_reader :entries
 
53
        LOCATION = '/etc/mtab'
 
54
        
 
55
        def initialize(filename = LOCATION)
 
56
          begin
 
57
            f = File.new(filename, File::RDONLY)
 
58
          rescue SystemCallError => e
 
59
            raise FileError(filename, "could not open #{filename} to read mount table", e)
 
60
          end
 
61
          @entries = Hash.new
 
62
          f.readlines.each do |line|
 
63
            entry = Entry.parse(line)
 
64
            @entries[entry.mpoint] = entry unless entry.nil?
 
65
          end          
 
66
        end
 
67
        
 
68
        def self.load
 
69
          self.new()
 
70
        end
 
71
      end
 
72
    end
 
73
  end
 
74
end