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