changelog tags changeset manifest revisions annotate raw

disks_block.rb

changeset 25: 19405d7dd94b
parent:d3de335ee807
author: frsyuki@vcore
date: Fri Mar 23 20:59:50 2007 +0900 (14 years ago)
permissions: -rw-r--r--
1require "vfs"
2require "log"
3
4
5class DiskManager
6
7
8 class BlockEntry < VFS
9 @@initrdfs = nil
10 @@arkfs = nil
11 def self.setInitrdFS(initrdfs)
12 @@initrdfs = initrdfs
13 end
14 def self.setArkFS(arkfs)
15 @@arkfs = arkfs
16 end
17
18
19
20 def initialize(major, minor, size, name, removable, type)
21 @major = major
22 @minor = minor
23 @size = size
24 @name = name
25 @removable = removable
26 @type = type
27
28 @probed = false
29 @probed_fstype = nil
30
31 # DynamicPath
32 @trialpoint = @@arkfs.trial + "/trial-#{@name}-#{@major}-#{@minor}"
33 @devpath = @@arkfs.dev + "/#{@name}"
34 Dir.mkdir(@trialpoint) rescue $log.warn $!
35 @@initrdfs.cmd_mknod(@devpath, "b", @major, @minor) rescue $log.debug $!
36 end
37 attr_reader :major, :minor, :size, :name, :removable, :type, :mounted_point, :probed_fstype
38
39 def probed?
40 return @probed
41 end
42 def probe_failed?
43 return @probed == true && @probed_fstype == nil
44 end
45 def probed_succeeded?
46 return @probed == true && @probed_fstype != nil
47 end
48
49
50 def guessFSType(type)
51 if type.include?("flash")
52 return ["vfat", "ntfs", "ext3", "hfsplus", "reiserfs", "xfs", "squashfs", "reiser4", "hfs", "udf", "ufs", "jfs", "ext2", "iso9660"]
53 elsif type.include?("optical")
54 return ["iso9660", "udf", "hfsplus", "hfs", "ext3", "squashfs", "ext2", "vfat", "ntfs", "xfs", "reiserfs", "reiser4", "jfs", "ufs"]
55 else
56 # hdd
57 return ["ntfs", "vfat", "ext3", "hfsplus", "xfs", "reiserfs", "reiser4", "hfs", "squashfs", "hfs", "ufs", "jfs", "ext2", "iso9660"]
58 end
59 end
60 private :guessFSType
61
62 def probeFSType
63 if probed?
64 return @fstype
65 end
66
67 fstype_not_tested = guessFSType(@type)
68
69 fstype_not_tested.each {|fstype|
70 begin
71 $log.debug0 "mount testing #{@name} as #{fstype}"
72 self.mountdev(@devpath, @trialpoint, fstype, "ro")
73 $log.success "probed volume: #{@name} #{fstype} (#{@type.join(",")})"
74
75 # マウント成功
76 @probed = true
77 @probed_fstype = @fstype
78 return @fstype
79 rescue
80 $log.debug0 $!
81 # マウント失敗
82 end
83 }
84
85 $log.info "unknown volume: #{@name} (#{@type.join(",")})"
86 @probed = true
87 return @fstype #=> nil
88 end
89
90 def mountedOnTrial?
91 if @point != nil && @point.to_s =~ /^#{@@arkfs.trial}.*/
92 return true
93 else
94 return false
95 end
96 end
97
98 class NotProbedError < MountError
99 def initialize(name, type)
100 @name = name
101 @type = type
102 end
103 def to_s
104 return "Attempt to mount #{@name} (#{@type.join(",")}) which is not probed"
105 end
106 end
107 def mount(path, opt)
108 opt.empty? && opt = "defaults"
109 if ! probed_succeeded?
110 raise NotProbedError.new(@name, @type)
111 end
112 self.mountdev(@devpath, path, @probed_fstype, opt)
113 end
114
115 end
116end
117
118
119$log.debug "#{File.basename(__FILE__, ".*")} loaded"