Skip to content

Commit d569264

Browse files
lundmanclaude
andcommitted
libzfs: dynamically report auto-assigned drive letter as temporary property
When a pool is imported with driveletter=- (auto-assign), zfs_prop_get() now checks the live mount table via libzfs_mnttab_find() each time the driveletter property is queried. If the dataset is mounted on a letter that differs from the stored value (or the stored value is "-"), the actual letter is returned with source=ZPROP_SRC_TEMPORARY so it appears as "temporary" in "zfs get driveletter" output without permanently writing the letter back to the property. Signed-off-by: Jorgen Lundman <lundman@lundman.net> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 36e0492 commit d569264

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

lib/libzfs/libzfs_dataset.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,43 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
30273027
zcp_check(zhp, prop, val, NULL);
30283028
break;
30293029

3030+
#ifdef _WIN32
3031+
case ZFS_PROP_DRIVELETTER:
3032+
/*
3033+
* Read the stored property first. Then dynamically check
3034+
* the mount table: if the dataset is currently mounted on a
3035+
* drive letter that differs from the stored value (or the
3036+
* stored value is the auto-assign default "-"), report the
3037+
* actual live letter with source=temporary. This way
3038+
* "zfs get driveletter" is always useful without permanently
3039+
* changing the property.
3040+
*/
3041+
str = getprop_string(zhp, prop, &source);
3042+
if (str == NULL)
3043+
return (-1);
3044+
(void) strlcpy(propbuf, str, proplen);
3045+
zcp_check(zhp, prop, 0, str);
3046+
{
3047+
struct mnttab mntent;
3048+
if (libzfs_mnttab_find(zhp->zfs_hdl, zhp->zfs_name,
3049+
&mntent) == 0 && mntent.mnt_mountp[1] == ':') {
3050+
char actual = (char)tolower(
3051+
(unsigned char)mntent.mnt_mountp[0]);
3052+
char stored = (char)tolower(
3053+
(unsigned char)propbuf[0]);
3054+
if (stored == '-' || actual != stored) {
3055+
propbuf[0] = actual;
3056+
propbuf[1] = ':';
3057+
propbuf[2] = '\0';
3058+
if (src)
3059+
*src = ZPROP_SRC_TEMPORARY;
3060+
return (0);
3061+
}
3062+
}
3063+
}
3064+
break;
3065+
#endif /* _WIN32 */
3066+
30303067
default:
30313068
switch (zfs_prop_get_type(prop)) {
30323069
case PROP_TYPE_NUMBER:

0 commit comments

Comments
 (0)