| 1 |
//go:build linux |
| 2 |
|
| 3 |
package desync |
| 4 |
|
| 5 |
import ( |
| 6 |
"os" |
| 7 |
"path" |
| 8 |
|
| 9 |
"golang.org/x/sys/unix" |
| 10 |
) |
| 11 |
|
| 12 |
// createDeviceNode creates a device node confined to the extraction root. |
| 13 |
// The parent directory is opened through the os.Root handle (which refuses to |
| 14 |
// traverse any symlink escaping the root) and the node is created relative to |
| 15 |
// that directory fd with a base name that has no path separators, so it |
| 16 |
// cannot escape Root. |
| 17 |
func (fs *LocalFS) createDeviceNode(r *os.Root, n NodeDevice) error { |
| 18 |
df, err := r.Open(path.Dir(n.Name)) |
| 19 |
if err != nil { |
| 20 |
return err |
| 21 |
} |
| 22 |
defer df.Close() |
| 23 |
return unix.Mknodat(int(df.Fd()), path.Base(n.Name), FilemodeToStatMode(n.Mode)|0666, int(mkdev(n.Major, n.Minor))) |
| 24 |
} |