aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c102
1 files changed, 47 insertions, 55 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index dd7db7d73..6ba5db773 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -172,8 +172,7 @@ getSizeRec (void *cls, const char *fn)
172#endif 172#endif
173 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) 173 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
174 gfsd->total += buf.st_size; 174 gfsd->total += buf.st_size;
175 if ((S_ISDIR (buf.st_mode)) && 175 if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
176 (0 == ACCESS (fn, X_OK)) &&
177 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) 176 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
178 { 177 {
179 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) 178 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
@@ -255,8 +254,8 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
255 * @return GNUNET_SYSERR on error, GNUNET_OK on success 254 * @return GNUNET_SYSERR on error, GNUNET_OK on success
256 */ 255 */
257int 256int
258GNUNET_DISK_file_size (const char *filename, 257GNUNET_DISK_file_size (const char *filename, uint64_t * size,
259 uint64_t * size, int includeSymLinks) 258 int includeSymLinks)
260{ 259{
261 struct GetFileSizeData gfsd; 260 struct GetFileSizeData gfsd;
262 int ret; 261 int ret;
@@ -286,8 +285,8 @@ GNUNET_DISK_file_size (const char *filename,
286 * @return GNUNET_OK on success 285 * @return GNUNET_OK on success
287 */ 286 */
288int 287int
289GNUNET_DISK_file_get_identifiers (const char *filename, 288GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
290 uint64_t * dev, uint64_t * ino) 289 uint64_t * ino)
291{ 290{
292#if LINUX 291#if LINUX
293 struct stat sbuf; 292 struct stat sbuf;
@@ -427,8 +426,8 @@ GNUNET_DISK_get_blocks_available (const char *part)
427 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) 426 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
428 { 427 {
429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
430 _("`%s' failed for drive `%s': %u\n"), 429 _("`%s' failed for drive `%s': %u\n"), "GetDiskFreeSpace",
431 "GetDiskFreeSpace", szDrive, GetLastError ()); 430 szDrive, GetLastError ());
432 431
433 return -1; 432 return -1;
434 } 433 }
@@ -772,15 +771,14 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
772 * @return number of bytes written on success, GNUNET_SYSERR on error 771 * @return number of bytes written on success, GNUNET_SYSERR on error
773 */ 772 */
774ssize_t 773ssize_t
775GNUNET_DISK_fn_write (const char *fn, const void *buffer, 774GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
776 size_t n, enum GNUNET_DISK_AccessPermissions mode) 775 enum GNUNET_DISK_AccessPermissions mode)
777{ 776{
778 struct GNUNET_DISK_FileHandle *fh; 777 struct GNUNET_DISK_FileHandle *fh;
779 ssize_t ret; 778 ssize_t ret;
780 779
781 fh = GNUNET_DISK_file_open (fn, 780 fh = GNUNET_DISK_file_open (fn,
782 GNUNET_DISK_OPEN_WRITE 781 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
783 | GNUNET_DISK_OPEN_TRUNCATE
784 | GNUNET_DISK_OPEN_CREATE, mode); 782 | GNUNET_DISK_OPEN_CREATE, mode);
785 if (!fh) 783 if (!fh)
786 return GNUNET_SYSERR; 784 return GNUNET_SYSERR;
@@ -862,10 +860,7 @@ GNUNET_DISK_directory_scan (const char *dirName,
862 /* dname can end in "/" only if dname == "/"; 860 /* dname can end in "/" only if dname == "/";
863 * if dname does not end in "/", we need to add 861 * if dname does not end in "/", we need to add
864 * a "/" (otherwise, we must not!) */ 862 * a "/" (otherwise, we must not!) */
865 GNUNET_snprintf (name, 863 GNUNET_snprintf (name, n_size, "%s%s%s", dname,
866 n_size,
867 "%s%s%s",
868 dname,
869 (strcmp (dname, DIR_SEPARATOR_STR) == 864 (strcmp (dname, DIR_SEPARATOR_STR) ==
870 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); 865 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
871 if (GNUNET_OK != callback (callback_cls, name)) 866 if (GNUNET_OK != callback (callback_cls, name))
@@ -954,8 +949,8 @@ directory_iterator_task (void *cls,
954 * GNUNET_SYSERR if abort was YES 949 * GNUNET_SYSERR if abort was YES
955 */ 950 */
956int 951int
957GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator 952GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
958 *iter, int can) 953 int can)
959{ 954{
960 struct dirent *finfo; 955 struct dirent *finfo;
961 956
@@ -972,8 +967,8 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
972 if ((0 == strcmp (finfo->d_name, ".")) || 967 if ((0 == strcmp (finfo->d_name, ".")) ||
973 (0 == strcmp (finfo->d_name, ".."))) 968 (0 == strcmp (finfo->d_name, "..")))
974 continue; 969 continue;
975 GNUNET_asprintf (&iter->next_name, 970 GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname,
976 "%s%s%s", iter->dirname, DIR_SEPARATOR_STR, finfo->d_name); 971 DIR_SEPARATOR_STR, finfo->d_name);
977 break; 972 break;
978 } 973 }
979 if (finfo == NULL) 974 if (finfo == NULL)
@@ -981,8 +976,8 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
981 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); 976 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
982 return GNUNET_NO; 977 return GNUNET_NO;
983 } 978 }
984 GNUNET_SCHEDULER_add_with_priority (iter->priority, 979 GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task,
985 &directory_iterator_task, iter); 980 iter);
986 return GNUNET_YES; 981 return GNUNET_YES;
987} 982}
988 983
@@ -1101,13 +1096,14 @@ GNUNET_DISK_file_copy (const char *src, const char *dst)
1101 GNUNET_DISK_PERM_NONE); 1096 GNUNET_DISK_PERM_NONE);
1102 if (!in) 1097 if (!in)
1103 return GNUNET_SYSERR; 1098 return GNUNET_SYSERR;
1104 out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE 1099 out =
1105 | GNUNET_DISK_OPEN_CREATE | 1100 GNUNET_DISK_file_open (dst,
1106 GNUNET_DISK_OPEN_FAILIFEXISTS, 1101 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
1107 GNUNET_DISK_PERM_USER_READ | 1102 GNUNET_DISK_OPEN_FAILIFEXISTS,
1108 GNUNET_DISK_PERM_USER_WRITE | 1103 GNUNET_DISK_PERM_USER_READ |
1109 GNUNET_DISK_PERM_GROUP_READ | 1104 GNUNET_DISK_PERM_USER_WRITE |
1110 GNUNET_DISK_PERM_GROUP_WRITE); 1105 GNUNET_DISK_PERM_GROUP_READ |
1106 GNUNET_DISK_PERM_GROUP_WRITE);
1111 if (!out) 1107 if (!out)
1112 { 1108 {
1113 GNUNET_DISK_file_close (in); 1109 GNUNET_DISK_file_close (in);
@@ -1152,8 +1148,8 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1152 { 1148 {
1153 c = *idx; 1149 c = *idx;
1154 1150
1155 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || 1151 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
1156 c == '"' || c == '<' || c == '>' || c == '|') 1152 c == '<' || c == '>' || c == '|')
1157 { 1153 {
1158 *idx = '_'; 1154 *idx = '_';
1159 } 1155 }
@@ -1181,8 +1177,8 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1181 if (pws == NULL) 1177 if (pws == NULL)
1182 { 1178 {
1183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1184 _("Cannot obtain information about user `%s': %s\n"), 1180 _("Cannot obtain information about user `%s': %s\n"), user,
1185 user, STRERROR (errno)); 1181 STRERROR (errno));
1186 return GNUNET_SYSERR; 1182 return GNUNET_SYSERR;
1187 } 1183 }
1188 if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) 1184 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
@@ -1226,8 +1222,9 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1226 memset (&o, 0, sizeof (OVERLAPPED)); 1222 memset (&o, 0, sizeof (OVERLAPPED));
1227 o.Offset = lockStart; 1223 o.Offset = lockStart;
1228 1224
1229 if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) 1225 if (!LockFileEx
1230 | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o)) 1226 (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
1227 0, lockEnd - lockStart, 0, &o))
1231 { 1228 {
1232 SetErrnoFromWinError (GetLastError ()); 1229 SetErrnoFromWinError (GetLastError ());
1233 return GNUNET_SYSERR; 1230 return GNUNET_SYSERR;
@@ -1295,8 +1292,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1295 * @return IO handle on success, NULL on error 1292 * @return IO handle on success, NULL on error
1296 */ 1293 */
1297struct GNUNET_DISK_FileHandle * 1294struct GNUNET_DISK_FileHandle *
1298GNUNET_DISK_file_open (const char *fn, 1295GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1299 enum GNUNET_DISK_OpenFlags flags,
1300 enum GNUNET_DISK_AccessPermissions perm) 1296 enum GNUNET_DISK_AccessPermissions perm)
1301{ 1297{
1302 char *expfn; 1298 char *expfn;
@@ -1385,8 +1381,9 @@ GNUNET_DISK_file_open (const char *fn,
1385 } 1381 }
1386 1382
1387 /* TODO: access priviledges? */ 1383 /* TODO: access priviledges? */
1388 h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ 1384 h = CreateFile (expfn, access,
1389 | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); 1385 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1386 disp, FILE_ATTRIBUTE_NORMAL, NULL);
1390 if (h == INVALID_HANDLE_VALUE) 1387 if (h == INVALID_HANDLE_VALUE)
1391 { 1388 {
1392 SetErrnoFromWinError (GetLastError ()); 1389 SetErrnoFromWinError (GetLastError ());
@@ -1713,10 +1710,9 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1713 Note that the return value is either NO_ERROR or GetLastError, 1710 Note that the return value is either NO_ERROR or GetLastError,
1714 unlike CreatePipe, which returns a bool for success or failure. */ 1711 unlike CreatePipe, which returns a bool for success or failure. */
1715static int 1712static int
1716create_selectable_pipe (PHANDLE read_pipe_ptr, 1713create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
1717 PHANDLE write_pipe_ptr, 1714 LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
1718 LPSECURITY_ATTRIBUTES sa_ptr, 1715 DWORD dwReadMode, DWORD dwWriteMode)
1719 DWORD psize, DWORD dwReadMode, DWORD dwWriteMode)
1720{ 1716{
1721 /* Default to error. */ 1717 /* Default to error. */
1722 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; 1718 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -1921,10 +1917,9 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1921 SetErrnoFromWinError (GetLastError ()); 1917 SetErrnoFromWinError (GetLastError ());
1922 return NULL; 1918 return NULL;
1923 } 1919 }
1924 if (!DuplicateHandle (GetCurrentProcess (), p->fd[0]->h, 1920 if (!DuplicateHandle
1925 GetCurrentProcess (), &tmp_handle, 0, 1921 (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
1926 inherit_read == GNUNET_YES ? TRUE : FALSE, 1922 inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1927 DUPLICATE_SAME_ACCESS))
1928 { 1923 {
1929 SetErrnoFromWinError (GetLastError ()); 1924 SetErrnoFromWinError (GetLastError ());
1930 CloseHandle (p->fd[0]->h); 1925 CloseHandle (p->fd[0]->h);
@@ -1935,10 +1930,9 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1935 CloseHandle (p->fd[0]->h); 1930 CloseHandle (p->fd[0]->h);
1936 p->fd[0]->h = tmp_handle; 1931 p->fd[0]->h = tmp_handle;
1937 1932
1938 if (!DuplicateHandle (GetCurrentProcess (), p->fd[1]->h, 1933 if (!DuplicateHandle
1939 GetCurrentProcess (), &tmp_handle, 0, 1934 (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
1940 inherit_write == GNUNET_YES ? TRUE : FALSE, 1935 inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1941 DUPLICATE_SAME_ACCESS))
1942 { 1936 {
1943 SetErrnoFromWinError (GetLastError ()); 1937 SetErrnoFromWinError (GetLastError ());
1944 CloseHandle (p->fd[0]->h); 1938 CloseHandle (p->fd[0]->h);
@@ -2093,8 +2087,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
2093 * @return pipe handle on success, NULL on error 2087 * @return pipe handle on success, NULL on error
2094 */ 2088 */
2095struct GNUNET_DISK_FileHandle * 2089struct GNUNET_DISK_FileHandle *
2096GNUNET_DISK_npipe_create (char **fn, 2090GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2097 enum GNUNET_DISK_OpenFlags flags,
2098 enum GNUNET_DISK_AccessPermissions perm) 2091 enum GNUNET_DISK_AccessPermissions perm)
2099{ 2092{
2100#ifdef MINGW 2093#ifdef MINGW
@@ -2226,8 +2219,7 @@ GNUNET_DISK_npipe_create (char **fn,
2226 * @return pipe handle on success, NULL on error 2219 * @return pipe handle on success, NULL on error
2227 */ 2220 */
2228struct GNUNET_DISK_FileHandle * 2221struct GNUNET_DISK_FileHandle *
2229GNUNET_DISK_npipe_open (const char *fn, 2222GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
2230 enum GNUNET_DISK_OpenFlags flags,
2231 enum GNUNET_DISK_AccessPermissions perm) 2223 enum GNUNET_DISK_AccessPermissions perm)
2232{ 2224{
2233#ifdef MINGW 2225#ifdef MINGW