Seek 4 Help!!!
Seek 4 Help!!!
Hi all:
i'm currently develop my own OS, and now i'm facing some problem, i wish to write a ''Dir" function just like in the MS-DOS, what i have to do is to call out the function like this??
my OS already support the FAT12 file system.My OS just currenty support the floppy drive file system.
Can any i can provide me some sample code like this?
Thanks....
<edit by="pype"> made a whole sentence </edit>
i'm currently develop my own OS, and now i'm facing some problem, i wish to write a ''Dir" function just like in the MS-DOS, what i have to do is to call out the function like this??
my OS already support the FAT12 file system.My OS just currenty support the floppy drive file system.
Can any i can provide me some sample code like this?
Thanks....
<edit by="pype"> made a whole sentence </edit>
Re:Seek 4 Help!!!
well if your OS supports FAT12 already, well then you need to implement a set of system calls to allow user programs and such to access your FAT12 driver in a defined way. Usually this is run through a sort of VFS, but it's not neccessary, you could just implement a select few calls such as:
getdirentry, open, close, read, write, seek
proxy
getdirentry, open, close, read, write, seek
proxy
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Seek 4 Help!!!
most functions such as "dir" will ask a parameter telling where in the directory you are actually pointing (e.g. the entry number). From there,
or
It's then usually up to the user-level program to make sense of the data filled in the buffer according to OS manuals
Code: Select all
new_number read_dir_entry(dir_handle, old_number [,search_pattern]);
Code: Select all
new_number read_dir_entries(dir_handle, old_number, how_many_entries, &buffer);
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Seek 4 Help!!!
Do you want to write a command line program (do you have command line in your OS), or you want to call function from some program?
Re:Seek 4 Help!!!
You need to start by displaying the contents of the root dir.
From there you can add, more functionality.
If you need some example code there some here:
http://alexfru.chat.ru/epm.html#los4d
Called "OS Development for Dummies"
From there you can add, more functionality.
If you need some example code there some here:
http://alexfru.chat.ru/epm.html#los4d
Called "OS Development for Dummies"
Re:Seek 4 Help!!!
heres mine:
you do need to supply "char *dir;" with is a pointer to there copy of the directory in memory(for root read sectors 19 to 33 and point dir to it)
Code: Select all
void put_dir()
{
int x, dirs = 0, files = 0, count = 0;
printf("\n Volume in drive A is %s\n Volume Serial Number is %i\n Directory of %s\n\n", \
floppy1.volume_label, floppy1.volume_id, current);
for(x = 0; x < 224; x++)
{
if(!((dir[(x * 32) + 11] & 0x80) || (dir[(x * 32) + 11] & 0x40) || (dir[(x * 32) + 11] & 0x08) || (dir[(x * 32) + 0] == 0xE5) || (dir[(x * 32) + 0] == 0x00)))
{
memdump(dir + (x * 32), 11);
if(dir[(x * 32) + 11] & 0x10)
{
puts(" <DIR>");
dirs++;
}
else
{
putintrm(*((int *)(dir + (x * 32) + 28)), 14);
printf(" %i-%i-%i", 1 + ((*((short *)(dir + (x * 32) + 24))) & 0xF0), 1 + ((*((short *)(dir + (x * 16) + 24))) & 0xF), ((*((short *)(dir + (x * 32) + 24))) & 0x3F00) - 20);
printf(" %i:%i%c", 10, 32, 'p');
putchar(' ');
while(count != 8)
{
if(dir[(x * 32) + count] != ' ')
putchar(dir[(x * 32) + count]);
count++;
}
putchar('.');
count = 0;
while(count != 3)
{
if(dir[(x * 32) + 8 + count] != ' ')
putchar(dir[(x * 32) + 8 + count]);
count++;
}
files++;
}
putchar('\n');
}
}
printf(" %i file(s)\n %i dir(s)\n", files, dirs);
}
Re:Seek 4 Help!!!
Yiieee-harrr! Look at all those magic numbers!
Every good solution is obvious once you've found it.
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Seek 4 Help!!!
WOW, where did all these numbers came from? ;D
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Seek 4 Help!!!
Well, Glneo, you might wish to use structures to access the directory entries. Right the way you pasted it, it looks like an IOCCC submission or something alike.
that makes it look like
Code: Select all
/* (from the FAQ) Bytes Meaning
0 - 10 File name with extension
11 Attributes of the file
12 - 21 Reserved Bytes
22 - 23 Indicate the time
24 - 25 Indicate the date
26 - 27 Indicate the entry cluster value
28 - 31 Indicate the size of the file
*/
struct fat_direntry {
unsigned char name[11];
unsigned char attr;
char _reserved[10];
unsigned short time;
unsigned short date;
unsigned short cluster;
unsigned size;
};
Code: Select all
struct fat_direntry* dir;
#define FAT_DELETED 0xE5
#define FAT_END_OF_DIRECTORY 0
void put_dir()
{
int x, dirs = 0, files = 0, count = 0;
printf("\n Volume in drive A is %s\n Volume Serial Number is %i\n Directory of %s\n\n", \
floppy1.volume_label, floppy1.volume_id, current);
for(x = 0; x < 224; x++)
{
if(!((dir[x].attr & 0x80) || (dir[x].attr & 0x40) || dir[x].attr & 0x08) ||
(dir[x].name[0] == FAT_DELETED) || (dir[x].name[0] == FAT_END_OF_DIRECTORY)))
{
memdump(dir[x], 11); // print the name ? debug ?
if(dir[x].attr & 0x10)
{
puts(" <DIR>");
dirs++;
}
else
{
putintrm(dir[x].size, 14);
printf(" %i-%i-%i", 1 + (dir[x].date & 0xF0), 1 + (dir[x].date & 0xF), (dir[x].date & 0x3F00) - 20);
printf(" %i:%i%c", 10, 32, 'p'); // fake time
putchar(' ');
while(count < 8)
{
if(dir[x].name[count] != ' ')
putchar(dir[x].name[count]);
count++;
}
putchar('.');
count = 0;
while(count < 3)
{
if(dir[x].name[count+8] != ' ')
putchar(dir[x].name[count+8]);
count++;
}
files++;
}
putchar('\n');
}
}
printf(" %i file(s)\n %i dir(s)\n", files, dirs);
}
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Seek 4 Help!!!
so we can later rewrite/* still from the faq
Starting with the right most bit, which is the zero bit and working over to the left most bit the 7th bit the attributes are; read only, hidden, system file, volume label, sub-directory, archive, and the last two bits the 6th and 7th bits indicate resolved. In this particular file it is the 5th bit that is on meaning that it is an achieve file.
*/
Code: Select all
enum fat_attributes {
READ_ONLY=1,
HIDDEN=2,
SYSTEM=4,
VOLUME_LABEL=8,
DIRECTORY=16,
ARCHIVE=32,
WEIRD0=64, // dunno the meaning for these (LFN ?)
WEIRD1=128, //ditto here.
};
Code: Select all
if(!((dir[x].attr & 0x80) || (dir[x].attr & 0x40) || dir[x].attr & 0x08) ||
(dir[x].name[0] == FAT_DELETED) || (dir[x].name[0] == FAT_END_OF_DIRECTORY)))
{
Code: Select all
// any 'unwanted' bit set and we just skip the entry.
if (dir[x].attr&(WEIRD0|WEIRD1|VOLUME_LABEL) continue;
if (dir[x].name[0]==FAT_DELETED || dir[x].name[0]==FAT_END_DIRECTORY) continue;
// rest of the 'if ...' block comes here
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Seek 4 Help!!!
It's much better now
Re:Seek 4 Help!!!
I am also working on my own OS, the kernel is already finished, but i do not know how to make or prog a simple FAT12... :'(
Voonwah, can you post me your FAT12 SourceCode or what it is?
Thank you very much!
Voonwah, can you post me your FAT12 SourceCode or what it is?
Thank you very much!
Re:Seek 4 Help!!!
I just had a scary thought.. if I were to reverse engineer GLNeo's OS.
Nevermind, you didn't hear that GLNeo.
Nevermind, you didn't hear that GLNeo.