⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apiutil.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    }
    else    /* If no cwd is set error */
    {
        return(0);
    }
}


/****************************************************************************
    PC_UPSTAT - Copy private information to public fields for a DSTAT struc.

 Description
    Given a pointer to a DSTAT structure that contains a pointer to an 
    initialized DROBJ structure, load the public elements of DSTAT with
    name filesize, date of modification et al. (Called by pc_gfirst &
    pc_gnext)

 Returns
    Nothing


****************************************************************************/

/* Copy internal stuf so the outside world can see it   */
void pc_upstat(DSTAT *statobj)                                  /*__fn__*/
{
    DROBJ *pobj;
    FINODE *pi;
    pobj = (DROBJ *)(statobj->pobj);

    pi = pobj->finode;
    
    copybuff( statobj->fname, pi->fname, 8);
    statobj->fname[8] = '\0';
    copybuff( statobj->fext, pi->fext, 3);
    statobj->fext[3] = '\0';

    /* put null termed file.ext into statobj   */
    pc_mfile((byte *)statobj->filename, (byte *)statobj->fname, 
             (byte *)statobj->fext);

    statobj->fattribute = pi->fattribute;
    statobj->ftime = pi->ftime;
    statobj->fdate = pi->fdate;
    statobj->fsize = pi->fsize;

#if (VFAT)
    pc_seglist2text(pobj->pdrive, &pi->s, (char *)statobj->lfname);
    if(*statobj->lfname == 0)
    {
        pc_mfile((byte *)statobj->lfname, (byte *)statobj->fname,
                    (byte *)statobj->fext);
    }
#endif
}




/* Synchronize file pointers. Read write Seek and close all call here.
    This fixes the following BUGS:
    1. If a file is created and left open and then opened again with a new 
        file handle before any writing takes place. Neither file will get
        its fptr_cluster set correctly initially. The first one to write 
        would get set up correctly but the other wouldn't. Thus if fptr_cluster
        is zero we see if we can set it.
    2. If one file seeked to the end of the file or has written to the end of 
        the file its file pointer will point beyond the last cluster in the 
        chain, the next call to write will notice the fptr is beyond the 
        file size and extend the file by allocating a new cluster to the
        chain. During this time the cluster/block and byte offsets are
        out of synch. If another instance extends the file during this time 
        the next call to write will miss this condition since fptr is not 
        >= fsize any more. To fix this we note in the file when this 
        condition is true AND, afterwards each time we work with the file 
        we see if the file has grown and adjust the cluster pointer and block
        pointer if needed.
 */
/* 
 * Note: The finode owned by the file is always locked when this routine is 
 *  called so the routine does not need to be reentrant with respect to
 *  the finode. Note too that pfile is not a shared structure so the
 *  routine doesn't have to be reentrant with respect to it either.
*/

void  _synch_file_ptrs(PC_FILE *pfile)      /*__fn__*/
{
CLUSTERTYPE clno;

    if (!pfile->fptr_cluster)
    {
        pfile->fptr_cluster = pc_finode_cluster(pfile->pobj->pdrive,pfile->pobj->finode); /* FAT32 */

        if (pfile->fptr_cluster)
            pfile->fptr_block = pc_cl2sector(pfile->pobj->pdrive, pfile->fptr_cluster);
        else
            pfile->fptr_block = 0;
    }
    if (pfile->at_eof)
    {
        if (pfile->fptr_cluster)
        {
            clno = pc_clnext(pfile->pobj->pdrive, pfile->fptr_cluster);
            if (clno)
            {
                pfile->fptr_cluster = clno;
                pfile->fptr_block = pc_cl2sector(pfile->pobj->pdrive, pfile->fptr_cluster);
                pfile->at_eof = FALSE;
            }
        }
    }
}




/****************************************************************************
    PC_FINODE_STAT - Convert finode information to stat info for stat and fstat

 Description
    Given a pointer to a FINODE and a STAT structure
    load STAT with filesize, date of modification et al. Interpret
    the fattributes field of the finode to fill in the st_mode field of the
    the stat structure.

 Returns
    Nothing


****************************************************************************/

void pc_finode_stat(FINODE *pi, STAT *pstat)                /*__fn__*/
{

    pstat->st_dev   = pi->my_drive->driveno;    /* (drive number, rtfs) */
    pstat->st_ino   = 0;                        /* inode number (0) */
    pstat->st_mode  = 0;                        /* (see S_xxxx below) */

    /* Store away the DOS file attributes in case someone needs them   */
    pstat->fattribute = pi->fattribute;
    pstat->st_mode |= S_IREAD;
    if(!(pstat->fattribute & ARDONLY))
        pstat->st_mode |= S_IWRITE;
    if (pstat->fattribute & ADIRENT)
        pstat->st_mode |= S_IFDIR;
    if (!(pstat->fattribute & (AVOLUME|ADIRENT)))
        pstat->st_mode |= S_IFREG;

    pstat->st_nlink  = 1;                       /* (always 1) */
    pstat->st_rdev  = pstat->st_dev;            /* (drive number, rtfs) */
    pstat->st_size  = pi->fsize;                /* file size, in bytes */

    pstat->st_atime.date  = pi->fdate;          /* last access  */
    pstat->st_atime.time  = pi->ftime;
    pstat->st_mtime  = pstat->st_atime;         /* last modification */
    pstat->st_ctime  = pstat->st_atime;         /* last status change */
    /* optimal buffering size. is a cluster   */
    pstat->st_blksize = (dword) pi->my_drive->bytespcluster;
    /* blocks is file size / 512. with round up   */
    pstat->st_blocks  =  (dword) ((pi->fsize + 511)>>9);
}


