コード例 #1
0
ファイル: ext2.py プロジェクト: acieroid/pyext2
 def find_inode(self, path):
     if path == '/':
         return self.root_i
     dirs = path.split('/')[1:]
     with open(self.disk, 'rb') as f:
         # TODO: deal with multiple-blocks directories
         next_de_pos = (self.root_i.get_blocks()[0] * 
                        self.sb.get_block_size())
         while dirs != []:
             f.seek(next_de_pos)
             data = f.read(DirEntrySize)
             de = DirEntry(data)
             if de.get_name_length() == 0:
                 raise NotFound("File %s not found" % path)
             if de.get_name() == dirs[0]:
                 dirs.pop()
                 inode_pos = (self.sb.get_block_size() * 
                              self.first_bg.get_inode_table() +
                              (de.get_inode()-1) * InodeSize)
                 f.seek(inode_pos)
                 data = f.read(InodeSize)
                 i = Inode(data)
                 if dirs == []: # we found it
                     return i
                 if i.is_file():
                     raise NotFound("%s is a file, not a directory" % 
                                    de.get_name())
                 # TODO
                 next_de_pos = (i.get_blocks()[0] *
                                self.sb.get_block_size())
             next_de_pos += de.get_length()
     raise NotFound("Invalid path: %s" % path)
コード例 #2
0
ファイル: ext2.py プロジェクト: acieroid/pyext2
 def readdir(self, path, offset):
     inode = self.find_inode(path)
     with open(self.disk, 'rb') as f:
         next_de_pos = (inode.get_blocks()[0] *
                        self.sb.get_block_size())
         while True:
             f.seek(next_de_pos)
             data = f.read(DirEntrySize)
             de = DirEntry(data)
             if de.get_name_length() == 0:
                 break
             yield fuse.Direntry(de.get_name())
             next_de_pos += de.get_length()
     return