Public Member Functions | Protected Member Functions | Protected Attributes

FATDirectory Struct Reference

FAT file system directory-entry. More...

#include <fatfs.h>

Inheritance diagram for FATDirectory:
Inheritance graph
[legend]
Collaboration diagram for FATDirectory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FATDirectory (FATDrive &drive, LPCTSTR root_path)
 FATDirectory (FATDrive &drive, Entry *parent, LPCTSTR path, unsigned cluster)
 ~FATDirectory ()
virtual void read_directory (int scan_flags=0)
virtual const void * get_next_path_component (const void *) const
virtual Entryfind_entry (const void *)

Protected Member Functions

bool read_dir ()

Protected Attributes

FATDrive_drive
struct dirsecz_secarr
int _cur_bufs
int _ents
struct dirent_dir
struct Kette_alloc

Detailed Description

FAT file system directory-entry.

Definition at line 47 of file fatfs.h.


Constructor & Destructor Documentation

FATDirectory::FATDirectory ( FATDrive drive,
LPCTSTR  root_path 
)

Definition at line 272 of file fatfs.cpp.

References FATEntry::_cluster, _cur_bufs, _dir, _ents, Directory::_path, and _secarr.

Referenced by read_directory().

 :  FATEntry(),
    _drive(drive)
{
    _path = _tcsdup(root_path);

    _secarr     = NULL;
    _cur_bufs   = 0;
    _ents       = 0;
    _dir        = NULL;
    _cluster    = 0;
}

Here is the caller graph for this function:

FATDirectory::FATDirectory ( FATDrive drive,
Entry parent,
LPCTSTR  path,
unsigned  cluster 
)

Definition at line 285 of file fatfs.cpp.

References _cur_bufs, _dir, _ents, Directory::_path, and _secarr.

 :  FATEntry(parent, cluster),
    _drive(drive)
{
    _path = _tcsdup(path);

    _secarr     = NULL;
    _cur_bufs   = 0;
    _ents       = 0;
    _dir        = NULL;
}
FATDirectory::~FATDirectory (  )

Definition at line 297 of file fatfs.cpp.

References Directory::_path.

{
    free(_path);
    _path = NULL;
}

Member Function Documentation

Entry * FATDirectory::find_entry ( const void *  p ) [virtual]

Reimplemented from Entry.

Definition at line 224 of file fatfs.cpp.

References Entry::_data, Entry::_down, Entry::_next, and TEXT.

{
    LPCTSTR name = (LPCTSTR)p;

    for(Entry*entry=_down; entry; entry=entry->_next) {
        LPCTSTR p = name;
        LPCTSTR q = entry->_data.cFileName;

        do {
            if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
                return entry;
        } while(tolower(*p++) == tolower(*q++));

        p = name;
        q = entry->_data.cAlternateFileName;

        do {
            if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
                return entry;
        } while(tolower(*p++) == tolower(*q++));
    }

    return NULL;
}
const void * FATDirectory::get_next_path_component ( const void *  p ) const [virtual]

Reimplemented from Entry.

Definition at line 207 of file fatfs.cpp.

References TEXT.

{
    LPCTSTR s = (LPCTSTR) p;

    while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
        ++s;

    while(*s==TEXT('\\') || *s==TEXT('/'))
        ++s;

    if (!*s)
        return NULL;

    return s;
}
bool FATDirectory::read_dir (  ) [protected]

Definition at line 303 of file fatfs.cpp.

References FATDrive::_boot_sector, FATDrive::_bufents, FATDrive::_bufl, FATEntry::_cluster, _cur_bufs, _dir, _drive, _ents, FATDrive::_SClus, _secarr, AddP, BootSector::BytesPerSector, Buffer::dat, BootSector::NumberFATs, FATDrive::read_FAT(), FATDrive::read_sector(), BootSector::ReservedSectors, BootSector::RootEntries, BootSector32::RootSectors, dirsecz::s, BootSector::SectorsPerFAT, and BootSector32::SectorsPerFAT32.

Referenced by read_directory().

