mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	zpool: allow relative vdev paths
`zpool create` won't let you use relative paths to disks. This is annoying when you want to do: zpool create tank ./diskfile But have to do.. zpool create tank `pwd`/diskfile This fixes it. Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Tony Hutter <hutter2@llnl.gov> Closes #17042
This commit is contained in:
		
							parent
							
								
									ab3db6d15d
								
							
						
					
					
						commit
						ece35e0e66
					
				| @ -57,6 +57,7 @@ int | ||||
| zfs_resolve_shortname(const char *name, char *path, size_t len) | ||||
| { | ||||
| 	const char *env = getenv("ZPOOL_IMPORT_PATH"); | ||||
| 	char resolved_path[PATH_MAX]; | ||||
| 
 | ||||
| 	if (env) { | ||||
| 		for (;;) { | ||||
| @ -85,6 +86,20 @@ zfs_resolve_shortname(const char *name, char *path, size_t len) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/*
 | ||||
| 	 * The user can pass a relative path like ./file1 for the vdev. The path | ||||
| 	 * must contain a directory prefix like './file1' or '../file1'.  Simply | ||||
| 	 * passing 'file1' is not allowed, as it may match a block device name. | ||||
| 	 */ | ||||
| 	if ((strncmp(name, "./", 2) == 0 || strncmp(name, "../", 3) == 0) && | ||||
| 	    realpath(name, resolved_path) != NULL) { | ||||
| 		if (access(resolved_path, F_OK) == 0) { | ||||
| 			if (strlen(resolved_path) + 1 <= len) { | ||||
| 				if (strlcpy(path, resolved_path, len) < len) | ||||
| 					return (0); /* success */ | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return (errno = ENOENT); | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tony Hutter
						Tony Hutter