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

📄 netdrv.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            netFdRelease (pNetFd);            return (ERROR);            }        }    else        {        if ((status = netSockOpen (pNetFd)) != OK) /* open the connection */            {            NETDRV_DEBUG ("netOpen:  error calling netSockOpen()  errno:0x%08x\n", \                          errno,1,2,3,4,5);            /* not able to open file from host */            semGive (pNetFd->netFdSem);            netFdRelease (pNetFd);            return (ERROR);            }        pNetFd->filePtrByte = 0;        pNetFd->bufBytes    = 0;        pNetFd->bufOffset   = 0;        }    semGive (pNetFd->netFdSem);    return ((int) pNetFd);    }/********************************************************************************* netClose - close a remote file.  Copy it to the remote machine.** If the file is O_WRONLY or O_RDWR mode and it has been written to (it's* dirty bit is set), then the file is copied over to UNIX.** Called only by the I/O system.** RETURNS: OK or ERROR.*/LOCAL STATUS netClose    (    FAST NET_FD *pNetFd    )    {    STATUS status = OK;   NETDRV_DEBUG ("netClose: entered\n",0,0,0,0,0,0);    semTake (pNetFd->netFdSem, WAIT_FOREVER);    if (pNetFd->pNetDev->bufSize == 0)        {        /* if file has dirty bit set, it's been changed. Copy it to the host */        if (pNetFd->options & FD_DIRTY)            status = netPut (pNetFd);        if (status == ERROR)            {            NETDRV_DEBUG ("netClose: error calling netPut to flush file errno=0x%08x\n",\                          errno,2,3,4,5,6);            }        }    else        {        status = netSockClose (pNetFd); /* close the connection */        if (status != OK)            {            NETDRV_DEBUG ("netClose: error calling netSockClose errno=0x%08x\n",  \                          errno,2,3,4,5,6);            }        }    semGive (pNetFd->netFdSem);    /* print out the statistic if the debug flag is on */    if ((netDrvDebugStats) && (pNetFd->pNetDev->bufSize > 0))        {        NETDRV_DEBUG ("read[hit=%d mis=%d] fseek[hit=%d mis=%d] bseek[hit=%d mis=%d]\n",\                      pNetFd->status[0], pNetFd->status[1], pNetFd->status[2],\                      pNetFd->status[3], pNetFd->status[4], pNetFd->status[5]);        }    netFdRelease (pNetFd);    return (status);    }/********************************************************************************* netLs - list a remote directory.** RETURNS: OK or ERROR.*/LOCAL STATUS netLs    (    FAST NET_FD *pNetFd    )    {    int dataSock;    int ctrlSock;    char buf [DATASIZE]; /* make buf the same size as NET_FD's databuf */    FAST int nBytes = -1;    char command[MAX_FILENAME_LENGTH];    char buffer [MAX_FILENAME_LENGTH];    STATUS status = OK;    char usr [MAX_IDENTITY_LEN];    char passwd [MAX_IDENTITY_LEN];    remCurIdGet (usr, passwd);    if (pNetFd->pNetDev->protocol == PROTO_FTP)        {        if (pNetFd->remFileName[0] == '.')            {            if (ftpXfer (pNetFd->pNetDev->host, usr, passwd, "", "NLST",                         pNetFd->remDirName, pNetFd->remFileName,                         &ctrlSock, &dataSock) == ERROR)                {                    NETDRV_DEBUG ("netLs:  error calling ftpXfer(\"NLST\")  errno:0x%08x\n", errno,1,2,3,4,5);                return (ERROR);                }            }        else           {           if (ftpXfer (pNetFd->pNetDev->host, usr, passwd, "", "NLST %s",                        pNetFd->remDirName, pNetFd->remFileName,                        &ctrlSock, &dataSock) == ERROR)               {               NETDRV_DEBUG ("netLs:  error calling ftpXfer(\"NLST\")  errno:0x%08x\n", errno,1,2,3,4,5);               return (ERROR);               }           }        }    else        {        if (pathCat (pNetFd->remDirName, pNetFd->remFileName, buffer) == ERROR)            {            NETDRV_DEBUG ("netLs:  error calling pathCat\(\"%s\", \"%s\")  errno:0x%08x\n",             pNetFd->remDirName, pNetFd->remFileName,errno,1,2,3);            return (ERROR);            }        sprintf (command, NET_LS_STRING, buffer);        dataSock = rcmd (pNetFd->pNetDev->host, RSHD, usr,                          usr, command, &ctrlSock);        if (dataSock == ERROR)            {            NETDRV_DEBUG ("netLs:  error calling rcmd() errno:0x%08x\n", errno,1,2,3,4,5);            return (ERROR);            }        }    /* read bytes from socket and write them     * to standard out one block at a time     */    while ((status == OK) &&           ((nBytes = read (dataSock, buf, sizeof (buf))) > 0))        {        if (write (STD_OUT, buf, nBytes) != nBytes)            {                NETDRV_DEBUG ("netLs:  error calling write()  errno:0x%08x\n", \                              errno,1,2,3,4,5);                status = ERROR;             }        }    if (nBytes < 0) /* recv error */        {        NETDRV_DEBUG ("netLs:  error calling read()  errno:0x%08x\n", errno,1,2,3,4,5);        status = ERROR;        }    close (dataSock);    if (pNetFd->pNetDev->protocol == PROTO_FTP)       {       if (ftpReplyGet (ctrlSock, TRUE) != FTP_COMPLETE)           {           NETDRV_DEBUG ("netLs:  error calling ftpReplyGet()  errno:0x%08x\n", \                         errno,1,2,3,4,5);           status = ERROR;           }       }    else       {       /* check control socket for error */       if ((nBytes = fioRead (ctrlSock, buf, sizeof (buf) - 1)) > 0)           {           /* print error message */           buf [nBytes] = EOS; /* insure string termination */           NETDRV_DEBUG ("netLs: %s:%s errno:0x%08x error calling fioread() \n",                           pNetFd->pNetDev->host, buf, errno,1,2,3);           /* set the task's status according to the UNIX error */           getNetStatus (buf);           status = ERROR;           }       }    if (pNetFd->pNetDev->protocol == PROTO_FTP &&       ftpCommand (ctrlSock, "QUIT",0,0,0,0,0,0) != FTP_COMPLETE)       {           NETDRV_DEBUG ("netLs:  error calling ftpCommand()  errno:0x%08x\n", \                         errno,1,2,3,4,5);           status = ERROR;       }    close (ctrlSock);    return (status);    }/******************************************************************************** netLsByName - list a remote directory by name** RETURNS: OK if successful, otherwise ERROR.  If the device is not a netDrv* device, errno is set to S_netDrv_UNKNOWN_REQUEST.** ERRNO*   S_netDrv_UNKNOWN_REQUEST** NOMANUAL*/STATUS netLsByName    (    char * dirName		/* name of the directory */    )    {    DEV_HDR * pDevHdr;		/* device header */    char      fullFileName [MAX_FILENAME_LENGTH];    NET_FD *  pNetFd;    STATUS    netLsReturn;    if (ioFullFileNameGet (dirName, &pDevHdr, fullFileName) == ERROR)        {        NETDRV_DEBUG ("netLsByName:  error calling ioFullFileNameGet()  errno:0x%08x\n",\                      errno,1,2,3,4,5);        return (ERROR);        }    /* make sure the device is a netDrv device */    if (drvTable [pDevHdr->drvNum].de_open != netOpen)        {        NETDRV_DEBUG ("netLsByName:  error UNKNOWN_REQUEST errno:0x%08x\n", \                      errno,1,2,3,4,5);        errno = S_netDrv_UNKNOWN_REQUEST;        return (ERROR);        }    /* create a NET_FD to pass to netLs */    pNetFd = (NET_FD *) netFdCreate ((NET_DEV *) pDevHdr, fullFileName, 0);    if (pNetFd == (NET_FD *)ERROR)        {        NETDRV_DEBUG ("netFdCreate:  error callinf netFdCreate errno:0x%08x\n", \                      errno,1,2,3,4,5);        return (ERROR);             /* SPR #28927 */        }    netLsReturn = netLs (pNetFd);    netFdRelease (pNetFd);    return (netLsReturn);    }/********************************************************************************* netFileExists - check for the existence of a file.** RETURNS: OK if the file exists, or ERROR.*/LOCAL STATUS netFileExists    (    NET_DEV *pNetDev,    char *name          /* remote file name */    )    {    int dataSock;    int ctrlSock;    char buf [DATASIZE];        /* make buf the same size as NET_FD's databuf */    char command[MAX_FILENAME_LENGTH];    STATUS status = OK;    char usr [MAX_IDENTITY_LEN];    char passwd [MAX_IDENTITY_LEN];    char *pDirName  = (char *) KHEAP_ALLOC ((unsigned) (strlen (name) + 1));    char *pFileName = (char *) KHEAP_ALLOC ((unsigned) (strlen (name) + 1));    /* don't allow null filenames */    if (name[0] == EOS)        {        errno = S_ioLib_NO_FILENAME;        NETDRV_DEBUG ("netFileExists:  error S_ioLib_NO_FILENAME errno:0x%08x\n", \                      errno,1,2,3,4,5);        return (ERROR);        }    /* get directory and filename */    pathSplit (name, pDirName, pFileName);    remCurIdGet (usr, passwd);    if (pNetDev->protocol == PROTO_FTP)        {        if (ftpXfer (pNetDev->host, usr, passwd, "",                     "NLST %s", pDirName, pFileName,                     &ctrlSock, &dataSock) == ERROR)            {            NETDRV_DEBUG ("netFileExists:  error calling ftpXfer(). errno:0x%08x\n", \                          errno,1,2,3,4,5);            KHEAP_FREE (pDirName);            KHEAP_FREE (pFileName);            return (ERROR);            }        }    else        {        sprintf (command, NET_LS_STRING, name);        dataSock = rcmd (pNetDev->host, RSHD, usr, usr, command, &ctrlSock);        if (dataSock == ERROR)            {            NETDRV_DEBUG ("netFileExists:  error calling rcmd(). errno:0x%08x\n", \                          errno,1,2,3,4,5);            KHEAP_FREE (pDirName);            KHEAP_FREE (pFileName);            return (ERROR);            }        }    if (pNetDev->protocol == PROTO_FTP)        {        /* check dataSock for ls error message */        if (read (dataSock, buf, sizeof (buf)) <= 0)            {            NETDRV_DEBUG ("netFileExists:  error calling read() on data socket for ls. errno:0x%08x\n", errno,1,2,3,4,5);            status = ERROR;            }        NETDRV_DEBUG ("netFileExists:  full message:%s\n", buf, 1,2,3,4,5);        NETDRV_DEBUG ("netFileExists:  message:%s\n", buf+ strlen (pFileName) + 1,                       1,2,3,4,5);        if ((_func_fileDoesNotExist != NULL))            {            if ((* _func_fileDoesNotExist) (pFileName, buf) == OK)                {                NETDRV_DEBUG ("netFileExists:  match error on ls \n", \                              errno,1,2,3,4,5);                status = ERROR;                }            else                {                NETDRV_DEBUG ("netFileExists:  file does not exist\n", errno,1,2,3,4,5);                }            }        if (close (dataSock) == ERROR)            {            status = ERROR;            NETDRV_DEBUG ("netFileExists:  error calling close() on dataSock. errno:0x%08x\n", errno,1,2,3,4,5);            }        if (ftpReplyGet (ctrlSock, FALSE) != FTP_COMPLETE)            {            NETDRV_DEBUG ("netFileExists: error calling ftpReplyGet(). errno:0x%08x\n",\                          errno,1,2,3,4,5);            status = ERROR;            }        }    else        {        /* check control socket for error */        if (read (ctrlSock, buf, sizeof (buf)) > 0)            {            /* set the task's status according to the UNIX error */               getNetStatus (buf);            NETDRV_DEBUG ("netFileExists:  error calling read() on control socket. errno:0x%08x\n", errno,1,2,3,4,5);            status = ERROR;            }        close (dataSock);        }

⌨️ 快捷键说明

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