Esempio n. 1
0
int
main(int argc, char *argv[])
{
	int c, modnum = -1;
	char *modname = NULL;
	char *endptr;
	int devfd;
	gid_t gid;

	while ((c = getopt(argc, argv, "i:n:")) != -1) {
		switch (c) {
		case 'i':
			modnum = (int)strtol(optarg, &endptr, 0);
			if (modnum < 0 || modnum > INT_MAX || *endptr != '\0')
				errx(1, "%s: not a valid number", optarg);
			break;
		case 'n':
			modname = optarg;
			break;
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 0)
		usage();

	/*
	 * Open the virtual device device driver for exclusive use (needed
	 * to ioctl() to retrive the loaded module(s) status).
	 */
	if ((devfd = open(_PATH_LKM, O_RDONLY)) == -1)
		err(2, "%s", _PATH_LKM);

	gid = getgid();
	if (setresgid(gid, gid, gid) == -1)
		err(1, "setresgid");

	printf("Type     Id Off %-*s Size %-*s Rev Module Name\n",
	    POINTERSIZE, "Loadaddr", POINTERSIZE, "Info");

	if (modnum != -1 || modname != NULL) {
		if (dostat(devfd, modnum, modname))
			exit(3);
		exit(0);
	}

	/* Start at 0 and work up until we receive EINVAL. */
	for (modnum = 0; dostat(devfd, modnum, NULL) < 2; modnum++)
		;

	exit(0);
}
Esempio n. 2
0
void do_ls(char dirname[])
/*
 * list files in directory called dirname
 * */
{
	DIR	*dir_ptr;	// the directory
	struct dirent	*direntp;	// each entry
	if((dir_ptr = opendir(dirname)) == NULL)
		fprintf(stderr, "ls: cannot open %s\n", dirname);
	else
	{
		while((direntp=readdir(dir_ptr)) != NULL){
			char *p = (char *)malloc(strlen(dirname) + strlen(direntp->d_name) + 2);
			if(p){
				strcpy(p, dirname);
				strcat(p, "/");
				strcat(p, direntp->d_name);
				dostat(p, direntp->d_name);
				free(p);
			}
			else
			{
				printf("Allocate memory failed!");
				exit(1);
			}
		}
		closedir(dir_ptr);
	}
}
Esempio n. 3
0
File: ls.c Progetto: iceout/uup
void do_ls(char dirname[])
{
    DIR *dir_ptr;
    struct dirent *direntp;
    char pathtofile[300] = "";
    char tmp[350];

    if ((dir_ptr = opendir(dirname)) == NULL)  {
        fprintf(stderr, "ls: cannot open %s\n", dirname);
    }
    else {
        printf("%s\n", dirname);
        strcat(pathtofile, dirname);
        strcat(pathtofile, "/");
        printf("path == %s\n", pathtofile);
        if (lsl == 1) {
            while ((direntp = readdir(dir_ptr)) != NULL) {
                tmp[0] = '\0';
                strcat(tmp, pathtofile);
                strcat(tmp, direntp->d_name);
                dostat(tmp);
            }
        }
        else {
            while ((direntp = readdir(dir_ptr)) != NULL) {
                printf("%s\n", direntp->d_name);
            }
        }
        closedir(dir_ptr);
    }
}
Esempio n. 4
0
static int
sizegen(int i, Dir *d, void *v)
{
	vlong path;
	Fid *fid;
	XFont *f;
	int j;

	fid = v;
	path = fid->qid.path;
	if(i == 0) {
		path += Qfontfile - Qsizedir;
		goto Done;
	}
	i--;
	f = &xfont[QFONT(path)];
	load(f);
	for(j=0; j<nelem(f->range); j++) {
		if(f->range[j] == 0)
			continue;
		if(i == 0) {
			path += Qsubfontfile - Qsizedir;
			path += qpath(0, 0, 0, 0, j);
			goto Done;
		}
		i--;
	}
	return -1;

Done:
	dostat(path, nil, d);
	return 0;
}
void do_ls(char dirname[], int check_rec)
{
printf("%s:\n", dirname);
DIR *dir_ptr;
struct dirent *direntp;
if((dir_ptr = opendir(dirname)) == NULL )
fprintf(stderr, "ls1: cannot open %s\n", dirname);
else
{
while((direntp = readdir(dir_ptr))!=NULL)
dostat(direntp->d_name,dirname);
closedir(dir_ptr);
printf("\n");

if(check_rec)
{
dir_ptr = opendir(dirname);
while((direntp = readdir(dir_ptr)) != NULL)
{
char sub_dir[255];
struct stat info;
if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0) continue;
sprintf(sub_dir, "%s/%s", dirname, direntp->d_name);
stat(sub_dir, &info);
if(S_ISDIR(info.st_mode)) do_ls(sub_dir, rec);
}
closedir(dir_ptr);
}
}
}
Esempio n. 6
0
void do_ls( char * dirname )
{
  DIR    *dir_ptr;
  struct dirent  *direntp;

  if ( ( dir_ptr = opendir( dirname ) ) == NULL ) {/*打开目录*/
    fprintf(stderr,"ls1: cannot open %s, not a directory. treat as a file shown below:\n", dirname);
    dostat( dirname ); //如果不是目录就当作文件来显示其属性
 }
  else
  {
    while ( ( direntp = readdir( dir_ptr ) ) != NULL )
      dostat( direntp->d_name );/*逐个显示目录里文件信息*/
    closedir(dir_ptr);
  }
}
Esempio n. 7
0
int main(int argc, char **argv) {
	int c; // getopt
	int i; // argument loop
	int ret = 0; // return code

	if (argc < 2) {
		usage();
		return 1;
	}

	while ((c = getopt(argc, argv, "h")) != EOF) {
		switch (c) {
			case 'h':
				usage();
				return 0;
			case '?':
				usage();
				return 1;
		}
	}

	// loop the remaining arguments and print them
	for (i = optind; i < argc; i++) {
		ret += dostat(argv[i]);
	}
	return ret;
}
Esempio n. 8
0
static void
xattach(Req *r)
{
	dostat(0, &r->ofcall.qid, nil);
	r->fid->qid = r->ofcall.qid;
	respond(r, nil);
}
Esempio n. 9
0
static int
rootgen(int i, Dir *d, void *v)
{
	if(i >= nxfont)
		return -1;
	dostat(qpath(Qfontdir, i, 0, 0, 0), nil, d);
	return 0;
}
Esempio n. 10
0
int main( int argc, char **argv){
	if(argc==1){
		printf("You must provide a file path as an arguement\n");
	} else {
		while(--argc)
			dostat(*++argv);
	}// if

	return 0;
}// end main
Esempio n. 11
0
/*
 * never invoked from glibc.  Probably a way to do files with large
 * offsets withint a 32 bit linux kernel.  This is invoked by the 32
 * bit glibc.
 */
