Path: blob/main/misc/far2l/files/patch-far2l_src_farwinapi.cpp
50018 views
--- far2l/src/farwinapi.cpp.orig 2025-10-26 08:39:52 UTC1+++ far2l/src/farwinapi.cpp2@@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF S3#include <fcntl.h>4#include <errno.h>5#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)6+#include <sys/disk.h>7#include <sys/mount.h>8#elif !defined(__HAIKU__)9#include <sys/statfs.h>10@@ -472,8 +473,8 @@ bool apiExpandEnvironmentStrings(const wchar_t *src, F11}1213BOOL apiGetVolumeInformation(const wchar_t *lpwszRootPathName, FARString *pVolumeName,14- DWORD64 *lpVolumeSerialNumber, LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags,15- FARString *pFileSystemName, FARString *pFileSystemMountPoint)16+ FARString *pDiskIdent, LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags,17+ FARString *pFileSystemName, FARString *pDeviceName, FARString *pFileSystemMountPoint)18{19struct statvfs svfs {};20const std::string &path = Wide2MB(lpwszRootPathName);21@@ -483,13 +484,9 @@ BOOL apiGetVolumeInformation(const wchar_t *lpwszRootP2223if (lpMaximumComponentLength)24*lpMaximumComponentLength = svfs.f_namemax;25- if (lpVolumeSerialNumber)26- *lpVolumeSerialNumber = (DWORD)svfs.f_fsid;27if (lpFileSystemFlags)28*lpFileSystemFlags = (DWORD)svfs.f_flag;2930- if (pVolumeName) {31- pVolumeName->Clear();32#if 033#if defined(FS_IOC_GETFSLABEL) && defined(FSLABEL_MAX)34int fd = open(path.c_str(), O_RDONLY);35@@ -502,13 +499,35 @@ BOOL apiGetVolumeInformation(const wchar_t *lpwszRootP36}37#endif38#endif39- }4041if (pFileSystemName) {42*pFileSystemName = MountInfo().GetFileSystem(path);43}44- if (*pFileSystemMountPoint) {45+ if (pFileSystemMountPoint) {46*pFileSystemMountPoint = MountInfo().GetFileSystemMountPoint(lpwszRootPathName);47+ }48+ // XXX: can we avoid calling GetFileSystemMountPoint() twice?49+ const std::string devname = MountInfo().GetFileSystemMountPoint(lpwszRootPathName, true);50+ if (pDeviceName) {51+ *pDeviceName = devname;52+ }53+ if (pDiskIdent) {54+ int fd = open(devname.c_str(), O_RDONLY);55+ if (fd != -1) {56+ char ident[DISK_IDENT_SIZE];57+ if (ioctl(fd, DIOCGIDENT, ident) != -1)58+ *pDiskIdent = ident;59+ close(fd);60+ }61+ }62+ if (pVolumeName) {63+ std::string reply{}, cmd{"fstyp -l " + devname};64+ if (POpen(reply, cmd.c_str())) {65+ const auto pos = reply.find(' ') + 1;66+ if (pos > 0) {67+ *pVolumeName = reply.substr(pos, reply.size() - pos - 1);68+ } //else pVolumeName->Clear();69+ } //else pVolumeName->Clear();70}7172return TRUE;737475