| 1 | package btrfsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.12 fmt/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.12 os/" |
| 6 | "path/filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.12 strings/" |
| 8 | "syscallscip-go gomod github.com/golang/go/src go1.12 syscall/" |
| 9 | "timescip-go gomod github.com/golang/go/src go1.12 time/" |
| 10 | ) |
| 11 | |
| 12 | func checkSubVolumeNamescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/checkSubVolumeName().(name string) bool { |
| 13 | return name != "" && name[0] != 0 && !stringsscip-go gomod github.com/golang/go/src go1.12 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.12 strings/ContainsRune().(name, '/') && |
| 14 | name != "." && name != ".." |
| 15 | } |
| 16 | |
| 17 | func IsSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/IsSubVolume().(path string) (bool, error) { |
| 18 | var st syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.Stat_tscip-go gomod github.com/golang/go/src go1.12 syscall/Stat_t# |
| 19 | if err := syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.Statscip-go gomod github.com/golang/go/src go1.12 syscall/Stat().(path, &st); err != nil { |
| 20 | return false, &osscip-go gomod github.com/golang/go/src go1.12 os/.PathErrorscip-go gomod github.com/golang/go/src go1.12 os/PathError#{Opscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Op.: "stat", Pathscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Path.: path, Errscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Err.: err} |
| 21 | } |
| 22 | if objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#(st.Inoscip-go gomod github.com/golang/go/src go1.12 syscall/Stat_t#Ino.) != firstFreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/firstFreeObjectid. || |
| 23 | st.Modescip-go gomod github.com/golang/go/src go1.12 syscall/Stat_t#Mode.&syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.S_IFMTscip-go gomod github.com/golang/go/src go1.12 syscall/S_IFMT. != syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.S_IFDIRscip-go gomod github.com/golang/go/src go1.12 syscall/S_IFDIR. { |
| 24 | return false, nil |
| 25 | } |
| 26 | return isBtrfsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/isBtrfs().(path) |
| 27 | } |
| 28 | |
| 29 | func CreateSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CreateSubVolume().(path string) error { |
| 30 | var inherit *btrfs_qgroup_inheritscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_qgroup_inherit# // TODO |
| 31 | |
| 32 | cpath, err := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Absscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Abs().(path) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | newName := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Base().(cpath) |
| 37 | dstDir := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Dir().(cpath) |
| 38 | if !checkSubVolumeNamescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/checkSubVolumeName().(newName) { |
| 39 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("invalid subvolume name: %s", newName) |
| 40 | } else if len(newName) >= volNameMaxscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/volNameMax. { |
| 41 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("subvolume name too long: %s", newName) |
| 42 | } |
| 43 | dst, err := openDirscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/openDir().(dstDir) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | defer dst.Closescip-go gomod github.com/golang/go/src go1.12 os/File#Close().() |
| 48 | if inherit != nil { |
| 49 | panic("not implemented") // TODO |
| 50 | args := btrfs_ioctl_vol_args_v2scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#{ |
| 51 | flagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#flags.: subvolQGroupInheritscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolQGroupInherit., |
| 52 | btrfs_ioctl_vol_args_v2_u1scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#btrfs_ioctl_vol_args_v2_u1.: btrfs_ioctl_vol_args_v2_u1scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2_u1#{ |
| 53 | //size: qgroup_inherit_size(inherit), |
| 54 | qgroup_inheritscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2_u1#qgroup_inherit.: inherit, |
| 55 | }, |
| 56 | } |
| 57 | copy(args.namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#name.[:], newName) |
| 58 | return iocSubvolCreateV2scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/iocSubvolCreateV2().(dst, &args) |
| 59 | } |
| 60 | var args btrfs_ioctl_vol_argsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args# |
| 61 | copy(args.namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args#name.[:], newName) |
| 62 | return iocSubvolCreatescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/iocSubvolCreate().(dst, &args) |
| 63 | } |
| 64 | |
| 65 | func DeleteSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/DeleteSubVolume().(path string) error { |
| 66 | if ok, err := IsSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/IsSubVolume().(path); err != nil { |
| 67 | return err |
| 68 | } else if !ok { |
| 69 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("not a subvolume: %s", path) |
| 70 | } |
| 71 | cpath, err := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Absscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Abs().(path) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | dname := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Dir().(cpath) |
| 76 | vname := filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Base().(cpath) |
| 77 | |
| 78 | dir, err := openDirscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/openDir().(dname) |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | defer dir.Closescip-go gomod github.com/golang/go/src go1.12 os/File#Close().() |
| 83 | var args btrfs_ioctl_vol_argsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args# |
| 84 | copy(args.namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args#name.[:], vname) |
| 85 | return iocSnapDestroyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/iocSnapDestroy().(dir, &args) |
| 86 | } |
| 87 | |
| 88 | func SnapshotSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SnapshotSubVolume().(subvol, dst string, ro bool) error { |
| 89 | if ok, err := IsSubVolumescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/IsSubVolume().(subvol); err != nil { |
| 90 | return err |
| 91 | } else if !ok { |
| 92 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("not a subvolume: %s", subvol) |
| 93 | } |
| 94 | exists := false |
| 95 | if st, err := osscip-go gomod github.com/golang/go/src go1.12 os/.Statscip-go gomod github.com/golang/go/src go1.12 os/Stat().(dst); err != nil && !osscip-go gomod github.com/golang/go/src go1.12 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.12 os/IsNotExist().(err) { |
| 96 | return err |
| 97 | } else if err == nil { |
| 98 | if !st.IsDirscip-go gomod github.com/golang/go/src go1.12 `io/fs`/FileInfo#IsDir().() { |
| 99 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("'%s' exists and it is not a directory", dst) |
| 100 | } |
| 101 | exists = true |
| 102 | } |
| 103 | var ( |
| 104 | newName string |
| 105 | dstDir string |
| 106 | ) |
| 107 | if exists { |
| 108 | newName = filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Base().(subvol) |
| 109 | dstDir = dst |
| 110 | } else { |
| 111 | newName = filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Base().(dst) |
| 112 | dstDir = filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Dir().(dst) |
| 113 | } |
| 114 | if !checkSubVolumeNamescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/checkSubVolumeName().(newName) { |
| 115 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("invalid snapshot name '%s'", newName) |
| 116 | } else if len(newName) >= volNameMaxscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/volNameMax. { |
| 117 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("snapshot name too long '%s'", newName) |
| 118 | } |
| 119 | fdst, err := openDirscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/openDir().(dstDir) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | defer fdst.Closescip-go gomod github.com/golang/go/src go1.12 os/File#Close().() |
| 124 | // TODO: make SnapshotSubVolume a method on FS to use existing fd |
| 125 | f, err := openDirscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/openDir().(subvol) |
| 126 | if err != nil { |
| 127 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("cannot open dest dir: %v", err) |
| 128 | } |
| 129 | defer f.Closescip-go gomod github.com/golang/go/src go1.12 os/File#Close().() |
| 130 | args := btrfs_ioctl_vol_args_v2scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#{ |
| 131 | fdscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#fd.: int64(f.Fdscip-go gomod github.com/golang/go/src go1.12 os/File#Fd().()), |
| 132 | } |
| 133 | if ro { |
| 134 | args.flagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#flags. |= SubvolReadOnlyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolReadOnly. |
| 135 | } |
| 136 | // TODO |
| 137 | //if inherit != nil { |
| 138 | // args.flags |= subvolQGroupInherit |
| 139 | // args.size = qgroup_inherit_size(inherit) |
| 140 | // args.qgroup_inherit = inherit |
| 141 | //} |
| 142 | copy(args.namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_vol_args_v2#name.[:], newName) |
| 143 | if err := iocSnapCreateV2scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/iocSnapCreateV2().(fdst, &args); err != nil { |
| 144 | return fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("snapshot create failed: %v", err) |
| 145 | } |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | func IsReadOnlyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/IsReadOnly().(path string) (bool, error) { |
| 150 | f, err := GetFlagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/GetFlags().(path) |
| 151 | if err != nil { |
| 152 | return false, err |
| 153 | } |
| 154 | return f.ReadOnlyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolFlags#ReadOnly().(), nil |
| 155 | } |
| 156 | |
| 157 | func GetFlagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/GetFlags().(path string) (SubvolFlagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolFlags#, error) { |
| 158 | fs, err := Openscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Open().(path, true) |
| 159 | if err != nil { |
| 160 | return 0, err |
| 161 | } |
| 162 | defer fs.Closescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/FS#Close().() |
| 163 | return fs.GetFlagsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/FS#GetFlags().() |
| 164 | } |
| 165 | |
| 166 | func listSubVolumesscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/listSubVolumes().(f *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, filter func(SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#) bool) (map[objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#]SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#, error) { |
| 167 | sk := btrfs_ioctl_search_keyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#{ |
| 168 | // search in the tree of tree roots |
| 169 | tree_idscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#tree_id.: rootTreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootTreeObjectid., |
| 170 | |
| 171 | // Set the min and max to backref keys. The search will |
| 172 | // only send back this type of key now. |
| 173 | min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type.: rootItemKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItemKey., |
| 174 | max_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_type.: rootBackrefKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootBackrefKey., |
| 175 | |
| 176 | min_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_objectid.: firstFreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/firstFreeObjectid., |
| 177 | |
| 178 | // Set all the other params to the max, we'll take any objectid |
| 179 | // and any trans. |
| 180 | max_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_objectid.: lastFreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/lastFreeObjectid., |
| 181 | max_offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_offset.: maxUint64scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/maxUint64., |
| 182 | max_transidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_transid.: maxUint64scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/maxUint64., |
| 183 | |
| 184 | nr_itemsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#nr_items.: 4096, // just a big number, doesn't matter much |
| 185 | } |
| 186 | m := make(map[objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#]SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#) |
| 187 | for { |
| 188 | out, err := treeSearchRawscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/treeSearchRaw().(f, sk) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } else if len(out) == 0 { |
| 192 | break |
| 193 | } |
| 194 | for _, obj := range out { |
| 195 | switch obj.Typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Type. { |
| 196 | //case rootBackrefKey: |
| 197 | // ref := asRootRef(obj.Data) |
| 198 | // o := m[obj.ObjectID] |
| 199 | // o.TransID = obj.TransID |
| 200 | // o.ObjectID = obj.ObjectID |
| 201 | // o.RefTree = obj.Offset |
| 202 | // o.DirID = ref.DirID |
| 203 | // o.Name = ref.Name |
| 204 | // m[obj.ObjectID] = o |
| 205 | case rootItemKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItemKey.: |
| 206 | o := m[obj.ObjectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#ObjectID.] |
| 207 | o.RootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RootID. = uint64(obj.ObjectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#ObjectID.) |
| 208 | robj := asRootItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/asRootItem().(obj.Datascip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Data.).Decodescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_root_item_raw#Decode().() |
| 209 | o.fillFromItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#fillFromItem().(&robj) |
| 210 | m[obj.ObjectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#ObjectID.] = o |
| 211 | } |
| 212 | } |
| 213 | // record the mins in key so we can make sure the |
| 214 | // next search doesn't repeat this root |
| 215 | last := out[len(out)-1] |
| 216 | sk.min_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_objectid. = last.ObjectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#ObjectID. |
| 217 | sk.min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type. = last.Typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Type. |
| 218 | sk.min_offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_offset. = last.Offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Offset. + 1 |
| 219 | if sk.min_offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_offset. == 0 { // overflow |
| 220 | sk.min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type.++ |
| 221 | } else { |
| 222 | continue |
| 223 | } |
| 224 | if sk.min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type. > rootBackrefKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootBackrefKey. { |
| 225 | sk.min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type. = rootItemKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItemKey. |
| 226 | sk.min_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_objectid.++ |
| 227 | } else { |
| 228 | continue |
| 229 | } |
| 230 | if sk.min_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_objectid. > sk.max_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_objectid. { |
| 231 | break |
| 232 | } |
| 233 | } |
| 234 | // resolve paths |
| 235 | for id, v := range m { |
| 236 | if path, err := subvolidResolvescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolve().(f, id); err == ErrNotFoundscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/ErrNotFound. { |
| 237 | delete(m, id) |
| 238 | continue |
| 239 | } else if err != nil { |
| 240 | return m, fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.12 fmt/Errorf().("cannot resolve path for %v: %v", id, err) |
| 241 | } else { |
| 242 | v.Pathscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#Path. = path |
| 243 | m[id] = v |
| 244 | } |
| 245 | if filter != nil && !filter(v) { |
| 246 | delete(m, id) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return m, nil |
| 251 | } |
| 252 | |
| 253 | type SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo# struct { |
| 254 | RootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RootID. uint64 |
| 255 | |
| 256 | UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#UUID. UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/UUID# |
| 257 | ParentUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#ParentUUID. UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/UUID# |
| 258 | ReceivedUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#ReceivedUUID. UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/UUID# |
| 259 | |
| 260 | CTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#CTime. timescip-go gomod github.com/golang/go/src go1.12 time/.Timescip-go gomod github.com/golang/go/src go1.12 time/Time# |
| 261 | OTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#OTime. timescip-go gomod github.com/golang/go/src go1.12 time/.Timescip-go gomod github.com/golang/go/src go1.12 time/Time# |
| 262 | STimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#STime. timescip-go gomod github.com/golang/go/src go1.12 time/.Timescip-go gomod github.com/golang/go/src go1.12 time/Time# |
| 263 | RTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RTime. timescip-go gomod github.com/golang/go/src go1.12 time/.Timescip-go gomod github.com/golang/go/src go1.12 time/Time# |
| 264 | |
| 265 | CTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#CTransID. uint64 |
| 266 | OTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#OTransID. uint64 |
| 267 | STransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#STransID. uint64 |
| 268 | RTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RTransID. uint64 |
| 269 | |
| 270 | Pathscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#Path. string |
| 271 | } |
| 272 | |
| 273 | func (s *SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#) fillFromItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#fillFromItem().(it *rootItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#) { |
| 274 | s.UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#UUID. = it.UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#UUID. |
| 275 | s.ReceivedUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#ReceivedUUID. = it.ReceivedUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#ReceivedUUID. |
| 276 | s.ParentUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#ParentUUID. = it.ParentUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#ParentUUID. |
| 277 | |
| 278 | s.CTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#CTime. = it.CTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#CTime. |
| 279 | s.OTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#OTime. = it.OTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#OTime. |
| 280 | s.STimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#STime. = it.STimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#STime. |
| 281 | s.RTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RTime. = it.RTimescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#RTime. |
| 282 | |
| 283 | s.CTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#CTransID. = it.CTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#CTransID. |
| 284 | s.OTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#OTransID. = it.OTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#OTransID. |
| 285 | s.STransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#STransID. = it.STransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#STransID. |
| 286 | s.RTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RTransID. = it.RTransIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootItem#RTransID. |
| 287 | } |
| 288 | |
| 289 | func subvolSearchByUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByUUID().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, uuid UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/UUID#) (*SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#, error) { |
| 290 | id, err := lookupUUIDSubvolItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/lookupUUIDSubvolItem().(mnt, uuid) |
| 291 | if err != nil { |
| 292 | return nil, err |
| 293 | } |
| 294 | return subvolSearchByRootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByRootID().(mnt, id, "") |
| 295 | } |
| 296 | |
| 297 | func subvolSearchByReceivedUUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByReceivedUUID().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, uuid UUIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/UUID#) (*SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#, error) { |
| 298 | id, err := lookupUUIDReceivedSubvolItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/lookupUUIDReceivedSubvolItem().(mnt, uuid) |
| 299 | if err != nil { |
| 300 | return nil, err |
| 301 | } |
| 302 | return subvolSearchByRootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByRootID().(mnt, id, "") |
| 303 | } |
| 304 | |
| 305 | func subvolSearchByPathscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByPath().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, path string) (*SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#, error) { |
| 306 | if !filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/IsAbs().(path) { |
| 307 | path = filepathscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.12 `path/filepath`/Join().(mnt.Namescip-go gomod github.com/golang/go/src go1.12 os/File#Name().(), path) |
| 308 | } |
| 309 | id, err := getPathRootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/getPathRootID().(path) |
| 310 | if err != nil { |
| 311 | return nil, err |
| 312 | } |
| 313 | return subvolSearchByRootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByRootID().(mnt, id, path) |
| 314 | } |
| 315 | |
| 316 | func subvolidResolvescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolve().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, subvolID objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#) (string, error) { |
| 317 | return subvolidResolveSubscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolveSub().(mnt, "", subvolID) |
| 318 | } |
| 319 | |
| 320 | func subvolidResolveSubscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolveSub().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, path string, subvolID objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#) (string, error) { |
| 321 | if subvolID == fsTreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/fsTreeObjectid. { |
| 322 | return "", nil |
| 323 | } |
| 324 | sk := btrfs_ioctl_search_keyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#{ |
| 325 | tree_idscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#tree_id.: rootTreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootTreeObjectid., |
| 326 | min_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_objectid.: subvolID, |
| 327 | max_objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_objectid.: subvolID, |
| 328 | min_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#min_type.: rootBackrefKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootBackrefKey., |
| 329 | max_typescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_type.: rootBackrefKeyscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootBackrefKey., |
| 330 | max_offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_offset.: maxUint64scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/maxUint64., |
| 331 | max_transidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#max_transid.: maxUint64scip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/maxUint64., |
| 332 | nr_itemsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_search_key#nr_items.: 1, |
| 333 | } |
| 334 | results, err := treeSearchRawscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/treeSearchRaw().(mnt, sk) |
| 335 | if err != nil { |
| 336 | return "", err |
| 337 | } else if len(results) < 1 { |
| 338 | return "", ErrNotFoundscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/ErrNotFound. |
| 339 | } |
| 340 | res := results[0] |
| 341 | if objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#(res.Offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Offset.) != fsTreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/fsTreeObjectid. { |
| 342 | spath, err := subvolidResolveSubscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolveSub().(mnt, path, objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#(res.Offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Offset.)) |
| 343 | if err != nil { |
| 344 | return "", err |
| 345 | } |
| 346 | path = spath + "/" |
| 347 | } |
| 348 | backRef := asRootRefscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/asRootRef().(res.Datascip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Data.) |
| 349 | if backRef.DirIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootRef#DirID. != firstFreeObjectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/firstFreeObjectid. { |
| 350 | arg := btrfs_ioctl_ino_lookup_argsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_ino_lookup_args#{ |
| 351 | treeidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_ino_lookup_args#treeid.: objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#(res.Offsetscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/searchResult#Offset.), |
| 352 | objectidscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_ino_lookup_args#objectid.: backRef.DirIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootRef#DirID., |
| 353 | } |
| 354 | if err := iocInoLookupscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/iocInoLookup().(mnt, &arg); err != nil { |
| 355 | return "", err |
| 356 | } |
| 357 | path += arg.Namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/btrfs_ioctl_ino_lookup_args#Name().() |
| 358 | } |
| 359 | return path + backRef.Namescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/rootRef#Name., nil |
| 360 | } |
| 361 | |
| 362 | // subvolSearchByRootID |
| 363 | // |
| 364 | // Path is optional, and will be resolved automatically if not set. |
| 365 | func subvolSearchByRootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolSearchByRootID().(mnt *osscip-go gomod github.com/golang/go/src go1.12 os/.Filescip-go gomod github.com/golang/go/src go1.12 os/File#, rootID objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#, path string) (*SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#, error) { |
| 366 | robj, err := readRootItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/readRootItem().(mnt, rootID) |
| 367 | if err != nil { |
| 368 | return nil, err |
| 369 | } |
| 370 | info := &SubvolInfoscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#{ |
| 371 | RootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RootID.: uint64(rootID), |
| 372 | Pathscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#Path.: path, |
| 373 | } |
| 374 | info.fillFromItemscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#fillFromItem().(robj) |
| 375 | if path == "" { |
| 376 | info.Pathscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#Path., err = subvolidResolvescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/subvolidResolve().(mnt, objectIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/objectID#(info.RootIDscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SubvolInfo#RootID.)) |
| 377 | } |
| 378 | return info, err |
| 379 | } |