/******************************************************************************
    pc_read_partition_table() -  Load a drive structure with partition info

 Description
    Read the partition table from a disk. If one is found then check the
    entry in the table that is specified by pdr->partition_number. If the
    entry is valid then load the fields 
        pdr->partition_base,pdr->partition_size and pdr->partition_type;

 Returns
    The following values.

    READ_PARTION_OK         Partition read succesfully 
    READ_PARTION_ERR        Internal error (couldn't allocate buffers ?)
    READ_PARTION_NO_TABLE   No partition table found
    READ_PARTION_NO_ENTRY   Request entry not found
    READ_PARTION_IOERROR    Device IO error 

****************************************************************************/

void pc_dump_partition_table(int driveno, DDRIVE *pdr);


int pc_read_partition_table(int driveno, DDRIVE *pdr)
{
    PTABLE *ppart;
    BLKBUFF *buf;
    byte *pbuf;
    word i;
    int ret_val;

#if (0)
	pc_dump_partition_table(driveno, pdr);
#endif

    /* Grab some working space   */
    buf = pc_scratch_blk();
    if (!buf)
    {
        return(READ_PARTION_ERR);
    }
    
    /* Read block zero   */
    if (!devio_read(driveno, 0 , buf->data , 1, TRUE))
    {
        ret_val = READ_PARTION_IOERROR;
        goto done;
    }
    /* Copy the table to a word alligned buffer   */
    pbuf = buf->data;
    pbuf += 0x1be;          /* The info starts at buf[1be] */
    copybuff(buf->data, pbuf, sizeof(PTABLE));
    ppart = (PTABLE *) buf->data;
    if (to_WORD((byte *) &ppart->signature)  !=  0xAA55)  /*X*/
    {
        ret_val = READ_PARTION_NO_TABLE;
        goto done;
    }
    /* Read through the partition table. Find the primary DOS partition   */

    i = (word)pdr->partition_number;

    if ( (ppart->ents[i].p_typ == 0x01) ||
         (ppart->ents[i].p_typ == 0x04) ||
#if (FAT32)
                 (ppart->ents[i].p_typ == 0x0B) ||   /* FAT32 Partition */
                 (ppart->ents[i].p_typ == 0x0C) ||   /* FAT32 Partition */
                 (ppart->ents[i].p_typ == 0x55) ||   /* FAT32 Partition */
#endif
          (ppart->ents[i].p_typ == 0x06) )
    {
        /* Get the relative start and size   */
        pdr->partition_base = to_DWORD ((byte *) &ppart->ents[i].r_sec);
        pdr->partition_size = to_DWORD ((byte *) &ppart->ents[i].p_size);
        pdr->partition_type = ppart->ents[i].p_typ;
        ret_val = READ_PARTION_OK;
    }
    else
    {
        ret_val = READ_PARTION_NO_ENTRY;
    }

done:
    pc_free_buf(buf, TRUE);
    return(ret_val);
}

#if (0)
void pc_dump_partition_table(int driveno, DDRIVE *pdr)
{
    PTABLE *ppart;
    BLKBUFF *buf;
    byte *pbuf;
    word i;
    int ret_val;

    /* Grab some working space   */
    buf = pc_scratch_blk();
    if (!buf)
    {
        return;
    }
    
    /* Read block zero   */
    if (!devio_read(driveno, 0 , buf->data , 1, TRUE))
    {
        goto done;
    }
    /* Copy the table to a word alligned buffer   */
    pbuf = buf->data;
    pbuf += 0x1be;          /* The info starts at buf[1be] */
    copybuff(buf->data, pbuf, sizeof(PTABLE));
    ppart = (PTABLE *) buf->data;
    if (to_WORD((byte *) &ppart->signature)  !=  0xAA55)  /*X*/
    {
        ret_val = READ_PARTION_NO_TABLE;
        goto done;
    }
    /* Read through the partition table. Find the primary DOS partition   */

    for (i = 0; i < 2; i++)
	{
	    printf("I== %X \n", (int)  i);
	    printf("boot %X \n", (int)  ppart->ents[i].boot);
	    printf("s_head %X \n", (int)  ppart->ents[i].s_head);
	    printf("s_cyl  %ld \n", (unsigned long)  ppart->ents[i].s_cyl);
	    printf("p_typ %X \n", (int)  ppart->ents[i].p_typ);
	    printf("e_hed %X \n", (int)  ppart->ents[i].e_head);
	    printf("e_cyl  %ld \n", (unsigned long)  ppart->ents[i].e_cyl);
	    printf("r_sec  %ld \n" ,(unsigned long)  ppart->ents[i].r_sec);
	    printf("p_size %ld \n", (unsigned long)  ppart->ents[i].p_size);
	}
done:
    pc_free_buf(buf, TRUE);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -