Long and Short file names

Source: Internet
Author: User
Tags time and date

There is a 8.3 rule for file naming.
8 indicates the file name, which is *** in *****. xxx ***
This part cannot exceed 8 characters. in DOS, if it exceeds 8 characters, it will not be recognized. the following XXX is an extension and does not have to be three characters. For example, the extension of a webpage file can be HTM or HTML, but it is used internationally to using three characters for extension.
"File name. Extension" is the complete name of a file.
A file name is used to identify a single file. It refers to an individual, and the extension identifies a type of file.


Storage of long file names in FAT32 system)

16:22:11 | category: real-time operating system | report | font size subscription

One important feature of FAT32 is its full support for long file names. The long file name is still recorded in the directory.

 

The system automaticallyCreates a short file name for all long file names.So that the corresponding data can be addressable with long file names or short file names. The OS or program that does not support long file names will ignore the long file name fields that it deems invalid, OS or programs that support long file names record and edit them with long file names as explicit items and hide short file names.


When creating a long file name, the system automatically adds the corresponding short file name. The general principle is as follows:
(1) Add "~ 1 "to form a short file name with the same extension.
(2) If the file name already exists, the symbol "~ "The number increases until 5.
(3) If the file name is "~ "If the number is 5, the short file name only uses the first two letters of the long file name. The last four letters of the short file name are generated by mathematical manipulation of the remaining letters of the long file name, followed by the suffix "~ 1 "until the end (if necessary, or other numbers to avoid repeated file names ).
(4) If there are characters that the old OS or program cannot read, replace them "_"

 

Short file directory. The parameter meanings are shown in Table 14:

Table 14 Definition of the 32-byte representation of the FAT32 short file directory item
Byte offset (hexadecimal) Bytes Definition
0x0 ~ 0x7 8 File Name
0x8 ~ 0xa 3 Extension
0xb * 1 Attribute bytes 00000000 (read/write)
00000001 (read-only)
00000010 (hidden)
00000100 (system)
00001000 (volume label)
00010000 (subdirectory)
00100000 (archive)
0xc 1 System reservation
0xd 1 Creation Time in 10 ms
0xe ~ 0xf 2 File Creation Time
0x10 ~ 0x11 2 File creation date
0x12 ~ 0x13 2 Last file access date
0x14 ~ 0x15 2 16-bit high of the starting cluster number of the file
0x16 ~ 0x17 2 Last file modification time
0x18 ~ 0x19 2 Last file modification date
0x1a ~ 0x1b 2 16-bit lower starting cluster number of the file
0x1c ~ 0x1f 4 Indicates the object length.

* This field cannot be set to 0fh in the short file directory. If it is set to 0fh, the directory segment is a long file name directory segment.

 

The implementation of a long file name depends on the attribute byte whose directory offset is 0xb. When the attribute of this byte is read-only, hidden, system, or volume label, that is, its value is 0fh, DOS and Win32 will regard it as illegal and ignore its existence. This is the basis for the existence of long file names.

 

Set the 0xb value of the Directory item to 0f. The others are defined by the system. Windows 9x, Windows 2000, and XP generally support a long file name of no more than 255 characters.

 

The system splits the long file name into 13 characters, each of which occupies a directory. Therefore, a file may need multiple directory items. In this case, the directory items of long file names are arranged in reverse order in the directory table to prevent confusion with other file names.
Characters in long file names are encoded in unicode format (a huge improvement). Each character occupies 2 bytes of space. Its Directory item definition is shown in table 15.

Table 15 definition of the 32-byte representation of the FAT32 long file directory item
Byte offset
(Hexadecimal)
Bytes Definition
0x0 1 Attribute byte meaning 7 Reserved unused
6 1 indicates the last directory item of the long file.
5 Reserved unused
4 Ordinal number
3
2
1
0
0x1 ~ 0xa 10 Long file name Unicode code ①
0xb 1 Long file name directory entry flag, value: 0fh
0xc 1 System reservation
0xd 1 Check value (calculated based on the short file name)
0xe ~ 0x19 12 Long file name Unicode code ②
0x1a ~ 0x1b 2 File start cluster number (usually 0 currently)
0x1c ~ 0x1f 4 Long file name Unicode code ③

 

 

When the system stores long file names, it always fills in the directory items of long file names in reverse order, and then keeps up with the corresponding short file names.As shown in table 15, long file names do not store the file start cluster, file size, various time and date attributes of the corresponding file. These attributes of a file are still stored in the short file name directory. A long file name always corresponds to the corresponding short file name. The short file name can be read without a long file name, however, if a long file name does not have a corresponding short file name, it will be ignored by any system. Therefore, short file names are crucial.

In an environment where long file names are not supported, changes to the file name and extension fields in short file names (including deletion, because deletion is to rewrite e5h for the first character) will make the long file name useless.

 

(How does a long file name correspond to a short file name? Depends only on the positional relationship between them ?)

The relationship between long file names and short file names depends on the positional relationship between them. In fact, the checksum of 0xd bytes of a long file name plays an important role. This checksum is obtained by using an operation of 11 characters of the short file name. The system determines whether the long file name matches the short file name based on the corresponding algorithm. This algorithm is not easy to use. We use a C program to explain it.
Assume that the file name contains 11 characters to form a string shortname [], and the checksum is represented by chknum. The process is as follows:

Int I, j, chknum = 0;
For (I = 11; I> 0; I --)
Chksum = (chksum & 1 )? 0x80: 0) + (chksum> 1) + shortname [J ++];

If the checksum calculated by the short file name is not the same as the 0xd offset in the long file name. The system will not match them anyway.
Based on the definition of the Directory item by the long file name and short file name, plus the number and link of the cluster, read data on FAT32 is easy.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.