From 66f0b2839a3ada6f65f136015f50497dc6438fdb Mon Sep 17 00:00:00 2001 From: Richard Goedeken Date: Thu, 29 Jun 2023 08:40:53 -0700 Subject: [PATCH] Treat extended attribute ltfs.mediaPool.name like a virtual extended attribute. Allow both reading and writing, and store in MAM data. (#388) --- src/libltfs/xattr.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libltfs/xattr.c b/src/libltfs/xattr.c index 40544105..1588a619 100644 --- a/src/libltfs/xattr.c +++ b/src/libltfs/xattr.c @@ -266,7 +266,6 @@ static inline bool _xattr_is_worm_ea(const char *name) static inline bool _xattr_is_stored_vea(const char *name) { if (strcmp(name, "ltfs.spannedFileOffset") && - strcmp(name, "ltfs.mediaPool.name") && strcasestr(name, "ltfs.permissions.") != name && strcasestr(name, "ltfs.hash.") != name) { @@ -480,6 +479,7 @@ static bool _xattr_is_virtual(struct dentry *d, const char *name, struct ltfs_vo || ! strcmp(name, "ltfs.mediaIndexPartitionAvailableSpace") || ! strcmp(name, "ltfs.mediaEncrypted") || ! strcmp(name, "ltfs.mediaPool.additionalInfo") + || ! strcmp(name, "ltfs.mediaPool.name") || ! strcmp(name, "ltfs.driveEncryptionState") || ! strcmp(name, "ltfs.driveEncryptionMethod") /* Vendor specific EAs */ @@ -787,9 +787,18 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons ret = _xattr_get_cartridge_capacity(&cap, &cap.remaining_ip, &val, name, vol); } else if (! strcmp(name, "ltfs.mediaEncrypted")) { ret = xattr_get_string(tape_get_media_encrypted(vol->device), &val, name); + } else if (! strcmp(name, "ltfs.mediaPool.name")) { + char *tmp=NULL; + ret = tape_get_media_pool_info(vol, &val, &tmp); + if (tmp) + free(tmp); + if (ret < 0 || !val) + ret = -LTFS_NO_XATTR; } else if (! strcmp(name, "ltfs.mediaPool.additionalInfo")) { char *tmp=NULL; ret = tape_get_media_pool_info(vol, &tmp, &val); + if (tmp) + free(tmp); if (ret < 0 || !val) ret = -LTFS_NO_XATTR; } else if (! strcmp(name, "ltfs.driveEncryptionState")) { @@ -1225,6 +1234,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va free(v); } else if (! strcmp(name, "ltfs.mediaPool.additionalInfo")) { ret = tape_set_media_pool_info(vol, value, size, false); + } else if (! strcmp(name, "ltfs.mediaPool.name")) { + ret = tape_set_media_pool_info(vol, value, size, true); } else ret = -LTFS_NO_XATTR; @@ -1443,15 +1454,6 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size } } - if (!strcmp(name, "ltfs.mediaPool.name")) { - ret = tape_set_media_pool_info(vol, value, size, true); - if (ret < 0) { - releasewrite_mrsw(&d->meta_lock); - goto out_unlock; - } - write_idx = true; - } - /* Set extended attribute */ ret = xattr_do_set(d, name, value, size, xattr); if (ret < 0) {