Page 1 of 2

Seek 4 Help!!!

Posted: Sun Jan 08, 2006 9:25 pm
by voonwah
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>

Re:Seek 4 Help!!!

Posted: Sun Jan 08, 2006 10:47 pm
by proxy
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

Re:Seek 4 Help!!!

Posted: Mon Jan 09, 2006 3:15 am
by Pype.Clicker
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,

Code: Select all

    new_number read_dir_entry(dir_handle, old_number [,search_pattern]);
or

Code: Select all

    new_number read_dir_entries(dir_handle, old_number, how_many_entries, &buffer);
It's then usually up to the user-level program to make sense of the data filled in the buffer according to OS manuals ;)

Re:Seek 4 Help!!!

Posted: Mon Jan 09, 2006 6:33 am
by kataklinger
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!!!

Posted: Mon Jan 09, 2006 10:59 am
by Dex4u
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"

Re:Seek 4 Help!!!

Posted: Mon Jan 09, 2006 3:13 pm
by GLneo
heres mine:

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);
}
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)

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 1:08 am
by RetainSoftware
we do like comments in code ;)

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 1:52 am
by Solar
Yiieee-harrr! Look at all those magic numbers! :D

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 7:46 am
by kataklinger
WOW, where did all these numbers came from? :o ;D

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 8:13 am
by Pype.Clicker
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.

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;
};
that makes it look like

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);
}

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 8:31 am
by Pype.Clicker
/* 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.
*/
so we can later rewrite

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.
};
and

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)))
        {
becomes

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 

Re:Seek 4 Help!!!

Posted: Tue Jan 10, 2006 8:40 am
by kataklinger
It's much better now 8)

Re:Seek 4 Help!!!

Posted: Sat Jun 10, 2006 6:47 am
by Infection 93
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!

Re:Seek 4 Help!!!

Posted: Sat Jun 10, 2006 8:10 am
by Ryu
I just had a scary thought.. if I were to reverse engineer GLNeo's OS.

Nevermind, you didn't hear that GLNeo. :P

Re:Seek 4 Help!!!

Posted: Sat Jun 10, 2006 11:34 am
by GLneo
*Glneo, tempted to post his IOCCC FAT12 driver, restrains himself* :P ;D