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

📄 util_os2.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
	    if (path[i + 1] == PATH_SEP) {
	        strcpy (path + i, path + i + 1);
	        i = start;
	        continue;
	    }

	    /* Handle `../' or trailing `..' by itself.
	       Remove the previous ?/ part with the exception of
	       ../, which we should leave intact. */
	    if (path[i + 1] == '.' && (path[i + 2] == PATH_SEP || !path[i + 2])) {
	        while (--start > -1 && path[start] != PATH_SEP);
	        if (!strncmp (path + start + 1, "..\\", 3))
	            continue;
	        strcpy (path + start + 1, path + i + 2);
	        i = start;
	        continue;
	    }
	}
    }

    if (!*path) {
        *path = stub_char;
        path[1] = '\0';
    }
    return path;
}


void
my_statfs (struct my_statfs *myfs_stats, char *path)
{
    PFSALLOCATE pBuf;
    PFSINFO     pFsInfo;
    ULONG       lghBuf;

    ULONG       diskNum = 0;
    ULONG       logical = 0;

    UCHAR       szDeviceName[3] = "A:";
    PBYTE       pszFSDName      = NULL;  /* pointer to FS name            */
    APIRET      rc              = NO_ERROR; /* Return code                */
    BYTE        fsqBuffer[sizeof(FSQBUFFER2) + (3 * CCHMAXPATH)] = {0};
    ULONG       cbBuffer   = sizeof(fsqBuffer);        /* Buffer length) */
    PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2) fsqBuffer;

    int i, len = 0;

    /* ------------------------------------------------------------------ */

    lghBuf = sizeof(FSALLOCATE);
    pBuf = (PFSALLOCATE) malloc(lghBuf);

    /* Get the free number of Bytes */
    rc = DosQueryFSInfo(0L, FSIL_ALLOC, (PVOID) pBuf, lghBuf);
    /* KBytes available */
    myfs_stats->avail = pBuf->cSectorUnit * pBuf->cUnitAvail * pBuf->cbSector / 1024;
    /* KBytes total */
    myfs_stats->total = pBuf->cSectorUnit * pBuf->cUnit * pBuf->cbSector / 1024;
    myfs_stats->nfree = pBuf->cUnitAvail;
    myfs_stats->nodes = pBuf->cbSector;

    lghBuf  = sizeof(FSINFO);
    pFsInfo = (PFSINFO) malloc(lghBuf);
    rc      = DosQueryFSInfo(0L,
                             FSIL_VOLSER,
                             (PVOID) pFsInfo,
                             lghBuf);
    /* Get name */
    myfs_stats->device = strdup(pFsInfo->vol.szVolLabel);    /* Label of the Disk */

    /* Get the current disk for DosQueryFSAttach */
    rc = DosQueryCurrentDisk(&diskNum, &logical);

    szDeviceName[0] = (UCHAR) (diskNum + (ULONG) 'A' - 1);
    /* Now get the type of the disk */
    rc = DosQueryFSAttach(szDeviceName,
                          0L,
                          FSAIL_QUERYNAME,
                          pfsqBuffer,
                          &cbBuffer);

    pszFSDName = pfsqBuffer->szName + pfsqBuffer->cbName + 1;
    myfs_stats->mpoint = strdup(pszFSDName);    /* FAT, HPFS ... */

    myfs_stats->type = pBuf->idFileSystem;
    /* What is about 3 ?*/
    if (myfs_stats->type == 0) {
       myfs_stats->typename = (char *) malloc(11);
       strcpy(myfs_stats->typename, "Local Disk");
    } else {
       myfs_stats->typename = (char *) malloc(13);
       strcpy(myfs_stats->typename, "Other Device");
    }

    free(pBuf);
    free(pFsInfo);
}

int
gettimeofday (struct timeval* tvp, void *p)
{
   DATETIME     pdt = {0};
   if (p != NULL)		/* what is "p"? */
	return 0;

    /* Since MC only calls this func from get_random_hint we return
     * some value, not exactly the "correct" one
     */
    DosGetDateTime(&pdt);
    tvp->tv_usec = (pdt.hours * 60 + pdt.minutes) * 60 + pdt.seconds;
    /* Number of milliseconds since Windows started */
    tvp->tv_sec = tvp->tv_usec * 1000 + pdt.hundredths * 10;
    return 0;
}

/* FAKE functions */

int
look_for_exe(const char* pathname)
{
   int j;
   char *p;
   int lgh = strlen(pathname);

   if (lgh < 4) {
      return 0;
   } else {
      p = (char *) pathname;
      for (j=0; j<lgh-4; j++) {
         p++;
      }
      if (!stricmp(p, ".exe") ||
          !stricmp(p, ".bat") ||
          !stricmp(p, ".com") ||
          !stricmp(p, ".cmd")) {
         return 1;
      }
   }
   return 0;
}

int
lstat (const char* pathname, struct stat *buffer)
{
   int rc = stat (pathname, buffer);
#ifdef __BORLANDC__
   if (rc == 0) {
     if (!(buffer->st_mode & S_IFDIR)) {
        if (!look_for_exe(pathname)) {
           buffer->st_mode &= !S_IXUSR & !S_IXGRP & !S_IXOTH;
	}
     }
   }
#endif
   return rc;
}

int
getuid ()
{
    return 0;
}

int
getgid ()
{
    return 0;
}

