Class: Ext3::FileData
- Inherits:
-
Object
- Object
- Ext3::FileData
- Defined in:
- lib/fs/ext3/file_data.rb
Constant Summary collapse
- SIZEOF_LONG =
4
- MAX_READ =
4294967296
- DEFAULT_BLOCK_SIZE =
1024
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#initialize(inodeObj, superblock) ⇒ FileData
constructor
Initialization.
- #read(bytes = @inodeObj.length) ⇒ Object
- #rewind ⇒ Object
- #seek(offset, method = IO::SEEK_SET) ⇒ Object
- #write(buf, _len = buf.length) ⇒ Object
Constructor Details
#initialize(inodeObj, superblock) ⇒ FileData
Initialization
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fs/ext3/file_data.rb', line 14 def initialize(inodeObj, superblock) raise "Ext3::FileData.initialize: Nil inode object" if inodeObj.nil? raise "Ext3::FileData.initialize: Nil superblock" if superblock.nil? @sb = superblock @inodeObj = inodeObj @blockSize = @sb.blockSize @path = BlockPointersPath.new(@blockSize / SIZEOF_LONG) rewind end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
11 12 13 |
# File 'lib/fs/ext3/file_data.rb', line 11 def pos @pos end |
Instance Method Details
#read(bytes = @inodeObj.length) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fs/ext3/file_data.rb', line 41 def read(bytes = @inodeObj.length) raise "Ext3::FileData.read: Can't read 4G or more at a time (use a smaller read size)" if bytes >= MAX_READ return nil if @pos >= @inodeObj.length # Handle symbolic links. if @inodeObj.symlnk out = @inodeObj.symlnk[@pos...bytes] @pos += bytes return out end bytes = @inodeObj.length - @pos if @pos + bytes > @inodeObj.length # get data. startBlock, startByte, endBlock, endByte, nblocks = getStartBlock(@pos, bytes) out = getBlocks(startBlock, nblocks) @pos += bytes out[startByte, bytes] end |
#rewind ⇒ Object
26 27 28 |
# File 'lib/fs/ext3/file_data.rb', line 26 def rewind @pos = 0 end |
#seek(offset, method = IO::SEEK_SET) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fs/ext3/file_data.rb', line 30 def seek(offset, method = IO::SEEK_SET) @pos = case method when IO::SEEK_SET then offset when IO::SEEK_CUR then @pos + offset when IO::SEEK_END then @inodeObj.length - offset end @pos = 0 if @pos < 0 @pos = @inodeObj.length if @pos > @inodeObj.length @pos end |
#write(buf, _len = buf.length) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/fs/ext3/file_data.rb', line 60 def write(buf, _len = buf.length) raise "Ext3::FileData.write: Write functionality is not yet supported on Ext3." # Commented out for now to avoid unreachable code # # @dirty = true end |