Skip to content

Commit d609cf6

Browse files
committed
Implement get_filesystem_type on macOS and Linux.
1 parent 45fc515 commit d609cf6

7 files changed

Lines changed: 184 additions & 2 deletions

File tree

core/io/dir_access.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ void DirAccess::_bind_methods() {
672672
ClassDB::bind_method(D_METHOD("set_include_hidden", "enable"), &DirAccess::set_include_hidden);
673673
ClassDB::bind_method(D_METHOD("get_include_hidden"), &DirAccess::get_include_hidden);
674674

675+
ClassDB::bind_method(D_METHOD("get_filesystem_type"), &DirAccess::get_filesystem_type);
676+
675677
ClassDB::bind_method(D_METHOD("is_case_sensitive", "path"), &DirAccess::is_case_sensitive);
676678
ClassDB::bind_method(D_METHOD("is_equivalent", "path_a", "path_b"), &DirAccess::is_equivalent);
677679

doc/classes/DirAccess.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@
213213
[b]Note:[/b] When used on a [code]res://[/code] path in an exported project, only the files included in the PCK at the given folder level are returned. In practice, this means that since imported resources are stored in a top-level [code].godot/[/code] folder, only paths to [code].gd[/code] and [code].import[/code] files are returned (plus a few other files, such as [code]project.godot[/code] or [code]project.binary[/code] and the project icon). In an exported project, the list of returned files will also vary depending on [member ProjectSettings.editor/export/convert_text_resources_to_binary].
214214
</description>
215215
</method>
216+
<method name="get_filesystem_type" qualifiers="const">
217+
<return type="String" />
218+
<description>
219+
Returns file system type name of the current directory's disk. Returned values are uppercase strings like [code]NTFS[/code], [code]FAT32[/code], [code]EXFAT[/code], [code]APFS[/code], [code]EXT4[/code], [code]BTRFS[/code], and so on.
220+
[b]Note:[/b] This method is implemented on macOS, Linux, Windows and for PCK virtual file system.
221+
</description>
222+
</method>
216223
<method name="get_next">
217224
<return type="String" />
218225
<description>

drivers/unix/dir_access_unix.cpp

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#include <fcntl.h>
4141
#include <sys/ioctl.h>
4242
#include <sys/stat.h>
43+
#ifdef __linux__
44+
#include <sys/statfs.h>
45+
#endif
4346
#include <sys/statvfs.h>
4447
#include <cerrno>
4548
#include <cstdio>
@@ -516,7 +519,166 @@ uint64_t DirAccessUnix::get_space_left() {
516519
}
517520

518521
String DirAccessUnix::get_filesystem_type() const {
522+
#ifdef __linux__
523+
struct statfs fs;
524+
if (statfs(current_dir.utf8().get_data(), &fs) != 0) {
525+
return "";
526+
}
527+
switch (fs.f_type) {
528+
case 0x0000adf5:
529+
return "ADFS";
530+
case 0x0000adff:
531+
return "AFFS";
532+
case 0x5346414f:
533+
return "AFS";
534+
case 0x00000187:
535+
return "AUTOFS";
536+
case 0x00c36400:
537+
return "CEPH";
538+
case 0x73757245:
539+
return "CODA";
540+
case 0x28cd3d45:
541+
return "CRAMFS";
542+
case 0x453dcd28:
543+
return "CRAMFS";
544+
case 0x64626720:
545+
return "DEBUGFS";
546+
case 0x73636673:
547+
return "SECURITYFS";
548+
case 0xf97cff8c:
549+
return "SELINUX";
550+
case 0x43415d53:
551+
return "SMACK";
552+
case 0x858458f6:
553+
return "RAMFS";
554+
case 0x01021994:
555+
return "TMPFS";
556+
case 0x958458f6:
557+
return "HUGETLBFS";
558+
case 0x73717368:
559+
return "SQUASHFS";
560+
case 0x0000f15f:
561+
return "ECRYPTFS";
562+
case 0x00414a53:
563+
return "EFS";
564+
case 0xe0f5e1e2:
565+
return "EROFS";
566+
case 0x0000ef53:
567+
return "EXTFS";
568+
case 0xabba1974:
569+
return "XENFS";
570+
case 0x9123683e:
571+
return "BTRFS";
572+
case 0x00003434:
573+
return "NILFS";
574+
case 0xf2f52010:
575+
return "F2FS";
576+
case 0xf995e849:
577+
return "HPFS";
578+
case 0x00009660:
579+
return "ISOFS";
580+
case 0x000072b6:
581+
return "JFFS2";
582+
case 0x58465342:
583+
return "XFS";
584+
case 0x6165676c:
585+
return "PSTOREFS";
586+
case 0xde5e81e4:
587+
return "EFIVARFS";
588+
case 0x00c0ffee:
589+
return "HOSTFS";
590+
case 0x794c7630:
591+
return "OVERLAYFS";
592+
case 0x65735546:
593+
return "FUSE";
594+
case 0xca451a4e:
595+
return "BCACHEFS";
596+
case 0x00004d44:
597+
return "FAT32";
598+
case 0x2011bab0:
599+
return "EXFAT";
600+
case 0x0000564c:
601+
return "NCP";
602+
case 0x00006969:
603+
return "NFS";
604+
case 0x7461636f:
605+
return "OCFS2";
606+
case 0x00009fa1:
607+
return "OPENPROM";
608+
case 0x0000002f:
609+
return "QNX4";
610+
case 0x68191122:
611+
return "QNX6";
612+
case 0x6b414653:
613+
return "AFS";
614+
case 0x52654973:
615+
return "REISERFS";
616+
case 0x0000517b:
617+
return "SMB";
618+
case 0xff534d42:
619+
return "CIFS";
620+
case 0x0027e0eb:
621+
return "CGROUP";
622+
case 0x63677270:
623+
return "CGROUP2";
624+
case 0x07655821:
625+
return "RDTGROUP";
626+
case 0x74726163:
627+
return "TRACEFS";
628+
case 0x01021997:
629+
return "V9FS";
630+
case 0x62646576:
631+
return "BDEVFS";
632+
case 0x64646178:
633+
return "DAXFS";
634+
case 0x42494e4d:
635+
return "BINFMTFS";
636+
case 0x00001cd1:
637+
return "DEVPTS";
638+
case 0x6c6f6f70:
639+
return "BINDERFS";
640+
case 0x0bad1dea:
641+
return "FUTEXFS";
642+
case 0x50495045:
643+
return "PIPEFS";
644+
case 0x00009fa0:
645+
return "PROC";
646+
case 0x534f434b:
647+
return "SOCKFS";
648+
case 0x62656572:
649+
return "SYSFS";
650+
case 0x00009fa2:
651+
return "USBDEVICE";
652+
case 0x11307854:
653+
return "MTD_INODE";
654+
case 0x09041934:
655+
return "ANON_INODE";
656+
case 0x73727279:
657+
return "BTRFS";
658+
case 0x6e736673:
659+
return "NSFS";
660+
case 0xcafe4a11:
661+
return "BPF_FS";
662+
case 0x5a3c69f0:
663+
return "AAFS";
664+
case 0x5a4f4653:
665+
return "ZONEFS";
666+
case 0x15013346:
667+
return "UDF";
668+
case 0x444d4142:
669+
return "DMA_BUF";
670+
case 0x454d444d:
671+
return "DEVMEM";
672+
case 0x5345434d:
673+
return "SECRETMEM";
674+
case 0x50494446:
675+
return "PID_FS";
676+
default:
677+
return "";
678+
}
679+
#else
519680
return ""; //TODO this should be implemented
681+
#endif
520682
}
521683

522684
bool DirAccessUnix::is_hidden(const String &p_name) {

drivers/windows/dir_access_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ String DirAccessWindows::get_filesystem_type() const {
362362
&dwFileSystemFlags,
363363
szFileSystemName,
364364
sizeof(szFileSystemName)) == TRUE) {
365-
return String::utf16((const char16_t *)szFileSystemName);
365+
return String::utf16((const char16_t *)szFileSystemName).to_upper();
366366
}
367367

368368
ERR_FAIL_V("");

editor/editor_file_system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3660,7 +3660,7 @@ EditorFileSystem::EditorFileSystem() {
36603660

36613661
// This should probably also work on Unix and use the string it returns for FAT32 or exFAT
36623662
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
3663-
using_fat32_or_exfat = (da->get_filesystem_type() == "FAT32" || da->get_filesystem_type() == "exFAT");
3663+
using_fat32_or_exfat = (da->get_filesystem_type() == "FAT32" || da->get_filesystem_type() == "EXFAT");
36643664

36653665
scan_total = 0;
36663666
ResourceSaver::set_get_resource_id_for_path(_resource_saver_get_resource_id_for_path);

platform/macos/dir_access_macos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class DirAccessMacOS : public DirAccessUnix {
5252
virtual bool is_hidden(const String &p_name) override;
5353
virtual bool is_case_sensitive(const String &p_path) const override;
5454

55+
virtual String get_filesystem_type() const override;
56+
5557
virtual bool is_bundle(const String &p_file) const override;
5658
};
5759

platform/macos/dir_access_macos.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@
3434

3535
#include "core/config/project_settings.h"
3636

37+
#include <sys/mount.h>
3738
#include <cerrno>
3839

3940
#import <AppKit/NSWorkspace.h>
4041
#import <Foundation/Foundation.h>
4142

43+
String DirAccessMacOS::get_filesystem_type() const {
44+
struct statfs fs;
45+
if (statfs(current_dir.utf8().get_data(), &fs) != 0) {
46+
return "";
47+
}
48+
return String::utf8(fs.f_fstypename).to_upper();
49+
}
50+
4251
String DirAccessMacOS::fix_unicode_name(const char *p_name) const {
4352
String fname;
4453
if (p_name != nullptr) {

0 commit comments

Comments
 (0)