aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2013-06-19 02:15:00 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2013-06-19 02:15:00 +0000
commite30ce44b5875645fbaef8af15950d2418b4bae4f (patch)
treea7c448dad3db4d08f46fcbb9bd5f8d5514c1c764 /src/util/disk.c
parent897ca26d4effabeab55bd1eaa9cc5e9ee52deaa3 (diff)
downloadgnunet-e30ce44b5875645fbaef8af15950d2418b4bae4f.tar.gz
gnunet-e30ce44b5875645fbaef8af15950d2418b4bae4f.zip
This should be a more portable GNUNET_DISK_file_get_identifiers.
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c110
1 files changed, 56 insertions, 54 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index 6da5c8c1d..4a7aa0b31 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -45,39 +45,24 @@
45 */ 45 */
46#define COPY_BLK_SIZE 65536 46#define COPY_BLK_SIZE 65536
47 47
48 48#include <sys/types.h>
49 49#if HAVE_SYS_VFS_H
50#if defined(LINUX) || defined(CYGWIN) || defined(GNU)
51#include <sys/vfs.h> 50#include <sys/vfs.h>
52#else 51#endif
53#if defined(SOMEBSD) || defined(DARWIN) 52#if HAVE_SYS_PARAM_H
54#include <sys/param.h> 53#include <sys/param.h>
54#endif
55#if HAVE_SYS_MOUNT_H
55#include <sys/mount.h> 56#include <sys/mount.h>
56#else 57#endif
57#ifdef SOLARIS 58#if HAVE_SYS_STATVFS_H
58#include <sys/types.h>
59#include <sys/statvfs.h> 59#include <sys/statvfs.h>
60#else
61#ifdef MINGW
62#ifndef PIPE_BUF
63#define PIPE_BUF 512
64ULONG PipeSerialNumber;
65#endif 60#endif
61
62#ifndef S_ISLNK
66#define _IFMT 0170000 /* type of file */ 63#define _IFMT 0170000 /* type of file */
67#define _IFLNK 0120000 /* symbolic link */ 64#define _IFLNK 0120000 /* symbolic link */
68#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) 65#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
69#else
70#error PORT-ME: need to port statfs (how much space is left on the drive?)
71#endif
72#endif
73#endif
74#endif
75
76#if !defined(SOMEBSD) && !defined(DARWIN) && !defined(WINDOWS)
77#include <wordexp.h>
78#endif
79#if LINUX
80#include <sys/statvfs.h>
81#endif 66#endif
82 67
83 68
@@ -343,49 +328,63 @@ int
343GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, 328GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
344 uint64_t * ino) 329 uint64_t * ino)
345{ 330{
346#if LINUX 331#if HAVE_STAT
347 struct stat sbuf;
348 struct statvfs fbuf;
349
350 if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf)))
351 { 332 {
352 *dev = (uint64_t) fbuf.f_fsid; 333 struct stat sbuf;
334
335 if (0 != stat (filename, &sbuf))
336 {
337 return GNUNET_SYSERR;
338 }
353 *ino = (uint64_t) sbuf.st_ino; 339 *ino = (uint64_t) sbuf.st_ino;
354 return GNUNET_OK;
355 } 340 }
356#elif SOMEBSD 341#else
357 struct stat sbuf; 342 *ino = 0;
358 struct statfs fbuf; 343#endif
344#if HAVE_STATVFS
345 {
346 struct statvfs fbuf;
359 347
360 if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf))) 348 if (0 != statvfs (filename, &fbuf))
349 {
350 return GNUNET_SYSERR;
351 }
352 *dev = (uint64_t) fbuf.f_fsid;
353 }
354#elif HAVE_STATFS
361 { 355 {
356 struct statfs fbuf;
357
358 if (0 != statfs (filename, &fbuf))
359 {
360 return GNUNET_SYSERR;
361 }
362 *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || 362 *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
363 ((uint64_t) fbuf.f_fsid.val[1]); 363 ((uint64_t) fbuf.f_fsid.val[1]);
364 *ino = (uint64_t) sbuf.st_ino;
365 return GNUNET_OK;
366 } 364 }
367#elif WINDOWS 365#elif WINDOWS
368 // FIXME NILS: test this
369 struct GNUNET_DISK_FileHandle *fh;
370 BY_HANDLE_FILE_INFORMATION info;
371 int succ;
372
373 fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 0);
374 if (fh == NULL)
375 return GNUNET_SYSERR;
376 succ = GetFileInformationByHandle (fh->h, &info);
377 GNUNET_DISK_file_close (fh);
378 if (succ)
379 { 366 {
367 // FIXME NILS: test this
368 struct GNUNET_DISK_FileHandle *fh;
369 BY_HANDLE_FILE_INFORMATION info;
370 int succ;
371
372 fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 0);
373 if (fh == NULL)
374 return GNUNET_SYSERR;
375 succ = GetFileInformationByHandle (fh->h, &info);
376 GNUNET_DISK_file_close (fh);
377 if (!succ)
378 {
379 return GNUNET_SYSERR;
380 }
380 *dev = info.dwVolumeSerialNumber; 381 *dev = info.dwVolumeSerialNumber;
381 *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) | info.nFileIndexLow); 382 *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) | info.nFileIndexLow);
382 return GNUNET_OK;
383 } 383 }
384 else 384#else
385 return GNUNET_SYSERR; 385 *dev = 0;
386
387#endif 386#endif
388 return GNUNET_SYSERR; 387 return GNUNET_OK;
389} 388}
390 389
391 390
@@ -2166,6 +2165,9 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
2166 2165
2167 2166
2168#if WINDOWS 2167#if WINDOWS
2168#ifndef PIPE_BUF
2169#define PIPE_BUF 512
2170#endif
2169/* Copyright Bob Byrnes <byrnes <at> curl.com> 2171/* Copyright Bob Byrnes <byrnes <at> curl.com>
2170 http://permalink.gmane.org/gmane.os.cygwin.patches/2121 2172 http://permalink.gmane.org/gmane.os.cygwin.patches/2121
2171*/ 2173*/