Recent

Author Topic: Function to determine if filesystem is casesensitive?  (Read 11945 times)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Function to determine if filesystem is casesensitive?
« on: August 16, 2007, 12:54:44 pm »
Hi,

Is there some predifined function that tells me if the OS I compile for uses a case-sensitive file system (*nix) or not (DOS, Win)

Telling Linux and Windows apart is piece of cake if I want to do this myself.
However I don't know about MAC, OS/2 etc.

Bart


Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: RE: Function to determine if filesystem is casesensitive
« Reply #2 on: August 17, 2007, 05:41:51 pm »
Quote from: "Vincent"
http://lazarus-ccr.sourceforge.net/docs/rtl/system/filenamecasesensitive.html

Quote from: "wiki"
FileNameCaseSensitive is True if case is important when using filenames on the current OS.

However, on Win32 using fpc 2.0.4 (or 2.1.4) this returns True, which seems wrong.

It is false for OS2 and go32v2 (in 2.1.4).

Should I bugrep this, or is this by design?

Bart

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Re: RE: Function to determine if filesystem is casesensi
« Reply #3 on: August 17, 2007, 06:41:40 pm »
Report it, the docs might need some clarification.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Function to determine if filesystem is casesensitive?
« Reply #4 on: August 17, 2007, 07:11:57 pm »

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Function to determine if filesystem is casesensitive?
« Reply #5 on: January 27, 2015, 12:16:15 pm »
Years after this thread was created, I am still searching the answer of the same question.
If I understood the description of FileNameCaseSensitive correctly, it determines the kind of the OS, and then wrongly assumes what if the systems is i.e. if OS is Linux, the filesystem is case sensitive, while actually a FAT volume could be accessed. This explains why  FileNameCaseSensitive takes no parameters.
Actually I need a function like  FileNameCaseSensitive (folder: string); which can tell me if a folder is located on a case-sensitive file system. Does anyone know a ready solution, or I shall find a way to struggle with something like this: http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/determining-filesystem-type.html   ?
« Last Edit: January 27, 2015, 12:18:02 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Basile B.

  • Guest
Re: Function to determine if filesystem is casesensitive?
« Reply #6 on: January 27, 2015, 12:33:09 pm »
dirty solution:

1/ choose an existing file, put its name in a string named fname.
2/ set a boolean according to the case of the last char in fname.
3/ if up then fname = lowcase of fname else fname = upcase of fname.
4/ try to create a filStream with the transformed fname.
5/ if stream created then FS is not CS else if an exception is raised then FS is CS.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Function to determine if filesystem is casesensitive?
« Reply #8 on: January 27, 2015, 11:18:56 pm »
There are also some border cases, like using NTFS on both Windows and Linux. It is a case sensitive FS, but Windows ignores filename case; OTOH, Linux can as usual create and read files on a NTFS volume which differ only in case...
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Function to determine if filesystem is casesensitive?
« Reply #9 on: January 29, 2015, 09:43:15 am »
 

dirty solution:
...
It took me a minute to find out this won't work. Shall I say why or shall I leave it as a riddle? ;)




Someone was looking for solution in .NET. http://stackoverflow.com/questions/430256/how-do-i-determine-whether-the-filesystem-is-case-sensitive-in-net
Thanks, here is the solution for Windows:
Code: [Select]
function GetFolderFS(Folder: String): String;
var
 Drive: String;
 fileSystemName, volumeName: array[0..99] of char;
 fileSystemFlags, serialNo, maxFilenameLength: DWORD;
begin
 Drive:= Copy(Folder,1,3);
 ShowMessage(Drive);
 if DirectoryExistsUTF8(Drive) then
 begin
   GetVolumeInformation(PChar(Drive), volumeName, SizeOf(volumeName), @serialNo, maxFilenameLength, fileSystemFlags, fileSystemName, SizeOf(fileSystemName));
   Result:=fileSystemName;
   end
 else
 Result:='NODEV';
end;
But, could s.o. check what will this function return on a EXT drive, mounted on Windows. My linux is on a Loop drive, so I could not mount it. I formatted a SD card to EXT4, but ext2fsd could not mount it.



There are also some border cases, like using NTFS on both Windows and Linux. It is a case sensitive FS, but Windows ignores filename case; OTOH, Linux can as usual create and read files on a NTFS volume which differ only in case...
Unfortunately you are right. And because it is documented, this irresponsible implementation of NTFS support under Linux is not a bug, but a feature. So when s.o. develops an app, this one should take care to prevent creation of multiple files with the same name. I tried it, all other files just disappear when saving the only accessible file in Windows.

