ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

loff_t alloc_rootdir_entry ( DOS_FS fs,
DIR_ENT de,
const char pattern 
)

Definition at line 51 of file check.c.

Referenced by reclaim_file().

{
    static int curr_num = 0;
    loff_t offset;

    if (fs->root_cluster) {
    DIR_ENT d2;
    int i = 0, got = 0;
    unsigned long clu_num, prev = 0;
    loff_t offset2;

    clu_num = fs->root_cluster;
    offset = cluster_start(fs,clu_num);
    while (clu_num > 0 && clu_num != -1) {
        fs_read(offset,sizeof(DIR_ENT),&d2);
        if (IS_FREE(d2.name) && d2.attr != VFAT_LN_ATTR) {
        got = 1;
        break;
        }
        i += sizeof(DIR_ENT);
        offset += sizeof(DIR_ENT);
        if ((i % fs->cluster_size) == 0) {
        prev = clu_num;
        if ((clu_num = next_cluster(fs,clu_num)) == 0 || clu_num == -1)
            break;
        offset = cluster_start(fs,clu_num);
        }
    }
    if (!got) {
        /* no free slot, need to extend root dir: alloc next free cluster
         * after previous one */
        if (!prev)
        die("Root directory has no cluster allocated!");
        for (clu_num = prev+1; clu_num != prev; clu_num++) {
        if (clu_num >= fs->clusters+2) clu_num = 2;
        if (!fs->fat[clu_num].value)
            break;
        }
        if (clu_num == prev)
        die("Root directory full and no free cluster");
        set_fat(fs,prev,clu_num);
        set_fat(fs,clu_num,-1);
        set_owner(fs, clu_num, get_owner(fs, fs->root_cluster));
        /* clear new cluster */
        memset( &d2, 0, sizeof(d2) );
        offset = cluster_start(fs,clu_num);
        for( i = 0; i < (int)fs->cluster_size; i += sizeof(DIR_ENT) )
        fs_write( offset+i, sizeof(d2), &d2 );
    }
    memset(de,0,sizeof(DIR_ENT));
    while (1) {
        sprintf((char*)de->name,pattern,curr_num);
        clu_num = fs->root_cluster;
        i = 0;
        offset2 = cluster_start(fs,clu_num);
        while (clu_num > 0 && clu_num != -1) {
        fs_read(offset2,sizeof(DIR_ENT),&d2);
        if (offset2 != offset &&
            !strncmp((char*)d2.name,(char*)de->name,MSDOS_NAME))
            break;
        i += sizeof(DIR_ENT);
        offset2 += sizeof(DIR_ENT);
        if ((i % fs->cluster_size) == 0) {
            if ((clu_num = next_cluster(fs,clu_num)) == 0 ||
            clu_num == -1)
            break;
            offset2 = cluster_start(fs,clu_num);
        }
        }
        if (clu_num == 0 || clu_num == -1)
        break;
        if (++curr_num >= 10000) die("Unable to create unique name");
    }
    }
    else {
    DIR_ENT *root;
    int next_free = 0, scan;

    root = vfalloc(fs->root_entries*sizeof(DIR_ENT));
    fs_read(fs->root_start,fs->root_entries*sizeof(DIR_ENT),root);

    while (next_free < (int)fs->root_entries)
        if (IS_FREE(root[next_free].name) &&
        root[next_free].attr != VFAT_LN_ATTR)
        break;
        else next_free++;
    if (next_free == (int)fs->root_entries)
        die("Root directory is full.");
    offset = fs->root_start+next_free*sizeof(DIR_ENT);
    memset(de,0,sizeof(DIR_ENT));
    while (1) {
        sprintf((char*)de->name,pattern,curr_num);
        for (scan = 0; scan < (int)fs->root_entries; scan++)
        if (scan != next_free &&
            !strncmp((char*)root[scan].name,(char*)de->name,MSDOS_NAME))
            break;
        if (scan == (int)fs->root_entries) break;
        if (++curr_num >= 10000) die("Unable to create unique name");
    }
    vffree(root);
    }
    ++FsCheckTotalFiles;
    return offset;
}

Generated on Sat May 26 2012 06:03:39 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.