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

« back to all changes in this revision

Viewing changes to lib/ec2/platform/linux/fstab.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
#------------------------------------------------------------------------------
 
12
# An abstraction of the File-System Table (fstab)
 
13
 
 
14
require 'ec2/amitools/version'
 
15
 
 
16
module EC2
 
17
  module Platform
 
18
    module Linux
 
19
      class Fstab
 
20
        class Entry
 
21
          REGEX = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$/
 
22
          attr_reader :device   # mounted device.
 
23
          attr_reader :mpoint   # mount point.
 
24
          attr_reader :fstype   # file system type.
 
25
          attr_reader :options  # options
 
26
          attr_reader :value    # everything on line
 
27
          
 
28
          def initialize(dev, mnt_point, fs_type, opts, line)
 
29
            @device = dev
 
30
            @mpoint = mnt_point
 
31
            @fstype = fs_type
 
32
            @options= opts
 
33
            @value  = line
 
34
          end
 
35
          
 
36
          def self.parse(line)
 
37
            return nil if line[0,1] == '#'
 
38
            if (m = REGEX.match(line))
 
39
              parts = m.captures
 
40
              return Entry.new(parts[0], parts[1], parts[2], parts[3], line.strip)
 
41
            else
 
42
              return nil
 
43
            end
 
44
          end
 
45
          
 
46
          def to_s
 
47
            value
 
48
          end
 
49
          
 
50
          def print
 
51
            puts(to_s)
 
52
          end
 
53
        end
 
54
                
 
55
        LOCATION = '/etc/fstab'
 
56
        attr_reader :entries
 
57
        
 
58
        def initialize(filename = LOCATION)
 
59
          begin
 
60
            f = File.new(filename, File::RDONLY)
 
61
          rescue SystemCallError => e
 
62
            raise FileError(filename, "could not open #{filename} to read file system table", e)
 
63
          end
 
64
          @entries = Hash.new
 
65
          f.readlines.each do |line|
 
66
            entry = Entry.parse(line)
 
67
            @entries[entry.mpoint] = entry unless entry.nil?
 
68
          end          
 
69
        end
 
70
        
 
71
        def self.load
 
72
          self.new()
 
73
        end
 
74
        
 
75
        DEFAULT = <<TEXT
 
76
# Default /etc/fstab
 
77
# Supplied by: #{PKG_NAME}-#{PKG_VERSION}-#{PKG_RELEASE}
 
78
/dev/sda1 /     ext3    defaults 1 1
 
79
/dev/sdb  /mnt  ext3    defaults 0 0
 
80
none      /dev/pts devpts  gid=5,mode=620 0 0
 
81
none      /proc proc    defaults 0 0
 
82
none      /sys  sysfs   defaults 0 0
 
83
TEXT
 
84
        LEGACY = <<TEXT
 
85
# Legacy /etc/fstab
 
86
# Supplied by: #{PKG_NAME}-#{PKG_VERSION}-#{PKG_RELEASE}
 
87
/dev/sda1 /     ext3    defaults 1 1
 
88
/dev/sda2 /mnt  ext3    defaults 0 0
 
89
/dev/sda3 swap  swap    defaults 0 0
 
90
none      /proc proc    defaults 0 0
 
91
none      /sys  sysfs   defaults 0 0
 
92
TEXT
 
93
      end
 
94
    end
 
95
  end
 
96
end