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

📄 util_nt.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
			errno = conv_nt_unx_rc(returnError);
			trunced_name = name_trunc(pathName, 30);
			fileName = (char *) malloc(strlen(trunced_name) + 16);
			strcpy(fileName, _("File "));
			strcat(fileName, trunced_name);
			strcat(fileName, _(" protected"));
		    result = query_dialog(fileName, _("Delete anyway?"), 3, 3, _(" No "), _(" Yes "), _(" All in the future!"));
			free(fileName);

		    switch (result) {
		    case 0:
			   do_refresh ();
			   return -1;
		    case 1:
		       do_refresh ();
			   break;
		    case 2:
			   do_refresh ();
			   erase_all = 1;
			   break;
		    default:
			   do_refresh ();
			   return -1;
			   break;
		   }
		}

		chmod(pathName, S_IWRITE); /* make it writable */
		rc = DeleteFile(pathName);
		returnError = GetLastError();
		if (rc == FALSE) {
			errno = conv_nt_unx_rc(returnError);
			return -1;
		}
	}
	if (rc == TRUE) return 0;
	else
		return -1;
}
#endif /*USE_VFS*/

void my_statfs (struct my_statfs *myfs_stats, char *path)
{
    int len = 0;
    DWORD lpSectorsPerCluster, lpBytesPerSector, lpFreeClusters, lpClusters;
       DWORD           lpMaximumComponentLength, lpFileSystemFlags;
       static char     lpVolumeNameBuffer[256], lpFileSystemNameBuffer[30];

       GetDiskFreeSpace(NULL, &lpSectorsPerCluster, &lpBytesPerSector,
			&lpFreeClusters, &lpClusters);

       /* KBytes available */
       myfs_stats->avail = (unsigned int)( ((double)lpSectorsPerCluster * lpBytesPerSector * lpFreeClusters) / 1024 );

       /* KBytes total */
       myfs_stats->total = (unsigned int)( ((double)lpSectorsPerCluster * lpBytesPerSector * lpClusters) / 1024 );
       myfs_stats->nfree = lpFreeClusters;
       myfs_stats->nodes = lpClusters;

       GetVolumeInformation(NULL, lpVolumeNameBuffer, 255, NULL,
			    &lpMaximumComponentLength, &lpFileSystemFlags,
			    lpFileSystemNameBuffer, 30);

       myfs_stats->mpoint = lpFileSystemNameBuffer;
       myfs_stats->device = lpVolumeNameBuffer;


       myfs_stats->type = GetDriveType(NULL);
       switch (myfs_stats->type) {
	   /*
	    * mmm. DeviceIoControl may fail if you are not root case
	    * F5_1Pt2_512,            5.25", 1.2MB,  512 bytes/sector
	    * myfs_stats->typename = "5.25\" 1.2MB"; break; case
	    * F3_1Pt44_512,           3.5",  1.44MB, 512 bytes/sector
	    * myfs_stats->typename = "3.5\" 1.44MB"; break; case
	    * F3_2Pt88_512,           3.5",  2.88MB, 512 bytes/sector
	    * myfs_stats->typename = "3.5\" 2.88MB"; break; case
	    * F3_20Pt8_512,           3.5",  20.8MB, 512 bytes/sector
	    * myfs_stats->typename = "3.5\" 20.8MB"; break; case
	    * F3_720_512,             3.5",  720KB,  512 bytes/sector
	    * myfs_stats->typename = "3.5\" 720MB"; break; case
	    * F5_360_512,             5.25", 360KB,  512 bytes/sector
	    * myfs_stats->typename = "5.25\" 360KB"; break; case
	    * F5_320_512,             5.25", 320KB,  512 bytes/sector
	    * case F5_320_1024,       5.25", 320KB,  1024
	    * bytes/sector myfs_stats->typename = "5.25\" 320KB"; break;
	    * case F5_180_512,        5.25", 180KB,  512
	    * bytes/sector myfs_stats->typename = "5.25\" 180KB"; break;
	    * case F5_160_512,        5.25", 160KB,  512
	    * bytes/sector myfs_stats->typename = "5.25\" 160KB"; break;
	    * case RemovableMedia,    Removable media other than
	    * floppy myfs_stats->typename = "Removable"; break; case
	    * FixedMedia              Fixed hard disk media
	    * myfs_stats->typename = "Hard Disk"; break; case Unknown:
	    * Format is unknown
	    */
       case DRIVE_REMOVABLE:
               myfs_stats->typename = _("Removable");
               break;
       case DRIVE_FIXED:
               myfs_stats->typename = _("Hard Disk");
               break;
       case DRIVE_REMOTE:
               myfs_stats->typename = _("Networked");
               break;
       case DRIVE_CDROM:
               myfs_stats->typename = _("CD-ROM");
               break;
       case DRIVE_RAMDISK:
               myfs_stats->typename = _("RAM disk");
               break;
       default:
               myfs_stats->typename = _("unknown");
               break;
       };
}