For Linux I suppose I could simply use mount and parse the output.
Similar for Mac OS- diskutil should do.

Android should be a problem- some dependencies of mount are not installed by default, according to this.
Does Lazarus run on some other OSes?
« Last Edit: January 29, 2015, 09:53:31 am by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Function to determine if filesystem is casesensitive?
« Reply #10 on: May 06, 2016, 09:22:59 pm »
Much later: here is what I found: FAT32 is case-insensitive for Latin filenames and case-sensitive for Cyrillic filenames, when run on Android :P
This is Android 4.1.2 running on a Samsung.
I wonder if this bug is Samsung only and if it is fixed in later Android versions.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Function to determine if filesystem is casesensitive?
« Reply #11 on: May 07, 2016, 04:13:54 am »
Much later: here is what I found: FAT32 is case-insensitive for Latin filenames and case-sensitive for Cyrillic filenames, when run on Android :P

I hate to disagree with you based on a guess.

Your system mounted this FAT32 partition in a code page that is not Cyrillic, that's why you see it as:
"case-insensitive for Latin filenames and case-sensitive for Cyrillic filenames"

IIRC, FAT32 has two entries for each file name: one used to store the short file name (compatible with DOS: 8.3 format) which is case insensitive (usually is stored in upper case - or lower case I don't remember), while the other is for long file names (up to ~255 chars) that preserves the case but is not used by the OS to find, sort.. etc.

Check your FAT32 code page using mount command in Terminal Emulator.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Function to determine if filesystem is casesensitive?
« Reply #12 on: May 07, 2016, 01:11:18 pm »
...Your system mounted this FAT32 partition in a code page that is not Cyrillic, that's why you see it as:
"case-insensitive for Latin filenames and case-sensitive for Cyrillic filenames"
8.3 filenames are used for legacy reasons and long file names (LFN) shall be stored in UTF-16.
So there should not be a reason to have a problem because of the mounting codepage.
In Windows XP a file ΔΞ and another file δξ (Greek) cannot be created in a single folder. Such is the case with ШЩ and шщ (Kirilik).

EDIT: Same on LUbuntu: Latin filenames are not case-sensitive, cyrilic and greek ones are case-sensitive.
Guess what happens when you mount the same drive on Windows after that? Exactly loss of data  :'(

Edit2: This is my post №666  >:D
« Last Edit: May 07, 2016, 08:54:27 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Function to determine if filesystem is casesensitive?
« Reply #13 on: May 07, 2016, 11:39:51 pm »
8.3 filenames are used for legacy reasons and long file names (LFN) shall be stored in UTF-16.
So there should not be a reason to have a problem because of the mounting codepage.

Check this page and specially these options: codepage, nonumtail, check, shortname.

In Windows XP a file ΔΞ and another file δξ (Greek) cannot be created in a single folder. Such is the case with ШЩ and шщ (Kirilik).

As I mentioned before, Windows converts to lower (or upper) case for short names before storing a file. If Windows is able to convert between ΔΞ and δξ then it will not allow these two names (as they are one). The same applies to ШЩ and шщ. Probably Windows uses WideString internally to do that conversion.

EDIT: Same on LUbuntu: Latin filenames are not case-sensitive, cyrilic and greek ones are case-sensitive.
Guess what happens when you mount the same drive on Windows after that? Exactly loss of data  :'(

Are you sure?  :o

Edit2: This is my post №666  >:D

Lol

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Function to determine if filesystem is casesensitive?
« Reply #14 on: May 11, 2016, 07:10:31 pm »
Check this page and specially these options: codepage, nonumtail, check, shortname.
All parameters mentioned by you are related to shortnames only.

EDIT: Same on LUbuntu: Latin filenames are not case-sensitive, cyrilic and greek ones are case-sensitive.
Guess what happens when you mount the same drive on Windows after that? Exactly loss of data 
Are you sure? 

Definitely. For example (tested):
   1. Create two files with same longnames (only case is different) in Linux/Android on FAT on NTFS. They occur to be created with different 8.3 names.
   2. Open the same drive in Windows
      3. Edit one of the files and save it-> The other file is gone
   or
     3. Delete one of the files-> The other file is gone too.


As I mentioned, both files have different 8.3 names.
I have tried to access two folders using the 8.3 names, but it occurs that only one is accessible  :o
« Last Edit: May 11, 2016, 07:13:50 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

 

TinyPortal © 2005-2018