extern "C" int
__k42_linux_stat64 ( char *filename, struct stat64 *output_stat)
{
    struct _gstat64 gstat;

    int rc = dostat(filename, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2lgstat64(output_stat, &gstat);
    return 0;
}
Esempio n. 12
0
File: ls2.c Progetto: Yokoloki/Books
void do_ls(char dirname[]){
    DIR *dir_ptr;
    struct dirent *direntp;
    if((dir_ptr = opendir(dirname)) == NULL)
        fprintf(stderr, "ls2: cannot open %s\n", dirname);
    else{
        while((direntp = readdir(dir_ptr)) != NULL)
            dostat(direntp->d_name);
        closedir(dir_ptr);
    }
}
Esempio n. 13
0
int
__k42_linux_stat (const char *filename, struct stat *kstat)
{
    struct _gstat64 gstat;

    int rc = dostat(filename, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2kstat(kstat, &gstat);
    return 0;
}
Esempio n. 14
0
/*
 * 32 bit within 64 bit kernel "stat"
 */
extern "C" int
__k42_linux_compat_sys_newstat (const char *filename, struct compat_stat *kstat)
{
    //err_printf("compat_sys_newstat: on %s(%016lx)\n", filename, (uval)kstat);
    struct _gstat64 gstat;

    int rc = dostat(filename, (void *) &gstat);
    if (rc < 0) return rc;

    _convert_gstat2kstat32(kstat, &gstat);	// kstat <- gstat
    return 0;
}
Esempio n. 15
0
File: fsys.c Progetto: npe9/harvey
static
Xfid*
fsysstat(Xfid *x, Fid *f)
{
    Fcall t;

    t.stat = emalloc(messagesize-IOHDRSZ);
    t.nstat = dostat(WIN(x->f->qid), f->dir, t.stat, messagesize-IOHDRSZ, getclock());
    x = respond(x, &t, nil);
    free(t.stat);
    return x;
}
Esempio n. 16
0
static int
fontgen(int i, Dir *d, void *v)
{
	vlong path;
	Fid *f;
	
	f = v;
	path = f->qid.path;
	if(i >= 2*nelem(sizes))
		return -1;
	dostat(qpath(Qsizedir, QFONT(path), sizes[i/2], i&1, 0), nil, d);
	return 0;
}
Esempio n. 17
0
/* Show files unsder the dir*/
static void b_ls(char dirname[])
{
    DIR *dir_ptr;   /*The directory to read*/
    struct dirent *direntp; /*The dir info struct*/
    if((dir_ptr = opendir(dirname)) == NULL)    /* Try to open the dir*/
        fprintf(stderr,"ls:cannot open %s\n",dirname);
    else
    {
        while((direntp = readdir(dir_ptr)) != NULL) /* Read the dir info */
            dostat(direntp->d_name, dirname); /* */
        closedir(dir_ptr);  /* Close the dir */
    }
}
Esempio n. 18
0
void do_ls(const char *dirname)
{
    DIR *dir_ptr;
    struct dirent *direntp;

    if ((dir_ptr = opendir(dirname)) == NULL) {
        fprintf(stderr, "ls2:cannot open %s\n", dirname);
    } else {
        printf("%s:\n", dirname);
        while ((direntp = readdir(dir_ptr)) != NULL)
            dostat(direntp->d_name);
        closedir(dir_ptr);
    }
}
Esempio n. 19
0
static void
rstat(Req *r)
{
	Xfile *f=xfile(r->fid, Asis);

	chat("stat(fid=%d)...", thdr.fid);
	errno = 0;
	if( !f )
		errno = Eio;
	else{
		dostat(r->fid->qid, f, &r->d);
	}
	response(r);
}
Esempio n. 20
0
fdata readfile(const char *filename, off_t extra, int fatal)
{
    FILE *fpi;
    size_t bytesread;
    fdata data = {0};
    struct stat sb;
    if (dostat(filename, &sb, fatal) == -1)	return data;
    fpi = dofopen(filename, "r");
    data.from = docalloc(sb.st_size + extra, sizeof(char), "readfile");
	bytesread = dofread(filename, data.from, sb.st_size, fpi);
	dofclose (fpi);
    data.to = data.from + bytesread + extra;
    return data;
} // readfile()
Esempio n. 21
0
File: ls2.c Progetto: orange8637/c
do_ls(char *dirname)
{
	DIR *dir_ptr;
	struct dirent **direntps;
	/*搜索目录下文件项并递增排序*/
	int num = scandir(dirname, &direntps, 0, alphasort);
	if(num < 0)
		fprintf(stderr, "ls2: cannot open %s\n", dirname);
	/*不含详细选项时*/
	else if(longlist == 0)
	{
		int count = 0, i = 0;
		for(; i < num; i++)
		{
			char fname[50];
			strcpy(fname, direntps[i]->d_name);
			if(fname[0] == '.')
				continue;
			printf("%-20s", fname);
			count++;
			/*分栏显示*/
			if(count == 6)
			{
				count = 0;
				printf("\n");
			}
		}
		if(count != 0)
			printf("\n");
	}
	/*详细选项显示*/
	else
	{
		int i = 0;
		for(; i < num; i++)
		{
			char fname[50];
			strcpy(fname, direntps[i]->d_name);
			if(fname[0] == '.')
				continue;
			/*得到文件的绝对路径*/
			char fullname[100];
			strcpy(fullname, dirname);
			strcat(fullname, "/");
			strcat(fullname, fname);
			dostat(fullname);
		}
	}
}
Esempio n. 22
0
void ListFile::ls()
{
		DIR *dir_ptr;
		struct dirent *direntp;
		
		if((dir_ptr = opendir(pfilename)) == NULL)
				fprintf(stderr, "ls2: cannot open %s\n", pfilename);
		else
		{
				while((direntp = readdir(dir_ptr)) != NULL)
						dostat(direntp->d_name);
				closedir(dir_ptr);
		}

}
Esempio n. 23
0
void ls(char *dirname)
{
    DIR *dirp;
    struct dirent *direntp;

    if((dirp = opendir(dirname)) == NULL){
        fprintf(stderr,"ls1:can not open %s\n",dirname);
    }
    else{
        while((direntp = readdir(dirp)) != NULL){
            dostat(direntp->d_name);
        }
        closedir(dirp);
    }
}
void do_ls(char dirname[])
/*
 * list files in directory called dirname 
 * */
{
  DIR *dir_ptr;           /* the directory */
  struct dirent *direntp; /* each entry */

  if ((dir_ptr = opendir(dirname)) == NULL )
     fprintf(stderr, "ls2:cannot open %s\n", dirname);
  else {
     while ((direntp = readdir(dir_ptr)) != NULL )
         dostat(direntp->d_name);
     closedir(dir_ptr);
  }
}
Esempio n. 25
0
void do_ls(char dirname[]) //список файлов в директории
{
    DIR *dir_ptr;
    struct dirent *direntp;
    if ((dir_ptr = opendir(dirname))==NULL)
        fprintf(stderr,"ls2:cannot open %s\n", dirname);
    else
    {
        while ((direntp=readdir(dir_ptr))!=NULL)
        {
            if (strcmp(direntp->d_name,".")==0 || strcmp(direntp->d_name,"..")==0) continue;
            dostat(direntp->d_name);
        }
        closedir(dir_ptr);
    }
}
Esempio n. 26
0
int copyDir(char *source, char *destination)
{
    DIR *dir_ptr = NULL;
    struct dirent *direntp;
    char tempDest[strlen(destination)+1];
    char tempSrc[strlen(source)+1];
    strcat(destination, "/");
    strcat(source, "/");
    strcpy(tempDest, destination);
    strcpy(tempSrc, source);
     
    //char *fileN;
    struct stat fileinfo;
     
    //printf("RIGHT BEFORE COPYING FILES in copyDir()\n");
    //printf("before strcat tempDest=%s\n", tempDest);
 
 
   if( (dir_ptr = opendir(source)) == NULL )
   {
      fprintf(stderr, "cp1: cannot open %s for copying\n", source);
      return 0;
   }
   else
   {
      while( (direntp = readdir(dir_ptr)))
      {      
      //printf("direntp DNAME is %s\n", direntp->d_name);
      //fileN = direntp->d_name;
      //printf("File name before Reg Check is %s\n", fileN);
       
      if(dostat(direntp->d_name))  
      {   
              strcat(tempDest, direntp->d_name);
          //printf("after strcat tempDest=%s\n", tempDest);          
          strcat(tempSrc, direntp->d_name);
          copyFiles(tempSrc, tempDest);
              strcpy(tempDest, destination);
          strcpy(tempSrc, source);            
      }
      }
      closedir(dir_ptr);
      return 1;
   }
 
 
}
Esempio n. 27
0
void do_mkdir(const char *head_dir, const char *newdir)
{
	struct stat sb;
	dostat(head_dir, &sb, 1);	// die if head_dir is not.
	mode_t m = sb.st_mode;
	char buf[PATH_MAX];
	if (strlen(head_dir) + strlen(newdir) > PATH_MAX - 2) {
		fputs("Insane lengths input for head_dir and newdir\n", stderr);
		exit(EXIT_FAILURE);
	}
	sprintf(buf, "%s/%s", head_dir, newdir);
	if (mkdir(buf, m) == -1) {
		fprintf(stderr, "Failed to create dir: %s\n", buf);
		perror(buf);
		exit(EXIT_FAILURE);
	}
} // do_mkdir()
Esempio n. 28
0
int
main(int argc, char **argv)
{
	struct opt *op;
	void (*func)(int, char **) = NULL;

	if (argc < 2)
		prusage(U_ALL, 1);
	Devname = argv[1];
	if (strcmp(Devname, "-") == 0) {
		alldev = 1;
	} else {
		sidev_t dev;
		int n;
		int card, port;

		n = sscanf(Devname, "%d:%d", &card, &port);
		if (n != 2)
			errx(1, "Devname must be in form card:port.  eg: 0:7");
		dev.sid_card = card;
		dev.sid_port = port;
		tc.tc_dev = dev;
	}
	ctlfd = opencontrol();
	if (argc == 2) {
		dostat();
		exit(0);
	}

	argc--; argv++;
	for (op = opt; op->o_name; op++) {
		if (strcmp(argv[1], op->o_name) == 0) {
			func = op->o_func;
			break;
		}
	}
	if (func == NULL)
		prusage(U_ALL, 1);

	argc -= 2;
	argv += 2;
	(*func)(argc, argv);
	exit(0);
}
Esempio n. 29
0
void do_ls(char dirname[])
{
	DIR * dir_ptr;
	struct dirent *direntp;
	char filename[512];
	if((dir_ptr = opendir(dirname)) == NULL)
		fprintf(stderr,"ls3: cannot open %s\n",dirname);
	else
	{
		while((direntp = readdir(dir_ptr))!=NULL) {
			//strncpy(filename, dirname, strlen(dirname));
			strcpy(filename, dirname);
			strcat(filename, direntp->d_name);
			//strncat(filename, direntp->d_name, strlen(direntp->d_name));
			dostat(filename);
		}
		closedir(dir_ptr);
	}
}
void do_ls(char dirname[])
{
	DIR		*dir_ptr;		// the directory
	struct dirent	*direntp;		// each entry
	
//	printf("dir name : %s\n", dirname);
	
	if((dir_ptr = opendir(dirname)) == NULL)
	{
		fprintf(stderr, "ls1 : cannot open %s\n",dirname);
	}
	else
	{
//		printf("do_ls else\n");
		while((direntp = readdir(dir_ptr)) != NULL)
			dostat(direntp->d_name);
		closedir(dir_ptr);
	}
}