-
Notifications
You must be signed in to change notification settings - Fork 73
support filesystem magic for linux #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| /* | ||
| Copyright 2013-2018 Docker, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // Original source: https://github.com/moby/moby/blob/v26.0.0/daemon/graphdriver/driver_linux.go | ||
|
|
||
| package fs | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "syscall" | ||
| ) | ||
|
|
||
| // Magic unsigned id of the filesystem in use. | ||
| type Magic uint32 | ||
|
|
||
| const ( | ||
| // MagicUnsupported is a predefined constant value other than a valid filesystem id. | ||
| MagicUnsupported = Magic(0x00000000) | ||
| ) | ||
|
|
||
| const ( | ||
| // MagicAufs filesystem id for Aufs | ||
| MagicAufs = Magic(0x61756673) | ||
| // MagicBtrfs filesystem id for Btrfs | ||
| MagicBtrfs = Magic(0x9123683E) | ||
| // MagicCramfs filesystem id for Cramfs | ||
| MagicCramfs = Magic(0x28cd3d45) | ||
| // MagicEcryptfs filesystem id for eCryptfs | ||
| MagicEcryptfs = Magic(0xf15f) | ||
| // MagicExtfs filesystem id for Extfs | ||
| MagicExtfs = Magic(0x0000EF53) | ||
| // MagicF2fs filesystem id for F2fs | ||
| MagicF2fs = Magic(0xF2F52010) | ||
| // MagicGPFS filesystem id for GPFS | ||
| MagicGPFS = Magic(0x47504653) | ||
| // MagicJffs2Fs filesystem if for Jffs2Fs | ||
| MagicJffs2Fs = Magic(0x000072b6) | ||
| // MagicJfs filesystem id for Jfs | ||
| MagicJfs = Magic(0x3153464a) | ||
| // MagicNfsFs filesystem id for NfsFs | ||
| MagicNfsFs = Magic(0x00006969) | ||
| // MagicRAMFs filesystem id for RamFs | ||
| MagicRAMFs = Magic(0x858458f6) | ||
| // MagicReiserFs filesystem id for ReiserFs | ||
| MagicReiserFs = Magic(0x52654973) | ||
| // MagicSmbFs filesystem id for SmbFs | ||
| MagicSmbFs = Magic(0x0000517B) | ||
| // MagicSquashFs filesystem id for SquashFs | ||
| MagicSquashFs = Magic(0x73717368) | ||
| // MagicTmpFs filesystem id for TmpFs | ||
| MagicTmpFs = Magic(0x01021994) | ||
| // MagicVxFS filesystem id for VxFs | ||
| MagicVxFS = Magic(0xa501fcf5) | ||
| // MagicXfs filesystem id for Xfs | ||
| MagicXfs = Magic(0x58465342) | ||
| // MagicZfs filesystem id for Zfs | ||
| MagicZfs = Magic(0x2fc12fc1) | ||
| // MagicOverlay filesystem id for overlay | ||
| MagicOverlay = Magic(0x794C7630) | ||
| ) | ||
|
|
||
| var ( | ||
| // FsNames maps filesystem id to name of the filesystem. | ||
| FsNames = map[Magic]string{ | ||
| MagicAufs: "aufs", | ||
| MagicBtrfs: "btrfs", | ||
| MagicCramfs: "cramfs", | ||
| MagicExtfs: "extfs", | ||
| MagicF2fs: "f2fs", | ||
| MagicGPFS: "gpfs", | ||
| MagicJffs2Fs: "jffs2", | ||
| MagicJfs: "jfs", | ||
| MagicNfsFs: "nfs", | ||
| MagicOverlay: "overlayfs", | ||
| MagicRAMFs: "ramfs", | ||
| MagicReiserFs: "reiserfs", | ||
| MagicSmbFs: "smb", | ||
| MagicSquashFs: "squashfs", | ||
| MagicTmpFs: "tmpfs", | ||
| MagicUnsupported: "unsupported", | ||
| MagicVxFS: "vxfs", | ||
| MagicXfs: "xfs", | ||
| MagicZfs: "zfs", | ||
| } | ||
| ) | ||
|
|
||
| // GetMagic returns the filesystem id given the path. | ||
| func GetMagic(rootpath string) (Magic, error) { | ||
| var buf syscall.Statfs_t | ||
| if err := syscall.Statfs(filepath.Dir(rootpath), &buf); err != nil { | ||
| return 0, err | ||
| } | ||
| return Magic(buf.Type), nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a permanent link to the original file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done