void testValues() { f = 2; dev_t dev = gnu_dev_makedev(12, 34); unsigned int a = gnu_dev_major(dev); //@ assert a == 12; //@ assert f == 2; //@ assert vacuous: \false; }
int is_on_physical_device(int fd) { struct stat sb; int ret; ret = fstat(fd, &sb); if(ret) { perror("fstat"); return -1; } return gnu_dev_major(sb.st_dev); }
void runSuccess() { dev_t dev; gnu_dev_major(dev); }
static long int distinguish_extX (const struct statfs *fsbuf, const char *file, int fd) { char buf[64]; char path[PATH_MAX]; struct stat64 st; if ((file == NULL ? fstat64 (fd, &st) : stat64 (file, &st)) != 0) /* Strange. The statfd call worked, but stat fails. Default to the more pessimistic value. */ return EXT2_LINK_MAX; __snprintf (buf, sizeof (buf), "/sys/dev/block/%u:%u", gnu_dev_major (st.st_dev), gnu_dev_minor (st.st_dev)); ssize_t n = __readlink (buf, path, sizeof (path)); if (n != -1 && n < sizeof (path)) { path[n] = '\0'; char *base = strdupa (basename (path)); __snprintf (path, sizeof (path), "/sys/fs/ext4/%s", base); return __access (path, F_OK) == 0 ? EXT4_LINK_MAX : EXT2_LINK_MAX; } /* XXX Is there a better way to distinguish ext2/3 from ext4 than iterating over the mounted filesystems and compare the device numbers? */ FILE *mtab = __setmntent ("/proc/mounts", "r"); if (mtab == NULL) mtab = __setmntent (_PATH_MOUNTED, "r"); /* By default be conservative. */ long int result = EXT2_LINK_MAX; if (mtab != NULL) { struct mntent mntbuf; char tmpbuf[1024]; /* No locking needed. */ (void) __fsetlocking (mtab, FSETLOCKING_BYCALLER); while (__getmntent_r (mtab, &mntbuf, tmpbuf, sizeof (tmpbuf))) { if (strcmp (mntbuf.mnt_type, "ext2") != 0 && strcmp (mntbuf.mnt_type, "ext3") != 0 && strcmp (mntbuf.mnt_type, "ext4") != 0) continue; struct stat64 fsst; if (stat64 (mntbuf.mnt_dir, &fsst) >= 0 && st.st_dev == fsst.st_dev) { if (strcmp (mntbuf.mnt_type, "ext4") == 0) result = EXT4_LINK_MAX; break; } } /* Close the file. */ __endmntent (mtab); } return result; }