954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

understanding file system

So I started doing c programing and now I want to understand how file systems like fat 32 and NTFS works. So I want to know how to create a file transfering program. So here's a few questions....

1 How do I do it the portable way?
-find file size
-what data type to use in C to do the transfer
-explain the following:
from what I understand txt files are treated differently from other files [I think this only applies for windows systems]
2 How to do it through windows
-how to call windows copy and cut functions, so that you get a popup dialog box that shows the trasfer in progress
-does it return anything to indicate a success or failure?

3 How to get file names from a given directory so that it is in the form of a 2d array
- how and where are those file names stored?

Mr.UNOwen
Junior Poster
133 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 
1 How do I do it the portable way? -find file size


Since you mentioned C, so I cannot suggest you Boost::Filesystem
You will have to use platform specific codes like stat of unix and some equivalent function in windows with chain of #ifdef's. You can also use fstat , or fseek to the end of the file and then use ftell . But both of will give you exact result only in case of binary files because of differing representation of end-of-line. -what data type to use in C to do the transfer
I guess you can use any(not sure)3 How to get file names from a given directory so that it is in the form of a 2d array
Again this is very compiler/OS specific. You can see some examples here

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

Getting the list of files from a directory is not too difficult but is os-dependent. In C there is no portable way to do it. In C++ boost libraries have portable functions.

these code snippets show how to do it in both linux and ms-windows.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

Isn't C portable to the point you can creat an OS with it???

Mr.UNOwen
Junior Poster
133 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 
Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

I think it's possible, but it's very complex as described in this wikipedia article .

Each sector the contains a file has a pointer which can point to the next sector if the file occupies more than one. In this way, a file is basically a linked list of sectors.
Isn't C portable to the point you can creat an OS with it???
Yes, it's possible to create an operating system with C. However, because of the low level-ness needed in the program, a lot of assembly is required, forcing it to be hardware-specific.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 
Isn't C portable to the point you can creat an OS with it???


I think you have your concepts blurred there. Portability roughly impiles the same standard C code can be compiled on Windows system as well as Unix system. (of course provided you don't use external libraries).

Yes, C can be used to create an OS with it (and it has already been achieved), but for interfacingexternal devices like the hard drive or floppy drive, you need to write a program (ie a driver) which will act as an interpreter between the OS and the device.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

HD's have aFile Alocation Table (FAT) or New Technology File System (NTFS) -- at least in Windows. They are two very different file systems. Linux uses FAT. Mac, who knows? A Google search will give you details of both.

Isn't C portable to the point you can creat an OS with it???

Yes. But you have to keep in mind each OS is written specifically for the hardware it runs on. So even though C is portable does not mean you can write an OS that's portable.So I started doing c programing and now I want to understand how file systems like fat 32 and NTFS works. So I want to know how to create a file transfering program. So here's a few questions....

1 How do I do it the portable way?
-find file size
The only standard way is to read each character. Each OS and Compiler generally will have a way, but it's not portable. -what data type to use in C to do the transferchar -explain the following:

2 How to do it through windows
-how to call windows copy and cut functions, so that you get a popup dialog box that shows the trasfer in progress
-does it return anything to indicate a success or failure?
Look at API information at http://MSDN.com

3 How to get file names from a given directory so that it is in the form of a 2d array - how and where are those file names stored?


Very non-portable.

C itself knows nothing about hard drives, monitors, or keyboards. The I/O functions defined by C are just skeleton definitions to be defined via the standards by the compiler designers to work within the confines of the O/S.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You