def readdir(self, path, offset): log.info("readdir(%s)" % path) yield fuse.Direntry('.') yield fuse.Direntry('..') if path == "/.command": for entry in self.readCommandDir(): yield entry return # Get field fieldset = self.getField(path) # if not fieldset: # return -errno.ENOENT if path == "/": entry = fuse.Direntry(".command") entry.type = stat.S_IFREG yield entry # Format file name count = len(fieldset) if count % 10: count += 10 - (count % 10) format = "%%0%ud-%%s" % (count//10) # Create entries for index, field in enumerate(fieldset): name = format % (1+index, field.name) entry = fuse.Direntry(name) if field.is_field_set: entry.type = stat.S_IFDIR else: entry.type = stat.S_IFREG yield entry log.info("readdir(%s) done" % path)
def readdir(self, path, offset): log.info("readdir(%s)" % path) yield fuse.Direntry('.') yield fuse.Direntry('..') if path == "/.command": for entry in self.readCommandDir(): yield entry return # Get field fieldset = self.getField(path) # if not fieldset: # return -errno.ENOENT if path == "/": entry = fuse.Direntry(".command") entry.type = stat.S_IFREG yield entry # Format file name count = len(fieldset) if count % 10: count += 10 - (count % 10) format = "%%0%ud-%%s" % (count // 10) # Create entries for index, field in enumerate(fieldset): name = format % (1 + index, field.name) entry = fuse.Direntry(name) if field.is_field_set: entry.type = stat.S_IFDIR else: entry.type = stat.S_IFREG yield entry log.info("readdir(%s) done" % path)
def write(self, path, data, offset): if path == "/.command/writeInto": if self.readonly: return -errno.EACCES try: data = data.strip(" \t\r\n\0") filename = unicode(data, self.fs_charset) except UnicodeDecodeError: log.info("writeInto(): unicode error!") return 0 log.info("writeInto(%s)" % filename) stream = FileOutputStream(filename) self.hachoir.writeInto(stream) return len(data)
def getField(self, path): try: field = self.hachoir try: for name in path.split("/")[1:]: if not name: break name = name.split("-", 1) if len(name) != 2: return None field = field[name[1]] return field except MissingField: return None except Exception, xx: log.info("Exception: %s" % str(xx)) raise
def unlink(self, path, *args): log.info("unlink(%s)" % path) field = self.getField(path) log.info("del %s" % field.name) if not field: return -errno.ENOENT if self.readonly: return -errno.EACCES log.info("del %s" % field.name) try: del field.parent[field.name] except Exception, err: log.info("del ERROR %s" % err)
def read(self, path, size, offset): try: log.info("read(%s, %s, %s)" % (path, size, offset)) field = self.getField(path) if not field: log.info("=> ENOENT") return -errno.ENOENT if not field.hasValue(): return '' except Exception, xx: log.info("ERR: %s" % xx) raise
def read(self, path, size, offset): try: log.info("read(%s, %s, %s)" % (path, size, offset)) field = self.getField(path) if not field: log.info("=> ENOENT") return -errno.ENOENT if not field.hasValue(): return '' except Exception as xx: log.info("ERR: %s" % xx) raise data = self.fieldValue(field) slen = len(data) if offset >= slen: return '' if offset + size > slen: size = slen - offset data = data[offset:offset + size] log.info("=> %s" % repr(data)) return data
def truncate(self, *args): log.info("truncate(): TODO!")
def stop(self): log.info("stop()")
def open(self, path, flags): log.info("open(%s)" % path)
if not field: log.info("=> ENOENT") return -errno.ENOENT if not field.hasValue(): return '' except Exception, xx: log.info("ERR: %s" % xx) raise data = self.fieldValue(field) slen = len(data) if offset >= slen: return '' if offset + size > slen: size = slen - offset data = data[offset:offset+size] log.info("=> %s" % repr(data)) return data def stop(self): log.info("stop()") def truncate(self, *args): log.info("truncate(): TODO!") def main(): usage=""" Userspace hello example """ + Fuse.fusage server = HelloFS(u'/home/haypo/testcase/KDE_Click.wav', version="%prog " + fuse.__version__,
if not field: log.info("=> ENOENT") return -errno.ENOENT if not field.hasValue(): return '' except Exception, xx: log.info("ERR: %s" % xx) raise data = self.fieldValue(field) slen = len(data) if offset >= slen: return '' if offset + size > slen: size = slen - offset data = data[offset:offset + size] log.info("=> %s" % repr(data)) return data def stop(self): log.info("stop()") def truncate(self, *args): log.info("truncate(): TODO!") def main(): usage = """ Userspace hello example """ + Fuse.fusage server = HelloFS(u'/home/haypo/testcase/KDE_Click.wav',