├── fileformat.md ├── README.md ├── fusepy.py └── LICENSE /fileformat.md: -------------------------------------------------------------------------------- 1 | # HDRFS file format specification 2 | 3 | The HDRFS volume file format consists of a sequence of variable-length blocks. 4 | 5 | Every volume begins with a BlockHeader. Every volume except the first then 6 | includes a BlockLinkTable. Every volume then contains zero or more blocks of the 7 | following types: BlockNull, BlockInode, BlockLink, BlockUnlink, BlockXattr, 8 | BlockRemovedXattr, BlockData, BlockRename. 9 | 10 | In the definitions below, the tables list the length and order of fields in 11 | the blocks. 12 | 13 | ## Common elements 14 | 15 | ### Timestamps 16 | 17 | Timestamps are stored as an integer number of microseconds since the epoch. 18 | Blocks in an HDRFS volume should have monotonically increasing timestamp values. 19 | Epoch timestamps are independent of timezone and DST so should never go 20 | backwards. Timestamps are always stored as 64-bit little-endian unsigned 21 | integers. 22 | 23 | ### CRCs 24 | 25 | The CRC is a 32-bit little-endian unsigned integer as returned from the CRC 26 | function. It defines the CRC value of all bytes in the block up to but not 27 | including the CRC value. 28 | 29 | ### Inode numbers 30 | 31 | The inode number is a 64-bit little-endian unsigned integer. 32 | 33 | ## BlockHeader 34 | 35 | The header is a fixed-length prefix for every volume file. 36 | 37 | | Length | Field | 38 | | ------ | -------------------------------------- | 39 | | 17 | Magic bytes | 40 | | 1 | Version | 41 | | 16 | Filesystem ID | 42 | | 1 | CRC algorithm | 43 | | 1 | Hash algorithm | 44 | | 8 | Volume sequence number | 45 | | 32 | Previous volume hash | 46 | | 4 | CRC | 47 | 48 | 49 | The file format magic bytes are: 50 | 51 | D3 48 44 52 46 53 0D 0A 1A 0A 00 48 44 52 46 53 00 52 | 53 | Magic bytes may be used to identify files as being in HDRFS format. 54 | 55 | Version is 00 for the current version of the HDRFS file format. 56 | 57 | Filesystem ID is a 16-byte random UUID. This must be consistent across all 58 | volume files in a filesystem. 59 | 60 | CRC algorithm values are as follows: 61 | 62 | | Value | Meaning | 63 | | ----- | ------------------------------ | 64 | | 00 | CRC-32 (polynomial 0x04C11DB7) | 65 | 66 | (Only one CRC algorithm is defined in the current version of HDRFS) 67 | 68 | Hash algorithm values are as follows: 69 | 70 | | Value | Meaning | 71 | | ----- | ------------------------------ | 72 | | 00 | SHA256 | 73 | 74 | (Only one value is defined in the current version of HDRFS) 75 | 76 | The volume sequence number is a 64-bit little-endian unsigned integer. It must 77 | be sequential from one volume to the next, starting from zero. 78 | 79 | The previous volume hash is a 32-byte value as returned from the hash algorithm. 80 | In the first volume, this position is occupied by 32 null bytes. In all other 81 | volumes, it is the hash of the previous volume file. 82 | 83 | Note that the size of the volume is not defined anywhere within the volume. 84 | 85 | ## BlockInode 86 | 87 | The inode block stores `stat` fields, and a list of extents mapping the logical 88 | structure of the file to the physical structure of HDRFS volumes. If the inode 89 | is a symlink, it stores the link target. For any given inode number, the most 90 | recent BlockInode represents the current version. 91 | 92 | | Length | Field | 93 | | ------ | -------------------------------------- | 94 | | 1 | Block ID | 95 | | 8 | Inode number | 96 | | 8 | Log timestamp | 97 | | 2 | st_mode | 98 | | 2 | st_uid | 99 | | 2 | st_gid | 100 | | 8 | st_atime | 101 | | 8 | st_mtime | 102 | | 8 | st_ctime | 103 | | 8 | st_btime | 104 | | 8 | st_size | 105 | | 8 | Variable Length Size | 106 | | n | Variable Length Portion | 107 | | 4 | CRC | 108 | 109 | 110 | Block ID is 1 111 | 112 | The Log timestamp records the moment the block was written. 113 | 114 | st_mode, st_uid, and st_gid are 16-bit little-endian unsigned integers recording the file mode 115 | bits, user ID and group ID respectively. 116 | 117 | st_atime, st_mtime, st_ctime, and st_btime are 64-bit little-endian unsigned 118 | integers recording the number of microseconds between the epoch and the file's 119 | latest access time, modification time, metadata change time, and file creation 120 | time respectively. 121 | 122 | st_size is a 64-bit little-endian unsigned integer recording the size 123 | of the file. The size of a regular file is its conventional size in bytes. The 124 | size of a symbolic link is 70 bytes plus the length of the link target. The size 125 | of all other file types is 70 bytes. 126 | 127 | Variable Length Size is a 64-bit little-endian unsigned integer recording the 128 | length n of the next part of the block. 129 | 130 | If the file is a regular file, then the Variable Length Portion is a List of 131 | Extent Structures. If the file is a symbolic link, then the Variable Length 132 | Portion is the UTF-8 encoded link target. If the file is anything else, the 133 | Variable Length Portion will have zero length. 134 | 135 | A List of Extent Structures is: 136 | 137 | | Length | Field | 138 | | ------ | -------------------------------------- | 139 | | 8 | Volume | 140 | | 8 | Physical Start Offset | 141 | | 8 | Block Size | 142 | | 1 | Block Multiplicity | 143 | | 8 | Block Count | 144 | | 8 | Pre Truncate | 145 | | 8 | Post Truncate | 146 | | 8 | Logical Start Offset | 147 | 148 | Each extent structure has a fixed length (57) so the number of extent structures 149 | will be the Variable Length Size divided by 57. 150 | 151 | Extents define a logical segment of the file, of length (Block Size) * (Block 152 | Count), starting at Logical Start Offset. 153 | 154 | These logical segments are mapped to physical segments on Volume, starting at 155 | Physical Start Offset. 156 | 157 | Pre Truncate and Post Truncate are used to modify the logical and physical 158 | segments. 159 | 160 | Block Multiplicity is either 82 or 67 (hex for 'R' and 'C' respectively, 161 | meaning Repeat and Count). Repeat extents repeat the block at Physical Start 162 | Offset (Block Count times). Count extents return a number of sequential blocks 163 | (again starting at Physical Start Offset) equal to Block Count. 164 | 165 | All values in the extent structure except Block Multiplicity are 64-bit 166 | little-endian unsigned integers. 167 | 168 | ## BlockLink 169 | 170 | A link associates an inode with a parent inode and gives that association a 171 | name. 172 | 173 | 174 | | Length | Field | 175 | | ------ | -------------------------------------- | 176 | | 1 | Block ID | 177 | | 8 | Log timestamp | 178 | | 8 | Child Inode | 179 | | 8 | Parent Inode | 180 | | 2 | Length of link name | 181 | | n | Link name | 182 | | 4 | CRC | 183 | 184 | Block ID is 2 185 | 186 | The Log timestamp records the moment the block was written. 187 | 188 | Child Inode is associated with Parent Inode, with the name Name. 189 | 190 | Length of link name is a 16-bit little-endian unsigned integer n defining the 191 | length of the name field that follows. 192 | 193 | Link name is the UTF-8 encoded name of the link. 194 | 195 | ## BlockUnlink 196 | 197 | An unlink disassociates a named inode from a parent inode. This represents the 198 | deletion of a file. 199 | 200 | | Length | Field | 201 | | ------ | -------------------------------------- | 202 | | 1 | Block ID | 203 | | 8 | Log Timestamp | 204 | | 8 | Child Inode | 205 | | 8 | Parent Inode | 206 | | 2 | Length of Link Name | 207 | | n | Link Name | 208 | | 4 | CRC | 209 | 210 | Block ID is 3. 211 | 212 | All other fields are the same as in BlockLink. 213 | 214 | ## BlockXattr 215 | 216 | An extended attribute is a name-value pair associated with an inode. 217 | 218 | | Length | Field | 219 | | ------ | -------------------------------------- | 220 | | 1 | Block ID | 221 | | 8 | Log Timestamp | 222 | | 8 | Inode Number | 223 | | 1 | Length of Attribute Name | 224 | | 2 | Length of Attribute Value | 225 | | n | Attribute Name | 226 | | m | Attribute Value | 227 | | 4 | CRC | 228 | 229 | 230 | Block ID is 4. 231 | 232 | Length of attribute name is an 8-bit unsigned integer n defining the 233 | length of the Attribute Name field. 234 | 235 | Length of attribute value is a 16-bit little-endian unsigned integer m defining the 236 | length of the Attribute Value field. 237 | 238 | Attribute Name is the UTF-8 encoded name of the attribute. 239 | 240 | Attribute Value is a sequence of m raw bytes. 241 | 242 | ## BlockRemovedXattr 243 | 244 | A removed extended attribute represents the deletion of an extended attribute 245 | from an inode. 246 | 247 | | Length | Field | 248 | | ------ | -------------------------------------- | 249 | | 1 | Block ID | 250 | | 8 | Log Timestamp | 251 | | 8 | Inode Number | 252 | | 1 | Length of Attribute Name | 253 | | n | Attribute Name | 254 | | 4 | CRC | 255 | 256 | 257 | Block ID is 5. 258 | 259 | All other fields are the same as in BlockXattr. 260 | 261 | ## BlockData 262 | 263 | This block stores file data. 264 | 265 | | Length | Field | 266 | | ------ | -------------------------------------- | 267 | | 1 | Block ID | 268 | | 8 | Log Timestamp | 269 | | 8 | Payload length | 270 | | n | Payload | 271 | | 4 | CRC | 272 | 273 | Block ID is 6 274 | 275 | Payload length is a 64-bit little-endian unsigned integer n defining the length 276 | of the block of data that follows. 277 | 278 | Payload is a sequence of n raw bytes. 279 | 280 | ## BlockRename 281 | 282 | Renaming is an atomic operation, hence is not simply a pair of link/unlink 283 | events. 284 | 285 | | Length | Field | 286 | | ------ | -------------------------------------- | 287 | | 1 | Block ID | 288 | | 8 | Log Timestamp | 289 | | 2 | Length of Previous Path | 290 | | 2 | Length of New Path | 291 | | n | Previous Path | 292 | | m | New Path | 293 | | 4 | CRC | 294 | 295 | Block ID is 7 296 | 297 | Length of Previous Path is a 16-bit little-endian unsigned integer n defining the 298 | length of the Previous Path field. 299 | 300 | Length of New Path is a 16-bit little-endian unsigned integer m defining the 301 | length of the New Path field. 302 | 303 | Previous Path and New Path are UTF-8 encoded full path names relative to the 304 | root of the HDRFS filesystem. 305 | 306 | ## BlockLinkTable 307 | 308 | The link table is a representation of the filesystem tree. It maps inodes 309 | to parent inodes, with a name for each relationship. An inode may be mapped to 310 | the same parent inode multiple times under different names. The link table is 311 | included in every volume. Strictly speaking this table is redundant, as all this 312 | information is already recorded in BlockLink blocks. But its purpose is to aid 313 | disaster recovery: with this table, it becomes possible to extract files to 314 | their correct location in the filesystem tree - without needing access to 315 | previous volumes. 316 | 317 | | Length | Field | 318 | | ------ | -------------------------------------- | 319 | | 1 | Block ID | 320 | | 8 | Number of links | 321 | | n | List of link structures | 322 | | 4 | CRC | 323 | 324 | Block ID is 8 325 | 326 | Number of links is a 64-bit little-endian unsigned integer n. It defines the 327 | number of link structures to follow. 328 | 329 | The CRC is a 32-bit little-endian unsigned integer as returned from the CRC 330 | function. 331 | 332 | List of link structures is: 333 | 334 | | Length | Field | 335 | | ------ | -------------------------------------- | 336 | | 8 | Child inode number | 337 | | 8 | Parent inode number | 338 | | 2 | Length of link name | 339 | | m | Link name | 340 | 341 | 342 | Child and parent inode numbers are 64-bit little-endian unsigned integers 343 | defining an is-in relationship. 344 | 345 | Length of link name is a 16-bit little-endian unsigned integer m defining 346 | the length of the name to follow. 347 | 348 | Link name is the UTF-8 encoded name of the link. 349 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Please note HDRFS is in its initial testing phase. Do not rely on it for storing critical data.* 2 | 3 | # What is HDRFS? 4 | 5 | HDRFS is a lossless filesystem application which stores a complete history of 6 | every byte ever written to it. It is backed by a strictly append-only log, but 7 | works as a fully read/write POSIX-compatible filesystem. Think of it as a cross 8 | between a filesystem and `tar`, with infinite versioning and tuned to maximise 9 | ease of backups. 10 | 11 | It is intended to be used by individuals to archive personal files. 12 | 13 | This repository contains a specification for the log file format, and a 14 | reference implementation in Python. 15 | 16 | HDRFS has the following properties: 17 | 18 | * The filesystem is backed by one or more volume files which exist on an 19 | underlying filesystem. You may tune the size of the volume files to whatever 20 | size you find easiest to manage. For example, you might choose a volume size 21 | of 4.7GB in order to write each to a DVD. 22 | 23 | * The volume files are *strictly* append-only. Once written, data is never 24 | overwritten or deleted. Users may still modify or delete data in the HDRFS 25 | filesystem, but modifications and deletions are recorded as additional events 26 | and it is always possible to wind back to a previous state of the filesystem. 27 | 28 | * HDRFS may be mounted with some or all of its volume files missing (e.g. if 29 | they have been moved to offline media). Data cannot be read from missing 30 | volumes, but the filesystem can still be browsed. Providing the most recent 31 | volume is not missing, the filesystem also supports writes. You can even write 32 | to a file which is held on offline media, as long as you don't try to read 33 | from it. 34 | 35 | * Backing up an HDRFS volume is very easy: only the most recent volume ever 36 | changes. Once a volume reaches its maximum size it becomes immutable, and the 37 | next volume is started. 38 | 39 | * HDRFS presents a virtual directory through which to browse historical 40 | snapshots. Full history of every write is generated at fsync-level 41 | granularity. There is no need to create snapshots - simply browse to whatever 42 | timestamp you wish. 43 | 44 | * HDRFS deduplicates data by default, though it can be turned off for a small 45 | performance improvement. 46 | 47 | * HDRFS checksums all data and metadata to help identify integrity issues. 48 | 49 | # Installation and quick start 50 | 51 | HDRFS is a single Python program, with one dependency (fusepy) which is 52 | available in Ubuntu 17.04 and above: 53 | 54 | # apt install python3-fusepy 55 | 56 | Alternatively, you can get fusepy from here: 57 | https://github.com/terencehonles/fusepy. If you don't want to install fusepy, 58 | you can just download `fuse.py` save it as `fusepy.py` in the same directory as 59 | `hdrfs.py`. 60 | 61 | Once fusepy is installed, download `hdrfs.py` and launch it like this: 62 | 63 | $ ./hdrfs.py /path/to/mount/point 64 | 65 | By default, it will create Log and Index files in the current directory. This 66 | can be changed using options. View all options as follows: 67 | 68 | $ ./hdrfs.py --help 69 | 70 | # Non-features 71 | 72 | * HDRFS does not compress data. If you wish to compress your data, use an 73 | underlying filesystem which supports compression (such as btrfs), or compress 74 | the volume files manually (this will take them offline - you must uncompress 75 | them before HDRFS will be able to read from them). 76 | 77 | * HDRFS does not encrypt data. If you wish to encrypt your data, use an 78 | underlying filesystem which 79 | supports encryption, or take the volume files offline and encrypt them using 80 | another tool. If you have a strong need for data security, you should consult a 81 | security professional. 82 | 83 | * HDRFS does not store parity data. Thanks to the use of checksums, 84 | data corruption in an HDRFS volume can be detected - but it cannot be fixed. 85 | Instead, HDRFS relies on its underlying filesystem to provide RAID-like 86 | features. 87 | 88 | * HDRFS does not enforce permissions checks. Permission bits, owners, and groups 89 | are recorded faithfully, but not used to grant or deny access.This means you 90 | can chown or chmod a file to whatever you like. This non-feature is consistent 91 | with HDRFS being a single-user personal filesystem. HDRFS makes no attempt to 92 | support locking. 93 | 94 | * HDRFS is not a high-performance multi-user filesystem. Although you *could* 95 | run a database server on it, performance may be problematic. Any application 96 | which writes and overwrites lots of transient data is likely to generate 97 | unmanageably large and useless Log files. 98 | 99 | # How does a filesystem help make backups easier? 100 | 101 | HDRFS's primary benefit is its volume management. It is very simple to manage a 102 | small number of large files which never change. You can take backups and layer 103 | on compression, encryption and erasure coding, and because the volumes never 104 | change, you only have to do this once. If you go to the effort of dividing your 105 | data into n erasure-coded blocks hosted on n different cloud storage providers, 106 | you don't want to have to repeat that when you do your next backup. 107 | 108 | # How does HDRFS operate with offline volumes? 109 | 110 | HDRFS maintains an index holding filesystem metadata. This allows you to mount 111 | the filesystem without *any* data volumes being available. You can also mount 112 | the filesystem with only *some* volumes available, for example with some 113 | transferred to tape and taken offline. As long as the most recent volume is 114 | available, you can even write to the filesystem. One possible use case for this 115 | might be an archive which needs to hold large files indefinitely, reorganise 116 | them and add metadata over time, but rarely access the actual data in the files. 117 | 118 | The index is not part of the HDRFS specification, and you don't strictly need to 119 | back it up: if it's missing at startup, HDRFS will regenerate it. You might 120 | still want to back it up because the regeneration process can be slow, and 121 | requires all volumes to be online. 122 | 123 | # How do I use the history feature? 124 | 125 | By default, HDRFS will create a directory at the root its filesystem named 126 | `history`. You can change the name of this top-level folder if you wish, using 127 | the `--history-directory` option. Within the history directory there are folders 128 | corresponding to change events. By default, there will be a folder for every day 129 | on which data was written, plus folders representing the first and last writes. 130 | The first folder will always be empty. You can use the 131 | `--history-directory-granularity` option to change the granularity of these 132 | directories - anything from year to microsecond. 133 | 134 | The format of the directory name is ISO8601 *including* timezone. 135 | 136 | Regardless of the granularity option, you can manually navigate to any timestamp 137 | of your choosing. 138 | 139 | History view will always give you file data as-at an fsync. 140 | 141 | You can get some useful metadata about the change history of a file by examining 142 | the `hdrfs.history` extended attribute. For example: 143 | 144 | $ getfattr --only-values -n hdrfs.history bigfile.zip 145 | Change time | Mode | UID | GID | Size (bytes) 146 | --------------------|----------|-------|-------|------------- 147 | 2017-07-30 20:22:42 | 0o100644 | 1000 | 1000 | 0 148 | 2017-07-30 20:22:43 | 0o100644 | 1000 | 1000 | 107644039 149 | 150 | Another useful extended attribute is `hdrfs.volumes`, which shows you a 151 | comma-separated list of the volumes that a file resides on: 152 | 153 | $ getfattr --only-values -n hdrfs.volumes bigfile.zip 154 | 0,1,2,3 155 | 156 | You could use this to ensure that all volumes are online before attempting to 157 | access a file. 158 | 159 | # How fast is HDRFS? 160 | 161 | HDRFS is extremely sensitive to file block size. It performs best when writes 162 | are in large blocks. `cp` will use a default block size of 128KiB, which is good 163 | for HDRFS performance. Other utilities may use a smaller block size such as 4KiB, 164 | which is not good for HDRFS performance. 165 | 166 | Worst case performance is reached when writing many small files using a small 167 | block size. 168 | 169 | Best case performance is reached when writing large files using a large block 170 | size. 171 | 172 | An HDRFS filesystem loaded with media files is capable of achieving decent 173 | performance - certainly enough to stream high bitrate video and perform interactive file 174 | management without the end-user experience being all that different from a 175 | native filesystem. 176 | 177 | As well as block size, there is overhead to creating volumes. For good 178 | performance, choose a large volume size that will fill up only occasionally. 179 | 180 | Example benchmark showing best case performance: 181 | 182 | $ dd if=/dev/zero count=8000 bs=131072 of=mnt/1 183 | 8000+0 records in 184 | 8000+0 records out 185 | 1048576000 bytes (1.0 GB, 1000 MiB) copied, 5.6616 s, 185 MB/s 186 | 187 | Example benchmark showing far worse performance: 188 | 189 | $ dd if=/dev/zero count=256000 bs=4096 of=mnt/2 190 | 256000+0 records in 191 | 256000+0 records out 192 | 1048576000 bytes (1.0 GB, 1000 MiB) copied, 25.028 s, 41.9 MB/s 193 | 194 | HDRFS attempts to counteract the effect of small writes by buffering into 128KiB 195 | chunks. This means that slow 4K writes won't compromise future reads: 196 | 197 | $ dd if=mnt/2 of=/dev/null bs=131072 198 | 8000+0 records in 199 | 8000+0 records out 200 | 1048576000 bytes (1.0 GB, 1000 MiB) copied, 2.262 s, 464 MB/s 201 | 202 | As a further benchmark, here is `postmark` running with default settings on an HDRFS 203 | filesystem: 204 | 205 | Creating files...Done 206 | Performing transactions..........Done 207 | Deleting files...Done 208 | Time: 209 | 14 seconds total 210 | 6 seconds of transactions (83 per second) 211 | 212 | Files: 213 | 764 created (54 per second) 214 | Creation alone: 500 files (100 per second) 215 | Mixed with transactions: 264 files (44 per second) 216 | 243 read (40 per second) 217 | 257 appended (42 per second) 218 | 764 deleted (54 per second) 219 | Deletion alone: 528 files (176 per second) 220 | Mixed with transactions: 236 files (39 per second) 221 | 222 | Data: 223 | 1.36 megabytes read (99.80 kilobytes per second) 224 | 4.45 megabytes written (325.20 kilobytes per second) 225 | 226 | And for comparison here it is running on the same hardware on an ext4 227 | filesystem: 228 | 229 | Creating files...Done 230 | Performing transactions..........Done 231 | Deleting files...Done 232 | Time: 233 | 1 seconds total 234 | 1 seconds of transactions (500 per second) 235 | 236 | Files: 237 | 764 created (764 per second) 238 | Creation alone: 500 files (500 per second) 239 | Mixed with transactions: 264 files (264 per second) 240 | 243 read (243 per second) 241 | 257 appended (257 per second) 242 | 764 deleted (764 per second) 243 | Deletion alone: 528 files (528 per second) 244 | Mixed with transactions: 236 files (236 per second) 245 | 246 | Data: 247 | 1.36 megabytes read (1.36 megabytes per second) 248 | 4.45 megabytes written (4.45 megabytes per second) 249 | 250 | You can see HDRFS is an order of magnitude slower than ext4. However, this is 251 | with file size set to range between 500 and 10000 bytes, with read and write 252 | block sizes of 512 bytes. HDRFS put in a stronger performance with file size set 253 | to range between 1,000,000 and 10,000,000 bytes, with read and write block sizes 254 | of 131,072 bytes. With these settings we get the following results: 255 | 256 | Creating files...Done 257 | Performing transactions..........Done 258 | Deleting files...Done 259 | Time: 260 | 51 seconds total 261 | 26 seconds of transactions (19 per second) 262 | 263 | Files: 264 | 757 created (14 per second) 265 | Creation alone: 500 files (22 per second) 266 | Mixed with transactions: 257 files (9 per second) 267 | 285 read (10 per second) 268 | 215 appended (8 per second) 269 | 757 deleted (14 per second) 270 | Deletion alone: 514 files (171 per second) 271 | Mixed with transactions: 243 files (9 per second) 272 | 273 | Data: 274 | 1619.88 megabytes read (31.76 megabytes per second) 275 | 4365.11 megabytes written (85.59 megabytes per second) 276 | 277 | And for comparison on ext4: 278 | 279 | Creating files...Done 280 | Performing transactions..........Done 281 | Deleting files...Done 282 | Time: 283 | 24 seconds total 284 | 16 seconds of transactions (31 per second) 285 | 286 | Files: 287 | 757 created (31 per second) 288 | Creation alone: 500 files (62 per second) 289 | Mixed with transactions: 257 files (16 per second) 290 | 285 read (17 per second) 291 | 215 appended (13 per second) 292 | 757 deleted (31 per second) 293 | Deletion alone: 514 files (514 per second) 294 | Mixed with transactions: 243 files (15 per second) 295 | 296 | Data: 297 | 1619.88 megabytes read (67.49 megabytes per second) 298 | 4365.11 megabytes written (181.88 megabytes per second) 299 | 300 | Now HDRFS is only about half as slow as ext4. You still wouldn't want to run a 301 | mail server on an HDRFS filesystem. 302 | 303 | By the way, you *can* run an HDRFS filesystem within another HDRFS filesystem if 304 | you wish to plumb the depths of awful performance. 305 | 306 | 307 | # How slow is HDRFS? 308 | 309 | HDRFS is written in Python, and uses FUSE. This adds several layers of 310 | abstraction over a native filesystem such as btrfs. 311 | 312 | Normal filesystem: Disk <-> Filesystem Driver <-> Kernel <-> User 313 | 314 | HDRFS filesystem: Disk <-> Filesystem Driver <-> Kernel <-> FUSE Kernel Module 315 | <-> fusepy.py <-> hdrfs.py <-> fusepy.py <-> FUSE Kernel Module <-> Kernel <-> 316 | User 317 | 318 | Greater performance could undoubtedly be achieved by rewriting HDRFS in a faster 319 | language such as C or Go - and in fact, the log file format is designed with C 320 | data types in mind - but even an assembly implementation would have to contend 321 | with all this layering and will never be as fast as a native filesystem. 322 | 323 | Fortunately, modern PCs have powerful CPUs, and for single-user purposes, the 324 | performance of even the Python implementation can be solidly adequate. 325 | 326 | # How big should my volumes be? 327 | 328 | Choose whatever size is convenient for you to manage. 329 | 330 | * If you backup to DVDs, you could choose 4.7G 331 | * If you backup to triple-layer BDXL discs, you could choose 100G. 332 | * If you backup to cloud storage, you could tune the volume size to your upload 333 | speed, so that a volume uploads in a reasonable time. 334 | 335 | Every time a volume is filled, it is hashed and the hash stored in the header of 336 | the next volume. This forms a chain of integrity checks, but does mean that each 337 | volume must be hashed in full - potentially in the middle of a write operation. 338 | This manifests as a pause, and the large the volume the longer the pause. 339 | 340 | Each volume can be a different size if you wish. The `--volume-size` option only 341 | takes effect at the moment a volume reaches that size, so if you started HDRFS 342 | with a volume size of 100P and meant to type 100G, don't worry - just restart 343 | HDRFS with the desired volume size. 344 | 345 | However, you cannot change the size of a volume which has already been 346 | finalized. 347 | 348 | The default volume size is 1G. 349 | 350 | # Why does HDRFS not support compression? 351 | 352 | It's a personal judgement call based on four reasons - one aesthetic, three 353 | pragmatic. 354 | 355 | 1. I believe compression is more effective elsewhere in the storage stack. The 356 | purpose of HDRFS is to create a canonical logical representation of your 357 | versioned data. Compression is a physical layer under that. It is better to 358 | have checksums of your data than of a compressed representation of your data. 359 | 360 | 2. Filesystem compression is a solved problem: if you use btrfs or ZFS as the 361 | underlying filesystem for your HDRFS volumes, you can enable transparent 362 | compression very easily. No need for HDRFS to reimplement that. 363 | 364 | 3. Compression ratios are better over large ranges of data, not small filesystem 365 | blocks. To get the most out of an algorithm like lrzip, you should compress the 366 | whole HDRFS volume. To take advantage of long range inter-block redundancies, it 367 | is essential that the data is not already compressed. 368 | 369 | 2. HDRFS is a singler-user personal filesystem, and the vast majority of 370 | personal files are already compressed. JPG, PNG, MOV, MP4, AVI, MP3, FLAC, OGG, 371 | GIF, ZIP, DOCX, XLSX, PPTX, and PDF are amongst the most common file types and 372 | all of them use their own compression. When your storage system is scaled to 373 | store 30GB Blu-Ray rips, it makes little difference whether your textfiles are 374 | compressed or not. 375 | 376 | # Is HDRFS multi-threaded? 377 | 378 | No. Writes are single-threaded by design and by necessity, as there is only a 379 | single Log. The Python implementation is single-threaded. 380 | 381 | If you are doing a large transfer of data into HDRFS, you should wait for that 382 | to complete before doing reads (whether reading specific files or just browsing 383 | directories). There's nothing to stop you reading and writing at the same time. 384 | It will just be slow. 385 | 386 | An alternative implementation could choose to do multi-threaded reads, but the 387 | Python implementation will never do this. 388 | 389 | # Can HDRFS store any type of file? 390 | 391 | Yes, but there are some patterns of data which will enjoy worst-case 392 | performance. Testing has shown that large files with alternating patterns of 393 | repeating blocks and non-repeating blocks will generate a lot of metadata, and 394 | therefore be slow to access. These types of files are atypical in normal usage. 395 | 396 | # At what level of granularity does deduplication operate? 397 | 398 | Under normal usage, and with reasonably large files, data will be deduplicated 399 | in 128KiB blocks. However, HDRFS uses a variable block size so there are 400 | scenarios where data may be deduplicated in smaller blocks. 401 | 402 | HDRFS has an internal write buffer which batches POSIX write() calls into blocks 403 | of up to 128KiB. A number of events can cause the write buffer to be flushed 404 | before it reaches this size. Examples include: any metadata operation (e.g. 405 | `chmod`), any attempt to read data from the buffered inode, or upon a `flush` or 406 | `fsync` call. This means a data block may be less than 128KiB. In degenerate 407 | cases, it could be as small as one byte! 408 | 409 | # How much memory does deduplication require? 410 | 411 | A deduplication index is stored in memory during normal operation, and saved when 412 | HDRFS exits. Deduplicating 1GB of random data requires approximately 1.4MB of 413 | memory. When saved following HDRFS exit, this same deduplication index requires 414 | approximately 1MB of disk space. 415 | 416 | You can turn off deduplication using the `--no-deduplication` option. This does 417 | not delete the deduplication index already stored on disk, and only takes effect from the 418 | point of starting HDRFS with this option. You can restart HDRFS with 419 | deduplication turned back on (this is the default) to resume deduplicating data, 420 | but any data stored while deduplication was off will not have generated entries 421 | in the deduplication index. 422 | 423 | # What operating systems will HDRFS run on? 424 | 425 | HDRFS uses FUSE, which is a feature of the Linux kernel. Other operating systems 426 | have similar features, but HDRFS has been developed and tested on Linux and I 427 | have no immediate plans to port it. 428 | 429 | # How do I delete data from an HDRFS filesystem? 430 | 431 | You may delete or overwrite files within the filesystem, but the history of 432 | those files remains. There is no option to permanently delete data which has 433 | been written to the Log. 434 | 435 | HDRFS is not designed for people who need to delete data. Take care not to write 436 | confidential data to HDRFS if you think you might ever need to delete it. 437 | 438 | However, if you have written data which must truly be destroyed, your options 439 | are: 440 | 441 | * Copy all data out of one HDRFS filesystem and into another - minus the unwanted file. 442 | * You would lose all history. 443 | * Delete the volume on which the unwanted data is stored. 444 | * HDRFS will function normally with a volume missing, but you will not be 445 | able to read any files on that volume, nor rebuild the index without 446 | that volume. 447 | * Encrypt the data on which the unwanted data is stored. 448 | * This takes the volume offline as far as HDRFS is concerned, but allows 449 | you the possibility of restoring the volume at a later date if you 450 | needed to do an Index rebuild. 451 | * You could use this option to mitigate the downsides of deleting the volume: 452 | * Start HDRFS with deduplication disabled. 453 | * Locate all files stored on the same volume as the unwanted file. 454 | * Copy each of these files to a temporary directory within the HDRFS 455 | filesystem. With deduplication disabled, this will created a new 456 | copy of each file on the current volume. 457 | * Restart HDRFS with deduplication enabled. Copy the files back to 458 | their desired location within the HDRFS filesystem. Encrypt the 459 | volume with the unwanted file. 460 | * The result is that all required files are available in an online 461 | volume, except the unwanted file which exists only on the encrypted 462 | volume. The downside is that history of those files is unavailable. 463 | 464 | * Parse the Log file(s) to locate the unwanted data and overwrite it 465 | with zeros. 466 | * N.B. This would cause checksums to fail. 467 | * N.B. This would still leave a zero-filled hole the same size as your data, so if even the length of your data is private, this is not an option. 468 | * Parse and rewrite all Log files to omit the unwanted files. 469 | 470 | A 3rd-party tool or alternative HDRFS implementation could be created to 471 | automate some or all of the above, as the Log files are written in a fully 472 | documented format and can be modified independently of any particular 473 | implementation of HDRFS. 474 | 475 | # What happens if I remove volumes while the filesystem is mounted? 476 | 477 | It's not recommended. 478 | 479 | If you remove the volume currently being written to, you risk corrupting the 480 | filesystem. If you remove an older volume, you won't corrupt anything, but you 481 | may get I/O errors if you try to read from a file stored on that volume. 482 | 483 | If you remove volumes before starting HDRFS, then reading a file stored on the 484 | removed volume will at least generate a meaningful error message printed on the 485 | terminal where you started HDRFS. 486 | 487 | Removing old volumes does *not* remove the ability to write to files - even to 488 | files stored on the removed volume. 489 | 490 | # How POSIX compliant is HDRFS? 491 | 492 | Enough for normal everyday use. 493 | 494 | Files may be opened, closed, truncated, appended, and written to at arbitrary 495 | offsets with arbitrary lengths of data. Reads follow writes with strong 496 | consistency. 497 | 498 | Sparse files, symlinks, hard links, FIFOs and extended attributes are supported. 499 | 500 | `st_btime` is supported in HDRFS's own internal data structures, but FUSE 501 | currently lacks the ability to implement the statx system call, so there is no 502 | way of viewing it. (Although you can query the Index file, which is in sqlite3 503 | format). 504 | 505 | HDRFS falls short of full POSIX compliance in the following areas. 506 | 507 | * Permissions are recorded but never enforced 508 | * No locking 509 | * atime is supported but off by default. Turn it on using the `--atime` option. 510 | 511 | 512 | # Can I use the Index file for any other purposes? 513 | 514 | Yes, though I wouldn't recommend doing so while the filesystem is mounted. The 515 | Index file is in sqlite3 format. You can browse it with `sqlitebrowser` and run 516 | SQL queries against it. If you like SQL better than `find`, you might find this 517 | useful for doing analytics on your filesystem. 518 | 519 | The schema is documented in the `hdrfs.py` source code. 520 | 521 | # Comparisons 522 | 523 | In this section I will explain the limitations of similar filesystems as 524 | compared to HDRFS. This is not to say that HDRFS is superior to any of these 525 | filesystems, simply that it offers features which are a subset of no single 526 | other filesystem. 527 | 528 | ## How is this different from LTFS? 529 | 530 | I've never used LTFS and only found out about it while researching similar 531 | filesystems for this README. It does appear to have a lot of similarities with LTFS. Both append changed data to a linear 532 | bytestream rather than overwrite it. But HDRFS makes a guarantee that the Log is 533 | immutable, whereas LTFS's tapes are mostly-immutable, and only due to the 534 | constraints of the underlying technology. 535 | 536 | My research indicates the following LTFS limitations, though I would happily be 537 | corrected by an LTFS expert: 538 | 539 | * If you change one byte of a large file, LTFS will rewrite the whole file, as 540 | opposed to HDRFS which will just write the one changed byte. 541 | 542 | * LTFS does not support spanning a filesystem across multiple volumes. 543 | 544 | * LTFS can only be used in conjunction with tape hardware. 545 | 546 | ## How is this different from NILFS? 547 | 548 | My research indicates the following NILFS limitations, though I would happily be 549 | corrected by a NILFS expert: 550 | 551 | * NILFS has no volume management features. 552 | * NILFS takes a *generally* log-structured approach, but will infact delete or 553 | overwrite data over time, as checkpoints expire without being converted to 554 | snapshots. 555 | 556 | ## How is this different from btrfs and ZFS? 557 | 558 | Those two are superficially similar to each other, and radically different from 559 | HDRFS. Both have far higher performance than HDRFS. Both offer volume 560 | management, but neither use immutable data structures, meaning they do not offer 561 | HDRFS's primary benefit of easy backups, nor its secondary benefit of preserving 562 | fine-grained change history of data and metadata. 563 | 564 | Either btrfs or ZFS would be a fine complement to HDRFS, as the underlying 565 | filesystem. 566 | 567 | # What do HDRFS version numbers mean? 568 | 569 | HDRFS is a file format specification, and a reference implementation of a FUSE 570 | filesystem that uses that file format. 571 | 572 | The file format is currently version 1. 573 | 574 | The Python implementation has a version number of the form `X.Y.Z TAG`, where X 575 | is the file format version, Y is the implementation major version, Z is the 576 | implementation minor version, and TAG is an optional string describing the 577 | release. 578 | 579 | For example, HDRFS 1.0.0 RC1 processes Log files in version 1 of the file 580 | format, is the first version of the software that does that, and is the first 581 | release candidate of that version. 582 | 583 | Major implementation versions add features. Minor implementation versions fix 584 | bugs. The file format version will only change if the file format changes. 585 | 586 | The reference implementation of HDRFS is guaranteed to read and write versions 587 | of the file format less than or equal to its file format version number, 588 | although it may only create new volumes in the latest file format. 589 | 590 | # What are HDRFS's limitations 591 | 592 | * All pathnames, filenames, and extended attribute names must be in UTF-8 encoding. 593 | * 2^64 maximum number of files 594 | * 2^64 maximum file size (approximately 18 Exabytes) 595 | * 2^64 maximum number of volumes 596 | * 2^64 maximum volume size 597 | -------------------------------------------------------------------------------- /fusepy.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012 Terence Honles (maintainer) 2 | # Copyright (c) 2008 Giorgos Verigakis (author) 3 | # 4 | # Permission to use, copy, modify, and distribute this software for any 5 | # purpose with or without fee is hereby granted, provided that the above 6 | # copyright notice and this permission notice appear in all copies. 7 | # 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | 16 | from __future__ import print_function, absolute_import, division 17 | 18 | from ctypes import * 19 | from ctypes.util import find_library 20 | from errno import * 21 | from os import strerror 22 | from platform import machine, system 23 | from signal import signal, SIGINT, SIG_DFL 24 | from stat import S_IFDIR 25 | from traceback import print_exc 26 | 27 | import logging 28 | 29 | try: 30 | from functools import partial 31 | except ImportError: 32 | # http://docs.python.org/library/functools.html#functools.partial 33 | def partial(func, *args, **keywords): 34 | def newfunc(*fargs, **fkeywords): 35 | newkeywords = keywords.copy() 36 | newkeywords.update(fkeywords) 37 | return func(*(args + fargs), **newkeywords) 38 | 39 | newfunc.func = func 40 | newfunc.args = args 41 | newfunc.keywords = keywords 42 | return newfunc 43 | 44 | try: 45 | basestring 46 | except NameError: 47 | basestring = str 48 | 49 | class c_timespec(Structure): 50 | _fields_ = [('tv_sec', c_long), ('tv_nsec', c_long)] 51 | 52 | class c_utimbuf(Structure): 53 | _fields_ = [('actime', c_timespec), ('modtime', c_timespec)] 54 | 55 | class c_stat(Structure): 56 | pass # Platform dependent 57 | 58 | _system = system() 59 | _machine = machine() 60 | 61 | if _system == 'Darwin': 62 | _libiconv = CDLL(find_library('iconv'), RTLD_GLOBAL) # libfuse dependency 63 | _libfuse_path = (find_library('fuse4x') or find_library('osxfuse') or 64 | find_library('fuse')) 65 | else: 66 | _libfuse_path = find_library('fuse') 67 | 68 | if not _libfuse_path: 69 | raise EnvironmentError('Unable to find libfuse') 70 | else: 71 | _libfuse = CDLL(_libfuse_path) 72 | 73 | if _system == 'Darwin' and hasattr(_libfuse, 'macfuse_version'): 74 | _system = 'Darwin-MacFuse' 75 | 76 | 77 | if _system in ('Darwin', 'Darwin-MacFuse', 'FreeBSD'): 78 | ENOTSUP = 45 79 | c_dev_t = c_int32 80 | c_fsblkcnt_t = c_ulong 81 | c_fsfilcnt_t = c_ulong 82 | c_gid_t = c_uint32 83 | c_mode_t = c_uint16 84 | c_off_t = c_int64 85 | c_pid_t = c_int32 86 | c_uid_t = c_uint32 87 | setxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 88 | c_size_t, c_int, c_uint32) 89 | getxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 90 | c_size_t, c_uint32) 91 | if _system == 'Darwin': 92 | c_stat._fields_ = [ 93 | ('st_dev', c_dev_t), 94 | ('st_mode', c_mode_t), 95 | ('st_nlink', c_uint16), 96 | ('st_ino', c_uint64), 97 | ('st_uid', c_uid_t), 98 | ('st_gid', c_gid_t), 99 | ('st_rdev', c_dev_t), 100 | ('st_atimespec', c_timespec), 101 | ('st_mtimespec', c_timespec), 102 | ('st_ctimespec', c_timespec), 103 | ('st_birthtimespec', c_timespec), 104 | ('st_size', c_off_t), 105 | ('st_blocks', c_int64), 106 | ('st_blksize', c_int32), 107 | ('st_flags', c_int32), 108 | ('st_gen', c_int32), 109 | ('st_lspare', c_int32), 110 | ('st_qspare', c_int64)] 111 | else: 112 | c_stat._fields_ = [ 113 | ('st_dev', c_dev_t), 114 | ('st_ino', c_uint32), 115 | ('st_mode', c_mode_t), 116 | ('st_nlink', c_uint16), 117 | ('st_uid', c_uid_t), 118 | ('st_gid', c_gid_t), 119 | ('st_rdev', c_dev_t), 120 | ('st_atimespec', c_timespec), 121 | ('st_mtimespec', c_timespec), 122 | ('st_ctimespec', c_timespec), 123 | ('st_size', c_off_t), 124 | ('st_blocks', c_int64), 125 | ('st_blksize', c_int32)] 126 | elif _system == 'Linux': 127 | ENOTSUP = 95 128 | c_dev_t = c_ulonglong 129 | c_fsblkcnt_t = c_ulonglong 130 | c_fsfilcnt_t = c_ulonglong 131 | c_gid_t = c_uint 132 | c_mode_t = c_uint 133 | c_off_t = c_longlong 134 | c_pid_t = c_int 135 | c_uid_t = c_uint 136 | setxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 137 | c_size_t, c_int) 138 | 139 | getxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 140 | c_size_t) 141 | 142 | if _machine == 'x86_64': 143 | c_stat._fields_ = [ 144 | ('st_dev', c_dev_t), 145 | ('st_ino', c_ulong), 146 | ('st_nlink', c_ulong), 147 | ('st_mode', c_mode_t), 148 | ('st_uid', c_uid_t), 149 | ('st_gid', c_gid_t), 150 | ('__pad0', c_int), 151 | ('st_rdev', c_dev_t), 152 | ('st_size', c_off_t), 153 | ('st_blksize', c_long), 154 | ('st_blocks', c_long), 155 | ('st_atimespec', c_timespec), 156 | ('st_mtimespec', c_timespec), 157 | ('st_ctimespec', c_timespec)] 158 | elif _machine == 'mips': 159 | c_stat._fields_ = [ 160 | ('st_dev', c_dev_t), 161 | ('__pad1_1', c_ulong), 162 | ('__pad1_2', c_ulong), 163 | ('__pad1_3', c_ulong), 164 | ('st_ino', c_ulong), 165 | ('st_mode', c_mode_t), 166 | ('st_nlink', c_ulong), 167 | ('st_uid', c_uid_t), 168 | ('st_gid', c_gid_t), 169 | ('st_rdev', c_dev_t), 170 | ('__pad2_1', c_ulong), 171 | ('__pad2_2', c_ulong), 172 | ('st_size', c_off_t), 173 | ('__pad3', c_ulong), 174 | ('st_atimespec', c_timespec), 175 | ('__pad4', c_ulong), 176 | ('st_mtimespec', c_timespec), 177 | ('__pad5', c_ulong), 178 | ('st_ctimespec', c_timespec), 179 | ('__pad6', c_ulong), 180 | ('st_blksize', c_long), 181 | ('st_blocks', c_long), 182 | ('__pad7_1', c_ulong), 183 | ('__pad7_2', c_ulong), 184 | ('__pad7_3', c_ulong), 185 | ('__pad7_4', c_ulong), 186 | ('__pad7_5', c_ulong), 187 | ('__pad7_6', c_ulong), 188 | ('__pad7_7', c_ulong), 189 | ('__pad7_8', c_ulong), 190 | ('__pad7_9', c_ulong), 191 | ('__pad7_10', c_ulong), 192 | ('__pad7_11', c_ulong), 193 | ('__pad7_12', c_ulong), 194 | ('__pad7_13', c_ulong), 195 | ('__pad7_14', c_ulong)] 196 | elif _machine == 'ppc': 197 | c_stat._fields_ = [ 198 | ('st_dev', c_dev_t), 199 | ('st_ino', c_ulonglong), 200 | ('st_mode', c_mode_t), 201 | ('st_nlink', c_uint), 202 | ('st_uid', c_uid_t), 203 | ('st_gid', c_gid_t), 204 | ('st_rdev', c_dev_t), 205 | ('__pad2', c_ushort), 206 | ('st_size', c_off_t), 207 | ('st_blksize', c_long), 208 | ('st_blocks', c_longlong), 209 | ('st_atimespec', c_timespec), 210 | ('st_mtimespec', c_timespec), 211 | ('st_ctimespec', c_timespec)] 212 | elif _machine == 'aarch64': 213 | c_stat._fields_ = [ 214 | ('st_dev', c_dev_t), 215 | ('st_ino', c_ulong), 216 | ('st_mode', c_mode_t), 217 | ('st_nlink', c_uint), 218 | ('st_uid', c_uid_t), 219 | ('st_gid', c_gid_t), 220 | ('st_rdev', c_dev_t), 221 | ('__pad1', c_ulong), 222 | ('st_size', c_off_t), 223 | ('st_blksize', c_int), 224 | ('__pad2', c_int), 225 | ('st_blocks', c_long), 226 | ('st_atimespec', c_timespec), 227 | ('st_mtimespec', c_timespec), 228 | ('st_ctimespec', c_timespec)] 229 | else: 230 | # i686, use as fallback for everything else 231 | c_stat._fields_ = [ 232 | ('st_dev', c_dev_t), 233 | ('__pad1', c_ushort), 234 | ('__st_ino', c_ulong), 235 | ('st_mode', c_mode_t), 236 | ('st_nlink', c_uint), 237 | ('st_uid', c_uid_t), 238 | ('st_gid', c_gid_t), 239 | ('st_rdev', c_dev_t), 240 | ('__pad2', c_ushort), 241 | ('st_size', c_off_t), 242 | ('st_blksize', c_long), 243 | ('st_blocks', c_longlong), 244 | ('st_atimespec', c_timespec), 245 | ('st_mtimespec', c_timespec), 246 | ('st_ctimespec', c_timespec), 247 | ('st_ino', c_ulonglong)] 248 | else: 249 | raise NotImplementedError('%s is not supported.' % _system) 250 | 251 | 252 | class c_statvfs(Structure): 253 | _fields_ = [ 254 | ('f_bsize', c_ulong), 255 | ('f_frsize', c_ulong), 256 | ('f_blocks', c_fsblkcnt_t), 257 | ('f_bfree', c_fsblkcnt_t), 258 | ('f_bavail', c_fsblkcnt_t), 259 | ('f_files', c_fsfilcnt_t), 260 | ('f_ffree', c_fsfilcnt_t), 261 | ('f_favail', c_fsfilcnt_t), 262 | ('f_fsid', c_ulong), 263 | #('unused', c_int), 264 | ('f_flag', c_ulong), 265 | ('f_namemax', c_ulong)] 266 | 267 | if _system == 'FreeBSD': 268 | c_fsblkcnt_t = c_uint64 269 | c_fsfilcnt_t = c_uint64 270 | setxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 271 | c_size_t, c_int) 272 | 273 | getxattr_t = CFUNCTYPE(c_int, c_char_p, c_char_p, POINTER(c_byte), 274 | c_size_t) 275 | 276 | class c_statvfs(Structure): 277 | _fields_ = [ 278 | ('f_bavail', c_fsblkcnt_t), 279 | ('f_bfree', c_fsblkcnt_t), 280 | ('f_blocks', c_fsblkcnt_t), 281 | ('f_favail', c_fsfilcnt_t), 282 | ('f_ffree', c_fsfilcnt_t), 283 | ('f_files', c_fsfilcnt_t), 284 | ('f_bsize', c_ulong), 285 | ('f_flag', c_ulong), 286 | ('f_frsize', c_ulong)] 287 | 288 | class fuse_file_info(Structure): 289 | _fields_ = [ 290 | ('flags', c_int), 291 | ('fh_old', c_ulong), 292 | ('writepage', c_int), 293 | ('direct_io', c_uint, 1), 294 | ('keep_cache', c_uint, 1), 295 | ('flush', c_uint, 1), 296 | ('padding', c_uint, 29), 297 | ('fh', c_uint64), 298 | ('lock_owner', c_uint64)] 299 | 300 | class fuse_context(Structure): 301 | _fields_ = [ 302 | ('fuse', c_voidp), 303 | ('uid', c_uid_t), 304 | ('gid', c_gid_t), 305 | ('pid', c_pid_t), 306 | ('private_data', c_voidp)] 307 | 308 | _libfuse.fuse_get_context.restype = POINTER(fuse_context) 309 | 310 | 311 | class fuse_operations(Structure): 312 | _fields_ = [ 313 | ('getattr', CFUNCTYPE(c_int, c_char_p, POINTER(c_stat))), 314 | ('readlink', CFUNCTYPE(c_int, c_char_p, POINTER(c_byte), c_size_t)), 315 | ('getdir', c_voidp), # Deprecated, use readdir 316 | ('mknod', CFUNCTYPE(c_int, c_char_p, c_mode_t, c_dev_t)), 317 | ('mkdir', CFUNCTYPE(c_int, c_char_p, c_mode_t)), 318 | ('unlink', CFUNCTYPE(c_int, c_char_p)), 319 | ('rmdir', CFUNCTYPE(c_int, c_char_p)), 320 | ('symlink', CFUNCTYPE(c_int, c_char_p, c_char_p)), 321 | ('rename', CFUNCTYPE(c_int, c_char_p, c_char_p)), 322 | ('link', CFUNCTYPE(c_int, c_char_p, c_char_p)), 323 | ('chmod', CFUNCTYPE(c_int, c_char_p, c_mode_t)), 324 | ('chown', CFUNCTYPE(c_int, c_char_p, c_uid_t, c_gid_t)), 325 | ('truncate', CFUNCTYPE(c_int, c_char_p, c_off_t)), 326 | ('utime', c_voidp), # Deprecated, use utimens 327 | ('open', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info))), 328 | 329 | ('read', CFUNCTYPE(c_int, c_char_p, POINTER(c_byte), c_size_t, 330 | c_off_t, POINTER(fuse_file_info))), 331 | 332 | ('write', CFUNCTYPE(c_int, c_char_p, POINTER(c_byte), c_size_t, 333 | c_off_t, POINTER(fuse_file_info))), 334 | 335 | ('statfs', CFUNCTYPE(c_int, c_char_p, POINTER(c_statvfs))), 336 | ('flush', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info))), 337 | ('release', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info))), 338 | ('fsync', CFUNCTYPE(c_int, c_char_p, c_int, POINTER(fuse_file_info))), 339 | ('setxattr', setxattr_t), 340 | ('getxattr', getxattr_t), 341 | ('listxattr', CFUNCTYPE(c_int, c_char_p, POINTER(c_byte), c_size_t)), 342 | ('removexattr', CFUNCTYPE(c_int, c_char_p, c_char_p)), 343 | ('opendir', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info))), 344 | 345 | ('readdir', CFUNCTYPE(c_int, c_char_p, c_voidp, 346 | CFUNCTYPE(c_int, c_voidp, c_char_p, 347 | POINTER(c_stat), c_off_t), 348 | c_off_t, POINTER(fuse_file_info))), 349 | 350 | ('releasedir', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info))), 351 | 352 | ('fsyncdir', CFUNCTYPE(c_int, c_char_p, c_int, 353 | POINTER(fuse_file_info))), 354 | 355 | ('init', CFUNCTYPE(c_voidp, c_voidp)), 356 | ('destroy', CFUNCTYPE(c_voidp, c_voidp)), 357 | ('access', CFUNCTYPE(c_int, c_char_p, c_int)), 358 | 359 | ('create', CFUNCTYPE(c_int, c_char_p, c_mode_t, 360 | POINTER(fuse_file_info))), 361 | 362 | ('ftruncate', CFUNCTYPE(c_int, c_char_p, c_off_t, 363 | POINTER(fuse_file_info))), 364 | 365 | ('fgetattr', CFUNCTYPE(c_int, c_char_p, POINTER(c_stat), 366 | POINTER(fuse_file_info))), 367 | 368 | ('lock', CFUNCTYPE(c_int, c_char_p, POINTER(fuse_file_info), 369 | c_int, c_voidp)), 370 | 371 | ('utimens', CFUNCTYPE(c_int, c_char_p, POINTER(c_utimbuf))), 372 | ('bmap', CFUNCTYPE(c_int, c_char_p, c_size_t, POINTER(c_ulonglong))), 373 | ('flag_nullpath_ok', c_uint, 1), 374 | ('flag_nopath', c_uint, 1), 375 | ('flag_utime_omit_ok', c_uint, 1), 376 | ('flag_reserved', c_uint, 29), 377 | ] 378 | 379 | 380 | def time_of_timespec(ts): 381 | return ts.tv_sec + ts.tv_nsec / 10 ** 9 382 | 383 | def set_st_attrs(st, attrs): 384 | for key, val in attrs.items(): 385 | if key in ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime'): 386 | timespec = getattr(st, key + 'spec', None) 387 | if timespec is None: 388 | continue 389 | timespec.tv_sec = int(val) 390 | timespec.tv_nsec = int((val - timespec.tv_sec) * 10 ** 9) 391 | elif hasattr(st, key): 392 | setattr(st, key, val) 393 | 394 | 395 | def fuse_get_context(): 396 | 'Returns a (uid, gid, pid) tuple' 397 | 398 | ctxp = _libfuse.fuse_get_context() 399 | ctx = ctxp.contents 400 | return ctx.uid, ctx.gid, ctx.pid 401 | 402 | 403 | class FuseOSError(OSError): 404 | def __init__(self, errno): 405 | super(FuseOSError, self).__init__(errno, strerror(errno)) 406 | 407 | 408 | class FUSE(object): 409 | ''' 410 | This class is the lower level interface and should not be subclassed under 411 | normal use. Its methods are called by fuse. 412 | 413 | Assumes API version 2.6 or later. 414 | ''' 415 | 416 | OPTIONS = ( 417 | ('foreground', '-f'), 418 | ('debug', '-d'), 419 | ('nothreads', '-s'), 420 | ) 421 | 422 | def __init__(self, operations, mountpoint, raw_fi=False, encoding='utf-8', 423 | **kwargs): 424 | 425 | ''' 426 | Setting raw_fi to True will cause FUSE to pass the fuse_file_info 427 | class as is to Operations, instead of just the fh field. 428 | 429 | This gives you access to direct_io, keep_cache, etc. 430 | ''' 431 | 432 | self.operations = operations 433 | self.raw_fi = raw_fi 434 | self.encoding = encoding 435 | 436 | args = ['fuse'] 437 | 438 | args.extend(flag for arg, flag in self.OPTIONS 439 | if kwargs.pop(arg, False)) 440 | 441 | kwargs.setdefault('fsname', operations.__class__.__name__) 442 | args.append('-o') 443 | args.append(','.join(self._normalize_fuse_options(**kwargs))) 444 | args.append(mountpoint) 445 | 446 | args = [arg.encode(encoding) for arg in args] 447 | argv = (c_char_p * len(args))(*args) 448 | 449 | fuse_ops = fuse_operations() 450 | for ent in fuse_operations._fields_: 451 | name, prototype = ent[:2] 452 | 453 | val = getattr(operations, name, None) 454 | if val is None: 455 | continue 456 | 457 | # Function pointer members are tested for using the 458 | # getattr(operations, name) above but are dynamically 459 | # invoked using self.operations(name) 460 | if hasattr(prototype, 'argtypes'): 461 | val = prototype(partial(self._wrapper, getattr(self, name))) 462 | 463 | setattr(fuse_ops, name, val) 464 | 465 | try: 466 | old_handler = signal(SIGINT, SIG_DFL) 467 | except ValueError: 468 | old_handler = SIG_DFL 469 | 470 | err = _libfuse.fuse_main_real(len(args), argv, pointer(fuse_ops), 471 | sizeof(fuse_ops), None) 472 | 473 | try: 474 | signal(SIGINT, old_handler) 475 | except ValueError: 476 | pass 477 | 478 | del self.operations # Invoke the destructor 479 | if err: 480 | raise RuntimeError(err) 481 | 482 | @staticmethod 483 | def _normalize_fuse_options(**kargs): 484 | for key, value in kargs.items(): 485 | if isinstance(value, bool): 486 | if value is True: yield key 487 | else: 488 | yield '%s=%s' % (key, value) 489 | 490 | @staticmethod 491 | def _wrapper(func, *args, **kwargs): 492 | 'Decorator for the methods that follow' 493 | 494 | try: 495 | return func(*args, **kwargs) or 0 496 | except OSError as e: 497 | return -(e.errno or EFAULT) 498 | except: 499 | print_exc() 500 | return -EFAULT 501 | 502 | def _decode_optional_path(self, path): 503 | # NB: this method is intended for fuse operations that 504 | # allow the path argument to be NULL, 505 | # *not* as a generic path decoding method 506 | if path is None: 507 | return None 508 | return path.decode(self.encoding) 509 | 510 | def getattr(self, path, buf): 511 | return self.fgetattr(path, buf, None) 512 | 513 | def readlink(self, path, buf, bufsize): 514 | ret = self.operations('readlink', path.decode(self.encoding)) \ 515 | .encode(self.encoding) 516 | 517 | # copies a string into the given buffer 518 | # (null terminated and truncated if necessary) 519 | data = create_string_buffer(ret[:bufsize - 1]) 520 | memmove(buf, data, len(data)) 521 | return 0 522 | 523 | def mknod(self, path, mode, dev): 524 | return self.operations('mknod', path.decode(self.encoding), mode, dev) 525 | 526 | def mkdir(self, path, mode): 527 | return self.operations('mkdir', path.decode(self.encoding), mode) 528 | 529 | def unlink(self, path): 530 | return self.operations('unlink', path.decode(self.encoding)) 531 | 532 | def rmdir(self, path): 533 | return self.operations('rmdir', path.decode(self.encoding)) 534 | 535 | def symlink(self, source, target): 536 | 'creates a symlink `target -> source` (e.g. ln -s source target)' 537 | 538 | return self.operations('symlink', target.decode(self.encoding), 539 | source.decode(self.encoding)) 540 | 541 | def rename(self, old, new): 542 | return self.operations('rename', old.decode(self.encoding), 543 | new.decode(self.encoding)) 544 | 545 | def link(self, source, target): 546 | 'creates a hard link `target -> source` (e.g. ln source target)' 547 | 548 | return self.operations('link', target.decode(self.encoding), 549 | source.decode(self.encoding)) 550 | 551 | def chmod(self, path, mode): 552 | return self.operations('chmod', path.decode(self.encoding), mode) 553 | 554 | def chown(self, path, uid, gid): 555 | # Check if any of the arguments is a -1 that has overflowed 556 | if c_uid_t(uid + 1).value == 0: 557 | uid = -1 558 | if c_gid_t(gid + 1).value == 0: 559 | gid = -1 560 | 561 | return self.operations('chown', path.decode(self.encoding), uid, gid) 562 | 563 | def truncate(self, path, length): 564 | return self.operations('truncate', path.decode(self.encoding), length) 565 | 566 | def open(self, path, fip): 567 | fi = fip.contents 568 | if self.raw_fi: 569 | return self.operations('open', path.decode(self.encoding), fi) 570 | else: 571 | fi.fh = self.operations('open', path.decode(self.encoding), 572 | fi.flags) 573 | 574 | return 0 575 | 576 | def read(self, path, buf, size, offset, fip): 577 | if self.raw_fi: 578 | fh = fip.contents 579 | else: 580 | fh = fip.contents.fh 581 | 582 | ret = self.operations('read', self._decode_optional_path(path), size, 583 | offset, fh) 584 | 585 | if not ret: return 0 586 | 587 | retsize = len(ret) 588 | assert retsize <= size, \ 589 | 'actual amount read %d greater than expected %d' % (retsize, size) 590 | 591 | data = create_string_buffer(ret, retsize) 592 | memmove(buf, data, retsize) 593 | return retsize 594 | 595 | def write(self, path, buf, size, offset, fip): 596 | data = string_at(buf, size) 597 | 598 | if self.raw_fi: 599 | fh = fip.contents 600 | else: 601 | fh = fip.contents.fh 602 | 603 | return self.operations('write', self._decode_optional_path(path), data, 604 | offset, fh) 605 | 606 | def statfs(self, path, buf): 607 | stv = buf.contents 608 | attrs = self.operations('statfs', path.decode(self.encoding)) 609 | for key, val in attrs.items(): 610 | if hasattr(stv, key): 611 | setattr(stv, key, val) 612 | 613 | return 0 614 | 615 | def flush(self, path, fip): 616 | if self.raw_fi: 617 | fh = fip.contents 618 | else: 619 | fh = fip.contents.fh 620 | 621 | return self.operations('flush', self._decode_optional_path(path), fh) 622 | 623 | def release(self, path, fip): 624 | if self.raw_fi: 625 | fh = fip.contents 626 | else: 627 | fh = fip.contents.fh 628 | 629 | return self.operations('release', self._decode_optional_path(path), fh) 630 | 631 | def fsync(self, path, datasync, fip): 632 | if self.raw_fi: 633 | fh = fip.contents 634 | else: 635 | fh = fip.contents.fh 636 | 637 | return self.operations('fsync', self._decode_optional_path(path), datasync, 638 | fh) 639 | 640 | def setxattr(self, path, name, value, size, options, *args): 641 | return self.operations('setxattr', path.decode(self.encoding), 642 | name.decode(self.encoding), 643 | string_at(value, size), options, *args) 644 | 645 | def getxattr(self, path, name, value, size, *args): 646 | ret = self.operations('getxattr', path.decode(self.encoding), 647 | name.decode(self.encoding), *args) 648 | 649 | retsize = len(ret) 650 | # allow size queries 651 | if not value: return retsize 652 | 653 | # do not truncate 654 | if retsize > size: return -ERANGE 655 | 656 | buf = create_string_buffer(ret, retsize) # Does not add trailing 0 657 | memmove(value, buf, retsize) 658 | 659 | return retsize 660 | 661 | def listxattr(self, path, namebuf, size): 662 | attrs = self.operations('listxattr', path.decode(self.encoding)) or '' 663 | ret = '\x00'.join(attrs).encode(self.encoding) 664 | if len(ret) > 0: 665 | ret += '\x00'.encode(self.encoding) 666 | 667 | retsize = len(ret) 668 | # allow size queries 669 | if not namebuf: return retsize 670 | 671 | # do not truncate 672 | if retsize > size: return -ERANGE 673 | 674 | buf = create_string_buffer(ret, retsize) 675 | memmove(namebuf, buf, retsize) 676 | 677 | return retsize 678 | 679 | def removexattr(self, path, name): 680 | return self.operations('removexattr', path.decode(self.encoding), 681 | name.decode(self.encoding)) 682 | 683 | def opendir(self, path, fip): 684 | # Ignore raw_fi 685 | fip.contents.fh = self.operations('opendir', 686 | path.decode(self.encoding)) 687 | 688 | return 0 689 | 690 | def readdir(self, path, buf, filler, offset, fip): 691 | # Ignore raw_fi 692 | for item in self.operations('readdir', self._decode_optional_path(path), 693 | fip.contents.fh): 694 | 695 | if isinstance(item, basestring): 696 | name, st, offset = item, None, 0 697 | else: 698 | name, attrs, offset = item 699 | if attrs: 700 | st = c_stat() 701 | set_st_attrs(st, attrs) 702 | else: 703 | st = None 704 | 705 | if filler(buf, name.encode(self.encoding), st, offset) != 0: 706 | break 707 | 708 | return 0 709 | 710 | def releasedir(self, path, fip): 711 | # Ignore raw_fi 712 | return self.operations('releasedir', self._decode_optional_path(path), 713 | fip.contents.fh) 714 | 715 | def fsyncdir(self, path, datasync, fip): 716 | # Ignore raw_fi 717 | return self.operations('fsyncdir', self._decode_optional_path(path), 718 | datasync, fip.contents.fh) 719 | 720 | def init(self, conn): 721 | return self.operations('init', '/') 722 | 723 | def destroy(self, private_data): 724 | return self.operations('destroy', '/') 725 | 726 | def access(self, path, amode): 727 | return self.operations('access', path.decode(self.encoding), amode) 728 | 729 | def create(self, path, mode, fip): 730 | fi = fip.contents 731 | path = path.decode(self.encoding) 732 | 733 | if self.raw_fi: 734 | return self.operations('create', path, mode, fi) 735 | else: 736 | fi.fh = self.operations('create', path, mode) 737 | return 0 738 | 739 | def ftruncate(self, path, length, fip): 740 | if self.raw_fi: 741 | fh = fip.contents 742 | else: 743 | fh = fip.contents.fh 744 | 745 | return self.operations('truncate', self._decode_optional_path(path), 746 | length, fh) 747 | 748 | def fgetattr(self, path, buf, fip): 749 | memset(buf, 0, sizeof(c_stat)) 750 | 751 | st = buf.contents 752 | if not fip: 753 | fh = fip 754 | elif self.raw_fi: 755 | fh = fip.contents 756 | else: 757 | fh = fip.contents.fh 758 | 759 | attrs = self.operations('getattr', self._decode_optional_path(path), fh) 760 | set_st_attrs(st, attrs) 761 | return 0 762 | 763 | def lock(self, path, fip, cmd, lock): 764 | if self.raw_fi: 765 | fh = fip.contents 766 | else: 767 | fh = fip.contents.fh 768 | 769 | return self.operations('lock', self._decode_optional_path(path), fh, cmd, 770 | lock) 771 | 772 | def utimens(self, path, buf): 773 | if buf: 774 | atime = time_of_timespec(buf.contents.actime) 775 | mtime = time_of_timespec(buf.contents.modtime) 776 | times = (atime, mtime) 777 | else: 778 | times = None 779 | 780 | return self.operations('utimens', path.decode(self.encoding), times) 781 | 782 | def bmap(self, path, blocksize, idx): 783 | return self.operations('bmap', path.decode(self.encoding), blocksize, 784 | idx) 785 | 786 | 787 | class Operations(object): 788 | ''' 789 | This class should be subclassed and passed as an argument to FUSE on 790 | initialization. All operations should raise a FuseOSError exception on 791 | error. 792 | 793 | When in doubt of what an operation should do, check the FUSE header file 794 | or the corresponding system call man page. 795 | ''' 796 | 797 | def __call__(self, op, *args): 798 | if not hasattr(self, op): 799 | raise FuseOSError(EFAULT) 800 | return getattr(self, op)(*args) 801 | 802 | def access(self, path, amode): 803 | return 0 804 | 805 | bmap = None 806 | 807 | def chmod(self, path, mode): 808 | raise FuseOSError(EROFS) 809 | 810 | def chown(self, path, uid, gid): 811 | raise FuseOSError(EROFS) 812 | 813 | def create(self, path, mode, fi=None): 814 | ''' 815 | When raw_fi is False (default case), fi is None and create should 816 | return a numerical file handle. 817 | 818 | When raw_fi is True the file handle should be set directly by create 819 | and return 0. 820 | ''' 821 | 822 | raise FuseOSError(EROFS) 823 | 824 | def destroy(self, path): 825 | 'Called on filesystem destruction. Path is always /' 826 | 827 | pass 828 | 829 | def flush(self, path, fh): 830 | return 0 831 | 832 | def fsync(self, path, datasync, fh): 833 | return 0 834 | 835 | def fsyncdir(self, path, datasync, fh): 836 | return 0 837 | 838 | def getattr(self, path, fh=None): 839 | ''' 840 | Returns a dictionary with keys identical to the stat C structure of 841 | stat(2). 842 | 843 | st_atime, st_mtime and st_ctime should be floats. 844 | 845 | NOTE: There is an incombatibility between Linux and Mac OS X 846 | concerning st_nlink of directories. Mac OS X counts all files inside 847 | the directory, while Linux counts only the subdirectories. 848 | ''' 849 | 850 | if path != '/': 851 | raise FuseOSError(ENOENT) 852 | return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2) 853 | 854 | def getxattr(self, path, name, position=0): 855 | raise FuseOSError(ENOTSUP) 856 | 857 | def init(self, path): 858 | ''' 859 | Called on filesystem initialization. (Path is always /) 860 | 861 | Use it instead of __init__ if you start threads on initialization. 862 | ''' 863 | 864 | pass 865 | 866 | def link(self, target, source): 867 | 'creates a hard link `target -> source` (e.g. ln source target)' 868 | 869 | raise FuseOSError(EROFS) 870 | 871 | def listxattr(self, path): 872 | return [] 873 | 874 | lock = None 875 | 876 | def mkdir(self, path, mode): 877 | raise FuseOSError(EROFS) 878 | 879 | def mknod(self, path, mode, dev): 880 | raise FuseOSError(EROFS) 881 | 882 | def open(self, path, flags): 883 | ''' 884 | When raw_fi is False (default case), open should return a numerical 885 | file handle. 886 | 887 | When raw_fi is True the signature of open becomes: 888 | open(self, path, fi) 889 | 890 | and the file handle should be set directly. 891 | ''' 892 | 893 | return 0 894 | 895 | def opendir(self, path): 896 | 'Returns a numerical file handle.' 897 | 898 | return 0 899 | 900 | def read(self, path, size, offset, fh): 901 | 'Returns a string containing the data requested.' 902 | 903 | raise FuseOSError(EIO) 904 | 905 | def readdir(self, path, fh): 906 | ''' 907 | Can return either a list of names, or a list of (name, attrs, offset) 908 | tuples. attrs is a dict as in getattr. 909 | ''' 910 | 911 | return ['.', '..'] 912 | 913 | def readlink(self, path): 914 | raise FuseOSError(ENOENT) 915 | 916 | def release(self, path, fh): 917 | return 0 918 | 919 | def releasedir(self, path, fh): 920 | return 0 921 | 922 | def removexattr(self, path, name): 923 | raise FuseOSError(ENOTSUP) 924 | 925 | def rename(self, old, new): 926 | raise FuseOSError(EROFS) 927 | 928 | def rmdir(self, path): 929 | raise FuseOSError(EROFS) 930 | 931 | def setxattr(self, path, name, value, options, position=0): 932 | raise FuseOSError(ENOTSUP) 933 | 934 | def statfs(self, path): 935 | ''' 936 | Returns a dictionary with keys identical to the statvfs C structure of 937 | statvfs(3). 938 | 939 | On Mac OS X f_bsize and f_frsize must be a power of 2 940 | (minimum 512). 941 | ''' 942 | 943 | return {} 944 | 945 | def symlink(self, target, source): 946 | 'creates a symlink `target -> source` (e.g. ln -s source target)' 947 | 948 | raise FuseOSError(EROFS) 949 | 950 | def truncate(self, path, length, fh=None): 951 | raise FuseOSError(EROFS) 952 | 953 | def unlink(self, path): 954 | raise FuseOSError(EROFS) 955 | 956 | def utimens(self, path, times=None): 957 | 'Times is a (atime, mtime) tuple. If None use current time.' 958 | 959 | return 0 960 | 961 | def write(self, path, data, offset, fh): 962 | raise FuseOSError(EROFS) 963 | 964 | 965 | class LoggingMixIn: 966 | log = logging.getLogger('fuse.log-mixin') 967 | 968 | def __call__(self, op, path, *args): 969 | self.log.debug('-> %s %s %s', op, path, repr(args)) 970 | ret = '[Unhandled Exception]' 971 | try: 972 | ret = getattr(self, op)(path, *args) 973 | return ret 974 | except OSError as e: 975 | ret = str(e) 976 | raise 977 | finally: 978 | self.log.debug('<- %s %s', op, repr(ret)) 979 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------