Question

In: Computer Science

When a user tries to write a file, the file system needs to detect if that...

When a user tries to write a file, the file system needs to detect if that file is a directory so that it can restrict writes to maintain the directory’s internal consistency. Given a file’s name, how would you design NTFS to keep track of whether each file is a regular file or a directory?

Solutions

Expert Solution

With the help of MASTER FILE TABLE the NTFS can identify the track of the files that either it is regular files or directory. When a unique record about the files is created in a special file. A unique record helps to locate a files possibly scattered clusters.

The NTFS always tries to identify the contiguous storage space which can hold the all files related to the project.

In the NTFS file system, a file can always keeps the same file ID until it can be erased. When you replace the one file with another file without changing their file ID then by using the ReplaceFile function.

The following code can justify the statement that how to get operation system file handle and then use it to get file ID. Once you can generate the file ID, you can keep track a file.

To test the code, create a new application and paste the code with the filename extension .cs

Then add a “File1.txt” file to the project you required to track and set it’s copy to the output directory and check the behavior of the new file directory. After saving the file run the file with the given project name.

Then you can choose the folder and rename or change the location of the file. Then update the path of the file and observed that the file ID has not been different. So after this process yo may have to enter the empty string to eliminate  the program.

using System;
using System.Collections.Generic;
using System.File;
using System.IO;
using System.Runtime.Services;
using Microsoft.Win32.SafeHandles;

namespace Filechange
{
    class Program
    {
        struct BY_HANDLE_FILE_INFORMATION
        {
            public uint FileAttribute;
            public System.Runtime.Services.ComTypes.FILETIME CreationTime;
            public System.Runtime.Services.ComTypes.FILETIME LastAccessTime;
            public System.Runtime.Services.ComTypes.FILETIME LastWriteTime;
            public uint VolumeSerialNumber;
            public uint FileSizeHigh;
            public uint FileSizeLow;
            public uint NumberOfLinks;
            public uint FileIndexHigh;
            public uint FileIndexLow;
        }
        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern bool GetFileInformationByHandle(SafeFileHandle pFile, out BY_HANDLE_FILE_INFORMATION lpFileInformation);

        static void Main(string[] args)
        {
            string fileName = "File1.txt";
            while (!string.IsNullOrEmpty(fileName))
            {
                FileStream strem = File.Open(fileName, FileMode.Open);
                BY_HANDLE_FILE_INFORMATION pInfo = new BY_HANDLE_FILE_INFORMATION();
                GetFileInformationByHandle(strem.SafeFileHandle, out pInfo);
                Console.WriteLine("File Name: " + fileName);
                Console.WriteLine("File ID: " + pInfo.FileIndexHigh.ToString() + " " + pInfo.FileIndexLow.ToString());
                Console.Write("Enter file name:");
                strem.Close();
                fileName = Console.ReadLine();
            }
        }
    }
}

Before using this process you have to make sure that whether the disk format is NTFS or not and if the disk format is not NTFS then you have to verify it with the given code and the code is as:

bool isNTFS = new DriveInfo(new FileInfo(fileName).FullName).DriveFormat == "NTFS";

Related Solutions

Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
Write a program that prompts the user to enter a file name, then opens the file...
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint:...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
Create an application that makes the user guess a number. The user must be allowed tries....
Create an application that makes the user guess a number. The user must be allowed tries. You must have a loop, user input (Scanner), and a constructor. (JAVA)
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
Write a program that allows the user to navigate the lines of text in a file....
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
Write a program that allows the user to navigate the lines of text in a file....
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT