예제 #1
0
파일: df.c 프로젝트: willsowerbutts/FUZIX
const char *devname(dev_t devno)
{
    static char namebuf[sizeof(DEV_PATH) + MAXNAMLEN + 2];
    static DIR dp;

    struct dirent *entry;
    struct stat fstat;

    if (opendir_r(&dp, DEV_PATH) != (DIR *) NULL) {
        while ((entry = readdir(&dp)) != (struct dirent *) NULL) {
            sprintf(namebuf, "%s/%s", DEV_PATH, entry->d_name);
            if (stat(namebuf, &fstat) != 0)
                continue;
            if (!S_ISBLK(fstat.st_mode))
                continue;
            if (fstat.st_rdev != devno)
                continue;
            closedir_r(&dp);
            return namebuf;
        }
    }
    closedir_r(&dp);

    sprintf(namebuf, "%d", devno);
    return namebuf;
}
예제 #2
0
파일: du.c 프로젝트: 8l/FUZIX
/*
 *	dodir - process the directory d. Return the long size (in blocks)
 *	of d and its descendants.
 */
long dodir(char *d, int thislev, dev_t dev)
{
    int  maybe_print;
    struct stat s;
    long total;
    DIR  dir;
    struct dirent *entry;
    static char dent[LINELEN];

    if (lstat(d, &s) < 0) {
	fprintf(stderr, "%s: %s: %s\n", prog, d, strerror(errno));
	return 0L;
    }

    if (s.st_dev != dev && dev != 0 && crosschk)
	return 0L;

    total = s.st_size;

    if (kbytes)
	total = (total + 1023L) / 1024L;
    else
	total = (total + (long) (BLOCK_SIZE - 1L)) / (long) BLOCK_SIZE;

    switch (s.st_mode & S_IFMT) {
    case S_IFDIR:
        /*
	 * Directories should not be linked except to "." and "..", so this
	 * directory should not already have been done.
	 */
	maybe_print = !silent;
	if (opendir_r(&dir, d) == NULL) break;
	while ((entry = readdir(&dir)) != NULL) {
	    if (strcmp(entry->d_name, ".") == 0 ||
		strcmp(entry->d_name, "..") == 0)
		continue;
	    if (!makedname(d, entry->d_name, dent, sizeof(dent)))
		continue;
	    total += dodir(dent, thislev - 1, s.st_dev);
	}
	closedir_r(&dir);
	break;

    case S_IFBLK:
    case S_IFCHR:
	/* st_size for special files is not related to blocks used. */
	total = 0L;
	/* Fall through. */
    default:
	if (s.st_nlink > 1 && done(s.st_dev, s.st_ino, s.st_nlink))
	    return 0L;
	maybe_print = all;
	break;
    }
    if (thislev >= levels || (maybe_print && thislev >= 0))
	printf("%ld\t%s\n", total, d);

    return (total);
}