Show
Ignore:
Timestamp:
09/20/11 02:45:19 (8 months ago)
Author:
Paulo Alcantara <pcacjr@…>
Children:
120523b681d08245d68d9db08998fad4018713db
Parents:
7e6065d5d1d8346683abf2f894d59c703fa60d87
git-committer:
Paulo Alcantara <pcacjr@gmail.com> / 2011-09-20T02:45:19Z+0000
Message:

ntfs: keep a state structure for ntfs_readdir() callers

Latetly, we kept a state information within the inode structure, that
was actually a mistake. Now, a ntfs_readdir_state structure is allocated
to keep a state that'll help on listing directory entries from sucessive
ntfs_readdir() calls.

Signed-off-by: Paulo Alcantara <pcacjr@…>

Location:
core/fs/ntfs
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • core/fs/ntfs/ntfs.c

    r7e6065 rd22401  
    3535#include "ntfs.h" 
    3636#include "runlist.h" 
     37 
     38static struct ntfs_readdir_state *readdir_state; 
    3739 
    3840/*** Function declarations */ 
     
    475477        } 
    476478 
    477         NTFS_PVT(inode)->in_idx_root = true; 
     479        /* check if we have a previous allocated state structure */ 
     480        if (readdir_state) { 
     481            free(readdir_state); 
     482            readdir_state = NULL; 
     483        } 
     484 
     485        /* allocate our state structure */ 
     486        readdir_state = malloc(sizeof *readdir_state); 
     487        if (!readdir_state) 
     488            malloc_error("ntfs_readdir_state structure"); 
     489 
     490        readdir_state->mft_no = mft_no; 
     491        /* obviously, the ntfs_readdir() caller will start from INDEX root */ 
     492        readdir_state->in_idx_root = true; 
    478493    } else if (d_type == DT_REG) {        /* file stuff */ 
    479494        dprintf("Got a file.\n"); 
     
    887902        goto index_err; 
    888903 
    889     if (!file->offset && NTFS_PVT(inode)->in_idx_root) { 
     904    if (!file->offset && readdir_state->in_idx_root) { 
    890905        file->offset = (uint32_t)((uint8_t *)&ir->index + 
    891906                                        ir->index.entries_offset); 
     
    893908 
    894909idx_root_next_entry: 
    895     if (NTFS_PVT(inode)->in_idx_root) { 
     910    if (readdir_state->in_idx_root) { 
    896911        ie = (struct ntfs_idx_entry *)(uint8_t *)file->offset; 
    897912        if (ie->flags & INDEX_ENTRY_END) { 
    898913            file->offset = 0; 
    899             NTFS_PVT(inode)->in_idx_root = false; 
    900             NTFS_PVT(inode)->idx_blks_count = 1; 
    901             NTFS_PVT(inode)->entries_count = 0; 
    902             NTFS_PVT(inode)->last_vcn = 0; 
     914            readdir_state->in_idx_root = false; 
     915            readdir_state->idx_blks_count = 1; 
     916            readdir_state->entries_count = 0; 
     917            readdir_state->last_vcn = 0; 
    903918            goto descend_into_child_node; 
    904919        } 
     
    929944next_run: 
    930945    stream = mapping_chunk_init(attr, &chunk, &offset); 
    931     count = NTFS_PVT(inode)->idx_blks_count; 
     946    count = readdir_state->idx_blks_count; 
    932947    while (count--) { 
    933948        err = parse_data_run(stream, &offset, attr_len, &chunk); 
     
    944959 
    945960    if (chunk.flags & MAP_UNALLOCATED) { 
    946        NTFS_PVT(inode)->idx_blks_count++; 
     961       readdir_state->idx_blks_count++; 
    947962       goto next_run; 
    948963    } 
    949964 
    950965next_vcn: 
    951     vcn = NTFS_PVT(inode)->last_vcn; 
     966    vcn = readdir_state->last_vcn; 
    952967    if (vcn >= chunk.len) { 
    953         NTFS_PVT(inode)->last_vcn = 0; 
    954         NTFS_PVT(inode)->idx_blks_count++; 
     968        readdir_state->last_vcn = 0; 
     969        readdir_state->idx_blks_count++; 
    955970        goto next_run; 
    956971    } 
     
    979994    ie = (struct ntfs_idx_entry *)((uint8_t *)&iblk->index + 
    980995                        iblk->index.entries_offset); 
    981     count = NTFS_PVT(inode)->entries_count; 
     996    count = readdir_state->entries_count; 
    982997    for ( ; count--; ie = (struct ntfs_idx_entry *)((uint8_t *)ie + ie->len)) { 
    983998        /* bounds checks */ 
     
    9921007        if (ie->flags & INDEX_ENTRY_END) { 
    9931008            /* go to the next VCN */ 
    994             NTFS_PVT(inode)->last_vcn += (blk_size / (1 << 
     1009            readdir_state->last_vcn += (blk_size / (1 << 
    9951010                                NTFS_SB(fs)->clust_byte_shift)); 
    996             NTFS_PVT(inode)->entries_count = 0; 
     1011            readdir_state->entries_count = 0; 
    9971012            goto next_vcn; 
    9981013        } 
    9991014    } 
    10001015 
    1001     NTFS_PVT(inode)->entries_count++; 
     1016    readdir_state->entries_count++; 
    10021017    len = ntfs_cvt_filename(filename, ie); 
    10031018    if (!is_filename_printable(filename)) 
     
    10071022 
    10081023out: 
    1009     NTFS_PVT(inode)->in_idx_root = true; 
     1024    readdir_state->in_idx_root = true; 
    10101025 
    10111026    free(mrec); 
  • core/fs/ntfs/ntfs.h

    r7e6065 rd22401  
    8484    uint32_t type;              /* Attribute type of this inode */ 
    8585    uint8_t non_resident; 
    86     bool in_idx_root; 
    87     uint32_t idx_blks_count; 
    88     uint32_t entries_count; 
    89     int64_t last_vcn; 
    9086    union {                 /* Non-resident $DATA attribute */ 
    9187        struct {            /* Used only if non_resident flags isn't set */ 
     
    10096    sector_t offset;        /* Current sector offset */ 
    10197    sector_t here;          /* Sector corresponding to offset */ 
     98}; 
     99 
     100/* This is structure is used to keep a state for ntfs_readdir() callers. 
     101 * As NTFS stores directory entries in a complex way, this is structure 
     102 * ends up saving a state required to find out where we must start from 
     103 * for the next ntfs_readdir() call. 
     104 */ 
     105struct ntfs_readdir_state { 
     106    unsigned long mft_no;       /* MFT record number */ 
     107    bool in_idx_root;           /* It's true if we're still in the INDEX root */ 
     108    uint32_t idx_blks_count;    /* Number of read INDX blocks */ 
     109    uint32_t entries_count;     /* Number of read INDEX entries */ 
     110    int64_t last_vcn;           /* Last VCN of the INDX block */ 
    102111}; 
    103112