programmtのブログ -2ページ目

programmtのブログ

ブログの説明を入力します。

If you are a regular reader of mine, then you should know that I'm looking for a perfect backup program, and finally I wrote my own bup-based encryption layer of. Write encbup time, I just restore a file you have to download the entire enormous archive of practice are not satisfied, but still hoping EncFS and rdiff-backup can be used together to achieve remote mount, encryption, deduplication version of the backup function. Try again obnam (long-winded one: it is surprisingly slow), I noticed that it Michael Kors Bedford Logo Large Ivory Totes has a mount command. After thorough research, I found a fuse-python and fusepy, written in Python feels a FUSE file system should be quite simple. The astute reader Michael Kors Bedford Logo Large Purple Crossbody Bags may have realized I am going to do: I decided to use Python to write an encrypted file system layer! EncFS it will be very Michael Kors Outlet similar, but there are also some important Michael Kors Crossbody Bags differences: it runs in reverse mode by default, files received normal and exposed an encrypted directory. Any backup program will find (and backup) These encrypted directory, does not require any additional storage. It can also accept the configuration file consists of a list of a directory, and the mount point to these directories is exposed. In this case, all of the backup scripts you need to back up Michael Kors Clutches the mount point, a variety of directories to be backed up immediately. It will be more emphasis on backup, instead of encrypted storage. Write it should be quite interesting. The first step in a FUSE file system is an example of writing this script to write a pure pass-through of the file system. It just takes a directory and mount point it is exposed, to ensure that any changes will be mirrored in the mount point to Michael Kors Bedford Signature Large White Totes the source data. fusepy ask you to write a class, which defines the various operating system level approach. You can choose to define those methods you want to support the file system, the other can temporarily not be defined, but I need to define all the way, because my file system is a pass-through of the file system, it should behave with the original Some file systems as consistent as possible. This code is very simple to write Michael Kors Bedford Gusset Medium Tan Crossbody Bags interesting, because most of the way just for some simple package os module (indeed, you can assign values ​​to them, such as open = os.open so on, but I need some path extension modules) ʱ?? Unfortunately, fuse-python has a bug (as far as I know) is when you open and read the file, it can not handle the file back to the file system. So I do not know when the script to read or write an application which corresponds to the file handle, resulting in a failure. Fusepy only need to make minimal changes, it can run well. It has only one file, so you can put it directly into your project. Code here, I am happy to give this code, when you intend to implement the file system can be used to reference the time. This code provides a good starting point, you can simply copy the class to your project and need to override some methods according to the inside. Next is the real code:! # / Usr / bin / env pythonfrom __future__ import with_statementimport osimport sysimport errnofrom fuse import FUSE, FuseOSError, Operationsclass Passthrough (Operations): def __init __ (self, root): self.root = root # Helpers # ======= def Michael Kors Berkley Logo Large Beige Clutches _full_path (self, partial): if partial.startswith (\u0026 quot; / \u0026 quot;): partial = partial [1:] path = os.path.join (self.root, partial) return path # Filesystem methods # ================== def access (self, path, mode): full_path = self._full_path (path) if not os.access (full_path, mode ): raise FuseOSError (errno.EACCES) def chmod (self, path, mode): full_path = self._full_path (path) Michael Kors Bedford Gusset Medium Blue Crossbody Bags return os.chmod (full_path, mode) def chown (self, path, uid, gid): full_path = self._full_path (path) return os.chown (full_path, uid, gid) def getattr (self, path, fh = None): full_path = self._full_path (path) st = os.lstat (full_path) return Michael Kors Berkley Logo Large Beige Clutches dict ((key , getattr (st, key)) for key in ('st_atime', 'st_ctime', 'st_gid', 'st_mode', 'st_mtime', 'st_nlink', 'st_size', 'st_uid')) def readdir (self, path, fh): full_path = self._full_path (path) dirents = [, '..' '.'] if os.path.isdir (full_path): dirents.extend (os.listdir (full_path)) for r in dirents : yield r def readlink (self, path): pathname = os.readlink (self._full_path (path)) if pathname.startswith (\u0026 quot; / \u0026 quot;): # Path name is absolute, sanitize it return os.path.. relpath (pathname, self.root) else: return pathname def mknod (self, path, mode, dev): return os.mknod (self._full_path (path), mode, dev) def rmdir (self, path): full_path = self._full_path (path) return os.rmdir (full_path) def mkdir (self, path, mode): return os.mkdir (self._full_path (path), mode) def statfs (self, path): full_path = self._full_path (path) stv = os.statvfs (full_path) return dict ((key, getattr (stv, key)) for key in ('f_bavail', 'f_bfree', 'f_blocks',' f_bsize ',' f_favail ',' f_ffree ',' f_files', 'f_flag', 'f_frsize', 'f_namemax')) def unlink (self, path): return os.unlink (self._full_path (path)) def symlink (self, target, name): return os.symlink Michael Kors Bedford Logo Large Gold Crossbody Bags (self._full_path (target), self._full_path (name)) def rename (self, old, new): return os.rename (self._full_path (old), self._full_path (new)) Michael Kors Bedford Large Orange Shoulder Bags def link ( self, target, name): return os.link (self._full_path (target), self._full_path (name)) def utimens (self, path, times = None): return os.utime (self._full_path (path), times) # File methods # ============ def open (self, path, flags): full_path = self._full_path (path) return os.open (full_path, flags) def create (self, path, mode, fi = None): full_path = self._full_path (path) return os.open (full_path, os.O_WRONLY | os.O_CREAT, mode) def read (self, path, length, offset, fh): os. lseek (fh, offset, os.SEEK_SET) return os.read (fh, length) def write (self, path, buf, offset, fh): os.lseek (fh, offset, os.SEEK_SET) return os.write Michael Michael Kors Berkley Logo Large Black Clutches Kors Berkley Logo Large Black Clutches ( fh, buf) def truncate (self, path, length, fh = None): full_path Michael Kors Bedford Logo Large Gold Crossbody Bags = self._full_path (path) with open (full_path, 'r +') as f: f.truncate (length) def flush (self, path , fh): return os.fsync (fh) def release (self, path, fh): return os.close (fh) def fsync (self, path, fdatasync, fh): return self.flush (path, fh) def main (mountpoint, root): FUSE (Passthrough (root), mountpoint, foreground = True) if __name__ == '__main__': main (sys.argv [2], sys.argv [1]) If you want to run it , only need to install fusepy, put this code into a file (such as myfuse.py) and run python myfuse.py / your directory / mount point directory. You will find all the files '/ your directory' have come under the path '/ mount point directory', but also the same as the operation of their native file systems used. Conclusion Overall, I do not think writing a file system is so simple. The next thing to do is add in the script encryption / decryption capabilities, as well as some help class. My goal is to make it in addition to a better scalability (because it is written in Python), and includes some additional features outside the backup file for, can become perfect substitutes for a EncFS. If you want to follow the script development process, below or to subscribe to my mailing list, or follow me on Twitter. Always welcome feedback (comments below very good).use Python to write a FUSE (user mode file system) file system