48 filesystems =
_free(filesystems);
49 fsnames =
_free(fsnames);
53 #if defined(HAVE_MNTCTL)
57 #include <sys/mntctl.h>
58 #include <sys/vmount.h>
83 num = mntctl(MCTL_QUERY,
sizeof(size), (
char *) &size);
98 num = mntctl(MCTL_QUERY, size, buf);
105 numFilesystems =
num;
107 filesystems = (
struct fsinfo *)
xcalloc((numFilesystems + 1),
sizeof(*filesystems));
108 fsnames = (
const char **)
xcalloc((numFilesystems + 1),
sizeof(
char *));
110 for (vm = buf, i = 0; i <
num; i++) {
112 fsnameLength = vm->vmt_data[VMT_STUB].vmt_size;
113 fsn = (
char *)
xmalloc(fsnameLength + 1);
114 strncpy(fsn, (
char *)vm + vm->vmt_data[VMT_STUB].vmt_off,
119 #if defined(RPM_VENDOR_OPENPKG)
120 if (!(strcmp(fsn,
"/proc") == 0)) {
122 if (
Stat(fsn, &sb) < 0) {
135 filesystems[
i].
dev = sb.st_dev;
137 #if defined(RPM_VENDOR_OPENPKG)
142 vm = (
struct vmount *)((
char *)vm + vm->vmt_length);
170 # if GETMNTENT_ONE || GETMNTENT_TWO
180 # elif defined(HAVE_GETMNTINFO_R)
182 struct statfs * mounts = NULL;
183 int mntCount = 0, bufSize = 0,
flags = MNT_NOWAIT;
186 getmntinfo_r(&mounts,
flags, &mntCount, &bufSize);
187 # elif defined(HAVE_GETMNTINFO)
189 #if defined(__NetBSD__)
190 struct statvfs * mounts = NULL;
192 struct statfs * mounts = NULL;
194 int mntCount = 0,
flags = MNT_NOWAIT;
198 mntCount = getmntinfo(&mounts,
flags);
201 filesystems = (
struct fsinfo *)
xcalloc((numAlloced + 1),
sizeof(*filesystems));
212 #if defined(MNTOPT_RO)
214 if (hasmntopt(itemptr, MNTOPT_RO) != NULL)
223 # elif defined(HAVE_GETMNTINFO_R)
225 if (nextMount == mntCount)
break;
226 mntdir = mounts[nextMount++].f_mntonname;
227 # elif defined(HAVE_GETMNTINFO)
229 if (nextMount == mntCount)
break;
230 mntdir = mounts[nextMount++].f_mntonname;
233 #if defined(RPM_VENDOR_OPENPKG)
234 if (strcmp(mntdir,
"/proc") == 0)
238 if (
Stat(mntdir, &sb) < 0) {
254 if ((numFilesystems + 2) == numAlloced) {
257 sizeof(*filesystems) * (numAlloced + 1));
266 (
unsigned) filesystems[numFilesystems].
dev,
267 (filesystems[numFilesystems].rdonly ?
"ro" :
"rw"),
268 filesystems[numFilesystems].
mntPoint);
273 # if GETMNTENT_ONE || GETMNTENT_TWO
275 # elif defined(HAVE_GETMNTINFO_R)
276 mounts =
_free(mounts);
283 fsnames = (
const char **)
xcalloc((numFilesystems + 1),
sizeof(*fsnames));
285 fsnames[i] = filesystems[i].
mntPoint;
300 if (listptr) *listptr =
fsnames;
317 const char * sourceDir;
319 dev_t lastDev = (dev_t)-1;
329 sourceDir =
rpmGetPath(
"%{_sourcedir}", NULL);
331 maxLen = strlen(sourceDir);
332 for (i = 0; i < numFiles; i++) {
333 len = strlen(fileList[i]);
334 if (maxLen < len) maxLen =
len;
337 buf = (
char *)
alloca(maxLen + 1);
338 lastDir = (
char *)
alloca(maxLen + 1);
339 dirName = (
char *)
alloca(maxLen + 1);
343 for (i = 0; i < numFiles; i++) {
344 if (*fileList[i] ==
'/') {
345 strcpy(buf, fileList[i]);
346 chptr = buf + strlen(buf) - 1;
347 while (*chptr !=
'/') chptr--;
354 strcpy(buf, sourceDir);
357 if (strcmp(lastDir, buf)) {
358 strcpy(dirName, buf);
359 chptr = dirName + strlen(dirName) - 1;
360 while (
Stat(dirName, &sb) < 0) {
372 while (*chptr !=
'/') chptr--;
374 if (chptr == dirName)
380 if (lastDev != sb.st_dev) {
382 if (filesystems && filesystems[j].dev == sb.st_dev)
385 if (j >= numFilesystems) {
387 _(
"file %s is on an unknown device\n"), buf);
396 strcpy(lastDir, buf);
397 usages[lastfs] += fssizes[
i];
402 sourceDir =
_free(sourceDir);
404 if (rc == 0 && usagesPtr)
407 usages =
_free(usages);
const char const char size_t len
static struct fsinfo * filesystems
char * xstrdup(const char *str)
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
int Stat(const char *path, struct stat *st)
stat(2) clone.
Access mounted file system information.
static void rpmlog(int code, const char *fmt,...)
Yet Another syslog(3) API clone.
static const char ** fsnames
void * xcalloc(size_t nmemb, size_t size)
struct our_mntent * getmntent(FILE *filep)
const char const bson * command
static int numFilesystems
unsigned long long rpmuint64_t
void rpmFreeFilesystems(void)
Release storage used by file system usage cache.
const char const bson int mongo_write_concern int flags
static const char * dirName
int rpmGetFilesystemList(const char ***listptr, rpmuint32_t *num)
Return (cached) file system mount points.
const char const char size_t size
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
static int getFilesystemList(void)
Get information for mounted file systems.
int rpmGetFilesystemUsage(const char **fileList, rpmuint32_t *fssizes, int numFiles, rpmuint64_t **usagesPtr, int flags)
Determine per-file system usage for a list of files.
const char const bson int num