int gettimeofday (struct timeval* tvp, void *p)
{
    if (p != NULL)
	return 0;

 /* Since MC only calls this func from get_random_hint we return
    some value, not exactly the "correct" one */
    tvp->tv_sec = GetTickCount()/1000; 	/* Number of milliseconds since Windows //started*/
    tvp->tv_usec = GetTickCount();
}

/* 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++;
      } /* endfor */
      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 ()
{
/*    SID sid;
    LookupAccountName (NULL, &sid...
    return 0;
*/
    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;
}

/* INHANDLE is a result of some mc_open call to any vfs, this function
   returns a normal handle (to be used with read) of a pipe for reading
   of the output of COMMAND with arguments ... (must include argv[0] as
   well) which gets as its input at most INLEN bytes from the INHANDLE
   using mc_read. You have to call mc_doublepclose to close the returned
   handle afterwards. If INLEN is -1, we read as much as we can :) */
int mc_doublepopen (int inhandle, int inlen, pid_t *the_pid, char *command, ...)
{
    int pipe0 [2], pipe1 [2], std_sav [2];
#define MAXARGS 16
	int argno;
	char *args[MAXARGS];
	char buffer [8192];
	int i;
	va_list ap;

    pid_t pid;

	// Create the pipes
	if(_pipe(pipe0, 8192, O_BINARY | O_NOINHERIT) == -1)
   	    exit (1);
	if(_pipe(pipe1, 8192, O_BINARY | O_NOINHERIT) == -1)
   	    exit (1);
	// Duplicate stdin/stdout handles (next line will close original)
	std_sav[0] = _dup(_fileno(stdin));
	std_sav[1] = _dup(_fileno(stdout));
	// Duplicate read end of pipe0 to stdin handle
	if(_dup2(pipe0[0], _fileno(stdin)) != 0)
   	    exit (1);
	// Duplicate write end of pipe1 to stdout handle
	if(_dup2(pipe1[1], _fileno(stdout)) != 0)
   	    exit (1);
	// Close original read end of pipe0
	close(pipe0[0]);
	// Close original write end of pipe1
	close(pipe1[1]);

	va_start (ap, command);
	argno = 0;
	while ((args[argno++] = va_arg(ap, char *)) != NULL)
		if (argno == (MAXARGS - 1)) {
		args[argno] = NULL;
		break;
	}
	va_end (ap);
	// Spawn process
	pid = spawnvp(P_NOWAIT,command, (const char* const*)args);// argv[1], (const char* const*)&argv[1]);
	if(!pid)
   	    exit (1);
	// Duplicate copy of original stdin back into stdin
	if(_dup2(std_sav[0], _fileno(stdin)) != 0)
   	    exit (1);
	// Duplicate copy of original stdout back into stdout
	if(_dup2(std_sav[1], _fileno(stdout)) != 0)
   	    exit (1);
	// Close duplicate copy of original stdout  and stdin
	close(std_sav[0]);
	close(std_sav[1]);


	while ((i = _read (inhandle, buffer,
							 (inlen == -1 || inlen > 8192)
							 ? 8192 : inlen)) > 0) {
		write (pipe0 [1], buffer, i);
		if (inlen != -1) {
			inlen -= i;
			if (!inlen)
				break;
		}
	}
	close (pipe0 [1]);
	*the_pid = pid;
    return pipe1 [0];

}

int mc_doublepclose (int pipe, pid_t pid)
{
    int status = 0;

    close (pipe);
    _cwait ( &status, pid, 0);
    return status;
}

/*hacks to get it compile, remove these after vfs works */

/*hacks to get it compile, remove these after vfs works */
#ifndef USE_VFS
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;
}
#endif

char *
get_default_editor (void)
{
   return "notepad.exe";
}

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

/* The MC library directory is by default the directory where mc.exe
   is situated. It is possible to specify this directory via MCHOME
   environment variable */
char *
get_mc_lib_dir ()
{
    char *cur;
    char *mchome = getenv("MCHOME");

    if (mchome && *mchome)
	return mchome;
    mchome = malloc(MC_MAXPATHLEN);
    GetModuleFileName(NULL, mchome, MC_MAXPATHLEN);
    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 + -