Example #1
0
File: ls.c Project: willmc/CS637
void
ls(char *path)
{
  char buf[512], *p;
  int fd;
  struct dirent de;
  struct stat st;
  
  if((fd = open(path, 0)) < 0){
    printf(2, "ls: cannot open %s\n", path);
    return;
  }
  
  if(fstat(fd, &st) < 0){
    printf(2, "ls: cannot stat %s\n", path);
    close(fd);
    return;
  }
  
  switch(st.type){
  case T_FILE:
    //printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
    printf(1, "%s %s %d %d\n", fmtname(path), "FILE", st.ino, st.size);
    break;
  
  case T_DIR:
    if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
      printf(1, "ls: path too long\n");
      break;
    }
    strcpy(buf, path);
    p = buf+strlen(buf);
    *p++ = '/';
    while(read(fd, &de, sizeof(de)) == sizeof(de)){
      if(de.inum == 0)
        continue;
      memmove(p, de.name, DIRSIZ);
      p[DIRSIZ] = 0;
      if(stat(buf, &st) < 0){
        printf(1, "ls: cannot stat %s\n", buf);
        continue;
      }
      char *tmp;
      if(st.type == T_DIR)
          tmp = "DIR ";
      else if (st.type == T_FILE )
          tmp = "FILE";
      else if (st.type == T_DEV )
          tmp = "DEV ";

      printf(1, "%s %s %d %d\n", fmtname(buf), tmp, st.ino, st.size);
    }
    break;
  }
  close(fd);
}
Example #2
0
File: ls.c Project: tim48134/xylos
void
ls(char *path)
{
	char buf[512], *p;
	int fd;
	struct dirent de;
	struct stat st;

	if((fd = open(path, 0)) < 0) {
		printf(2, "ls: cannot open %s\n", path);
		return;
	}

	if(fstat(fd, &st) < 0) {
		printf(2, "ls: cannot stat %s\n", path);
		close(fd);
		return;
	}

	switch(st.type) {
		case T_FILE:
			printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
			break;

		case T_DIR:
			if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf) {
				printf(1, "ls: path too long\n");
				break;
			}
			strcpy(buf, path);
			p = buf + strlen(buf);
			*p++ = '/';
			while(read(fd, &de, sizeof(de)) == sizeof(de)) {
				if(de.inum == 0) {
					continue;
				}
				memmove(p, de.name, DIRSIZ);
				p[DIRSIZ] = 0;
				if(stat(buf, &st) < 0) {
					printf(1, "ls: cannot stat %s\n", buf);
					continue;
				}
				if(st.type == T_DIR && strcmp(p, ".") != 0 && strcmp(p, "..") != 0) {
					printf_color(COLOR_BLACK, COLOR_LIGHT_BLUE, true, 1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
				} else if(st.type == T_DEV) {
					printf_color(COLOR_BLACK, COLOR_YELLOW, true, 1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
				} else {
					printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
				}
			}
			break;
	}
	close(fd);
}
Example #3
0
void ls(char *path)
{
	char buf[512], *p;
	int fd;
	struct dirent de;
	struct stat st;
	
	if((fd = open(path, 0)) < 0)
	{
		printf(2, "cannot open %s\n", path);
		return;
	}
	
	if(fstat(fd, &st) < 0)
	{
		printf(2, "cannot stat %s\n", path);
		close(fd);
		return;
	}
	
	switch(st.type)
	{
		case T_FILE:
		printf(1, "name = %s, type = file, size = %d\n", fmtname(path), st.size);
		break;
		
		case T_DIR:
		if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf)
		{
			printf(1, "path too long\n");
			break;
		}
		strcpy(buf, path);
		p = buf+strlen(buf);
		*p++ = '/';
		
		while(read(fd, &de, sizeof(de)) == sizeof(de))
		{
			if(de.inum == 0)
				continue;
			memmove(p, de.name, DIRSIZ);
			p[DIRSIZ] = 0;
			if(stat(buf, &st) < 0)
			{
				printf(1, "cannot stat %s\n", buf);
				continue;
			}
			printf(1, "name = %s, type = directory, size = %d\n", fmtname(buf), st.size);
		}
		break;
	}
	close(fd);
}
Example #4
0
void test_copy(uint32_t w, uint32_t h, uint32_t sformat, uint32_t dformat)
{
	PixmapPtr src, dest;
	C2D_OBJECT blit = {};
	C2D_RECT rect;
	c2d_ts_handle curTimestamp;

	RD_START("copy", "%dx%d format:%s->%s", w, h,
			fmtname(sformat), fmtname(dformat));

	dest = create_pixmap(w, h, dformat);
	src  = create_pixmap(13, 17, sformat);

	rect.x = 1;
	rect.y = 2;
	rect.width = w - 2;
	rect.height = h - 3;
	CHK(c2dFillSurface(dest->id, 0xff556677, &rect));

	rect.x = 0;
	rect.y = 0;
	rect.width = 13;
	rect.height = 17;
	CHK(c2dFillSurface(src->id, 0xff223344, &rect));

	blit.surface_id = src->id;
	blit.config_mask = DEFAULT_BLIT_MASK;
	blit.next = NULL;

	blit.source_rect.x = FIXED(1);
	blit.source_rect.y = FIXED(2);
	blit.source_rect.width = FIXED(13-1);
	blit.source_rect.height = FIXED(17-2);

	blit.target_rect.x = FIXED((w - 13) / 2);
	blit.target_rect.y = FIXED((h - 17) / 2);
	blit.target_rect.width = FIXED(13);
	blit.target_rect.height = FIXED(17);
	CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	free_pixmap(src);
	free_pixmap(dest);

	RD_END();

//	dump_pixmap(dest, "copy-%04dx%04d-%08x.bmp", w, h, dformat);
}
Example #5
0
static const char *
conf_namemask(char *b, size_t l, const struct conf *c)
{
	strlcpy(b, fmtname(c->c_name), l);
	fmtmask(b, l, c->c_family, c->c_rmask);
	return b;
}
Example #6
0
File: ls.c Project: joaobatalha/zv6
void
ls(char *path)
{
    char buf[512], *p;
    int fd;
    struct dirent de;
    struct stat st;
    int r;

    if((fd = open(path, 0)) < 0) {
        printf(2, "ls: cannot open %s", path);
        if (fd == E_CORRUPTED)
            printf(2, ": CORRUPTED");
        printf(2, "\n");
        return;
    }

    if((r = fstat(fd, &st)) < 0) {
        printf(2, "ls: cannot stat %s", path);
        if (r == E_CORRUPTED)
            printf(2, ": CORRUPTED");
        printf(2, "\n");
        close(fd);
        return;
    }

    switch(st.type) {
    case T_FILE:
        printf(1, "%s %d %d %d %d %d %x\n", fmtname(path), st.type, st.ino, st.size, st.child1, st.child2, st.checksum);
        break;

    case T_DIR:
        if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf) {
            printf(1, "ls: path too long\n");
            break;
        }
        strcpy(buf, path);
        p = buf+strlen(buf);
        *p++ = '/';
        while(read(fd, &de, sizeof(de)) == sizeof(de)) {

            if(de.inum == 0)
                continue;

            memmove(p, de.name, DIRSIZ);
            p[DIRSIZ] = 0;

            r = stat(buf, &st);

            if (r == E_CORRUPTED || r == -E_CORRUPTED) {
                printf(1, "%s CORRUPTED\n", fmtname(buf));
                continue;
            } else if (r < 0) {
                printf(1, "ls: cannot stat %s\n", buf);
                continue;
            }
            printf(1, "%s %d %d %d %d %d %x\n", fmtname(buf), st.type, st.ino, st.size, st.child1, st.child2, st.checksum);
        }
        break;
    }
    close(fd);
}