How does the operating system recognize the end of a text file?

For example, there is a text file called "Hello.txt"

Hello World!

Then how does the operating system (I use MS-DOS) recognize the end of this text file? Is any character or symbol hidden after "!" which indicates the end of the file?

+6
source share
1 answer

If you are using MS-Dos, then there is some chance that there is a special character at the end of the line. MS-Dos was obtained from Tim Paterson QDos, who wrote it as compatible as possible with the then dominant CP / M. OS for 8-bit machines, it only tracks the file size by counting the number of disk sectors used by the file. Which made the file size always a multiple of 128 bytes.

This requires a hack to indicate the real end of the text file, since it can be located in the middle of the sector, he used the control character Ctrl + Z (character code 0x1A). This required an implementation of the runtime language to delete it again and declare the end of the file when it encounters a character. Ctrl + Z is not completely forgotten, it still works when you type it in the Windows console to complete the input. Compare with Ctrl + D in a Unix terminal.

Whether it really is present in the file depends on which program created the file. Which should be the MS-Dos program, as well as to add Ctrl + Z. This, of course, is not required. Paterson improved CP / M to remove some of his limitations, which greatly facilitated the availability of a much larger address space (1 MB vs 64 KB), MS-Dos tracks the actual number of bytes in a file. Thus, it can always reliably indicate the true end of the file. This is probably the most accurate answer to your question.

Ancient history by the way, invest your time wisely.

+3
source

All Articles