int
readlink (char* path, char* buf, int size)
{
    return -1;
}

int
symlink (char *n1, char *n2)
{
    return -1;
}

int
link (char *p1, char *p2)
{
    return -1;
}

int
chown (char *path, int owner, int group)
{
    return -1;
}

int
mknod (char *path, int mode, int dev)
{
    return -1;
}

void
init_uid_gid_cache (void)
{
    return;
}

int
mc_doublepopen (int inhandle, int inlen, pid_t *the_pid, char *command, ...)
{
	return 0;
}

int
mc_doublepclose (int pipe, pid_t pid)
{
	return 0;
}

/*hacks to get it compile, remove these after vfs works */
char *
vfs_get_current_dir (void)
{
	return NULL;
}

int
vfs_current_is_extfs (void)
{
	return 0;
}

int
vfs_file_is_ftp (char *filename)
{
	return 0;
}

int
mc_utime (char *path, void *times)
{
	return 0;
}


void
extfs_run (char *file)
{
   return;
}

int
geteuid(void)
{
   return 0;
}


int
mc_chdir(char *pathname)
{
   APIRET       ret;
   register int lgh = strlen(pathname);

   /* Set the current drive */
   if (lgh == 0) {
      return -1;
   } else {
      /* First set the default drive */
      if (lgh > 1) {
         if (pathname[1] == ':') {
             ret = DosSetDefaultDisk(toupper(pathname[0]) - 'A' + 1);
         }
      }
      /* After that, set the current dir! */
      ret = DosSetCurrentDir(pathname);
   }
   return ret;
}

int
mc_chmod(char *pathName, int unxmode)
{
   /* OS/2 does not need S_REG */
   int os2Mode = unxmode & 0x0FFF;
   return chmod(pathName, os2Mode);
}

static int
conv_os2_unx_rc(int os2rc)
{
   int errCode;
   switch (os2rc) {
      case ERROR_FILE_NOT_FOUND:
      case ERROR_PATH_NOT_FOUND:
      case ERROR_FILENAME_EXCED_RANGE:
         errCode = ENOENT;
         break;
      case ERROR_NOT_DOS_DISK:
      case ERROR_SHARING_VIOLATION:
      case ERROR_SHARING_BUFFER_EXCEEDED:
      case ERROR_ACCESS_DENIED:
         errCode = EACCES;
         break;
      case ERROR_INVALID_PARAMETER:
         errCode = EINVAL;
         break;
      default:
         errCode = EINVAL;
        break;
   }
   return errCode;
}

int
mc_open (char *file, int flags, int pmode)
{
    return open(file, (flags | O_BINARY), pmode);
}

int
mc_unlink(char *pathName)
{
   /* Use OS/2 API to delete a file, if the file is set as read-only,
      the file will be deleted without asking the user! */
   APIRET       rc;
   rc = DosDelete(pathName);
   if (!rc) {
      return 0;
   }
   if (rc == ERROR_ACCESS_DENIED) {
      chmod(pathName, (S_IREAD|S_IWRITE));
      rc = DosDelete(pathName);
      if (rc) {
         errno = conv_os2_unx_rc(rc) ;
         return -1;
      } else {
         return 0;
      }
   } else {
      errno = conv_os2_unx_rc(rc) ;
      return -1;
   }
}

char *
get_default_editor (void)
{
	char *tmp;
	APIRET  rc;
	char    pathValue[5] = "PATH";
	UCHAR   searchResult[MC_MAXPATHLEN + 1];

        /* EPM is not always be installed */
	rc = DosSearchPath((SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY),
			   (PSZ) pathValue,
			   "EPM.EXE",
			   searchResult,
			   sizeof(searchResult));
	if (rc != 0) {
                /* The system editor is always there */
		return strdup("e.exe");
	} else {
                /* Let it be searched from my_system */
		return strdup("epm.exe");
	}
}

/* get_default_shell
   Get the default shell for the current hardware platform
   TODO: Get the value of %OS2_SHELL% or %SHELL%: which one?
*/
char *
get_default_shell()
{
    return getenv ("COMSPEC");
}

int
errno_dir_not_empty (int err)
{
    if (err == ENOTEMPTY)
	return 1;
    return 0;
}

/* The MC library directory is by default the directory where mc.exe
   is situated. It is recommended to specify this directory via MCHOME
   environment variable, otherwise you will be unable to rename mc.exe */
char *
get_mc_lib_dir ()
{
    HMODULE mc_hm;
    int rc;
    char *cur = NULL;
    char *mchome = getenv("MCHOME");

    if (mchome && *mchome)
	return mchome;
    mchome = malloc(MC_MAXPATHLEN);
    rc = DosQueryModuleHandle ("MC.EXE", &mc_hm);
    if (!rc)
	rc = DosQueryModuleName (mc_hm, MC_MAXPATHLEN, mchome);
    if (!rc)
    {
	for (cur = mchome + strlen(mchome); \
	    (cur > mchome) && (*cur != PATH_SEP); cur--);
	*cur = 0;
	cur = strdup(mchome);
	free(mchome);
    }
    if (!cur || !*cur) {
	free(cur);
        return "C:\\MC";
    }
    return cur;
}

int get_user_rights (struct stat *buf)
{
    return 2;
}
void init_groups (void)
{
}
void delete_groups (void)
{
}

⌨️ 快捷键说明

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