How to determine the file size. Drives on magnetic disks


  Probably, you often see on the site a signature indicating the size of the file. This indicator is not signed by anyone. This question is solved by writing a function on php. As a result, it will output a line like:

File size: 2.3 MB
  It is very convenient in case of downloading any materials from the site. So, let's get started.

Create a PHP function that determines the size of the file

  The function will be fairly simple and understandable. It uses three built-in functions:

file_exists  - check for the presence of the specified file or directory.

filesize  - determine the size of the file. Returns the result in bytes. If the file is larger than 2 GB, then, depending on the server, it can output an incorrect result.

round  - built-in function, shortening the displayed value to an integer and one-tenth after the separating character of the point.
  The function checks the presence of the file itself, then sequentially tries to determine how large the file is - if more than 1024 bytes, then the result should be output in MB, if more than 1024 MB, then output in GB. And at the end of each stage, the built-in function round rounds the result from a set of digits to an integer value and one-tenth with a separating character.

Now create the function file. Such files are usually held in a separate folder. for example function.

PHP code  (file function.php)

  // arguments of the function will be the path to the file
  function get_filesize ($ file)
{
   // go file
   if (! file_exists ($ file)) return "File not found";
   // Now define the file size in several steps
   $ filesize = filesize ($ file);
   // If the size is greater than 1 KB
   if ($ filesize\u003e 1024)
{

   // If the file size is larger than Kilobyte
   // it's better to display it in Megabytes. We recalculate in Mb
   if ($ filesize\u003e 1024)
{
   $ filesize = ($ filesize / 1024);
   // And if the file is more than 1 megabyte, then we check
   // Is it more than 1 Gigabyte
   if ($ filesize\u003e 1024)
{
   $ filesize = ($ filesize / 1024);

   return $ filesize. "GB";
}
   else
{
   $ filesize = round ($ filesize, 1);
   return $ filesize. "MB";
}
}
   else
{
   $ filesize = round ($ filesize, 1);
   return $ filesize. "KB";
}
}
   else
{
   $ filesize = round ($ filesize, 1);
   return $ filesize. "byte";
}
}
?>
  We created the function. Then it remains to apply it.

PHP code

  include_once "function / function.php"; // we connect a file with function

  // insert a path or a variable with a path for processing by its function
  $ size = get_filesize ("images / photo.jpg");
  echo "File size: ". $ size.""; // print the result with the size
?>
  All is ready! Use your health!
Thank you for attention! And good luck in your work!