{
    int i;

    if (_cluster == 0) {
        if (!_drive._boot_sector.SectorsPerFAT) {   // FAT32? [boot_sector32->reserved0==0]
            BootSector32* boot_sector32 = (BootSector32*) &_drive._boot_sector;
            DWORD sect = _drive._boot_sector.ReservedSectors + _drive._boot_sector.NumberFATs*boot_sector32->SectorsPerFAT32;  // lese Root-Directory ein
            int RootEntries = boot_sector32->RootSectors * 32;  //@@

            _secarr = (struct dirsecz*)malloc(sizeof(DWORD) * (_cur_bufs = (int)((_ents=RootEntries)/_drive._bufents)));

            for(i=0; i<_cur_bufs; i++)
                _secarr->s[i] = sect+i;

            _dir = (struct dirent*)malloc((size_t)(_ents+16)*sizeof(union DEntry));
            if (!_dir)
                return false;

            if (!(_drive.read_sector(*_secarr->s,(Buffer*)_dir,_cur_bufs)))
                return false;
        } else {
            DWORD sect = _drive._boot_sector.ReservedSectors + _drive._boot_sector.NumberFATs*_drive._boot_sector.SectorsPerFAT;  // read in root directory

            _secarr = (struct dirsecz*)malloc(sizeof(DWORD) * (_cur_bufs = (int)((_ents=_drive._boot_sector.RootEntries)/_drive._bufents)));

            for(i=0; i<_cur_bufs; i++)
                _secarr->s[i] = sect+i;

            _dir = (struct dirent*)malloc((size_t)(_ents+16)*sizeof(union DEntry));
            if (!_dir)
                return false;

            if (!_drive.read_sector(*_secarr->s,(Buffer*)_dir,_cur_bufs))
                return false;
        }
    } else {
        Buffer* buf;
        bool ok;

        DWORD h = _cluster;

        _cur_bufs = 0;

        do {
            h = _drive.read_FAT(h, ok);

            if (!ok)
                return false;

            _cur_bufs++;
        } while (h<0x0ffffff0 && h);

        _secarr = (struct dirsecz*) malloc(sizeof(DWORD) * _cur_bufs);

        if (!_secarr)
            return false;

        _ents = _drive._bufents * (size_t)_cur_bufs * _drive._SClus;

        if ((buf=(Buffer*)(_dir=(struct dirent*)malloc((size_t) (_ents+16)*sizeof(union DEntry)))) == NULL)
            return false;

        h = _cluster;

        DWORD fdatsec;

        if (!_drive._boot_sector.SectorsPerFAT) {   // FAT32 ?
            BootSector32* boot_sector32 = (BootSector32*) &_drive._boot_sector;
            //int RootEntries = boot_sector32->RootSectors * 32;    //@@
            //fdatsec = _drive._boot_sector.ReservedSectors + _drive._boot_sector.NumberFATs*boot_sector32->SectorsPerFAT32 + RootEntries*sizeof(DEntry)/_drive._boot_sector.BytesPerSector;    // dpb.fdirsec
            fdatsec = _drive._boot_sector.ReservedSectors +
                        _drive._boot_sector.NumberFATs*boot_sector32->SectorsPerFAT32 + boot_sector32->RootSectors;
        } else
            fdatsec = _drive._boot_sector.ReservedSectors +
                        _drive._boot_sector.NumberFATs*_drive._boot_sector.SectorsPerFAT +
                        _drive._boot_sector.RootEntries*sizeof(DEntry)/_drive._boot_sector.BytesPerSector;  // dpb.fdirsec

            for(i=0; i<_cur_bufs; i++) {
                _secarr->s[i] = fdatsec + (DWORD)_drive._SClus*(h-2);

                h = _drive.read_FAT(h, ok);

                if (!ok)
                    return false;
            }

            for(i=0; i<_cur_bufs; i++) {
                if ((ok = (_drive.read_sector(_secarr->s[i], buf, _drive._SClus))) == true)
                    AddP(buf, _drive._bufl*_drive._SClus)
                else {
                    //@@FPara = _secarr->s[i];
                    return false;
                }
            }

        buf->dat[0] = 0;     // Endekennzeichen für Rekurs setzen
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FATDirectory::read_directory ( int  scan_flags = 0 ) [virtual]

Reimplemented from Entry.

Definition at line 52 of file fatfs.cpp.

References _A_DELETED, _A_ILLEGAL, _alloc, Entry::_content, Entry::_data, _dir, _drive, _ents, Entry::_level, Entry::_next, Directory::_path, _tcscpy_s, _tcslen, FAT_attribute::a, AddP, DEntry_E::attr, ATTRIBUTE_ERASED, ATTRIBUTE_LONGNAME, ATTRIBUTE_VOLNAME, DEntry::B, FAT_attribute::b, CONTEXT, COUNTOF, fdate::day, fattr::directory, DEntry::E, FAT_DEL_CHAR, FATDirectory(), FATEntry::FATEntry(), ftime::hour, IS_LNAME, ftime::min, fdate::month, DEntry_E::name, read_dir(), ftime::sec2, fattr::volume, and fdate::year.

{
    CONTEXT("FATDirectory::read_directory()");

    read_dir();

    union DEntry* p = (union DEntry*) _dir;
    int i = 0;

    do {
/*      if (!IS_LNAME(p->E.attr) && p->E.name[0]!=FAT_DEL_CHAR)
            gesBytes += p->E.size;
*/

        AddP(p, sizeof(union DEntry));
    } while(++i<_ents && p->E.name[0]);

    _alloc = (struct Kette*) malloc((size_t)((_ents=i)+8)*sizeof(struct Kette));
    if (!_alloc)
        return;

    link_dir_entries(_dir, _alloc, i);

    Entry* first_entry = NULL;
    int level = _level + 1;

    Entry* last = NULL;

    WIN32_FIND_DATA w32fd;
    FAT_attribute attr;
    String long_name;

    TCHAR buffer[MAX_PATH];

    _tcscpy(buffer, (LPCTSTR)_path);
    LPTSTR pname = buffer + _tcslen(buffer);
    int plen = COUNTOF(buffer) - _tcslen(buffer);

    *pname++ = '\\';
    --plen;

    for(Kette*p=_alloc; p; p=p->Vorw) {
        memset(&w32fd, 0, sizeof(WIN32_FIND_DATA));

        DEntry_E& e = p->Ent->E;

         // get file/directory attributes
        attr.b = e.attr;

        if (attr.b & (_A_DELETED | _A_ILLEGAL))
            attr.b |= _A_ILLEGAL;

        const char* s = e.name;
        LPTSTR d = w32fd.cFileName;

        if (!IS_LNAME(attr.b) || e.name[0]==FAT_DEL_CHAR) {
            if (e.name[0] == FAT_DEL_CHAR)
                w32fd.dwFileAttributes |= ATTRIBUTE_ERASED;
            else if (IS_LNAME(attr.b))
                w32fd.dwFileAttributes |= ATTRIBUTE_LONGNAME;
            else if (attr.a.directory)
                w32fd.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
            else if (attr.a.volume)
                w32fd.dwFileAttributes |= ATTRIBUTE_VOLNAME;    //@@ -> in Volume-Name der Root kopieren

             // get file name
            *d++ = *s==FAT_DEL_CHAR? '?': *s;
            ++s;

            for(i=0; i<7; ++i)
                *d++ = *s++;

            while(d>w32fd.cFileName && d[-1]==' ')
                --d;

            *d++ = '.';

            for(; i<10; ++i)
                *d++ = *s++;

            while(d>w32fd.cFileName && d[-1]==' ')
                --d;

            if (d>w32fd.cFileName && d[-1]=='.')
                --d;

            *d = '\0';
        } else {
            s = (const char*)p->Ent->B; // no change of the pointer, just to avoid overung warnings in code checkers

             // read long file name
            TCHAR lname[] = {s[1], s[3], s[5], s[7], s[9], s[14], s[16], s[18], s[20], s[22], s[24], s[28], s[30]};

            long_name = String(lname, 13) + long_name;
        }

        if (!IS_LNAME(attr.b) && !attr.a.volume) {
             // get file size
            w32fd.nFileSizeLow = e.size;

             // convert date/time attribute into FILETIME
            const fdate& date = e.date;
            const ftime& time = e.time;
            SYSTEMTIME stime;
            FILETIME ftime;

            stime.wYear = date.year + 1980;
            stime.wMonth = date.month;
            stime.wDayOfWeek = (WORD)-1;
            stime.wDay = date.day;
            stime.wHour = time.hour;
            stime.wMinute = time.min;
            stime.wSecond = time.sec2 * 2;
            stime.wMilliseconds = 0;

            if (SystemTimeToFileTime(&stime, &ftime))
                LocalFileTimeToFileTime(&ftime, &w32fd.ftLastWriteTime);

            if (!(w32fd.dwFileAttributes & ATTRIBUTE_ERASED)) { //@@
                Entry* entry;

                if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                    _tcscpy_s(pname, plen, w32fd.cFileName);
                    entry = new FATDirectory(_drive, this, buffer, e.fclus);
                } else
                    entry = new FATEntry(this, e.fclus);

                memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));

                if (!long_name.empty()) {
                    entry->_content = _tcsdup(long_name);
                    long_name.erase();
                }

                if (!first_entry)
                    first_entry = entry;

                if (last)
                    last->_next = entry;

                entry->_level = level;

                last = entry;
            }
        }
    }

    if (last)
        last->_next = NULL;

    _down = first_entry;
    _scanned = true;
}

Here is the call graph for this function:


Member Data Documentation

struct Kette* FATDirectory::_alloc [protected]

Definition at line 64 of file fatfs.h.

Referenced by read_directory().

int FATDirectory::_cur_bufs [protected]

Definition at line 61 of file fatfs.h.

Referenced by FATDirectory(), and read_dir().

struct dirent* FATDirectory::_dir [protected]

Definition at line 63 of file fatfs.h.

Referenced by FATDirectory(), read_dir(), and read_directory().

Definition at line 58 of file fatfs.h.

Referenced by read_dir(), read_directory(), FATDrive::read_sector(), and FATDrive::small_cache().

int FATDirectory::_ents [protected]

Definition at line 62 of file fatfs.h.

Referenced by FATDirectory(), read_dir(), and read_directory().

struct dirsecz* FATDirectory::_secarr [protected]

Definition at line 60 of file fatfs.h.

Referenced by FATDirectory(), and read_dir().


The documentation for this struct was generated from the following files:

ROS Explorer Source Code Documentation
generated on 02.01.2013 by doxygen

ROS Explorer Homepage