├── .gitignore ├── .golangci.yml ├── .goreleaser.yml ├── CONTRIBUTING.md ├── CREDITS ├── DESIGN.md ├── LICENSE ├── Makefile ├── MinFS.svg ├── README.md ├── buildscripts ├── build.env ├── checkdeps.sh ├── cross-compile.sh └── go-coverage.sh ├── cmd ├── build-constants.go └── cmd.go ├── docs ├── minfs.8 └── mount.minfs.8 ├── fs ├── config.go ├── dir.go ├── file.go ├── filehandle.go ├── fs.go ├── globals.go ├── lock.go ├── operations.go ├── rand.go └── signals.go ├── go.mod ├── go.sum ├── meta └── db.go ├── minfs.go └── mount.minfs /.gitignore: -------------------------------------------------------------------------------- 1 | cover.out 2 | ./minfs 3 | *~ 4 | *.test 5 | release 6 | experimental 7 | cache 8 | minfs 9 | coverage.txt 10 | dist/ -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters-settings: 2 | golint: 3 | min-confidence: 0 4 | 5 | misspell: 6 | locale: US 7 | 8 | linters: 9 | disable-all: true 10 | enable: 11 | - typecheck 12 | - goimports 13 | - misspell 14 | - govet 15 | - golint 16 | - ineffassign 17 | - gosimple 18 | - deadcode 19 | - structcheck 20 | - gomodguard 21 | - gofmt 22 | 23 | issues: 24 | exclude-use-default: false 25 | exclude: 26 | - should have a package comment 27 | - error strings should not be capitalized or end with punctuation or a newline 28 | 29 | service: 30 | golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly 31 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example goreleaser.yaml file with some sane defaults. 2 | # Make sure to check the documentation at http://goreleaser.com 3 | project_name: minfs 4 | 5 | release: 6 | name_template: "Release version {{.Tag}}" 7 | github: 8 | owner: minio 9 | name: minfs 10 | 11 | before: 12 | hooks: 13 | # you may remove this if you don't use vgo 14 | - go mod tidy 15 | 16 | builds: 17 | - 18 | goos: 19 | - linux 20 | - freebsd 21 | goarch: 22 | - amd64 23 | - ppc64le 24 | - s390x 25 | - arm64 26 | 27 | env: 28 | - CGO_ENABLED=0 29 | 30 | flags: 31 | - -trimpath 32 | - --tags=kqueue 33 | 34 | ldflags: 35 | - -s -w -X github.com/minio/minfs/cmd.ReleaseTag={{.Tag}} -X github.com/minio/minfs/cmd.CommitID={{.FullCommit}} -X github.com/minio/minfs/cmd.Version={{.Version}} -X github.com/minio/minfs/cmd.ShortCommitID={{.ShortCommit}} 36 | 37 | archives: 38 | - 39 | name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" 40 | format: binary 41 | replacements: 42 | arm: arm 43 | 44 | snapshot: 45 | name_template: v0.0.0@{{.ShortCommit}} 46 | 47 | changelog: 48 | sort: asc 49 | 50 | nfpms: 51 | - 52 | vendor: MinIO, Inc. 53 | homepage: https://github.com/minio/minfs 54 | maintainer: MinIO Development 55 | description: Fuse driver for Object Storage Server 56 | license: GNU Affero General Public License v3.0 57 | formats: 58 | - deb 59 | - rpm 60 | bindir: /sbin 61 | contents: 62 | # Basic file that applies to all packagers 63 | - src: docs/minfs.8 64 | dst: /usr/share/man/man8/minfs.8 65 | - src: docs/mount.minfs.8 66 | dst: /usr/share/man/man8/mount.minfs.8 67 | - src: mount.minfs 68 | dst: /sbin/mount.minfs 69 | 70 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ### Install Golang 2 | 3 | If you do not have a working Golang environment setup please follow [Golang Installation Guide](https://docs.min.io/docs/how-to-install-golang). 4 | 5 | ### Setup your Minfs Github Repository 6 | Fork [MinIO upstream](https://github.com/minio/minfs/fork) source repository to your own personal repository. Copy the URL for minio from your personal github repo (you will need it for the `git clone` command below). 7 | ```sh 8 | $ mkdir -p $GOPATH/src/github.com/minio 9 | $ cd $GOPATH/src/github.com/minio 10 | $ git clone 11 | $ cd minfs 12 | ``` 13 | 14 | ### Compiling MinIO from source 15 | MinIO uses ``Makefile`` to wrap around some of redundant checks done through command line. 16 | 17 | ```sh 18 | $ make 19 | Checking if proper environment variables are set.. Done 20 | ... 21 | Checking dependencies for MinIO.. Done 22 | Installed govet 23 | Building Libraries 24 | ... 25 | ... 26 | ``` 27 | 28 | ### Setting up git remote as ``upstream`` 29 | ```sh 30 | $ cd $GOPATH/src/github.com/minio/minfs 31 | $ git remote add upstream https://github.com/minio/minfs 32 | $ git fetch upstream 33 | $ git merge upstream/master 34 | ... 35 | ... 36 | $ make 37 | Checking if proper environment variables are set.. Done 38 | ... 39 | Checking dependencies for MinIO.. Done 40 | Installed govet 41 | Building Libraries 42 | ... 43 | ``` 44 | 45 | ### Developer Guidelines 46 | ``MinIO`` community welcomes your contribution. To make the process as seamless as possible, we ask for the following: 47 | * Go ahead and fork the project and make your changes. We encourage pull requests to discuss code changes. 48 | - Fork it 49 | - Create your feature branch (git checkout -b my-new-feature) 50 | - Commit your changes (git commit -am 'Add some feature') 51 | - Push to the branch (git push origin my-new-feature) 52 | - Create new Pull Request 53 | 54 | * If you have additional dependencies for ``MinIO``, ``MinIO`` manages its dependencies using [govendor](https://github.com/kardianos/govendor) 55 | - Run `go get foo/bar` 56 | - Edit your code to import foo/bar 57 | - Run `make pkg-add PKG=foo/bar` from top-level directory 58 | 59 | * If you have dependencies for ``MinIO`` which needs to be removed 60 | - Edit your code to not import foo/bar 61 | - Run `make pkg-remove PKG=foo/bar` from top-level directory 62 | 63 | * When you're ready to create a pull request, be sure to: 64 | - Have test cases for the new code. If you have questions about how to do it, please ask in your pull request. 65 | - Run `make verifiers` 66 | - Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request. 67 | - Make sure `go test -race ./...` and `go build` completes. 68 | 69 | * Read [Effective Go](https://github.com/golang/go/wiki/CodeReviewComments) article from Golang project 70 | - `MinIO` project is fully conformant with Golang style 71 | - if you happen to observe offending code, please feel free to send a pull request 72 | -------------------------------------------------------------------------------- /DESIGN.md: -------------------------------------------------------------------------------- 1 | Introduction [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) 2 | ------------ 3 | 4 | This fuse driver allows MinIO bucket or any bucket on S3 compatible storage to be mounted as a local, as a prerequesite you need [fusermount](http://man7.org/linux/man-pages/man1/fusermount3.1.html). This feature allows MinIO to serve a bucket over a minimal POSIX API. 5 | 6 | Limitations 7 | ---------- 8 | 9 | ### Read 10 | 11 | For every operation the latest version will be retrieved from the server. For now we don't have a method of verifying if the file has been changed by the provider. 12 | 13 | ### Write 14 | 15 | When a **dirty** file has been closed, it will be uploaded to the bucket, when the file is completely uploaded it will be unlocked. 16 | 17 | ### Locking 18 | 19 | The locking mechanism is defensive and doesn't implement granular byte range locking from POSIX API, only one operation is allowed at a time per object. This trade-off is intention and kept to keep the fuse driver simpler. 20 | 21 | FUSE options 22 | ---------- 23 | 24 | ### Options 25 | 26 | * **gid**: The default gid to assign for files from storage. 27 | * **uid**: The default gid to assign for files from storage. 28 | * **cache**: Location for cache folder. 29 | * **debug**: Enables debug logs 30 | 31 | ### Work in Progress. 32 | 33 | - Use MinIO notifications to actively update metadata. 34 | - One mountpoint per bucket. 35 | - Each mountpoint will have its own cache folders and can be mounted to one bucket. 36 | - Renaming directories will cause an error when directly accessing the newly moved folder. 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PWD := $(shell pwd) 2 | GOPATH := $(shell go env GOPATH) 3 | 4 | GOOS := $(shell go env GOOS) 5 | BUILD_LDFLAGS := '-s -w' 6 | 7 | all: build 8 | 9 | checks: ## check dependencies 10 | @echo "Checking dependencies" 11 | @(env bash $(PWD)/buildscripts/checkdeps.sh) 12 | 13 | getdeps: ## get necessary dependencies 14 | @mkdir -p ${GOPATH}/bin 15 | @which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0) 16 | 17 | crosscompile: ## check cross-compilation works 18 | @(env bash $(PWD)/buildscripts/cross-compile.sh) 19 | 20 | help: ## print this help 21 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 22 | 23 | verifiers: getdeps lint 24 | 25 | lint: ## run linters 26 | @echo "Running $@ check" 27 | @GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean 28 | @GO111MODULE=on ${GOPATH}/bin/golangci-lint run --build-tags kqueue --timeout=10m --config ./.golangci.yml 29 | 30 | test: verifiers build 31 | @echo "Running unit tests" 32 | @GO111MODULE=on CGO_ENABLED=0 go test -tags kqueue ./... 1>/dev/null 33 | 34 | coverage: build 35 | @echo "Running all coverage for MinIO" 36 | @(env bash $(PWD)/buildscripts/go-coverage.sh) 37 | 38 | build: checks ## builds MinFS locally 39 | @echo "Building minfs binary to './minfs'" 40 | @GO111MODULE=on CGO_ENABLED=0 go build -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/minfs 41 | 42 | install: build ## builds MinFS and installs it to $GOPATH/bin 43 | @sudo /usr/bin/install -m 755 minfs /sbin/minfs && echo "Installing minfs binary to '/sbin/minfs'" 44 | @sudo /usr/bin/install -m 755 mount.minfs /sbin/mount.minfs && echo "Installing '/sbin/mount.minfs'" 45 | @echo "Installing man pages" 46 | @sudo /usr/bin/install -m 644 docs/minfs.8 /usr/share/man/man8/minfs.8 47 | @sudo /usr/bin/install -m 644 docs/mount.minfs.8 /usr/share/man/man8/mount.minfs.8 48 | @echo "Installation successful. To learn more, try \"minfs --help\"." 49 | 50 | clean: ## clean all temporary files 51 | @echo "Cleaning up all the generated files" 52 | @find . -name '*.test' | xargs rm -fv 53 | @find . -name '*~' | xargs rm -fv 54 | @rm -rvf minfs 55 | @rm -rvf build 56 | @rm -rvf release 57 | 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MinFS Quickstart Guide [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) [![Go Report Card](https://goreportcard.com/badge/minio/minfs)](https://goreportcard.com/report/minio/minfs) 2 | 3 | > NOTE: This project is frozen and is not accepting any new features, feel free to send a [pull request](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) for any such features. 4 | 5 | MinFS is a fuse driver for Amazon S3 compatible object storage server. MinFS lets you mount a remote bucket (from a S3 compatible object store), as if it were a local directory. This allows you to read and write from the remote bucket just by operating on the local mount directory. 6 | 7 | MinFS helps legacy applications use modern object stores with minimal config changes. MinFS uses [BoltDB](https://github.com/boltdb/bolt) for caching and saving metadata, list of files, permissions, owners etc. 8 | 9 | > Be careful, it is always possible to remove boltdb cache. Cache will be recreated by MinFS synchronizing metadata from the server. 10 | 11 | # Architecture 12 | ![architecture](https://raw.githubusercontent.com/minio/minfs/master/MinFS.svg?sanitize=true) 13 | 14 | ## POSIX Compatibility 15 | > MinFS is not a POSIX conformant filesystem and it does not intend to be one. MinFS is built for legacy applications that needs to access an object store but does not expect strict POSIX compatibility. Please use MinFS if this fits your needs. 16 | 17 | Use cases not suitable for MinFS use are: 18 | - Running a database on MinFS such as postgres, mysql etc. 19 | - Running virtual machines on MinFS such as qemu/kvm. 20 | - Running rich POSIX applications which rely on POSIX locks, Extended attribute operations etc. 21 | 22 | Some use cases suitable for MinFS are: 23 | - Serving a static web-content with NGINX, Apache2 web servers. 24 | - Serving as backup destination for legacy tools unable to speak S3 protocol. 25 | 26 | ## MinFS RPMs 27 | ### Minimum Requirements 28 | - [RPM Package Manager](http://rpm.org/) 29 | 30 | ### Install 31 | Download the pre-built RPMs from [here](https://github.com/minio/minfs/releases/tag/RELEASE.2017-02-26T20-20-56Z) 32 | ```sh 33 | yum install minfs-0.0.20170226202056-1.x86_64.rpm 34 | ``` 35 | 36 | ### Update `config.json` 37 | Create a new `config.json` in /etc/minfs directory with your S3 server access and secret keys. 38 | 39 | > This example uses [play.min.io](https://play.min.io) 40 | 41 | ```json 42 | {"version":"1","accessKey":"Q3AM3UQ867SPQQA43P2F","secretKey":"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"} 43 | ``` 44 | 45 | ### Mount `mybucket` 46 | Create an `/etc/fstab` entry 47 | ``` 48 | https://play.min.io/mybucket /mnt/mounted/mybucket minfs defaults,cache=/tmp/mybucket 0 0 49 | ``` 50 | 51 | Now proceed to mount `fstab` entry. 52 | ```sh 53 | mount /mnt/mounted/mybucket 54 | ``` 55 | 56 | Verify if `mybucket` is mounted and is accessible. 57 | ``` 58 | ls -F /mnt/mounted/mybucket 59 | etc/ issue 60 | ``` 61 | -------------------------------------------------------------------------------- /buildscripts/build.env: -------------------------------------------------------------------------------- 1 | ## FIXME: 2 | ## In OSX, 'sort -V' option does not exist, hence 3 | ## we have our own version compare function. 4 | ## Once OSX has the option, below function is good enough. 5 | ## 6 | ## check_minimum_version() { 7 | ## versions=($(echo -e "$1\n$2" | sort -V)) 8 | ## return [ "$1" == "${versions[0]}" ] 9 | ## } 10 | ## 11 | check_minimum_version() { 12 | IFS='.' read -r -a varray1 <<< "$1" 13 | IFS='.' read -r -a varray2 <<< "$2" 14 | 15 | for i in "${!varray1[@]}"; do 16 | if [[ ${varray1[i]} -lt ${varray2[i]} ]]; then 17 | return 0 18 | elif [[ ${varray1[i]} -gt ${varray2[i]} ]]; then 19 | return 1 20 | fi 21 | done 22 | 23 | return 0 24 | } 25 | 26 | -------------------------------------------------------------------------------- /buildscripts/checkdeps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck source=buildscripts/build.env 3 | . "$(pwd)/buildscripts/build.env" 4 | 5 | _init() { 6 | 7 | shopt -s extglob 8 | 9 | ## Minimum required versions for build dependencies 10 | GIT_VERSION="1.0" 11 | GO_VERSION="1.12" 12 | OSX_VERSION="10.8" 13 | KNAME=$(uname -s) 14 | ARCH=$(uname -m) 15 | case "${KNAME}" in 16 | SunOS ) 17 | ARCH=$(isainfo -k) 18 | ;; 19 | esac 20 | } 21 | 22 | ## FIXME: 23 | ## In OSX, 'readlink -f' option does not exist, hence 24 | ## we have our own readlink -f behavior here. 25 | ## Once OSX has the option, below function is good enough. 26 | ## 27 | ## readlink() { 28 | ## return /bin/readlink -f "$1" 29 | ## } 30 | ## 31 | readlink() { 32 | TARGET_FILE=$1 33 | 34 | cd `dirname $TARGET_FILE` 35 | TARGET_FILE=`basename $TARGET_FILE` 36 | 37 | # Iterate down a (possible) chain of symlinks 38 | while [ -L "$TARGET_FILE" ] 39 | do 40 | TARGET_FILE=$(env readlink $TARGET_FILE) 41 | cd `dirname $TARGET_FILE` 42 | TARGET_FILE=`basename $TARGET_FILE` 43 | done 44 | 45 | # Compute the canonicalized name by finding the physical path 46 | # for the directory we're in and appending the target file. 47 | PHYS_DIR=`pwd -P` 48 | RESULT=$PHYS_DIR/$TARGET_FILE 49 | echo $RESULT 50 | } 51 | 52 | assert_is_supported_arch() { 53 | case "${ARCH}" in 54 | x86_64 | amd64 | ppc64le | aarch64 | arm* | s390x ) 55 | return 56 | ;; 57 | *) 58 | echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, ppc64le, aarch64, arm*, s390x]" 59 | exit 1 60 | esac 61 | } 62 | 63 | assert_is_supported_os() { 64 | case "${KNAME}" in 65 | Linux | FreeBSD | OpenBSD | NetBSD | DragonFly | SunOS ) 66 | return 67 | ;; 68 | Darwin ) 69 | osx_host_version=$(env sw_vers -productVersion) 70 | if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then 71 | echo "OSX version '${osx_host_version}' is not supported. Minimum supported version: ${OSX_VERSION}" 72 | exit 1 73 | fi 74 | return 75 | ;; 76 | *) 77 | echo "OS '${KNAME}' is not supported. Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]" 78 | exit 1 79 | esac 80 | } 81 | 82 | assert_check_golang_env() { 83 | if ! which go >/dev/null 2>&1; then 84 | echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at https://docs.min.io/docs/how-to-install-golang" 85 | exit 1 86 | fi 87 | 88 | installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/') 89 | if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then 90 | echo "Go runtime version '${installed_go_version}' is unsupported. Minimum supported version: ${GO_VERSION} to compile." 91 | exit 1 92 | fi 93 | } 94 | 95 | assert_check_deps() { 96 | # support unusual Git versions such as: 2.7.4 (Apple Git-66) 97 | installed_git_version=$(git version | perl -ne '$_ =~ m/git version (.*?)( |$)/; print "$1\n";') 98 | if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then 99 | echo "Git version '${installed_git_version}' is not supported. Minimum supported version: ${GIT_VERSION}" 100 | exit 1 101 | fi 102 | } 103 | 104 | main() { 105 | ## Check for supported arch 106 | assert_is_supported_arch 107 | 108 | ## Check for supported os 109 | assert_is_supported_os 110 | 111 | ## Check for Go environment 112 | assert_check_golang_env 113 | 114 | ## Check for dependencies 115 | assert_check_deps 116 | } 117 | 118 | _init && main "$@" 119 | -------------------------------------------------------------------------------- /buildscripts/cross-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Enable tracing if set. 4 | [ -n "$BASH_XTRACEFD" ] && set -ex 5 | 6 | function _init() { 7 | ## All binaries are static make sure to disable CGO. 8 | export CGO_ENABLED=0 9 | 10 | ## List of architectures and OS to test coss compilation. 11 | SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64" 12 | } 13 | 14 | function _build() { 15 | local osarch=$1 16 | IFS=/ read -r -a arr <<<"$osarch" 17 | os="${arr[0]}" 18 | arch="${arr[1]}" 19 | package=$(go list -f '{{.ImportPath}}') 20 | printf -- "--> %15s:%s\n" "${osarch}" "${package}" 21 | 22 | # Go build to build the binary. 23 | export GOOS=$os 24 | export GOARCH=$arch 25 | export GO111MODULE=on 26 | go build -tags kqueue -o /dev/null 27 | } 28 | 29 | function main() { 30 | echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}" 31 | for each_osarch in ${SUPPORTED_OSARCH}; do 32 | _build "${each_osarch}" 33 | done 34 | } 35 | 36 | _init && main "$@" 37 | -------------------------------------------------------------------------------- /buildscripts/go-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | GO111MODULE=on CGO_ENABLED=0 go test -v -coverprofile=coverage.txt -covermode=atomic ./... 6 | -------------------------------------------------------------------------------- /cmd/build-constants.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package cmd 17 | 18 | var ( 19 | // Version - version time.RFC3339. 20 | Version = "DEVELOPMENT.GOGET" 21 | // ReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ. 22 | ReleaseTag = "DEVELOPMENT.GOGET" 23 | // CommitID - latest commit id. 24 | CommitID = "DEVELOPMENT.GOGET" 25 | // ShortCommitID - first 12 characters from CommitID. 26 | ShortCommitID = CommitID[:12] 27 | ) 28 | -------------------------------------------------------------------------------- /cmd/cmd.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // Package cmd parses the parameters and runs MinFS 17 | package cmd 18 | 19 | import ( 20 | "errors" 21 | "fmt" 22 | "log" 23 | "strconv" 24 | "strings" 25 | 26 | "github.com/minio/cli" 27 | minfs "github.com/minio/minfs/fs" 28 | ) 29 | 30 | var ( 31 | // global flags for minfs. 32 | minfsFlags = []cli.Flag{} 33 | ) 34 | 35 | // Collection of minio flags currently supported. 36 | var globalFlags = []cli.Flag{ 37 | cli.StringFlag{ 38 | Name: "o", 39 | Usage: "Fuse mount options.", 40 | }, 41 | } 42 | 43 | // Help template for minfs. 44 | var minfsHelpTemplate = `NAME: 45 | {{.Name}} - {{.Usage}} 46 | 47 | DESCRIPTION: 48 | {{.Description}} 49 | 50 | USAGE: 51 | {{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...] 52 | {{if .Commands}} 53 | COMMANDS: 54 | {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 55 | {{end}}{{end}}{{if .Flags}} 56 | FLAGS: 57 | {{range .Flags}}{{.}} 58 | {{end}}{{end}} 59 | VERSION: 60 | ` + Version + `{{ "\n"}}` 61 | 62 | // NewApp initializes CLI framework for minfs. 63 | func NewApp() *cli.App { 64 | app := cli.NewApp() 65 | app.HideHelpCommand = true 66 | app.Name = "minfs" 67 | app.Author = "min.io" 68 | app.Version = Version 69 | app.Usage = "Fuse driver for Cloud Storage Server." 70 | app.Description = `MinFS is a fuse driver for MinIO server.` 71 | app.Flags = append(minfsFlags, globalFlags...) 72 | app.CustomAppHelpTemplate = minfsHelpTemplate 73 | app.Before = func(c *cli.Context) error { 74 | if _, err := minfs.InitMinFSConfig(); err != nil { 75 | return fmt.Errorf("Unable to initialize minfs config %s", err) 76 | } 77 | if !c.Args().Present() { 78 | cli.ShowAppHelpAndExit(c, 1) 79 | } 80 | return nil 81 | } 82 | app.Action = func(c *cli.Context) error { 83 | opts := []func(*minfs.Config){} 84 | for _, option := range strings.Split(c.String("o"), ",") { 85 | vals := strings.Split(option, "=") 86 | switch vals[0] { 87 | case "uid": 88 | if len(vals) == 1 { 89 | return errors.New("Uid has no value") 90 | } 91 | val, err := strconv.Atoi(vals[1]) 92 | if err != nil { 93 | return fmt.Errorf("Uid is not a valid value: %s", vals[1]) 94 | } 95 | opts = append(opts, minfs.SetUID(uint32(val))) 96 | case "gid": 97 | if len(vals) == 1 { 98 | return errors.New("Gid has no value") 99 | } 100 | val, err := strconv.Atoi(vals[1]) 101 | if err != nil { 102 | return fmt.Errorf("Gid is not a valid value: %s", vals[1]) 103 | } 104 | opts = append(opts, minfs.SetGID(uint32(val))) 105 | case "cache": 106 | if len(vals) == 1 { 107 | return errors.New("Cache has no value") 108 | } 109 | opts = append(opts, minfs.CacheDir(vals[1])) 110 | case "insecure": 111 | opts = append(opts, minfs.Insecure()) 112 | case "debug": 113 | opts = append(opts, minfs.Debug()) 114 | } 115 | 116 | target := c.Args().Get(0) 117 | mountpoint := c.Args().Get(1) 118 | 119 | opts = append(opts, minfs.Mountpoint(mountpoint), minfs.Target(target)) 120 | } 121 | 122 | fs, err := minfs.New(opts...) 123 | if err != nil { 124 | return fmt.Errorf("Unable to initialize minfs %s", err) 125 | } 126 | 127 | err = fs.Serve() 128 | if err != nil { 129 | return fmt.Errorf("Unable to serve minfs %s", err) 130 | } 131 | 132 | return nil 133 | } 134 | 135 | return app 136 | } 137 | 138 | // Main is the actual run function 139 | func Main(app *cli.App, args []string) { 140 | // Enable profiling supported modes are [cpu, mem, block]. 141 | /* 142 | switch os.Getenv("MINFS_PROFILER") { 143 | case "cpu": 144 | defer profile.Start(profile.CPUProfile, profile.ProfilePath(mustGetProfileDir())).Stop() 145 | case "mem": 146 | defer profile.Start(profile.MemProfile, profile.ProfilePath(mustGetProfileDir())).Stop() 147 | case "block": 148 | defer profile.Start(profile.BlockProfile, profile.ProfilePath(mustGetProfileDir())).Stop() 149 | } 150 | */ 151 | 152 | // Options: 153 | // -- debug 154 | // -- bucket 155 | // -- target 156 | // -- permissions 157 | // -- uid / gid 158 | 159 | // Run the app - exit on error. 160 | if err := app.Run(args); err != nil { 161 | log.Fatalln(err) 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /docs/minfs.8: -------------------------------------------------------------------------------- 1 | .TH MinFS 8 "Fuse driver for Object Storage" "23 January 2021" "MinIO, Inc." 2 | .SH NAME 3 | MinFS \- fuse driver for Object Storage 4 | .SH SYNOPSIS 5 | .B minfs 6 | .I [flags] command [arguments...] 7 | .PP 8 | .SH DESCRIPTION 9 | MinFS is a fuse driver for Amazon S3 compatible object storage server. 10 | Use it to store photos, videos, VMs, containers, log files, or any blob 11 | of data as objects on your object storage server. 12 | 13 | .SH OPTIONS 14 | 15 | .SS "Miscellaneous Options" 16 | .PP 17 | .TP 18 | 19 | \fB\-h, \fB\-\-help\fR 20 | Show help. 21 | .TP 22 | \fB\-V, \fB\-\-version\fR 23 | Print the minfs version. 24 | 25 | .PP 26 | .SH FILES 27 | /etc/minfs/config.json 28 | .SH EXAMPLES 29 | mount a bucket named foo at server play.min.io:9000 on mount point /mnt/foo 30 | 31 | # minfs https://play.min.io:9000/foo /mnt/foo 32 | 33 | .SH SEE ALSO 34 | .nf 35 | \fBfusermount\fR(1), \fBmount.minfs\fR(8) 36 | \fR 37 | .fi 38 | .SH COPYRIGHT 39 | .nf 40 | Copyright(c) 2017 MinIO, Inc. 41 | \fR 42 | .fi 43 | -------------------------------------------------------------------------------- /docs/mount.minfs.8: -------------------------------------------------------------------------------- 1 | .TH mount.minfs 8 "MinFS mount wrapper for Object Storage" "23 January 2021" "MinIO, Inc." 2 | .SH NAME 3 | MinFS \- fuse driver for Object Storage 4 | .SH SYNOPSIS 5 | .B mount -t minfs -o / 6 | .PP 7 | .SH DESCRIPTION 8 | This tool is part of \fBminfs\fR(8) package, which is used to mount using 9 | MinFS native binary. 10 | 11 | \fBmount.minfs\fR is meant to be used by the mount(8) command for mounting 12 | native MinFS client. This subcommand, however, can also be used as a 13 | standalone command with limited functionality. 14 | 15 | .SH OPTIONS 16 | 17 | .SS "Miscellaneous Options" 18 | .PP 19 | .TP 20 | 21 | \fB\-h, \fB\-\-help\fR 22 | Show help. 23 | .TP 24 | \fB\-V, \fB\-\-version\fR 25 | Print the minfs version. 26 | 27 | .PP 28 | .TP 29 | .I /etc/fstab 30 | A typical MinFS entry in /etc/fstab looks like below 31 | 32 | \fBhttp://server1/bucket /mnt/bucket minfs defaults 0 0\fR 33 | 34 | .TP 35 | .I /proc/mounts 36 | An example entry of a MinFS mountpoint in /proc/mounts looks like below 37 | 38 | \fBMinFS /mnt/ramdisk fuse.MinFS rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0\fR 39 | 40 | .SH SEE ALSO 41 | .nf 42 | \fBfusermount\fR(1), \fBmount.minfs\fR(8) 43 | \fR 44 | .fi 45 | .SH COPYRIGHT 46 | .nf 47 | Copyright(c) 2021 MinIO, Inc. 48 | \fR 49 | .fi 50 | -------------------------------------------------------------------------------- /fs/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "encoding/json" 20 | "errors" 21 | "io/ioutil" 22 | "log" 23 | "net/url" 24 | "os" 25 | "path" 26 | "strings" 27 | ) 28 | 29 | // Config is being used for storge of configuration items 30 | type Config struct { 31 | bucket string 32 | basePath string 33 | 34 | cache string 35 | accountID string 36 | accessKey string 37 | secretKey string 38 | secretToken string 39 | target *url.URL 40 | mountpoint string 41 | insecure bool 42 | debug bool 43 | 44 | uid uint32 45 | gid uint32 46 | mode os.FileMode 47 | } 48 | 49 | // AccessConfig - access credentials and version of `config.json`. 50 | type AccessConfig struct { 51 | Version string `json:"version"` 52 | AccessKey string `json:"accessKey"` 53 | SecretKey string `json:"secretKey"` 54 | SecretToken string `json:"secretToken"` 55 | } 56 | 57 | // InitMinFSConfig - Initialize MinFS configuration file. 58 | func InitMinFSConfig() (*AccessConfig, error) { 59 | // Create db directory. 60 | if err := os.MkdirAll(globalDBDir, 0777); err != nil { 61 | return nil, err 62 | } 63 | // Config doesn't exist create it based on environment values. 64 | if _, err := os.Stat(globalConfigFile); err != nil { 65 | if os.IsNotExist(err) { 66 | log.Println("Initializing config.json for the first time, please update your access credentials.") 67 | ac := &AccessConfig{ 68 | Version: "1", 69 | AccessKey: os.Getenv("MINFS_ACCESS_KEY"), 70 | SecretKey: os.Getenv("MINFS_SECRET_KEY"), 71 | SecretToken: os.Getenv("MINFS_SECRET_TOKEN"), 72 | } 73 | acBytes, jerr := json.Marshal(ac) 74 | if jerr != nil { 75 | return nil, jerr 76 | } 77 | if err = ioutil.WriteFile(globalConfigFile, acBytes, 0666); err != nil { 78 | return nil, err 79 | } 80 | return ac, nil 81 | } // Exists but not accessible, fail. 82 | return nil, err 83 | } // Config exists, proceed to read. 84 | acBytes, err := ioutil.ReadFile(globalConfigFile) 85 | if err != nil { 86 | return nil, err 87 | } 88 | ac := &AccessConfig{} 89 | if err = json.Unmarshal(acBytes, ac); err != nil { 90 | return nil, err 91 | } 92 | // Override if access keys are set through env. 93 | accessKey := os.Getenv("MINFS_ACCESS_KEY") 94 | secretKey := os.Getenv("MINFS_SECRET_KEY") 95 | secretToken := os.Getenv("MINFS_SECRET_TOKEN") 96 | if accessKey != "" { 97 | ac.AccessKey = accessKey 98 | } 99 | if secretKey != "" { 100 | ac.SecretKey = secretKey 101 | } 102 | if secretToken != "" { 103 | ac.SecretToken = secretToken 104 | } 105 | return ac, nil 106 | } 107 | 108 | // Mountpoint configures the target mountpoint 109 | func Mountpoint(mountpoint string) func(*Config) { 110 | return func(cfg *Config) { 111 | cfg.mountpoint = mountpoint 112 | } 113 | } 114 | 115 | // Target url target option for Config 116 | func Target(target string) func(*Config) { 117 | return func(cfg *Config) { 118 | if u, err := url.Parse(target); err == nil { 119 | cfg.target = u 120 | 121 | if len(u.Path) > 1 { 122 | parts := strings.Split(u.Path[1:], "/") 123 | if len(parts) >= 0 { 124 | cfg.bucket = parts[0] 125 | } 126 | if len(parts) >= 1 { 127 | cfg.basePath = path.Join(parts[1:]...) 128 | } 129 | } 130 | } 131 | } 132 | } 133 | 134 | // CacheDir - cache directory path option for Config 135 | func CacheDir(path string) func(*Config) { 136 | return func(cfg *Config) { 137 | cfg.cache = path 138 | } 139 | } 140 | 141 | // SetGID - sets a custom gid for the mount. 142 | func SetGID(gid uint32) func(*Config) { 143 | return func(cfg *Config) { 144 | cfg.gid = gid 145 | } 146 | } 147 | 148 | // SetUID - sets a custom uid for the mount. 149 | func SetUID(uid uint32) func(*Config) { 150 | return func(cfg *Config) { 151 | cfg.uid = uid 152 | } 153 | } 154 | 155 | // Insecure - enable insecure mode. 156 | func Insecure() func(*Config) { 157 | return func(cfg *Config) { 158 | cfg.insecure = true 159 | } 160 | } 161 | 162 | // Debug - enables debug logging. 163 | func Debug() func(*Config) { 164 | return func(cfg *Config) { 165 | cfg.debug = true 166 | } 167 | } 168 | 169 | // Validates the config for sane values. 170 | func (cfg *Config) validate() error { 171 | // check if mountpoint exists 172 | if cfg.mountpoint == "" { 173 | return errors.New("Mountpoint not set") 174 | } 175 | 176 | if cfg.target == nil { 177 | return errors.New("Target not set") 178 | } 179 | 180 | if cfg.bucket == "" { 181 | return errors.New("Bucket not set") 182 | } 183 | 184 | return nil 185 | } 186 | -------------------------------------------------------------------------------- /fs/dir.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "context" 20 | "os" 21 | "path" 22 | "strings" 23 | "time" 24 | 25 | "bazil.org/fuse" 26 | "bazil.org/fuse/fs" 27 | 28 | "github.com/minio/minfs/meta" 29 | minio "github.com/minio/minio-go/v7" 30 | ) 31 | 32 | // Dir implements both Node and Handle for the root directory. 33 | type Dir struct { 34 | mfs *MinFS 35 | 36 | dir *Dir 37 | 38 | Path string 39 | Inode uint64 40 | Mode os.FileMode 41 | 42 | Size uint64 43 | ETag string 44 | 45 | Atime time.Time 46 | Mtime time.Time 47 | 48 | UID uint32 49 | GID uint32 50 | 51 | // OS X only 52 | Bkuptime time.Time 53 | Chgtime time.Time 54 | Crtime time.Time 55 | Flags uint32 // see chflags(2) 56 | 57 | scanned bool 58 | } 59 | 60 | func (dir *Dir) needsScan() bool { 61 | return !dir.scanned 62 | } 63 | 64 | // Attr returns the attributes for the directory 65 | func (dir *Dir) Attr(ctx context.Context, a *fuse.Attr) error { 66 | *a = fuse.Attr{ 67 | Inode: dir.Inode, 68 | Size: dir.Size, 69 | Atime: dir.Atime, 70 | Mtime: dir.Mtime, 71 | Ctime: dir.Chgtime, 72 | Crtime: dir.Crtime, 73 | Mode: dir.Mode, 74 | Uid: dir.UID, 75 | Gid: dir.GID, 76 | Flags: dir.Flags, 77 | } 78 | 79 | return nil 80 | } 81 | 82 | // Lookup returns the file node, and scans the current dir if necessary 83 | func (dir *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) { 84 | if err := dir.scan(ctx); err != nil { 85 | return nil, err 86 | } 87 | 88 | // we are not statting each object here because of performance reasons 89 | var o interface{} // meta.Object 90 | if err := dir.mfs.db.View(func(tx *meta.Tx) error { 91 | b := dir.bucket(tx) 92 | return b.Get(name, &o) 93 | }); err == nil { 94 | } else if meta.IsNoSuchObject(err) { 95 | return nil, fuse.ENOENT 96 | } else if err != nil { 97 | return nil, err 98 | } 99 | 100 | if file, ok := o.(File); ok { 101 | file.mfs = dir.mfs 102 | file.dir = dir 103 | return &file, nil 104 | } else if subdir, ok := o.(Dir); ok { 105 | subdir.mfs = dir.mfs 106 | subdir.dir = dir 107 | return &subdir, nil 108 | } 109 | 110 | return nil, fuse.ENOENT 111 | } 112 | 113 | // RemotePath returns the full path including parent paths for current dir on the remote 114 | func (dir *Dir) RemotePath() string { 115 | return path.Join(dir.mfs.config.basePath, dir.FullPath()) 116 | } 117 | 118 | // FullPath returns the full path including parent paths for current dir 119 | func (dir *Dir) FullPath() string { 120 | fullPath := "" 121 | 122 | p := dir 123 | for { 124 | if p == nil { 125 | break 126 | } 127 | 128 | fullPath = path.Join(p.Path, fullPath) 129 | 130 | p = p.dir 131 | } 132 | 133 | return fullPath 134 | } 135 | 136 | func (dir *Dir) storeFile(bucket *meta.Bucket, tx *meta.Tx, baseKey string, objInfo minio.ObjectInfo) error { 137 | var f File 138 | err := bucket.Get(baseKey, &f) 139 | if err == nil { 140 | // Object already exists and accessible, update values as needed. 141 | f.dir = dir 142 | f.mfs = dir.mfs 143 | f.Size = uint64(objInfo.Size) 144 | f.ETag = objInfo.ETag 145 | if objInfo.LastModified.After(f.Chgtime) { 146 | f.Chgtime = objInfo.LastModified 147 | } 148 | if objInfo.LastModified.After(f.Crtime) { 149 | f.Crtime = objInfo.LastModified 150 | } 151 | if objInfo.LastModified.After(f.Mtime) { 152 | f.Mtime = objInfo.LastModified 153 | } 154 | if objInfo.LastModified.After(f.Atime) { 155 | f.Atime = objInfo.LastModified 156 | } 157 | } else if meta.IsNoSuchObject(err) { 158 | // Object not found, allocate a new inode. 159 | var seq uint64 160 | seq, err = dir.mfs.NextSequence(tx) 161 | if err != nil { 162 | return err 163 | } 164 | f = File{ 165 | dir: dir, 166 | Path: baseKey, 167 | Size: uint64(objInfo.Size), 168 | Inode: seq, 169 | Mode: dir.mfs.config.mode, 170 | GID: dir.mfs.config.gid, 171 | UID: dir.mfs.config.uid, 172 | Chgtime: objInfo.LastModified, 173 | Crtime: objInfo.LastModified, 174 | Mtime: objInfo.LastModified, 175 | Atime: objInfo.LastModified, 176 | ETag: objInfo.ETag, 177 | } 178 | if err = f.store(tx); err != nil { 179 | return err 180 | } 181 | } // else { 182 | // Returns failure for all other errors. 183 | return err 184 | } 185 | 186 | func (dir *Dir) storeDir(bucket *meta.Bucket, tx *meta.Tx, baseKey string, objInfo minio.ObjectInfo) error { 187 | var d Dir 188 | err := bucket.Get(baseKey, &d) 189 | if err == nil { 190 | // Prefix already exists and accessible, update values as needed. 191 | d.dir = dir 192 | d.mfs = dir.mfs 193 | } else if meta.IsNoSuchObject(err) { 194 | // Prefix not found allocate a new inode and create a new directory. 195 | var seq uint64 196 | seq, err = dir.mfs.NextSequence(tx) 197 | if err != nil { 198 | return err 199 | } 200 | d = Dir{ 201 | dir: dir, 202 | Path: baseKey, 203 | Inode: seq, 204 | Mode: 0770 | os.ModeDir, 205 | GID: dir.mfs.config.gid, 206 | UID: dir.mfs.config.uid, 207 | 208 | Chgtime: objInfo.LastModified, 209 | Crtime: objInfo.LastModified, 210 | Mtime: objInfo.LastModified, 211 | Atime: objInfo.LastModified, 212 | } 213 | if err = d.store(tx); err != nil { 214 | return err 215 | } 216 | } // else { 217 | // For all other errors this operation fails. 218 | return err 219 | } 220 | 221 | func (dir *Dir) scan(ctx context.Context) error { 222 | if !dir.needsScan() { 223 | return nil 224 | } 225 | 226 | tx, err := dir.mfs.db.Begin(true) 227 | if err != nil { 228 | return err 229 | } 230 | 231 | defer tx.Rollback() 232 | 233 | b := dir.bucket(tx) 234 | 235 | objects := map[string]interface{}{} 236 | 237 | // we'll compare the current bucket contents against our cache folder, and update the cache 238 | if err := b.ForEach(func(k string, o interface{}) error { 239 | if k[len(k)-1] != '/' { 240 | objects[k] = &o 241 | } 242 | return nil 243 | }); err != nil { 244 | return err 245 | } 246 | 247 | prefix := dir.RemotePath() 248 | if prefix != "" { 249 | prefix = prefix + "/" 250 | } 251 | 252 | ch := dir.mfs.api.ListObjects(ctx, dir.mfs.config.bucket, minio.ListObjectsOptions{ 253 | Prefix: prefix, 254 | Recursive: false, 255 | }) 256 | 257 | for objInfo := range ch { 258 | key := objInfo.Key[len(prefix):] 259 | baseKey := path.Base(key) 260 | 261 | // object still exists 262 | objects[baseKey] = nil 263 | 264 | if strings.HasSuffix(key, "/") { 265 | dir.storeDir(b, tx, baseKey, objInfo) 266 | } else { 267 | dir.storeFile(b, tx, baseKey, objInfo) 268 | } 269 | } 270 | 271 | // cache housekeeping 272 | for k, o := range objects { 273 | if o == nil { 274 | continue 275 | } 276 | 277 | // purge from cache 278 | b.Delete(k) 279 | 280 | if _, ok := o.(Dir); !ok { 281 | continue 282 | } 283 | 284 | b.DeleteBucket(k + "/") 285 | } 286 | 287 | if err := tx.Commit(); err != nil { 288 | return err 289 | } 290 | 291 | dir.scanned = true 292 | return nil 293 | } 294 | 295 | // ReadDirAll will return all files in current dir 296 | func (dir *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { 297 | if err := dir.scan(ctx); err != nil { 298 | return nil, err 299 | } 300 | 301 | var entries = []fuse.Dirent{} 302 | 303 | // update cache folder with bucket list 304 | if err := dir.mfs.db.View(func(tx *meta.Tx) error { 305 | return dir.bucket(tx).ForEach(func(k string, o interface{}) error { 306 | if file, ok := o.(File); ok { 307 | file.dir = dir 308 | entries = append(entries, file.Dirent()) 309 | } else if subdir, ok := o.(Dir); ok { 310 | subdir.dir = dir 311 | entries = append(entries, subdir.Dirent()) 312 | } else { 313 | panic("Could not find type. Try to remove cache.") 314 | } 315 | 316 | return nil 317 | }) 318 | }); err != nil { 319 | return nil, err 320 | } 321 | 322 | return entries, nil 323 | } 324 | 325 | func (dir *Dir) bucket(tx *meta.Tx) *meta.Bucket { 326 | // Root folder. 327 | if dir.dir == nil { 328 | return tx.Bucket("minio/") 329 | } 330 | 331 | b := dir.dir.bucket(tx) 332 | 333 | return b.Bucket(dir.Path + "/") 334 | } 335 | 336 | // Mkdir will make a new directory below current dir 337 | func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { 338 | subdir := Dir{ 339 | dir: dir, 340 | mfs: dir.mfs, 341 | 342 | Path: req.Name, 343 | 344 | Mode: 0770 | os.ModeDir, 345 | GID: dir.mfs.config.gid, 346 | UID: dir.mfs.config.uid, 347 | 348 | Chgtime: time.Now(), 349 | Crtime: time.Now(), 350 | Mtime: time.Now(), 351 | Atime: time.Now(), 352 | } 353 | 354 | tx, err := dir.mfs.db.Begin(true) 355 | if err != nil { 356 | return nil, err 357 | } 358 | 359 | defer tx.Rollback() 360 | 361 | if err := subdir.store(tx); err != nil { 362 | return nil, err 363 | } 364 | 365 | // Commit the transaction and check for error. 366 | if err := tx.Commit(); err != nil { 367 | return nil, err 368 | } 369 | 370 | return &subdir, nil 371 | } 372 | 373 | // Remove will delete a file or directory from current directory 374 | func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error { 375 | if err := dir.mfs.wait(path.Join(dir.FullPath(), req.Name)); err != nil { 376 | return err 377 | } 378 | 379 | tx, err := dir.mfs.db.Begin(true) 380 | if err != nil { 381 | return err 382 | } 383 | 384 | defer tx.Rollback() 385 | 386 | b := dir.bucket(tx) 387 | 388 | var o interface{} 389 | if err := b.Get(req.Name, &o); meta.IsNoSuchObject(err) { 390 | return fuse.ENOENT 391 | } else if err != nil { 392 | return err 393 | } else if err := b.Delete(req.Name); err != nil { 394 | return err 395 | } 396 | 397 | if req.Dir { 398 | b.DeleteBucket(req.Name + "/") 399 | } 400 | 401 | if err := dir.mfs.api.RemoveObject(ctx, dir.mfs.config.bucket, path.Join(dir.RemotePath(), req.Name), minio.RemoveObjectOptions{}); err != nil { 402 | return err 403 | } 404 | 405 | return tx.Commit() 406 | } 407 | 408 | // store the dir object in cache 409 | func (dir *Dir) store(tx *meta.Tx) error { 410 | // directories will be stored in their parent buckets 411 | b := dir.dir.bucket(tx) 412 | 413 | subbucketPath := path.Base(dir.Path) 414 | if _, err := b.CreateBucketIfNotExists(subbucketPath + "/"); err != nil { 415 | return err 416 | } 417 | 418 | return b.Put(subbucketPath, dir) 419 | } 420 | 421 | // Dirent will return the fuse Dirent for current dir 422 | func (dir *Dir) Dirent() fuse.Dirent { 423 | return fuse.Dirent{ 424 | Inode: dir.Inode, Name: dir.Path, Type: fuse.DT_Dir, 425 | } 426 | } 427 | 428 | // Create will return a new empty file in current dir, if the file is currently locked, it will 429 | // wait for the lock to be freed. 430 | func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) { 431 | if err := dir.mfs.wait(path.Join(dir.FullPath(), req.Name)); err != nil { 432 | return nil, nil, err 433 | } 434 | 435 | tx, err := dir.mfs.db.Begin(true) 436 | if err != nil { 437 | return nil, nil, err 438 | } 439 | 440 | defer tx.Rollback() 441 | 442 | b := dir.bucket(tx) 443 | 444 | name := req.Name 445 | 446 | var f File 447 | if gerr := b.Get(name, &f); gerr == nil { 448 | f.mfs = dir.mfs 449 | f.dir = dir 450 | } else if i, nerr := dir.mfs.NextSequence(tx); nerr != nil { 451 | return nil, nil, nerr 452 | } else { 453 | f = File{ 454 | mfs: dir.mfs, 455 | dir: dir, 456 | 457 | Size: uint64(0), 458 | Inode: i, 459 | Path: req.Name, 460 | Mode: req.Mode, // dir.mfs.config.mode, // should we use same mode for scan? 461 | UID: dir.mfs.config.uid, 462 | GID: dir.mfs.config.gid, 463 | Chgtime: time.Now().UTC(), 464 | Crtime: time.Now().UTC(), 465 | Mtime: time.Now().UTC(), 466 | Atime: time.Now().UTC(), 467 | ETag: "", 468 | 469 | // req.Umask 470 | } 471 | } 472 | 473 | if serr := f.store(tx); serr != nil { 474 | return nil, nil, serr 475 | } 476 | 477 | var fh *FileHandle 478 | if fh, err = dir.mfs.Acquire(&f); err != nil { 479 | return nil, nil, err 480 | } 481 | fh.dirty = true 482 | if fh.cachePath, err = dir.mfs.NewCachePath(); err != nil { 483 | return nil, nil, err 484 | } 485 | if fh.File, err = os.OpenFile(fh.cachePath, int(req.Flags), dir.mfs.config.mode); err != nil { 486 | return nil, nil, err 487 | } 488 | 489 | // Commit the transaction and check for error. 490 | if err = tx.Commit(); err != nil { 491 | return nil, nil, err 492 | } 493 | 494 | resp.Handle = fuse.HandleID(fh.handle) 495 | return &f, fh, nil 496 | } 497 | 498 | // Rename will rename files 499 | func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, nd fs.Node) error { 500 | tx, err := dir.mfs.db.Begin(true) 501 | if err != nil { 502 | return err 503 | } 504 | 505 | defer tx.Rollback() 506 | 507 | b := dir.bucket(tx) 508 | 509 | newDir := nd.(*Dir) 510 | 511 | var o interface{} 512 | if err := b.Get(req.OldName, &o); err != nil { 513 | return err 514 | } else if file, ok := o.(File); ok { 515 | file.dir = dir 516 | 517 | if err := b.Delete(file.Path); err != nil { 518 | return err 519 | } 520 | 521 | oldPath := file.RemotePath() 522 | 523 | file.Path = req.NewName 524 | file.dir = newDir 525 | file.mfs = dir.mfs 526 | 527 | sr := newMoveOp(oldPath, file.RemotePath()) 528 | if err := dir.mfs.sync(&sr); err == nil { 529 | } else if meta.IsNoSuchObject(err) { 530 | return fuse.ENOENT 531 | } else if err != nil { 532 | return err 533 | } 534 | 535 | // we'll wait for the request to be uploaded and synced, before 536 | // releasing the file 537 | if err := <-sr.Error; err != nil { 538 | return err 539 | } 540 | 541 | if err := file.store(tx); err != nil { 542 | return err 543 | } 544 | 545 | } else if subdir, ok := o.(Dir); ok { 546 | // rescan in case of abort / partial / failure 547 | // this will repair the cache 548 | dir.scanned = false 549 | 550 | if err := b.Delete(req.OldName); err != nil { 551 | return err 552 | } 553 | 554 | if err := b.DeleteBucket(req.OldName + "/"); err != nil { 555 | return err 556 | } 557 | 558 | newDir.scanned = false 559 | 560 | // fusebug? 561 | // the cached node is still invalid, contains the old name 562 | // but there is no way to retrieve the old node to update the new 563 | // name. refreshing the parent node won't fix the issue when 564 | // direct access. Fuse should add the targetnode (subdir) as well, 565 | // that can be updated. 566 | 567 | subdir.Path = req.NewName 568 | subdir.dir = newDir 569 | subdir.mfs = dir.mfs 570 | 571 | if err := subdir.store(tx); err != nil { 572 | return err 573 | } 574 | 575 | oldPath := path.Join(dir.RemotePath(), req.OldName) 576 | 577 | ch := dir.mfs.api.ListObjects(ctx, dir.mfs.config.bucket, minio.ListObjectsOptions{ 578 | Prefix: oldPath + "/", 579 | Recursive: true, 580 | }) 581 | 582 | for message := range ch { 583 | newPath := path.Join(newDir.RemotePath(), req.NewName, message.Key[len(oldPath):]) 584 | 585 | sr := newMoveOp(message.Key, newPath) 586 | if err := dir.mfs.sync(&sr); err == nil { 587 | } else if meta.IsNoSuchObject(err) { 588 | return fuse.ENOENT 589 | } else if err != nil { 590 | return err 591 | } 592 | 593 | // we'll wait for the request to be uploaded and synced, before 594 | // releasing the file 595 | if err := <-sr.Error; err != nil { 596 | return err 597 | } 598 | } 599 | } else { 600 | return fuse.ENOSYS 601 | } 602 | 603 | // Commit the transaction and check for error. 604 | return tx.Commit() 605 | } 606 | -------------------------------------------------------------------------------- /fs/file.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "context" 20 | "crypto/sha256" 21 | "io" 22 | "os" 23 | "path" 24 | "time" 25 | 26 | "bazil.org/fuse" 27 | "bazil.org/fuse/fs" 28 | "github.com/minio/minfs/meta" 29 | minio "github.com/minio/minio-go/v7" 30 | ) 31 | 32 | // File implements both Node and Handle for the hello file. 33 | type File struct { 34 | mfs *MinFS 35 | 36 | dir *Dir 37 | 38 | Path string 39 | 40 | Inode uint64 41 | 42 | Mode os.FileMode 43 | 44 | Size uint64 45 | ETag string 46 | 47 | Atime time.Time 48 | Mtime time.Time 49 | 50 | UID uint32 51 | GID uint32 52 | 53 | // OS X only 54 | Bkuptime time.Time 55 | Chgtime time.Time 56 | Crtime time.Time 57 | Flags uint32 // see chflags(2) 58 | 59 | Hash []byte 60 | } 61 | 62 | func (f *File) store(tx *meta.Tx) error { 63 | b := f.bucket(tx) 64 | return b.Put(path.Base(f.Path), f) 65 | } 66 | 67 | // Attr - attr file context. 68 | func (f *File) Attr(ctx context.Context, a *fuse.Attr) error { 69 | *a = fuse.Attr{ 70 | Inode: f.Inode, 71 | Size: f.Size, 72 | Atime: f.Atime, 73 | Mtime: f.Mtime, 74 | Ctime: f.Chgtime, 75 | Crtime: f.Crtime, 76 | Mode: f.Mode, 77 | Uid: f.UID, 78 | Gid: f.GID, 79 | Flags: f.Flags, 80 | } 81 | 82 | return nil 83 | } 84 | 85 | // Setattr - set attribute. 86 | func (f *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error { 87 | // update cache with new attributes 88 | return f.mfs.db.Update(func(tx *meta.Tx) error { 89 | if req.Valid.Mode() { 90 | f.Mode = req.Mode 91 | } 92 | 93 | if req.Valid.Uid() { 94 | f.UID = req.Uid 95 | } 96 | 97 | if req.Valid.Gid() { 98 | f.GID = req.Gid 99 | } 100 | 101 | if req.Valid.Size() { 102 | f.Size = req.Size 103 | } 104 | 105 | if req.Valid.Atime() { 106 | f.Atime = req.Atime 107 | } 108 | 109 | if req.Valid.Mtime() { 110 | f.Mtime = req.Mtime 111 | } 112 | 113 | if req.Valid.Crtime() { 114 | f.Crtime = req.Crtime 115 | } 116 | 117 | if req.Valid.Chgtime() { 118 | f.Chgtime = req.Chgtime 119 | } 120 | 121 | if req.Valid.Bkuptime() { 122 | f.Bkuptime = req.Bkuptime 123 | } 124 | 125 | if req.Valid.Flags() { 126 | f.Flags = req.Flags 127 | } 128 | 129 | return f.store(tx) 130 | }) 131 | } 132 | 133 | // RemotePath will return the full path on bucket 134 | func (f *File) RemotePath() string { 135 | return path.Join(f.dir.RemotePath(), f.Path) 136 | } 137 | 138 | // FullPath will return the full path 139 | func (f *File) FullPath() string { 140 | return path.Join(f.dir.FullPath(), f.Path) 141 | } 142 | 143 | // Saves a new file at cached path and fetches the object based on 144 | // the incoming fuse request. 145 | func (f *File) cacheSave(ctx context.Context, path string, req *fuse.OpenRequest) error { 146 | file, err := os.Create(path) 147 | if err != nil { 148 | return err 149 | } 150 | defer file.Close() 151 | 152 | if req.Flags&fuse.OpenTruncate == fuse.OpenTruncate { 153 | f.Size = 0 154 | return nil 155 | } 156 | 157 | object, err := f.mfs.api.GetObject(ctx, f.mfs.config.bucket, f.RemotePath(), minio.GetObjectOptions{}) 158 | if err != nil { 159 | if meta.IsNoSuchObject(err) { 160 | return fuse.ENOENT 161 | } 162 | return err 163 | } 164 | defer object.Close() 165 | 166 | hasher := sha256.New() 167 | size, err := io.Copy(file, io.TeeReader(object, hasher)) 168 | if err != nil { 169 | return err 170 | } 171 | 172 | // update actual file size 173 | f.Size = uint64(size) 174 | 175 | // hash will be used when encrypting files 176 | _ = hasher.Sum(nil) 177 | 178 | // Success. 179 | return nil 180 | } 181 | 182 | // Open return a file handle of the opened file 183 | func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) { 184 | if err := f.dir.mfs.wait(f.Path); err != nil { 185 | return nil, err 186 | } 187 | 188 | // Start a writable transaction. 189 | tx, err := f.mfs.db.Begin(true) 190 | if err != nil { 191 | return nil, err 192 | } 193 | 194 | defer tx.Rollback() 195 | 196 | cachePath, err := f.dir.mfs.NewCachePath() 197 | if err != nil { 198 | return nil, err 199 | } 200 | 201 | err = f.cacheSave(ctx, cachePath, req) 202 | if err != nil { 203 | return nil, err 204 | } 205 | 206 | fh, err := f.mfs.Acquire(f) 207 | if err != nil { 208 | return nil, err 209 | } 210 | 211 | fh.cachePath = cachePath 212 | 213 | fh.File, err = os.OpenFile(fh.cachePath, int(req.Flags), f.mfs.config.mode) 214 | if err != nil { 215 | return nil, err 216 | } 217 | 218 | if err = f.store(tx); err != nil { 219 | return nil, err 220 | } 221 | 222 | if err = tx.Commit(); err != nil { 223 | return nil, err 224 | } 225 | 226 | resp.Handle = fuse.HandleID(fh.handle) 227 | return fh, nil 228 | } 229 | 230 | func (f *File) bucket(tx *meta.Tx) *meta.Bucket { 231 | b := f.dir.bucket(tx) 232 | return b 233 | } 234 | 235 | // Getattr returns the file attributes 236 | func (f *File) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error { 237 | resp.Attr = fuse.Attr{ 238 | Inode: f.Inode, 239 | Size: f.Size, 240 | Atime: f.Atime, 241 | Mtime: f.Mtime, 242 | Ctime: f.Chgtime, 243 | Crtime: f.Crtime, 244 | Mode: f.Mode, 245 | Uid: f.UID, 246 | Gid: f.GID, 247 | Flags: f.Flags, 248 | } 249 | 250 | return nil 251 | } 252 | 253 | // Dirent returns the File object as a fuse.Dirent 254 | func (f *File) Dirent() fuse.Dirent { 255 | return fuse.Dirent{ 256 | Inode: f.Inode, Name: f.Path, Type: fuse.DT_File, 257 | } 258 | } 259 | 260 | func (f *File) delete(tx *meta.Tx) error { 261 | // purge from cache 262 | b := f.bucket(tx) 263 | return b.Delete(f.Path) 264 | } 265 | -------------------------------------------------------------------------------- /fs/filehandle.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "context" 20 | "io" 21 | "os" 22 | 23 | "bazil.org/fuse" 24 | 25 | "github.com/minio/minfs/meta" 26 | ) 27 | 28 | // FileHandle - Contains an opened file which can be read from and written to 29 | type FileHandle struct { 30 | // the os file handle 31 | *os.File 32 | 33 | // the fuse file 34 | f *File 35 | 36 | // cache file has been written to 37 | dirty bool 38 | 39 | cachePath string 40 | 41 | handle uint64 42 | } 43 | 44 | // Read from the file handle 45 | func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { 46 | buff := make([]byte, req.Size) 47 | n, err := fh.File.ReadAt(buff, req.Offset) 48 | if err != nil && err != io.EOF { 49 | return err 50 | } 51 | resp.Data = buff[:n] 52 | return nil 53 | } 54 | 55 | // Write to the file handle 56 | func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error { 57 | if _, err := fh.File.Seek(req.Offset, 0); err != nil { 58 | return err 59 | } 60 | n, err := fh.File.Write(req.Data) 61 | if err != nil { 62 | return err 63 | } 64 | // Writes that grow the file are expected to update the file size 65 | // (as seen through Attr). Note that file size changes are 66 | // communicated also through Setattr. 67 | if fh.f.Size < uint64(req.Offset)+uint64(n) { 68 | fh.f.Size = uint64(req.Offset) + uint64(n) 69 | } 70 | resp.Size = n 71 | fh.dirty = true 72 | return nil 73 | } 74 | 75 | // Fsync because of bug in fuse lib, this is on file. -- FIXME - needs more context (y4m4). 76 | func (f *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { 77 | // fmt.Println("fsync", f.FullPath()) 78 | return nil 79 | } 80 | 81 | // Release the file handle 82 | func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error { 83 | if err := fh.Close(); err != nil { 84 | return err 85 | } 86 | 87 | defer fh.f.mfs.Release(fh) 88 | 89 | os.Remove(fh.cachePath) 90 | return nil 91 | } 92 | 93 | // Flush - experimenting with uploading at flush, this slows operations down till it has been 94 | // completely flushed 95 | func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error { 96 | if !fh.dirty { 97 | return nil 98 | } 99 | 100 | sr := newPutOp(fh.Name(), fh.f.RemotePath(), int64(fh.f.Size)) 101 | if err := fh.f.mfs.sync(&sr); err != nil { 102 | return err 103 | } 104 | 105 | // we'll wait for the request to be uploaded and synced, before 106 | // releasing the file 107 | if err := <-sr.Error; err != nil { 108 | return err 109 | } 110 | 111 | // update cache 112 | if err := fh.f.mfs.db.Update(func(tx *meta.Tx) error { 113 | return fh.f.store(tx) 114 | }); err != nil { 115 | return err 116 | } 117 | 118 | fh.dirty = false 119 | return nil 120 | } 121 | -------------------------------------------------------------------------------- /fs/fs.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // Package minfs contains the MinFS core package 17 | package minfs 18 | 19 | import ( 20 | "context" 21 | "crypto/tls" 22 | "fmt" 23 | "log" 24 | "mime" 25 | "net" 26 | "net/http" 27 | "os" 28 | "path" 29 | "path/filepath" 30 | "sync" 31 | "syscall" 32 | "time" 33 | 34 | "github.com/minio/minfs/meta" 35 | "github.com/minio/minio-go/v7" 36 | "github.com/minio/minio-go/v7/pkg/credentials" 37 | 38 | "bazil.org/fuse" 39 | "bazil.org/fuse/fs" 40 | ) 41 | 42 | var ( 43 | _ = meta.RegisterExt(1, File{}) 44 | _ = meta.RegisterExt(2, Dir{}) 45 | ) 46 | 47 | // MinFS contains the meta data for the MinFS client 48 | type MinFS struct { 49 | config *Config 50 | api *minio.Client 51 | 52 | db *meta.DB 53 | 54 | // Logger instance. 55 | log *log.Logger 56 | 57 | // contains all open handles 58 | handles []*FileHandle 59 | 60 | locks map[string]bool 61 | 62 | m sync.Mutex 63 | 64 | syncChan chan interface{} 65 | 66 | listenerDoneCh chan struct{} 67 | } 68 | 69 | // New will return a new MinFS client 70 | func New(options ...func(*Config)) (*MinFS, error) { 71 | // Initialize config. 72 | ac, err := InitMinFSConfig() 73 | if err != nil { 74 | return nil, err 75 | } 76 | 77 | // Initialize log file. 78 | logW, err := os.OpenFile(globalLogFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666) 79 | if err != nil { 80 | return nil, err 81 | } 82 | 83 | // Set defaults 84 | cfg := &Config{ 85 | cache: globalDBDir, 86 | basePath: "", 87 | accountID: fmt.Sprintf("%d", time.Now().UTC().Unix()), 88 | gid: 0, 89 | uid: 0, 90 | accessKey: ac.AccessKey, 91 | secretKey: ac.SecretKey, 92 | mode: os.FileMode(0660), 93 | } 94 | 95 | for _, optionFn := range options { 96 | optionFn(cfg) 97 | } 98 | 99 | if err := cfg.validate(); err != nil { 100 | return nil, err 101 | } 102 | 103 | // Initialize MinFS. 104 | fs := &MinFS{ 105 | config: cfg, 106 | syncChan: make(chan interface{}), 107 | locks: map[string]bool{}, 108 | log: log.New(logW, "MinFS ", log.Ldate|log.Ltime|log.Lshortfile), 109 | listenerDoneCh: make(chan struct{}), 110 | } 111 | 112 | // Success.. 113 | return fs, nil 114 | } 115 | 116 | func (mfs *MinFS) mount() (*fuse.Conn, error) { 117 | return fuse.Mount( 118 | mfs.config.mountpoint, 119 | fuse.FSName("MinFS"), 120 | fuse.Subtype("MinFS"), 121 | fuse.LocalVolume(), 122 | fuse.VolumeName(mfs.config.bucket), 123 | fuse.AllowOther(), 124 | fuse.DefaultPermissions(), 125 | ) 126 | } 127 | 128 | // Serve starts the MinFS client 129 | func (mfs *MinFS) Serve() (err error) { 130 | if mfs.config.debug { 131 | fuse.Debug = func(msg interface{}) { 132 | mfs.log.Printf("%#v\n", msg) 133 | } 134 | } 135 | 136 | defer mfs.shutdown() 137 | 138 | mfs.log.Println("Mounting target....") 139 | // mount the drive 140 | var c *fuse.Conn 141 | c, err = mfs.mount() 142 | if err != nil { 143 | return err 144 | } 145 | 146 | defer c.Close() 147 | 148 | // channel to receive errors 149 | trapCh := signalTrap(os.Interrupt, syscall.SIGTERM, os.Kill) 150 | 151 | go func() { 152 | <-trapCh 153 | 154 | mfs.shutdown() 155 | }() 156 | 157 | // Initialize database. 158 | mfs.log.Println("Opening cache database...") 159 | mfs.db, err = meta.Open(path.Join(mfs.config.cache, "cache.db"), 0600, nil) 160 | if err != nil { 161 | return err 162 | } 163 | defer mfs.db.Close() 164 | 165 | mfs.log.Println("Initializing cache database...") 166 | if err = mfs.db.Update(func(tx *meta.Tx) error { 167 | _, berr := tx.CreateBucketIfNotExists([]byte("minio/")) 168 | return berr 169 | }); err != nil { 170 | return err 171 | } 172 | 173 | mfs.log.Println("Initializing minio client...") 174 | 175 | var ( 176 | host = mfs.config.target.Host 177 | access = mfs.config.accessKey 178 | secret = mfs.config.secretKey 179 | token = mfs.config.secretToken 180 | secure = mfs.config.target.Scheme == "https" 181 | ) 182 | 183 | var transport http.RoundTripper = &http.Transport{ 184 | Proxy: http.ProxyFromEnvironment, 185 | DialContext: (&net.Dialer{ 186 | Timeout: 30 * time.Second, 187 | KeepAlive: 30 * time.Second, 188 | }).DialContext, 189 | MaxIdleConns: 100, 190 | IdleConnTimeout: 90 * time.Second, 191 | TLSHandshakeTimeout: 10 * time.Second, 192 | ExpectContinueTimeout: 1 * time.Second, 193 | TLSClientConfig: &tls.Config{ 194 | InsecureSkipVerify: mfs.config.insecure, 195 | }, 196 | // Set this value so that the underlying transport round-tripper 197 | // doesn't try to auto decode the body of objects with 198 | // content-encoding set to `gzip`. 199 | // 200 | // Refer: 201 | // https://golang.org/src/net/http/transport.go?h=roundTrip#L1843 202 | DisableCompression: true, 203 | } 204 | 205 | creds := credentials.NewStaticV4(access, secret, token) 206 | options := &minio.Options{ 207 | Creds: creds, 208 | Secure: secure, 209 | Transport: transport, 210 | } 211 | 212 | mfs.api, err = minio.New(host, options) 213 | if err != nil { 214 | return err 215 | } 216 | 217 | // Validate if the bucket is valid and accessible. 218 | exists, err := mfs.api.BucketExists(context.Background(), mfs.config.bucket) 219 | if err != nil { 220 | return err 221 | } 222 | if !exists { 223 | mfs.log.Println("Bucket doesn't not exist... aborting") 224 | return os.ErrNotExist 225 | } 226 | 227 | if err = mfs.startSync(); err != nil { 228 | return err 229 | } 230 | 231 | mfs.log.Println("Serving... Have fun!") 232 | // Serve the filesystem 233 | if err = fs.Serve(c, mfs); err != nil { 234 | mfs.log.Println("Error while serving the file system.", err) 235 | return err 236 | } 237 | 238 | <-c.Ready 239 | return c.MountError 240 | } 241 | 242 | func (mfs *MinFS) shutdown() { 243 | fuse.Unmount(mfs.config.mountpoint) 244 | mfs.log.Println("MinFS stopped cleanly.") 245 | } 246 | 247 | func (mfs *MinFS) sync(req interface{}) error { 248 | mfs.syncChan <- req 249 | return nil 250 | } 251 | 252 | func (mfs *MinFS) moveOp(req *MoveOperation) { 253 | dst := minio.CopyDestOptions{ 254 | Bucket: mfs.config.bucket, 255 | Object: req.Target, 256 | } 257 | src := minio.CopySrcOptions{ 258 | Bucket: mfs.config.bucket, 259 | Object: req.Source, 260 | } 261 | if _, err := mfs.api.CopyObject(context.Background(), dst, src); err != nil { 262 | req.Error <- err 263 | return 264 | } 265 | req.Error <- mfs.api.RemoveObject(context.Background(), mfs.config.bucket, req.Source, minio.RemoveObjectOptions{}) 266 | } 267 | 268 | func (mfs *MinFS) copyOp(req *CopyOperation) { 269 | dst := minio.CopyDestOptions{ 270 | Bucket: mfs.config.bucket, 271 | Object: req.Target, 272 | } 273 | src := minio.CopySrcOptions{ 274 | Bucket: mfs.config.bucket, 275 | Object: req.Source, 276 | } 277 | _, err := mfs.api.CopyObject(context.Background(), dst, src) 278 | req.Error <- err 279 | } 280 | 281 | func (mfs *MinFS) putOp(req *PutOperation) { 282 | r, err := os.Open(req.Source) 283 | if err != nil { 284 | req.Error <- err 285 | return 286 | } 287 | defer r.Close() 288 | 289 | ops := minio.PutObjectOptions{ 290 | ContentType: mime.TypeByExtension(filepath.Ext(req.Target)), 291 | } 292 | _, err = mfs.api.PutObject(context.Background(), mfs.config.bucket, req.Target, r, req.Length, ops) 293 | if err != nil { 294 | req.Error <- err 295 | return 296 | } 297 | mfs.log.Printf("Upload finished: %s -> %s.\n", req.Source, req.Target) 298 | req.Error <- nil 299 | } 300 | 301 | func (mfs *MinFS) startSync() error { 302 | go func() { 303 | for req := range mfs.syncChan { 304 | switch req := req.(type) { 305 | case *MoveOperation: 306 | mfs.moveOp(req) 307 | case *CopyOperation: 308 | mfs.copyOp(req) 309 | case *PutOperation: 310 | mfs.putOp(req) 311 | default: 312 | panic("Unknown type") 313 | } 314 | } 315 | }() 316 | return nil 317 | } 318 | 319 | // Statfs will return meta information on the minio filesystem 320 | func (mfs *MinFS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.StatfsResponse) error { 321 | resp.Blocks = 0x1000000000 322 | resp.Bfree = 0x1000000000 323 | resp.Bavail = 0x1000000000 324 | resp.Namelen = 32768 325 | resp.Bsize = 1024 326 | return nil 327 | } 328 | 329 | // Acquire will return a new FileHandle 330 | func (mfs *MinFS) Acquire(f *File) (*FileHandle, error) { 331 | if err := mfs.Lock(f.FullPath()); err != nil { 332 | return nil, err 333 | } 334 | 335 | h := &FileHandle{ 336 | f: f, 337 | } 338 | 339 | mfs.handles = append(mfs.handles, h) 340 | 341 | h.handle = uint64(len(mfs.handles) - 1) 342 | return h, nil 343 | } 344 | 345 | // Release release the filehandle 346 | func (mfs *MinFS) Release(fh *FileHandle) error { 347 | if err := mfs.Unlock(fh.f.FullPath()); err != nil { 348 | return err 349 | } 350 | 351 | mfs.handles[fh.handle] = nil 352 | return nil 353 | } 354 | 355 | // NextSequence will return the next free iNode 356 | func (mfs *MinFS) NextSequence(tx *meta.Tx) (sequence uint64, err error) { 357 | bucket := tx.Bucket("minio/") 358 | return bucket.NextSequence() 359 | } 360 | 361 | // Root is the root folder of the MinFS mountpoint 362 | func (mfs *MinFS) Root() (fs.Node, error) { 363 | return &Dir{ 364 | dir: nil, 365 | mfs: mfs, 366 | Path: "", 367 | 368 | UID: mfs.config.uid, 369 | GID: mfs.config.gid, 370 | Mode: os.ModeDir | 0750, 371 | }, nil 372 | } 373 | 374 | // Storer - 375 | type Storer interface { 376 | store(tx *meta.Tx) 377 | } 378 | 379 | // NewCachePath - 380 | func (mfs *MinFS) NewCachePath() (string, error) { 381 | cachePath := path.Join(mfs.config.cache, nextSuffix()) 382 | for { 383 | if _, err := os.Stat(cachePath); err == nil { 384 | } else if os.IsNotExist(err) { 385 | return cachePath, nil 386 | } else { 387 | return "", err 388 | } 389 | cachePath = path.Join(mfs.config.cache, nextSuffix()) 390 | } 391 | } 392 | -------------------------------------------------------------------------------- /fs/globals.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | // Package cmd contains all the global variables and constants. 19 | const ( 20 | globalConfigFile = "/etc/minfs/config.json" 21 | globalDBDir = "/etc/minfs/db" 22 | globalLogFile = "/var/log/minfs.log" 23 | ) 24 | -------------------------------------------------------------------------------- /fs/lock.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "time" 20 | 21 | "bazil.org/fuse" 22 | ) 23 | 24 | // Unlock - unlock the lock at path. 25 | func (mfs *MinFS) Unlock(path string) error { 26 | mfs.m.Lock() 27 | defer mfs.m.Unlock() 28 | 29 | delete(mfs.locks, path) 30 | 31 | return nil 32 | } 33 | 34 | // Lock - acquires a lock at path. 35 | func (mfs *MinFS) Lock(path string) error { 36 | mfs.m.Lock() 37 | defer mfs.m.Unlock() 38 | 39 | mfs.locks[path] = true 40 | return nil 41 | } 42 | 43 | // IsLocked returns if the path is currently locked 44 | func (mfs *MinFS) IsLocked(path string) bool { 45 | mfs.m.Lock() 46 | defer mfs.m.Unlock() 47 | 48 | _, ok := mfs.locks[path] 49 | return ok 50 | } 51 | 52 | // wait for the file lock to be unlocked 53 | func (mfs *MinFS) wait(path string) error { 54 | // check if the file is locked, and wait for max 5 seconds for the file to be 55 | // acquired 56 | for i := 0; ; /* retries */ i++ { 57 | if !mfs.IsLocked(path) { 58 | break 59 | } 60 | 61 | if i > 25 /* max number of retries */ { 62 | return fuse.EPERM 63 | } 64 | 65 | time.Sleep(time.Millisecond * 200) 66 | } 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /fs/operations.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | // Operation - 19 | type Operation struct { 20 | Error chan error 21 | } 22 | 23 | // MoveOperation - Move source object to target object. Copy source to target, delete the source. 24 | type MoveOperation struct { 25 | *Operation 26 | 27 | Source string 28 | Target string 29 | } 30 | 31 | func newMoveOp(sourcePath, targetPath string) MoveOperation { 32 | return MoveOperation{ 33 | Source: sourcePath, 34 | Target: targetPath, 35 | Operation: &Operation{ 36 | Error: make(chan error), 37 | }, 38 | } 39 | } 40 | 41 | // CopyOperation - Copy source object to target. 42 | type CopyOperation struct { 43 | *Operation 44 | 45 | Source string 46 | Target string 47 | } 48 | 49 | // PutOperation - Copy source file to target. 50 | type PutOperation struct { 51 | *Operation 52 | 53 | Length int64 54 | 55 | Source string 56 | Target string 57 | } 58 | 59 | func newPutOp(sourcePath string, targetPath string, length int64) PutOperation { 60 | return PutOperation{ 61 | Source: sourcePath, 62 | Target: targetPath, 63 | Length: int64(length), 64 | Operation: &Operation{ 65 | Error: make(chan error), 66 | }, 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /fs/rand.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "fmt" 20 | "os" 21 | "strconv" 22 | "sync" 23 | "time" 24 | ) 25 | 26 | var rand uint32 27 | var randmu sync.Mutex 28 | 29 | func reseed() uint32 { 30 | return uint32(time.Now().UnixNano() + int64(os.Getpid())) 31 | } 32 | 33 | func nextSuffix() string { 34 | randmu.Lock() 35 | defer randmu.Unlock() 36 | 37 | r := rand 38 | if r == 0 { 39 | r = reseed() 40 | } 41 | r = r*1664525 + 1013904223 // constants from Numerical Recipes 42 | rand = r 43 | return fmt.Sprintf("%x", strconv.Itoa(int(1e9 + r%1e9))[1:]) 44 | } 45 | -------------------------------------------------------------------------------- /fs/signals.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package minfs 17 | 18 | import ( 19 | "os" 20 | "os/signal" 21 | ) 22 | 23 | // signalTrap traps the registered signals and notifies the caller. 24 | func signalTrap(sig ...os.Signal) <-chan bool { 25 | // channel to notify the caller. 26 | trapCh := make(chan bool, 1) 27 | 28 | go func(chan<- bool) { 29 | // channel to receive signals. 30 | sigCh := make(chan os.Signal, 1) 31 | defer close(sigCh) 32 | 33 | // `signal.Notify` registers the given channel to 34 | // receive notifications of the specified signals. 35 | signal.Notify(sigCh, sig...) 36 | 37 | // Wait for the signal. 38 | <-sigCh 39 | 40 | // Once signal has been received stop signal Notify handler. 41 | signal.Stop(sigCh) 42 | 43 | // Notify the caller. 44 | trapCh <- true 45 | }(trapCh) 46 | 47 | return trapCh 48 | } 49 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/minio/minfs 2 | 3 | go 1.16 4 | 5 | require ( 6 | bazil.org/fuse v0.0.0-20200524192727-fb710f7dfd05 7 | github.com/golang/protobuf v1.5.2 // indirect 8 | github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect 9 | github.com/klauspost/cpuid/v2 v2.1.1 // indirect 10 | github.com/kr/pretty v0.1.0 // indirect 11 | github.com/minio/cli v1.23.0 12 | github.com/minio/minio-go/v7 v7.0.35 13 | github.com/sevlyar/go-daemon v0.1.6 14 | go.etcd.io/bbolt v1.3.6 15 | golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect 16 | golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect 17 | golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect 18 | google.golang.org/appengine v1.6.7 // indirect 19 | google.golang.org/protobuf v1.28.1 // indirect 20 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect 21 | gopkg.in/ini.v1 v1.67.0 // indirect 22 | gopkg.in/vmihailenco/msgpack.v2 v2.9.2 23 | ) 24 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | bazil.org/fuse v0.0.0-20200524192727-fb710f7dfd05 h1:UrYe9YkT4Wpm6D+zByEyCJQzDqTPXqTDUI7bZ41i9VE= 2 | bazil.org/fuse v0.0.0-20200524192727-fb710f7dfd05/go.mod h1:h0h5FBYpXThbvSfTqthw+0I4nmHnhTHkO5BoOHsBWqg= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/Julusian/godocdown v0.0.0-20170816220326-6d19f8ff2df8/go.mod h1:INZr5t32rG59/5xeltqoCJoNY7e5x/3xoY9WSWVWg74= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= 9 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= 10 | github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= 11 | github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= 12 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 13 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 14 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 15 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 16 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 17 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 18 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 19 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 20 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 21 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 22 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 23 | github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= 24 | github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= 25 | github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= 26 | github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= 27 | github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 28 | github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 29 | github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= 30 | github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0= 31 | github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= 32 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 33 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 34 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 35 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 36 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 37 | github.com/minio/cli v1.23.0 h1:hNuf8xi/JU5EJRX+T38e2zcnh2EpdVqs8aH4lNXWe3w= 38 | github.com/minio/cli v1.23.0/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY= 39 | github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= 40 | github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= 41 | github.com/minio/minio-go/v7 v7.0.35 h1:JuPPxWLdxQmNLSaS8AWZnO5HBadeI1xg6FGrEELQEVU= 42 | github.com/minio/minio-go/v7 v7.0.35/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw= 43 | github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= 44 | github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= 45 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 46 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 47 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 48 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 49 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 50 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 51 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 52 | github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s= 53 | github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= 54 | github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= 55 | github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs= 56 | github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE= 57 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 58 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 59 | github.com/stephens2424/writerset v1.0.2/go.mod h1:aS2JhsMn6eA7e82oNmW4rfsgAOp9COBTTl8mzkwADnc= 60 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 61 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 62 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 63 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 64 | github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ= 65 | github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= 66 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 67 | go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= 68 | go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= 69 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 70 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 71 | golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 72 | golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM= 73 | golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 74 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 75 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 76 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 77 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 78 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 79 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 80 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 81 | golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= 82 | golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= 83 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 84 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 85 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 86 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 87 | golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 88 | golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 89 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 90 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 91 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 92 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 93 | golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 94 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 95 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 96 | golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 97 | golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY= 98 | golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 99 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 100 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 101 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 102 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 103 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 104 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 105 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 106 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 107 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 108 | golang.org/x/tools v0.0.0-20200423201157-2723c5de0d66/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 109 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 110 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 111 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 112 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 113 | google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= 114 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 115 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 116 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 117 | google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= 118 | google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 119 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 120 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 121 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 122 | gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 123 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 124 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 125 | gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= 126 | gopkg.in/vmihailenco/msgpack.v2 v2.9.2 h1:gjPqo9orRVlSAH/065qw3MsFCDpH7fa1KpiizXyllY4= 127 | gopkg.in/vmihailenco/msgpack.v2 v2.9.2/go.mod h1:/3Dn1Npt9+MYyLpYYXjInO/5jvMLamn+AEGwNEOatn8= 128 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 129 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 130 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 131 | -------------------------------------------------------------------------------- /meta/db.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // Package meta maintains the caching of all meta data of the files and directories. 17 | package meta 18 | 19 | import ( 20 | "errors" 21 | "os" 22 | "path/filepath" 23 | 24 | "gopkg.in/vmihailenco/msgpack.v2" 25 | 26 | minio "github.com/minio/minio-go/v7" 27 | "go.etcd.io/bbolt" 28 | ) 29 | 30 | // RegisterExt - 31 | func RegisterExt(id int8, value interface{}) interface{} { 32 | msgpack.RegisterExt(id, value) 33 | return value 34 | } 35 | 36 | // Open - 37 | func Open(path string, mode os.FileMode, options *bbolt.Options) (*DB, error) { 38 | dname := filepath.Dir(path) 39 | if err := os.MkdirAll(dname, 0700); err != nil { 40 | return nil, err 41 | } 42 | db, err := bbolt.Open(path, 0600, nil) 43 | if err != nil { 44 | return nil, err 45 | } 46 | 47 | return &DB{ 48 | db, 49 | }, nil 50 | 51 | } 52 | 53 | // DB - 54 | type DB struct { 55 | *bbolt.DB 56 | } 57 | 58 | // Begin - 59 | func (db *DB) Begin(writable bool) (*Tx, error) { 60 | tx, err := db.DB.Begin(writable) 61 | return &Tx{tx}, err 62 | } 63 | 64 | // Update - 65 | func (db *DB) Update(fn func(*Tx) error) error { 66 | return db.DB.Update(func(tx *bbolt.Tx) error { 67 | return fn(&Tx{tx}) 68 | }) 69 | } 70 | 71 | // View - 72 | func (db *DB) View(fn func(*Tx) error) error { 73 | return db.DB.View(func(tx *bbolt.Tx) error { 74 | return fn(&Tx{tx}) 75 | }) 76 | } 77 | 78 | // Bucket - 79 | type Bucket struct { 80 | InnerBucket *bbolt.Bucket 81 | } 82 | 83 | // Bucket - 84 | func (b *Bucket) Bucket(name string) *Bucket { 85 | return &Bucket{ 86 | b.InnerBucket.Bucket([]byte(name)), 87 | } 88 | } 89 | 90 | // NextSequence - 91 | func (b *Bucket) NextSequence() (uint64, error) { 92 | return b.InnerBucket.NextSequence() 93 | } 94 | 95 | // ForEach - 96 | func (b *Bucket) ForEach(fn func(string, interface{}) error) error { 97 | return b.InnerBucket.ForEach(func(k, v []byte) error { 98 | if k[len(k)-1] == '/' { 99 | return nil 100 | } 101 | 102 | var o interface{} 103 | if err := msgpack.Unmarshal(v, &o); err != nil { 104 | return err 105 | } 106 | 107 | return fn(string(k), o) 108 | }) 109 | } 110 | 111 | // CreateBucketIfNotExists - 112 | func (b *Bucket) CreateBucketIfNotExists(key string) (*Bucket, error) { 113 | child, err := b.InnerBucket.CreateBucketIfNotExists([]byte(key)) 114 | return &Bucket{child}, err 115 | } 116 | 117 | // Tx - transaction struct. 118 | type Tx struct { 119 | *bbolt.Tx 120 | } 121 | 122 | // Bucket - 123 | func (tx *Tx) Bucket(name string) *Bucket { 124 | return &Bucket{ 125 | tx.Tx.Bucket([]byte(name)), 126 | } 127 | } 128 | 129 | // ErrNoSuchObject - returned when object is not found. 130 | var ErrNoSuchObject = errors.New("No such object") 131 | 132 | // IsNoSuchObject - is err ErrNoSuchObject ? 133 | func IsNoSuchObject(err error) bool { 134 | if err == nil { 135 | return false 136 | } 137 | // Validate if the type is same as well. 138 | if err == ErrNoSuchObject { 139 | return true 140 | } else if err.Error() == ErrNoSuchObject.Error() { 141 | // Reaches here when type did not match but err string matches. 142 | // Someone wrapped this error? - still return true since 143 | // they are the same. 144 | return true 145 | } 146 | errorResponse := minio.ToErrorResponse(err) 147 | return errorResponse.Code == "NoSuchKey" 148 | } 149 | 150 | // DeleteBucket - 151 | func (b *Bucket) DeleteBucket(key string) error { 152 | return b.InnerBucket.DeleteBucket([]byte(key)) 153 | } 154 | 155 | // Delete - 156 | func (b *Bucket) Delete(key string) error { 157 | return b.InnerBucket.Delete([]byte(key)) 158 | } 159 | 160 | // Get - 161 | func (b *Bucket) Get(key string, v ...interface{}) error { 162 | data := b.InnerBucket.Get([]byte(key)) 163 | if data == nil { 164 | return ErrNoSuchObject 165 | } 166 | return msgpack.Unmarshal(data, v...) 167 | } 168 | 169 | // Put - 170 | func (b *Bucket) Put(key string, v interface{}) error { 171 | data, err := msgpack.Marshal(v) 172 | if err != nil { 173 | return err 174 | } 175 | return b.InnerBucket.Put([]byte(key), data) 176 | } 177 | -------------------------------------------------------------------------------- /minfs.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 MinIO, Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | package main // import "github.com/minio/minfs" 17 | 18 | import ( 19 | "log" 20 | "os" 21 | 22 | minfs "github.com/minio/minfs/cmd" 23 | daemon "github.com/sevlyar/go-daemon" 24 | ) 25 | 26 | func main() { 27 | app := minfs.NewApp() 28 | if len(os.Args) == 1 || (len(os.Args) == 2 && (os.Args[1] == "--help" || os.Args[1] == "--version" || 29 | os.Args[1] == "-h" || os.Args[1] == "-v")) { 30 | if err := app.Run(os.Args); err != nil { 31 | log.Fatal(err) 32 | } 33 | return 34 | } 35 | 36 | dctx := &daemon.Context{ 37 | PidFileName: "/var/log/minfs.pid", 38 | PidFilePerm: 0644, 39 | LogFileName: "/var/log/minfs.log", 40 | LogFilePerm: 0640, 41 | WorkDir: "./", 42 | Umask: 027, 43 | Args: os.Args, 44 | } 45 | 46 | d, err := dctx.Reborn() 47 | if err != nil { 48 | log.Fatalln("Unable to run: ", err) 49 | } 50 | if d != nil { 51 | return 52 | } 53 | defer dctx.Release() 54 | 55 | // daemon business logic starts here 56 | minfs.Main(app, os.Args) 57 | } 58 | -------------------------------------------------------------------------------- /mount.minfs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | 4 | warn () 5 | { 6 | echo "$@" >&2 7 | } 8 | 9 | _init () 10 | { 11 | PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH 12 | export PATH 13 | prefix="/sbin"; 14 | cmd_line=$(echo "/sbin/minfs"); 15 | mounttab=/proc/mounts 16 | UPDATEDBCONF="/etc/updatedb.conf" 17 | } 18 | 19 | start_minfs () 20 | { 21 | cmd_line=$(echo "$cmd_line $mount_opts $minio_endpoint $mount_point"); 22 | $cmd_line 23 | } 24 | 25 | print_usage () 26 | { 27 | cat << EOF 28 | USAGE: $0 -o / 29 | To display the version number of the mount helper: $0 -V 30 | EOF 31 | } 32 | 33 | update_updatedb() 34 | { 35 | # Append MinFS to PRUNEFS variable in updatedb.conf(5). 36 | # updatedb(8) should not index files under MinFS. MinFS 37 | # does its own indexing. 38 | test -f $UPDATEDBCONF && { 39 | if ! grep -q 'fuse.MinFS' $UPDATEDBCONF; then 40 | sed 's/\(PRUNEFS.*\)"/\1 fuse.MinFS"/' $UPDATEDBCONF \ 41 | > ${UPDATEDBCONF}.bak 42 | mv -f ${UPDATEDBCONF}.bak $UPDATEDBCONF 43 | fi 44 | } 45 | } 46 | 47 | main () 48 | { 49 | minio_endpoint=$1 50 | mount_point=$2 51 | mount_opts=$3 52 | if [ "x${mount_opts}" = "x-o" ] ; then 53 | mount_opts="$3 $4" 54 | fi 55 | while getopts "Vh" opt; do 56 | case "${opt}" in 57 | V) 58 | ${cmd_line} -V; 59 | exit 0; 60 | ;; 61 | h) 62 | print_usage; 63 | exit 0; 64 | ;; 65 | ?) 66 | print_usage; 67 | exit 0; 68 | ;; 69 | esac 70 | done 71 | 72 | grep_ret=$(echo ${mount_point} | grep '^\-o'); 73 | [ "x" != "x${grep_ret}" ] && { 74 | cat <&2 75 | -o options cannot be specified in either first two arguments. Please specify correct style. 76 | EOF 77 | exit 1; 78 | } 79 | 80 | # No need to do a ! -d test, it is taken care while initializing the 81 | # variable mount_point 82 | [ -z "$mount_point" -o ! -d "$mount_point" ] && { 83 | cat <&2 84 | Mount point does not exist, Please specify a valid mount point. 85 | EOF 86 | exit 1; 87 | } 88 | 89 | # Simple check to avoid multiple identical mounts 90 | if grep -q "[[:space:]+]${mount_point}[[:space:]+]fuse" $mounttab; then 91 | warn "$0: according to mtab, MinFS is already mounted on" \ 92 | "$mount_point" 93 | exit 32; 94 | fi 95 | 96 | update_updatedb; 97 | 98 | start_minfs; 99 | } 100 | 101 | _init "$@" && main "$@"; 102 | --------------------------------------------------------------------------------