Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	if(argc == 1)
		lsdir(".");
	else
		while(--argc)
			lsdir(*++argv);
	return 0;
}
Ejemplo n.º 2
0
int
ls(const char *path) {
    struct stat __stat, *stat = &__stat;
    int ret, type;
    if ((ret = getstat(path, stat)) != 0) {
        return ret;
    }

    static const char *filetype[] = {
        " [  file   ]",
        " [directory]",
        " [ symlink ]",
        " [character]",
        " [  block  ]",
        " [  ?????  ]",
    };
    switch (getmode(stat->st_mode)) {
    case '0': type = 0; break;
    case 'd': type = 1; break;
    case 'l': type = 2; break;
    case 'c': type = 3; break;
    case 'b': type = 4; break;
    default:  type = 5; break;
    }

    printf(" @ is %s", filetype[type]);
    printf(" %d(hlinks)", stat->st_nlinks);
    printf(" %d(blocks)", stat->st_blocks);
    printf(" %d(bytes) : @'%s'\n", stat->st_size, path);
    if (S_ISDIR(stat->st_mode)) {
        return lsdir(path);
    }
    return 0;
}
Ejemplo n.º 3
0
int FileCommands::analyze(string command, FileSystemUser* fileSystem) {
	vector<string> args = StringService::commandSplit(command);
	if(args.size() == 0) {
		notFoundCommand(command);
		return DEFAULT;
	}
	if(args[0] == commands[MKDIR])  { 
		mkdir(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[EXIT]){ 
		return SHUTDOWN;
	}
	if(args[0] == commands[MKFILE]) {
		mkfile(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[REMDIR]) {
		remdir(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[REMFILE]) {
		remfile(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[CD]) {
		cd(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[LS]) {
		ls(fileSystem);
		return DEFAULT;
	}
	if(args[0] == commands[LSDIR]) {
		lsdir(fileSystem);
		return DEFAULT;
	}
	if(args[0] == commands[LSFILE]) {
		lsfile(fileSystem);
		return DEFAULT;
	}
	if(args[0] == commands[EDIT]) {
		edit(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[SHOW]) {
		show(fileSystem, args[1]);
		return DEFAULT;
	}
	if(args[0] == commands[HELP]) {
		help();
		return DEFAULT;
	}

	notFoundCommand(args[0]);
	return DEFAULT;
}
Ejemplo n.º 4
0
Archivo: ls.c Proyecto: rovaughn/distro
static void
ls(const struct entry *ent, int recurse)
{
	if (recurse && (S_ISDIR(ent->mode) || (S_ISLNK(ent->mode) &&
	     S_ISDIR(ent->tmode) && !Fflag && !lflag)) && !dflag)
		lsdir(ent->name);
	else
		output(ent);
}
Ejemplo n.º 5
0
static int
lsfiles (int fd, uid_t uid, int msize, char *aname, int lopt, char **av, int ac)
{
    Npcfsys *fs = NULL;
    Npcfid *afid = NULL, *root = NULL;
    int i, ret = -1;

    if (!(fs = npc_start (fd, fd, msize, 0))) {
        errn (np_rerror (), "error negotiating protocol with server");
        goto done;
    }
    if (!(afid = npc_auth (fs, aname, uid, diod_auth)) && np_rerror () != 0) {
        errn (np_rerror (), "error authenticating to server");
        goto done;
    }
    if (!(root = npc_attach (fs, afid, aname, uid))) {
        errn (np_rerror (), "error attaching to aname='%s'", aname ? aname : "");
        goto done;
    }
    if (ac == 0) {
        if (lsdir(1, 1, root, lopt, NULL) < 0)
            goto done;
    } else {
        for (i = 0; i < ac; i++) {
            if (lsdir (i, ac, root, lopt, av[i]) < 0)
                goto done;
        }
    }
    ret = 0;
done:
    if (root && npc_clunk (root) < 0) {
        errn (np_rerror (), "error clunking %s", aname);
        ret = -1;
    }
    if (afid && npc_clunk (afid) < 0) {
        errn (np_rerror (), "error clunking afid");
        ret = -1;
    }
    if (fs)
        npc_finish (fs);
    return ret;
}
Ejemplo n.º 6
0
void *client_handler(void * arg){
	struct sockaddr_in client_addr;
	socklen_t addrlen=sizeof(struct sockaddr);

	char buf[255];
	int sockfd=*((int *)arg);
	int client_fd;
	int toterr=0;
	int readlen=0;	
	while(1){
		toterr=0;
		sprintf(buf,"I am FileRobot No.%u welcome to file_server\n",(unsigned int)pthread_self());
		client_fd=accept(sockfd,(struct sockaddr*)&client_addr,&addrlen);

		if(write(client_fd,buf,strlen(buf))<0){
			toterr++;
			perror("FileRobot write error!");
		}

		while(toterr<10){
			if((readlen=read(client_fd,buf,sizeof(buf)))<0){
				toterr++;
				perror("FileRobot write error!");
				sleep(1);
				continue;
			}
			else{
				if(buf[readlen-1]=='\n'){
					buf[readlen-1]='\0';
				}
				else{
					buf[readlen]='\0';
				}
				
				//客户端离开
				if(strncmp(buf,"bye",3)==0){
					printf("client bye!\n");
					break;
				}
				//列出当前目录下的文件
				else if(strncmp(buf,"ls",2)==0){
					lsdir(client_fd,&buf[3]);
				}
				//获取指定的文件
				else if(strncmp(buf,"get",3)==0){
					file_write(client_fd,&buf[4]);
				}

			}
			toterr=0;
		}
		close(client_fd);
	}
}
Ejemplo n.º 7
0
Archivo: ls.c Proyecto: RudoIf/J-O-S
void
ls(const char *path, const char *prefix)
{
	int r;
	struct Stat st;

	if ((r = stat(path, &st,0)) < 0)
		panic("stat %s: %e", path, r);
	if ((st.st_isdir == FTYPE_DIR) && !flag['d'])
		lsdir(path, prefix);
	else
		ls1(0, st.st_isdir, st.st_size, path,st.rwx,st.fuid,st.fgid);
}
Ejemplo n.º 8
0
void
ls(char *path, char *prefix)
{
	int r;
	struct Stat st;

	if ((r=stat(path, &st)) < 0)
		panic("stat %s: %e", path, r);
	if (st.st_isdir && !flag['d'])
		lsdir(path, prefix);
	else
		ls1(0, st.st_isdir, st.st_size, path);
}
Ejemplo n.º 9
0
void
ls(const char *path)
{
	int r;
	struct stat st;

	const char *realpath = path[0] ? path : ".";
	if (stat(realpath, &st) < 0)
		panic("stat %s: %s", realpath, strerror(errno));
	if (S_ISDIR(st.st_mode) && !flag['d'])
		lsdir(path, realpath);
	else
		lsfile(path, realpath);
}
Ejemplo n.º 10
0
int main(int argc, char* argv[]) {

  if (argc < 2) {
    fprintf(stdout, "Usage: %s <disk.d64> [track] [sector]\n", argv[0]);
    return 1;
  }

  char *d = load_disk(argv[1]);

  if (argc == 4) {
    read_file(d, atoi(argv[2]), atoi(argv[3]));
    return 0;
  }

  char label[19];  // Includes null & quotes

  // Read Disk header
  char *b = BLOCK(d, DIR_TRACK, 0);

  // Volume label
#ifdef D1581
  trim(&label[1], &b[4], sizeof(label)-2);
  label[0] = '"';
  strcat(label, "\"");
  printf("0 %s    %c %c\n", label, b[0x19], b[0x1a]);
#else
  trim(&label[1], &b[0x90], sizeof(label)-2);
  label[0] = '"';
  strcat(label, "\"");
  printf("0 %s    %2.2s %2.2s\n", label, &b[0xa2], &b[0xa5]);
#endif

  assert(b[0] == DIR_TRACK);
#ifdef D1581
  assert(b[1] == 3);
  assert(b[2] == 'D');
#else
  assert(b[1] == 1);
  assert(b[2] == 'A');
#endif
  //hexdump(b);

  //write(1, &b[0x90], 16);

  lsdir(d, nextblock(d, b));
  printf("%d BLOCKS FREE.\n", compute_blocks_free(&b[0]));

}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
	int fd, opt, recurse = 0, want_ctime = 0;
	struct stat st;

	char *scratch, *dir = NULL, *file = NULL;
	size_t ssize = 0;

	char *buf;

	while ((opt = getopt(argc, argv, "rd:f:t")) > 0) {
		switch (opt) {
			case 'd':
				dir = optarg;
				break;
			case 'f':
				file = optarg;
				break;
			case 'r':
				recurse++;
				break;
			case 't':
				want_ctime++;
				break;
			default:
				fprintf(stderr,
						"Usage: %s <image> [-d|-f] < path >\n",
						PROGRAM_NAME);
				exit(EXIT_FAILURE);
		}
	}

	fd = open(argv[optind], O_RDONLY);
	if (fd == -1)
		sys_errmsg_die("%s", argv[optind]);

	if (fstat(fd, &st))
		sys_errmsg_die("%s", argv[optind]);

	buf = xmalloc((size_t) st.st_size);

	if (read(fd, buf, st.st_size) != (ssize_t) st.st_size)
		sys_errmsg_die("%s", argv[optind]);

	if (dir)
		lsdir(buf, st.st_size, dir, recurse, want_ctime);

	if (file) {
		scratch = xmalloc(SCRATCH_SIZE);

		catfile(buf, st.st_size, file, scratch, SCRATCH_SIZE, &ssize);
		free(scratch);
	}

	if (!dir && !file)
		lsdir(buf, st.st_size, "/", 1, want_ctime);


	free(buf);
	exit(EXIT_SUCCESS);
}
Ejemplo n.º 12
0
void printdir(char *o, size_t size, struct dir *d, const char *path, int recurse,
		int want_ctime)
{
	char m;
	char *filetime;
	time_t age;
	struct jffs2_raw_inode *ri;
	jint32_t mode;

	if (!path)
		return;
	if (strlen(path) == 1 && *path == '/')
		path++;

	while (d != NULL) {
		switch (d->type) {
			case DT_REG:
				m = ' ';
				break;

			case DT_FIFO:
				m = '|';
				break;

			case DT_CHR:
				m = ' ';
				break;

			case DT_BLK:
				m = ' ';
				break;

			case DT_DIR:
				m = '/';
				break;

			case DT_LNK:
				m = ' ';
				break;

			case DT_SOCK:
				m = '=';
				break;

			default:
				m = '?';
		}
		ri = find_raw_inode(o, size, d->ino);
		if (!ri) {
			warnmsg("bug: raw_inode missing!");
			d = d->next;
			continue;
		}

		filetime = ctime((const time_t *) &(ri->ctime));
		age = time(NULL) - je32_to_cpu(ri->ctime);
		mode.v32 = ri->mode.m;
		printf("%s %-4d %-8d %-8d ", mode_string(je32_to_cpu(mode)),
				1, je16_to_cpu(ri->uid), je16_to_cpu(ri->gid));
		if ( d->type==DT_BLK || d->type==DT_CHR ) {
			dev_t rdev;
			size_t devsize;
			putblock((char*)&rdev, sizeof(rdev), &devsize, ri);
			printf("%4d, %3d ", major(rdev), minor(rdev));
		} else {
			printf("%9ld ", (long)je32_to_cpu(ri->dsize));
		}
		d->name[d->nsize]='\0';
		if (want_ctime) {
			if (age < 3600L * 24 * 365 / 2 && age > -15 * 60)
				/* hh:mm if less than 6 months old */
				printf("%6.6s %5.5s ", filetime + 4, filetime + 11);
			else
				printf("%6.6s %4.4s ", filetime + 4, filetime + 20);
		}
		printf("%s/%s%c", path, d->name, m);
		if (d->type == DT_LNK) {
			char symbuf[1024];
			size_t symsize;
			putblock(symbuf, sizeof(symbuf), &symsize, ri);
			symbuf[symsize] = 0;
			printf(" -> %s", symbuf);
		}
		printf("\n");

		if (d->type == DT_DIR && recurse) {
			char *tmp;
			tmp = xmalloc(BUFSIZ);
			sprintf(tmp, "%s/%s", path, d->name);
			lsdir(o, size, tmp, recurse, want_ctime);	/* Go recursive */
			free(tmp);
		}

		d = d->next;
	}
}