Modern applications not only take up more and more space on the media, but also require quite a noticeable amount of free space on your hard drive for your correct operation. For example, operating system  Windows 7, occupying a whole DVD-5 disk (it's 4.7 GB), will not be able to work properly if after installation it will not be available 16 GB on the drive, and the 64-bit version needs 20 GB already. This means that the owner of the computer system must somehow solve the problem with disk space. Most often, one more hDD  or a device based on the technology of SSD, and the problem is temporarily removed. However, having come home with a recently purchased device, the user may have to choose the file system: FAT32 or NTFS. Despite the fact that the times when manufacturers supplied drives to the market without preliminary formatting, are in the past, it is impossible to guess which requirements the user is proposing to "breakdown" the device. In particular, many newcomers are surprised to discover that there is a notion of " maximum size  file FAT32 ". About what it is, we'll talk.

File system

In order for those most cherished gigabytes hard drive  or flash drives became "visible" in the operating system, a file system must be created on the drive.

The purpose of this operation is to create on the surface of the disk a special magnetic marking and a special area where the service information will be stored. After that it becomes possible to work with files on the this drive. The file system stores information about the location of files on the disk and manages their writing / reading. The most famous are NTFS and FAT32. The second was introduced by Microsoft in 1996, so it's no surprise that there is a file size limit of FAT32. NTFS is more sophisticated, but it also has a number of features.

When the maximum file size is important FAT32

Imagine a simple situation: the user purchased a new flash drive with a capacity of more than 8 GB and began to copy files to it. If their size (not total!) Does not exceed 4 GB, then it may never know that there is some maximum size of the FAT32 file. However, if you need to copy a 4 GB file to a drive with such a file system, the operating system displays a message that the operation can not be completed. Change of name, moving to the directory, changing attributes - all is useless. The reason for this is simple: the maximum file size of FAT32 is exactly the same 4 GB. In other words, the usual ISO image of a favorite toy can not be written to a drive with FAT32. The restriction is caused by the peculiarity of addressing the chains of clusters and just bypassing it will not succeed.

How to record large file  FAT32: Solutions

Nevertheless, there is a solution. And a few. The easiest way is to reformat the drive into another file system, which can work with files larger than 4 GB. It can be a solution either from the Linux world: systems like EXT, or NTFS and exFAT from Microsoft. The latter does not work in all operating systems. In Windows, you need to open "My Computer", call up the properties of the desired drive and start "Formatting". This operation will erase all data from it, so you must first save important files. It is possible to convert file systems one to another without deleting data. This can be done using the utility convert.exe, which is part of the operating system, or third-party program  Partition Magic. However, if you want to write a large file, and the time to change file system  no, then you need to use any archiver (RAR, ZIP), selecting the archiving of the file without compression, but with a breakdown into smaller files. For example, in WinRAR the order of the action is the following: launching the program, specifying the file in it, the "Add" command, where you should activate the "Divide into volumes" item. Obviously, the size should not be more than 4,095 MB. Then such a broken file consisting of several, you can write to the drive, and unpack the addressee.

If we talk about information in general, it is measured in BYTES. The measurement in these units began in the distant 1956. Then this magnitude was quite enough. To make it clearer, what size is being discussed, I will tell you that 1 byte = 1 character. With the development of technology, the amount of information increased, and it was not convenient to measure a large amount of information in BYTES. Then came the prefixes KILO-BYTE (KB), MEGA-BYTE (MB), GIGA-BYTE (GB), TERA-BYTE (TB), etc.

To understand how large or small these values ​​are, I will give this comparison:
  - 1KB (one kilobyte) = 1024 bytes, and this is the amount of information in about one A4-size printed sheet;

- 1MB (one megabyte) = 1024 kilobytes, and this is the amount of information already a decent volume of pages for 600-700!

- 1GB (one gigabyte) = 1024 megabytes, and this is already a whole library of 1024 books of 600 pages!

- 1TB (one terabyte) = 1024 gigabytes, this amount of information is comparable to the average European library, which contains about 8 million books. For example, in the Russian State Library there are about 43 million units.

Now let's compare the volume and type of information about media on which this information can be recorded.

- A diskette with a capacity of 1.44MB. Once a floppy disk was the main available medium digital information, t. To write down on it it was possible really much that. Now, floppy disks are used mainly by the accountant to store electronic keys and signatures. The reason is banal - there is not enough storage space on the diskette modern information. On the floppy disk, you can record one, two photos taken on the mobile phone  with a 3 megapixel camera; five, ten Word, Excel documents.

- Flash drive with a capacity of 1GB. The most convenient to date media information. The capacity of a flash drive 1GB I took for the multiplicity of the account, but in general at the time of writing the article there are 64GB flash drives!
  What can be written on a flash drive with a capacity of 1GB: one film, relatively good quality; about 200 music files in the format.mp3; about 200 photos of good quality; a lot of documents and programs of small size.

- A CD with a capacity of 700MB. On CD, you can record: one movie in .avi format, in a relatively good quality; about 150 music files in the format.mp3; about 150 photos of good quality; a lot of documents and programs of small size.

DVD disc  with a capacity of 4.7GB. A DVD disc can be recorded: one movie in DVD or HDTV format; 4-5 films in .avi format of good quality; about 1200 music files in the format.mp3; about 1000 photos of good quality; oooochen many documents and programs.

- Winchester with a capacity of 120GB. Here, not to paint up to the documents, I will compare it with the number of films that can be written to such a hard drive. So, on a hard drive with a capacity of 120 GB, you can burn 25 movies in DVD or HDTV quality!

Now let's take turns analyzing how to determine the size of a disk, file or folder.
  In Windows, you can determine the size of a file, folder or disk in the CONDUCTOR. Run "Explorer" by clicking TWO times LEFT clicking on the "My Computer" icon on the desktop or using the "Win + E" shortcut.

If you, for example, want to know how much free space left on the disk, in particular on the flash drive, then click the RIGHT mouse button over the image of the removable disk, usually it is signed as "Removable Disk (F :)" or "Flash Drive Name (F :)", as in the picture:

So, click the RIGHT mouse button on the image of the removable disk - flash drive and choose the menu item "Properties" in the menu that appears at the bottom. Then the window opens:


  Here you can see how much is occupied (highlighted in blue), how many are free (highlighted in pink) and how much total disk space.

Thus, you can find the rest of the free space, not only on the flash drive, but also on any removable or logical drive  hard drive.

The scheme for determining the size of a file or folder is the same as for a disk. Those. find the desired file or folder on the disk, click on it with the RIGHT mouse button and look at the "Properties".


  There will be all the necessary information.


  If you want to know the size of a group of files or folders, then you must select them and do the same operations, i.e. click the RIGHT mouse button on one of the selected files or folders, select "Properties" and see the size.

Yes, the second part of the lesson does not quite fall into the rubric "Computer Basics", but nevertheless. If you have any questions, you can always ask them in the comments.

In NMD, a similar NML is provided for the possibility of sequential access to information. A magnetic disk storage device combines several serial access devices, and the reduction in the data retrieval time is ensured by the independence of access to the record from its location relative to other records.

The design of NDA is more complicated than that of NML, and therefore, their cost is higher. In NMD as a storage medium, a package of magnetic disks (or plotters) fixed on a single rod is used around which they rotate at a constant speed. The surface of a magnetic disk covered with a ferromagnetic layer is called a working one.

The first such devices were equipped with removable MD packages. Inserted into a casing with a hermetically sealed tray, they formed compact storage units, called volumes. The most common volumes were 7.25, 29.100 MB. The operator put the package on the spindle of the device, removed the casing (the package was automatically fixed on the spindle) and included the engines of the package promotion. After reaching a certain rotation speed, the magnetic heads ("combs") are inserted into the space between the discs of the package.

The principle of placing the heads is floating, since they are held at the necessary distance from the surface of the disk by the divergent airflows that arise when the packet rotates. In the future, either full-contact heads (flexible disks) or mechanically fixed in vacuum at a certain distance from the surface ("hard drive") were mainly used. Attempts to use liquid media (various oils) to ensure the necessary placement of heads were not successful.



The number of magnetic heads is equal to the number of working surfaces on one package of disks. If the package consists of 11 disks, the access mechanism consists of 10 holders with two magnetic heads on each of them. The collection of tracks that are accessed at a fixed position of the block is called a cylinder. Holders of magnetic heads are united in a single unit in such a way as to ensure their synchronous movement along all the cylinders. Fixing the block of access mechanism to any of the cylinders, you can make the transition from one track to another of this cylinder by electronic switching heads.

Any operation of reading (writing) information from (on) a magnetic disk consists of three stages. At the first stage, the magnetic head is mechanically supplied to the track containing the required data. In the second stage, the moment is waiting until the required record is in the magnetic head zone. At the third stage, the process of information exchange between the computer and the magnetic disk is realized. Thus, the total time spent on a write-read operation consists of the sum of the search times of the corresponding track, the wait for the record input (the so-called rotational delay time), and the exchange with the computer. The maximum value of the rotational delay time is equal to the time during which the complete revolution of the magnetic disk is performed.

There are several ways to physically store data on the hard disk. Ordinary hard disks  use a "vertical" display. Data is written first on one cylinder from top to bottom, then the heads go to another cylinder and so on. With a "horizontal" display, data is first recorded sequentially from the cylinder to the cylinder on the surface of one disc, then also on the surface of the next plotter, and so on. This method is better suited for recording a continuous high-speed data stream, for example, when recording live video.

The mechanism is hermetically sealed in a housing with a partial vacuum inside. This design is often called the main disk unit (HDA). The environment inside the hard drive must be cleaned of dust, for this purpose, air entering the HDA is passed through special filters. An engine that rotates a disc at a constant speed, measured in revolutions per minute (rpm), turns on when power is applied to the disk and remains on until the power is removed.

Between the plates, there is a distance for the reading / writing head mounted on the end of the moving arm. The head is removed from the plate by a fraction of a millimeter. In the first systems this distance was 0.2 millimeters, for today it is reduced to 0.07 millimeters. Therefore, the slightest contamination can destroy the head, bringing it closer to the disc, and also damage the magnetic coating of the disc.

The heads are designed to touch the disc only after it stops, when the power is turned off. When the rotation speed decreases, the air flow weakens and, when it stops completely, the head gently touches the surface of the disc. The touch point is called Landing Zone LZ (land zone), which is specifically designed to touch the head and does not contain data.

When a disk is formatted at the physical level, it is divided into sectors and tracks. Physically the tracks are located one above the other and form cylinders, which are then divided into sectors. There are 512 bytes in one sector. The sector is the minimum unit for measuring the size of a disk. All hard disks have spare sectors, which are used by its control scheme, if defective sectors are found on the disk.

In theory, external cylinders may contain more data, since they have a longer circumference. However, in drives that do not use the zone recording method, all cylinders contain the same amount of data, despite the fact that the circumference of the outer cylinders can be twice that of the internal ones. As a result, the space of external tracks is lost, since it is used extremely inefficiently.

The process of controlling the recording density is called precompensation. To compensate for the different recording densities, the Zone Bit Recording method is used, where the whole disk space is divided into zones (eight or more), each of which usually contains 20 to 30 cylinders with the same number of sectors.

In the zone located on the outer radius (the lowest zone), a greater number of sectors per track (120-96) is recorded. To the center of the disk, the number of sectors decreases and in the oldest region reaches 64-56. The capacity hard disks  can be increased by approximately 30%.

With the increase in the write density on the disc, difficulties arise in detecting peaks of analog signals coming from the magnetic heads. Recently, the PRLM method (Partial Response Maximum Likelihood), which uses a special algorithm for digital filtering of the input signal, has been used to eliminate this disadvantage.

For installation disk drives  at the system unit  special mounting compartments are provided. The overall dimensions, corresponding to the horizontal and vertical dimensions of the hard drive, are standardized and characterized by size or form factor.

In the past, the disk controller did not have time to read physically contiguous sectors, so the disk needed to complete a complete revolution before the next logical sector could be considered. To reduce the waiting time, an interlace factor is used (for example, N: 1, when one sector is read and N is skipped). In modern HDDs, an integrated controller and its own data buffer are used to improve performance.

When the computer accesses the data, the operating system uses the FAT (File Allocation Table) table to determine their position on the disk (in which sector, on which track the requested data can be found).

The HDD can contain from 256 KB to 8 MB of cache, which stores all information about sectors, cylinders and provides it if necessary.

Disc plates can be out of balance due to temperature changes. During multimedia playback, this can be expressed as sudden pauses in the sound and lost video frames. To prevent this, the device constantly conducts temperature calibration.

Each file and each folder with files occupies a certain place on the computer. That is, all files and folders have a volume, in other words, weight or size.

We are used to such concepts as grams and kilograms, meters and kilometers. The computer also has its own units of measurement. In them we will measure files and folders. In other words, we will determine how much "weight" a particular file or folder. This "weight" is calculated in bytes, kilobytes, megabytes and gigabytes.

And now we will pass to practice. Look at this size chart:

This is a very simple scheme. It stands for:

1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB

And now in more detail:

In one KB (kilobyte) there are 1024 bytes
  In one MB (megabyte) there are 1024 KB (kilobytes)
  In one GB (gigabyte) are 1024 MB (megabytes)

Why do we need size? For example, to determine whether we can write a file / folder to a disk or a USB flash drive.

In order for us to determine this, we need to know how much information is placed on a disk or a USB flash drive. We use the scheme:

Flash drive - from 1 GB

CD drive - 700 MB

DVD drive - from 4 GB

The standard capacity of a DVD is 4.7 GB. Still there are two-sided DVD disks. This means that the recording can be from two sides - with one and with the second. These disks have a capacity of 9.4 GB. Also there are two-layer discs, but they are less common. These disks have the following volumes: 1-sided 2-layer - 8.5 GB; 2-sided 2-ply - 17.1 Gb.

How to know the size of a file or folder

To find out the size of a file or folder with files, hover the cursor (arrow) on it and hold it for a few seconds. A small window will appear with the characteristics of the file or folder. As you can see in the picture, this characteristic shows the size:

If nothing appears when hovering on a file or folder, then right-click on that file or folder. From the opened list, select the "Properties" item. A window will open in which the size of this file or folder will be specified.

And now we will practice to determine the size:

Task:

We have a file of 30 MB in size. Can we burn it to disk? Flash drive 1 GB in size?

Decision:

700 MB is placed on the CD. Our file is 30 MB in size. 700 MB is more than 30 MB. Conclusion: the file will fit on a CD.

The DVD disc is 4.7 GB. One Gigabyte equals 1024 megabytes. That is, on a DVD disc about 5000 MB are placed. And 5000 MB is much more than 30 MB. Conclusion: our DVD file will fit.

We are given a flash drive 1 GB in size. One GB contains 1024 MB. 1024 more than 30. Conclusion: on the USB flash drive 1 GB file will fit.

Do you like the article? Share with friends: