Files & File Systems: Crash Course Computer Science #20
Summary
TLDR本视频介绍了计算机文件的工作原理和组织方式。文件是数据的集合,可以是文本、音乐、图片或视频等类型。为了便于使用和理解,数据通常以某种方式组织,称为文件格式。例如,文本文件使用ASCII编码,而WAV文件则包含音频的元数据和样本数据。BMP文件存储图像,由像素组成,每个像素由红绿蓝三色值定义。计算机使用文件系统来存储和管理文件,文件系统通过目录文件记录文件的位置和大小,允许文件跨多个存储块分布,从而实现文件的动态扩展和收缩。此外,现代文件系统还支持文件的碎片整理,以及层次化存储结构,使得文件和文件夹可以按层次组织,便于管理和访问。视频以深入浅出的方式,让观众对文件系统有了基础的理解。
Takeaways
- 📚 文件系统是计算机组织和存储数据的方式,它允许数据以文件的形式存在。
- 📁 文件格式是文件内部数据的组织方式,常见的有文本文件(TXT)、音频文件(WAV)、图片文件(BMP)等。
- 🔢 计算机文件归根结底是由二进制数字组成的长列表,ASCII编码用于文本文件中字符的表示。
- 🎵 WAV文件是一种音频文件格式,它在文件的头部存储元数据,如比特率和声道信息。
- 🖼️ BMP文件是一种图像文件格式,由像素组成,每个像素由红色、绿色和蓝色的值混合而成。
- 📝 目录文件(Directory File)记录了存储设备上所有文件的位置和大小,类似于书籍的目录。
- 🔄 随着文件的增加,简单的背靠背存储方式会导致问题,因此现代文件系统采用块存储和文件跨多个块存储的方式。
- 🧩 文件系统允许文件大小的动态变化,通过分配和回收块来实现文件的扩展和缩减。
- 🗑️ 删除文件时,文件系统仅删除目录文件中的记录,实际数据并未立即被擦除,这是数据恢复的可能方式之一。
- 🔄 磁盘碎片整理(Defragmentation)是将分散的文件块重新排列,以便更高效地读取文件。
- 📁 现代文件系统采用分层结构,允许创建无限深度的文件和文件夹层次结构,这被称为分层文件系统。
- 📈 文件系统为用户抽象了底层存储介质的细节,使得数据管理更加直观和方便。
Q & A
什么是文件系统,它如何帮助计算机组织文件?
-文件系统是操作系统的一部分,用于管理和跟踪存储的文件。它允许计算机通过目录文件(Directory File)记录文件的位置和大小,从而帮助组织和访问存储设备上的文件。
为什么需要文件格式,它有什么作用?
-文件格式是数据在文件内部的组织方式。它允许数据以一种有用的和实用的方式被组织和解释。使用现有的标准文件格式(如JPEG和MP3)通常是最好的选择,因为它们定义了数据如何被编码和解码。
ASCII编码标准是如何帮助解释文本文件的?
-ASCII是一个字符编码标准,它将数字映射到字符。在文本文件中,每个字符都由一个数字表示,这个数字根据ASCII表映射到相应的字符,从而允许我们读取和理解文本内容。
WAV文件中的元数据是什么,它存储在哪里?
-元数据是关于数据的数据,它提供了文件的一些基本信息,比如比特率、音轨类型(单声道或立体声)。在WAV文件中,元数据存储在文件的头部(Header),位于实际音频数据之前。
在计算机中,位图(BMP)文件是如何存储图片的?
-位图文件通过像素(Pixels)来存储图片,每个像素由红色、绿色和蓝色的组合构成。这些颜色被称为加性原色,可以混合在一起在电子显示屏上创造出任何颜色。BMP文件同样以元数据开始,包括图像宽度、高度和颜色深度等关键值。
什么是目录文件,它在文件系统中扮演什么角色?
-目录文件是一种特殊类型的文件,它记录了存储设备上其他文件的位置。它包含所有文件的名称、文件扩展名和关于这些文件的元数据,如创建和最后修改时间、所有者以及文件的读写权限。目录文件对于文件系统的运作至关重要,因为它帮助系统知道文件存储的具体位置。
文件系统如何允许文件跨越多个存储块?
-现代文件系统通过将文件分割成多个块(Chunks),并将这些块存储在不同的存储块中,允许文件跨越多个存储块。目录文件需要存储每个文件所占用的块的列表,从而实现对这些分散的块的管理。
什么是文件碎片化,它对存储设备有什么影响?
-文件碎片化是指文件被分散存储在存储设备的不同块中,这是文件创建、删除和修改的不可避免的副产品。对于许多存储技术来说,碎片化可能导致性能下降,因为读取文件时可能需要在存储设备上多次寻址和跳转。
什么是文件的去碎片化,它如何帮助提高存储性能?
-去碎片化是计算机通过复制数据,使得文件的块在存储中顺序相连并正确排序的过程。这个过程可以减少读取文件时的寻址和跳转次数,从而提高文件的访问速度和存储设备的整体性能。
什么是层次文件系统,它与平铺文件系统有何不同?
-层次文件系统是一种文件系统,它允许通过文件夹(目录)将相关的文件组织在一起,并且可以创建无限深度的文件夹层次结构。与平铺文件系统不同,层次文件系统不将所有文件存储在单一目录下,而是允许通过多级目录结构来组织文件。
文件系统如何帮助普通用户操作和管理数据?
-文件系统提供了一种抽象层,允许用户以文件和目录的形式来思考和操作数据,而不是直接与存储设备的原始位操作。这样,用户可以更容易地打开文件、组织数据,而不需要了解底层存储技术的细节。
Outlines
📁 文件系统与文件格式入门
本段介绍了计算机文件系统的基础知识。首先解释了文件格式的重要性,如文本文件(TXT)和音频文件(WAV),并详细描述了如何通过ASCII和元数据解码这些文件的数据。接着,介绍了位图(BMP)文件格式,讲述了如何通过RGB值来表达图像的颜色信息。最后,强调了不同文件格式的通用性,即它们本质上都是二进制形式存储的数字序列。
🖥️ 计算机文件系统的进阶知识
这一段深入讨论了文件系统的高级概念。从简单的顺序存储转变为更复杂的文件系统,如平面文件系统和分块存储。解释了目录文件的角色和如何管理文件的存储位置和元数据。还讨论了文件碎片化和整理碎片化的必要性,以及现代文件系统如何允许文件跨多个块存储并动态调整大小。最后,介绍了层次化文件系统,这种系统通过文件夹组织文件,使得文件管理更为高效和系统化。
🌐 文件系统的层次结构和数据管理
本段探讨了文件系统的层次结构和如何管理和访问存储在不同层次的文件和文件夹。通过“根”目录文件的例子,展示了文件和子目录的管理方式。详细描述了如何在不同目录间移动文件而不需要重新安排存储块,凸显了文件系统在现代计算中的抽象和便利性。最后,强调了文件系统不仅是技术性的存储管理,它也为用户提供了更直观和易于操作的数据组织方式。
Mindmap
Keywords
💡数据存储
💡文件系统
💡文件格式
💡元数据
💡像素
💡目录文件
💡块存储
💡文件碎片
💡层次文件系统
💡根目录
💡ASCII编码
Highlights
文件系统允许计算机存储和组织数百万、数十亿甚至数万亿比特的数据,即使在没有电源的情况下也能持续很长时间。
计算机文件是存储相关数据的“大数据块”,可以是文本文件、音乐文件、照片和视频等类型。
文件格式是组织文件内部数据的方式,如JPEG和MP3是常用的标准格式。
TXT文件使用ASCII字符编码标准,将数字转换为可读文本。
WAV文件存储音频数据,需要知道比特率和音轨信息等元数据才能正确读取。
元数据是关于数据的数据,它存储在文件的头部,位于实际数据之前。
数字麦克风通过多次采样声音压力,每个样本可以表示为一个数字。
BMP文件存储图片,由像素组成,每个像素是红绿蓝三种颜色的组合。
BMP文件的元数据包括图像宽度、高度和颜色深度等关键值。
文件系统将数据存储在块中,留有额外空间以便于修改,称为松弛空间。
现代文件系统允许文件被分成多个块并存储在多个块中,从而实现文件的动态扩展和缩减。
目录文件(Directory File)记录了其他文件的位置和大小,类似于书籍的目录。
删除文件时,实际上是从目录文件中移除条目,而不是真正擦除存储中的数据。
文件碎片化是文件创建、删除和修改的不可避免的副产品,影响存储技术的读取效率。
文件系统通过碎片整理将文件块重新排列,提高文件读取速度。
分层文件系统允许无限深度的文件和文件夹层次结构,便于管理和移动文件。
文件系统是操作系统的一部分,负责管理和跟踪存储的文件,提供了一种抽象层,隐藏了存储介质上原始的比特。
文件系统允许用户(非程序员)操作数据,如打开文件和组织文件,预示着系列后续将讨论的内容。
Transcripts
Hi, I'm Carrie Anne, and welcome to Crash Course Computer Science!
Last episode we talked about data storage, how technologies like magnetic tape and hard
disks can store millions, billions and trillions of bits of data, for long durations, even
without power.
Which is perfect for recording “big blobs” of related data, what are more commonly called
computer files.
You’ve no doubt encountered many types, like text files, music files, photos and videos.
Today, we’re going to talk about how files work, and how computers keep them all organized
with File Systems.
INTRO
It’s perfectly legal for a file to contain arbitrary, unformatted data, but it’s most
useful and practical if the data inside the file is organized somehow.
This is called a file format.
You can invent your own, and programmers do that from time to time, but it’s usually
best and easiest to use an existing standard, like JPEG and MP3.
Let’s look at some simple file formats.
The most straightforward are T-X-T files, which contain, surprise, text.
Like all computer files, this is just a huge list of numbers, stored as binary.
If we look at the raw values of a T-X-T file in storage, it would look something like this:
We can view this as decimal numbers instead of binary, but that still doesn’t help us
read the text.
The key to interpreting this data is knowing that T-X-T files use ASCII, a character encoding
standard we discussed way back in Episode 4.
So, in ASCII, our first value, 72, maps to the capital letter H. And in this way, we
decode the whole file.
Let’s look at a more complicated example: a WAVE File – also called a WAV – which
stores audio.
Before we can correctly read the data, we need to know some information, like the bit
rate and whether it’s a single track or stereo.
Data, about data, is called meta data.
This metadata is stored at the front of the file, ahead of any actual data, in what’s
known as a Header.
Here’s what the first 44 bytes of a WAV file looks like.
Some parts are always the same, like where it spells out W-A-V-E.
Other parts contain numbers that change depending on the data contained within.
The audio data comes right behind the metadata, and it’s stored as a long list of numbers.
These values represent the amplitude of sound captured many times per second, and if you
want a primer on sound, check out our video all about it in Crash Course Physics.
Link in the dobblydoo.
As an example, let’s look at a waveform of me saying: "hello!" Hello!
Now that we’ve captured some sound, let’s zoom into a little snippet.
A digital microphone, like the one in your computer or smartphone, samples the sound
pressure thousands of times.
Each sample can be represented as a number.
Larger numbers mean higher sound pressure, what’s called amplitude.
And these numbers are exactly what gets stored in a WAVE file!
Thousands of amplitudes for every single second of audio!
When it’s time to play this file, an audio program needs to actuate the computer's speakers
such that the original waveform is emitted.
“Hello!”
So, now that you’re getting the hang of file formats, let’s talk about bitmaps or
B-M-Ps, which store pictures.
On a computer, PICtures are made up of little tiny square ELements called pixels.
Each pixel is a combination of three colors: red, green and blue.
These are called additive primary colors, and they can be mixed together to create any
other color on our electronic displays.
Now, just like WAV files, BMPs start with metadata, including key values like image
width, image height, and color depth.
As an example, let’s say the metadata specified an image 4 pixels wide, by 4 pixels tall,
with a 24-bit color depth - that’s 8-bits for red, 8-bits for green, and 8-bits for blue.
As a reminder, 8 bits is the same as one byte.
The smallest number a byte can store is 0, and the largest is 255.
Our image data is going to look something like this:
Let’s look at the color of our first pixel.
It has 255 for its red value, 255 for green and 255 for blue.
This equates to full intensity red, full intensity green and full intensity blue.
These colors blend together on your computer monitor to become white.
So our first pixel is white!
The next pixel has a Red-Green-Blue, or RGB value of 255, 255, 0.
That’s the color yellow!
The pixel after that has a RGB value of 0,0,0 - that’s zero intensity everything, which is black.
And the next one is yellow.
Because the metadata specified this was a 4 by 4 image, we know that we’ve reached
the end of our first row of pixels.
So, we need to drop down a row.
The next RGB value is 255,255,0 – yellow again.
Okay, let’s go ahead and read all the pixels in our 4x4 image… tada!
A very low resolution pac-man!
Obviously this is a simple example of a small image, but we could just as easily store this
image in a BMP.
I want to emphasize again that it doesn’t matter if it’s a text file, WAV, BMP, or
fancier formats we don’t have time to discuss, like ZIPs and PPTs.
Under the hood, they’re all the same: long lists of numbers, stored as binary, on a storage device.
File formats are the key to reading and understanding the data inside.
Now that you understand files a little better, let’s move on to how computers go about
storing them.
Even though the underlying storage medium might be a strip of tape, a drum, a disk,
or integrated circuits... hardware and software abstractions let us think of storage as a
long line of little buckets that store values.
In the early days, when computers only performed one computation like calculating artillery
range tables – the entire storage operated like one big file.
Data started at the beginning of storage, and then filled it up in order as output was
produced, up to the storage capacity.
However, as computational power and storage capacity improved, it became possible, and
useful, to store more than one file at a time.
The simplest option is to store files back-to-back.
This can work... but how does the computer know where files begin and end?
Storage devices have no notion of files – they’re just a mechanism for storing lots of bits.
So, for this to work, we need to have a special file that records where other ones are located.
This goes by many names, but a good general term is Directory File.
Most often, it’s kept right at the front of storage, so we always know where to access it.
Location zero!
Inside the Directory File are the names of all the other files in storage.
In our example, they each have a name, followed by a period, and end with what’s called
a File Extension, like “BMP” or “WAV”.
Those further assist programs in identifying file types.
The Directory File also stores metadata about these files, like when they were created and
last modified, who the owner is, and if it can be read, written or both.
But most importantly, the directory file contains where these files begin in storage, and how
long they are.
If we want to add a file, remove a file, change a filename, or similar, we have to update
the information in the Directory File.
It’s like the Table of Contents in a book, if you make a chapter shorter, or move it
somewhere else, you have to update the table of contents, otherwise the page numbers won’t match!
The Directory File, and the maintenance of it, is an example of a very basic File System,
the part of an Operating System that manages and keep track of stored files.
This particular example is a called a Flat File System, because they’re all stored at one level.
It’s flat!
Of course, packing files together, back-to-back, is a bit of a problem, because if we want
to add some data to let’s say “todo.txt”, there’s no room to do it without overwriting
part of “carrie.bmp”.
So modern File Systems do two things.
First, they store files in blocks.
This leaves a little extra space for changes, called slack space.
It also means that all file data is aligned to a common size, which simplifies management.
In a scheme like this, our Directory File needs to keep track of what block each one
is stored in.
The second thing File Systems do, is allow files to be broken up into chunks and stored
across many blocks.
So let’s say we open “todo.txt”, and we add a few more items then the file becomes
too big to be saved in its one block.
We don’t want to overwrite the neighboring one, so instead, the File System allocates
an unused block, which can accommodate extra data.
With a File System scheme like this, the Directory File needs to store not just one block per
file, but rather a list of blocks per file.
In this way, we can have files of variable sizes that can be easily expanded and shrunk,
simply by allocating and deallocating blocks.
If you watched our episode on Operating Systems, this should sound a lot like Virtual Memory.
Conceptually it’s very similar!
Now let’s say we want to delete “carrie.bmp”.
To do that, we can simply remove the entry from the Directory File.
This, in turn, causes one block to become free.
Note that we didn’t actually erase the file’s data in storage, we just deleted the record of it.
At some point, that block will be overwritten with new data, but until then, it just sits there.
This is one way that computer forensic teams can “recover” data from computers even
though people think it has been deleted. Crafty!
Ok, let’s say we add even more items to our todo list, which causes the File System
to allocate yet another block to the file, in this case, recycling the block freed from
carrie.bmp.
Now our “todo.txt” is stored across 3 blocks, spaced apart, and also out of order.
Files getting broken up across storage like this is called fragmentation.
It’s the inevitable byproduct of files being created, deleted and modified.
For many storage technologies, this is bad news.
On magnetic tape, reading todo.txt into memory would require seeking to block 1, then fast
forwarding to block 5, and then rewinding to block 3 – that’s a lot of back and forth!
In real world File Systems, large files might be stored across hundreds of blocks, and you
don’t want to have to wait five minutes for your files to open.
The answer is defragmentation!
That might sound like technobabble, but the process is really simple, and once upon a
time it was really fun to watch!
The computer copies around data so that files have blocks located together in storage and
in the right order.
After we’ve defragged, we can read our todo file, now located in blocks 1 through 3, in
a single, quick read pass.
So far, we’ve only been talking about Flat File Systems, where they’re all stored in
one directory.
This worked ok when computers only had a little bit of storage, and you might only have a
dozen or so files.
But as storage capacity exploded, like we discussed last episode, so did the number
of files on computers.
Very quickly, it became impractical to store all files together at one level.
Just like documents in the real world, it’s handy to store related files together in folders.
Then we can put connected folders into folders, and so on.
This is a Hierarchical File System, and its what your computer uses.There are a variety
of ways to implement this, but let’s stick with the File System example we’ve been
using to convey the main idea.
The biggest change is that our Directory File needs to be able to point not just to files,
but also other directories.
To keep track of what’s a file and what’s a directory, we need some extra metadata.
This Directory File is the top-most one, known as the Root Directory.
All other files and folders lie beneath this directory along various file paths.
We can see inside of our “Root” Directory File that we have 3 files and 2 subdirectories:
music and photos.
If we want to see what’s stored in our music directory, we have to go to that block and
read the Directory File located there; the format is the same as our root directory.
There’s a lot of great songs in there!
In addition to being able to create hierarchies of unlimited depth, this method also allows
us to easily move around files.
So, if we wanted to move “theme.wav” from our root directory to the music directory,
we don’t have to re-arrange any blocks of data.
We can simply modify the two Directory Files, removing an entry from one and adding it to another.
Importantly, the theme.wav file stays in block 5.
So that’s a quick overview of the key principles of File Systems.
They provide yet another way to move up a new level of abstraction.
File systems allow us to hide the raw bits stored on magnetic tape, spinning disks and
the like, and they let us think of data as neatly organized and easily accessible files.
We even started talking about users, not programmers, manipulating data, like opening files and
organizing them, foreshadowing where the series will be going in a few episodes.
I’ll see you next week.
浏览更多相关视频
The Ultimate Guide to File Organization: 5 Systems You Must Know
Introduction to windows | computer software language learning | Computer Education for All
GridFinity Parametric File #freecad #cad #design
Basic Computing Skills - Orientation
Computer and System Software | Types of Computer and System Software
Block reference parts of images just like text with Obsidian Excalidraw
5.0 / 5 (0 votes)