understanding file system

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

understanding file system

 
0
  #1
Dec 24th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: understanding file system

 
0
  #2
Dec 24th, 2006
Originally Posted by Mr.UNOwen View Post
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.

Originally Posted by Mr.UNOwen View Post
-what data type to use in C to do the transfer
I guess you can use any(not sure)

Originally Posted by Mr.UNOwen View Post
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: understanding file system

 
0
  #3
Dec 24th, 2006
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: understanding file system

 
0
  #4
Jan 3rd, 2007
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???
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: understanding file system

 
0
  #5
Jan 3rd, 2007
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.
Originally Posted by Mr.UNOwen View Post
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.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: understanding file system

 
0
  #6
Jan 3rd, 2007
Originally Posted by Mr.UNOwen View Post
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 interfacing external 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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: understanding file system

 
0
  #7
Jan 3rd, 2007
Originally Posted by Mr.UNOwen View Post
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 a File 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.

Originally Posted by Mr.UNOwen View Post
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.


Originally Posted by Mr.UNOwen View Post
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.

Originally Posted by Mr.UNOwen View Post
-what data type to use in C to do the transfer
char

Originally Posted by Mr.UNOwen View Post
-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

Originally Posted by Mr.UNOwen View Post
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC