int main(int ac, char **av) { int lc, i; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); } /* perform global setup for test */ setup(); /* check looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { if (i == 0) { TEST(ustat(dev_num[i], ubuf)); } else { TEST(ustat(dev_num[i], (struct ustat *)-1)); } if ((TEST_RETURN == -1) && (TEST_ERRNO == testcase[i]. exp_errno)) { tst_resm(TPASS, "ustat(2) expected failure;" " Got errno - %s : %s", testcase[i].exp_errval, testcase[i].err_desc); } else { tst_resm(TFAIL, "ustat(2) failed to produce" " expected error; %d, errno" ": %s and got %d", testcase[i].exp_errno, testcase[i].exp_errval, TEST_ERRNO); } TEST_ERROR_LOG(TEST_ERRNO); } /*End of TEST LOOPS */ } /* End of TEST_LOOPING */ /*Clean up and exit */ cleanup(); /*NOTREACHED*/ return 0; } /*End of main */
int main(int argc, char *argv[]) { int lc, i; char *msg; /*parse standard options */ if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { TEST(ustat(dev_num, ubuf)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "ustat(2) failed and set" "the errno to %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "ustat(2) passed"); } } } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int lc, i; tst_parse_opts(argc, argv, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { TEST(ustat(dev_num, &ubuf)); if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS) tst_brkm(TCONF, cleanup, "ustat not supported"); if (TEST_RETURN == -1) { tst_resm(TFAIL, "ustat(2) failed and set" "the errno to %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "ustat(2) passed"); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; /* loop counter */ char *msg; /* message returned from parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { if (i == 0) { TEST(ustat(dev_num[i], ubuf)); } else { TEST(ustat(dev_num[i], (struct ustat *)-1)); } if ((TEST_RETURN == -1) && (TEST_ERRNO == testcase[i]. exp_errno)) { tst_resm(TPASS, "ustat(2) expected failure;" " Got errno - %s : %s", testcase[i].exp_errval, testcase[i].err_desc); } else { tst_resm(TFAIL, "ustat(2) failed to produce" " expected error; %d, errno" ": %s and got %d", testcase[i].exp_errno, testcase[i].exp_errval, TEST_ERRNO); } TEST_ERROR_LOG(TEST_ERRNO); } /*End of TEST LOOPS */ } /*Clean up and exit */ cleanup(); tst_exit(); } /*End of main */
/* **************************************************************** * Função para obter o tamanho do bloco * **************************************************************** */ int round_file_size_to_BL (const STAT *sp) { static dev_t cache_dev = NODEV; static int cache_symlink_sz; int size; /* * Em primeiro lugar, obtém o tamanho do bloco */ if (!blkmask_given && sp->st_dev != cache_dev) { USTAT *up = alloca (sizeof (USTAT)); if (ustat (sp->st_dev, up) < 0) { error ( "$*Não consegui obter o estado do sistema de arquivos %d::%d", MAJOR (sp->st_dev), MINOR (sp->st_dev) ); } cache_dev = sp->st_dev; cache_symlink_sz = up->f_symlink_sz; blkmask = up->f_bsize - 1; } /* * Verifica o tipo de arquivo */ size = sp->st_size; switch (sp->st_mode & S_IFMT) { case S_IFREG: case S_IFDIR: break; case S_IFLNK: if (size < cache_symlink_sz) return (0); break; default: return (0); } /* * Agora arredonda */ return (((size + blkmask) & ~blkmask) >> BLSHIFT); } /* end round_file_size_to_BL */
/*---------------------------------------------------------------------*/ UINT64 DiskSpace(CHAR * pathname) { struct stat sbuf; struct ustat ubuf; if (stat((char *) pathname, &sbuf) != 0) return 0; if (ustat(sbuf.st_dev, &ubuf) != 0) return 0; return (UINT64) ubuf.f_tfree * (UINT64) 512; }
long test_nfs (int fd) { struct stat sbuf; struct ustat usbuf; struct statvfs vsbuf; /* Any base type that begins with "nfs" or "afs" is considered to be a * network filesystem. */ return ((!fstat (fd,&sbuf) && !ustat (sbuf.st_dev,&usbuf) && !++usbuf.f_tinode) || (!fstatvfs (fd,&vsbuf) && (vsbuf.f_basetype[1] == 'f') && (vsbuf.f_basetype[2] == 's') && ((vsbuf.f_basetype[0] == 'n') || (vsbuf.f_basetype[0] == 'a')))) ? LONGT : NIL; }
void com_probe(struct consdev *cn) { int i; struct linux_stat sb; for (i = 0; i < NCOM; i++) { if (ustat(compath[i], &sb) != 0) continue; printf("com%d ", i); } cn->cn_pri = CN_LOWPRI; /* XXX from arm/conf.c */ cn->cn_dev = makedev(12, 0); }
int main (int argc, char **argv) { struct stat sbuf; struct ustat buf; if (argc != 2) err_quit ("Usage: ustat file"); if (stat (argv [1], &sbuf) == -1) err_msg ("stat of %s failed", argv [1]); if (ustat (sbuf.st_dev, &buf) == -1) err_msg ("ustat of %s failed", argv [1]); printf ("File system containing: %s\n", argv [1]); printf (" Total free blocks: %lu\n", buf.f_tfree); printf (" Total free inodes: %lu\n", buf.f_tinode); printf (" File system name: %s\n", buf.f_fname); printf (" File system pack name: %s\n", buf.f_fpack); return (0); }
/* * Eject the current CD, if there is one. */ int gen_eject( struct wm_drive *d ) { struct stat stbuf; struct ustat ust; if (fstat(d->fd, &stbuf) != 0) return -2; /* Is this a mounted filesystem? */ if (ustat(stbuf.st_rdev, &ust) == 0) return -3; if (CD_AutoEject(d->fd)) return -1); /* Close the device if it needs to vanish. */ if (intermittent_dev) gen_close(d); return 0; } /* gen_eject() */
int main(int ac, char **av) { int lc, i; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { TEST(ustat(*tc[i].dev, tc[i].buf)); if ((TEST_RETURN == -1) && (TEST_ERRNO == tc[i].exp_errno)) { tst_resm(TPASS, "ustat(2) expected failure;" " Got errno - %s : %s", tc[i].exp_errval, tc[i].err_desc); } else { tst_resm(TFAIL | TTERRNO, "ustat(2) failed to produce" " expected error; %d, errno" ": %s", tc[i].exp_errno, tc[i].exp_errval); } TEST_ERROR_LOG(TEST_ERRNO); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { TEST(ustat(*tc[i].dev, tc[i].buf)); if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS) tst_brkm(TCONF, cleanup, "ustat not supported"); if ((TEST_RETURN == -1) && (TEST_ERRNO == tc[i].exp_errno)) { tst_resm(TPASS, "ustat(2) expected failure;" " Got errno - %s : %s", tc[i].exp_errval, tc[i].err_desc); } else { tst_resm(TFAIL | TTERRNO, "ustat(2) failed to produce" " expected error; %d, errno" ": %s", tc[i].exp_errno, tc[i].exp_errval); } } } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { char *special, *name, *mountpoint = NULL; struct stat64 st; int i, mountfd; int Aflag = 0; char *chg[2]; int opt; struct fiotune fiotune; if (argc < 3) usage(); special = argv[argc - 1]; /* * For performance, don't search mnttab unless necessary */ if (stat64(special, &st) >= 0) { /* * If mounted directory, search mnttab for special */ if ((st.st_mode & S_IFMT) == S_IFDIR) { if (st.st_ino == UFSROOTINO) searchmnttab(&special, &mountpoint); /* * If mounted device, search mnttab for mountpoint */ } else if ((st.st_mode & S_IFMT) == S_IFBLK || (st.st_mode & S_IFMT) == S_IFCHR) { if (ustat(st.st_rdev, &ustatarea) >= 0) searchmnttab(&special, &mountpoint); } } /* * Doesn't appear to be mounted; take ``unmounted'' path */ if (mountpoint == NULL) searchvfstab(&special); if ((special = getfullrawname(special)) == NULL) { fprintf(stderr, "tunefs: malloc failed\n"); exit(32); } if (*special == '\0') { fprintf(stderr, "tunefs: Could not find raw device for %s\n", argv[argc -1]); exit(32); } if (stat64(special, &st) < 0) { fprintf(stderr, "tunefs: "); perror(special); exit(31+1); } /* * If a mountpoint has been found then we will ioctl() the file * system instead of writing to the file system's device */ /* ustat() ok because max number of UFS inodes can fit in ino_t */ if (ustat(st.st_rdev, &ustatarea) >= 0) { if (mountpoint == NULL) { printf("%s is mounted, can't tunefs\n", special); exit(32); } } else mountpoint = NULL; if ((st.st_mode & S_IFMT) != S_IFBLK && (st.st_mode & S_IFMT) != S_IFCHR) fatal("%s: not a block or character device", special); getsb(&sblock, special); while ((opt = getopt(argc, argv, "o:m:e:d:a:AV")) != EOF) { switch (opt) { case 'A': Aflag++; continue; case 'a': name = "maximum contiguous block count"; if (!isnumber(optarg)) fatal("%s: %s must be >= 1", *argv, name); i = atoi(optarg); if (i < 1) fatal("%s: %s must be >= 1", *argv, name); fprintf(stdout, "%s changes from %d to %d\n", name, sblock.fs_maxcontig, i); sblock.fs_maxcontig = i; continue; case 'd': sblock.fs_rotdelay = 0; continue; case 'e': name = "maximum blocks per file in a cylinder group"; if (!isnumber(optarg)) fatal("%s: %s must be >= 1", *argv, name); i = atoi(optarg); if (i < 1) fatal("%s: %s must be >= 1", *argv, name); fprintf(stdout, "%s changes from %d to %d\n", name, sblock.fs_maxbpg, i); sblock.fs_maxbpg = i; continue; case 'm': name = "minimum percentage of free space"; if (!isnumber(optarg)) fatal("%s: bad %s", *argv, name); i = atoi(optarg); if (i < 0 || i > 99) fatal("%s: bad %s", *argv, name); fprintf(stdout, "%s changes from %d%% to %d%%\n", name, sblock.fs_minfree, i); sblock.fs_minfree = i; continue; case 'o': name = "optimization preference"; chg[FS_OPTSPACE] = "space"; chg[FS_OPTTIME] = "time"; if (strcmp(optarg, chg[FS_OPTSPACE]) == 0) i = FS_OPTSPACE; else if (strcmp(optarg, chg[FS_OPTTIME]) == 0) i = FS_OPTTIME; else fatal("%s: bad %s (options are `space' or `time')", optarg, name); if (sblock.fs_optim == i) { fprintf(stdout, "%s remains unchanged as %s\n", name, chg[i]); continue; } fprintf(stdout, "%s changes from %s to %s\n", name, chg[sblock.fs_optim], chg[i]); sblock.fs_optim = i; continue; case 'V': { char *opt_text; int opt_count; (void) fprintf(stdout, "tunefs -F ufs "); for (opt_count = 1; opt_count < argc; opt_count++) { opt_text = argv[opt_count]; if (opt_text) (void) fprintf(stdout, " %s ", opt_text); } (void) fprintf(stdout, "\n"); } break; default: usage(); } } if ((argc - optind) != 1) usage(); if (mountpoint) { mountfd = open(mountpoint, O_RDONLY); if (mountfd == -1) { perror(mountpoint); fprintf(stderr, "tunefs: can't tune %s\n", mountpoint); exit(32); } fiotune.maxcontig = sblock.fs_maxcontig; fiotune.rotdelay = sblock.fs_rotdelay; fiotune.maxbpg = sblock.fs_maxbpg; fiotune.minfree = sblock.fs_minfree; fiotune.optim = sblock.fs_optim; if (ioctl(mountfd, _FIOTUNE, &fiotune) == -1) { perror(mountpoint); fprintf(stderr, "tunefs: can't tune %s\n", mountpoint); exit(32); } close(mountfd); } else { bwrite((diskaddr_t)SBLOCK, (char *)&sblock, SBSIZE); if (Aflag) for (i = 0; i < sblock.fs_ncg; i++) bwrite(fsbtodb(&sblock, cgsblock(&sblock, i)), (char *)&sblock, SBSIZE); } close(fi); return (0); }