posixutils-rs icon indicating copy to clipboard operation
posixutils-rs copied to clipboard

[Draft] Improve file to support modern os

Open rishadbaniya opened this issue 1 year ago • 2 comments

this is a very early draft

rishadbaniya avatar May 01 '24 16:05 rishadbaniya

Great start. One early file organization comment: Prefer to follow the ls style of:

  1. toplevel source in $category/src/$utility.rs
  2. secondary sources in $category/src/$utility_util/ directory.,

jgarzik avatar May 01 '24 16:05 jgarzik

through many research and scouring(the code of linux file utility v5.41) i've come to following high level conclusions

To make a "file" utility means to "abide" by the code of the linux "file" utility of a certain version(not the man page specification of magic)

Let me clarify what i mean: Let's start with what's a compiled magic file

It's simply nothing but a file that has those lines of of text based magic file laid in a a C struct called struct magic and placed in a binary file

So to parse the binary magic file means to simply parse it to the struct magic, parsing the binary magic file is as simple as that and for each version of "file" utility this struct changes(it's size, it has new fields)...for example for 5.45 and 5.41 the binary magic file isn't compatible with each other. Why? Because the structure of the struct magic has been changed and having a supporting every single version is very painful as we need to be up to date with the "file" utility of as it's responsible for creating those compiled magic files

the complexity however comes in the raw magic file, the specification is not the "man page" itself but rather the code, without the code writing the "file" utility is absolutely impossible i.e parsing the raw magic file.

So, here' some details of this file utility:

It's planning to parse binary magic file and the text based magic file supported by file 5.41 as it's the version currently being used in OS X

rishadbaniya avatar May 01 '24 16:05 rishadbaniya

Referenced permanently in issue #144, so closing this PR.

jgarzik avatar Jun 22 '24 00:06 jgarzik