Deleted Added
full compact
archive_read_disk_posix.c (305754) archive_read_disk_posix.c (306321)
1/*-
2 * Copyright (c) 2003-2009 Tim Kientzle
3 * Copyright (c) 2010-2012 Michihiro NAKAJIMA
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 151 unchanged lines hidden (view full) ---

160 struct restore_time restore_time;
161};
162
163struct filesystem {
164 int64_t dev;
165 int synthetic;
166 int remote;
167 int noatime;
1/*-
2 * Copyright (c) 2003-2009 Tim Kientzle
3 * Copyright (c) 2010-2012 Michihiro NAKAJIMA
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 151 unchanged lines hidden (view full) ---

160 struct restore_time restore_time;
161};
162
163struct filesystem {
164 int64_t dev;
165 int synthetic;
166 int remote;
167 int noatime;
168#if defined(HAVE_READDIR_R)
168#if defined(USE_READDIR_R)
169 size_t name_max;
170#endif
171 long incr_xfer_size;
172 long max_xfer_size;
173 long min_xfer_size;
174 long xfer_align;
175
176 /*

--- 18 unchanged lines hidden (view full) ---

195 * Local data for this package.
196 */
197struct tree {
198 struct tree_entry *stack;
199 struct tree_entry *current;
200 DIR *d;
201#define INVALID_DIR_HANDLE NULL
202 struct dirent *de;
169 size_t name_max;
170#endif
171 long incr_xfer_size;
172 long max_xfer_size;
173 long min_xfer_size;
174 long xfer_align;
175
176 /*

--- 18 unchanged lines hidden (view full) ---

195 * Local data for this package.
196 */
197struct tree {
198 struct tree_entry *stack;
199 struct tree_entry *current;
200 DIR *d;
201#define INVALID_DIR_HANDLE NULL
202 struct dirent *de;
203#if defined(HAVE_READDIR_R)
203#if defined(USE_READDIR_R)
204 struct dirent *dirent;
205 size_t dirent_allocated;
206#endif
207 int flags;
208 int visit_type;
209 /* Error code from last failed operation. */
210 int tree_errno;
211

--- 1375 unchanged lines hidden (view full) ---

1587
1588#if defined(MNT_NOATIME)
1589 if (sfs.f_flags & MNT_NOATIME)
1590 t->current_filesystem->noatime = 1;
1591 else
1592#endif
1593 t->current_filesystem->noatime = 0;
1594
204 struct dirent *dirent;
205 size_t dirent_allocated;
206#endif
207 int flags;
208 int visit_type;
209 /* Error code from last failed operation. */
210 int tree_errno;
211

--- 1375 unchanged lines hidden (view full) ---

1587
1588#if defined(MNT_NOATIME)
1589 if (sfs.f_flags & MNT_NOATIME)
1590 t->current_filesystem->noatime = 1;
1591 else
1592#endif
1593 t->current_filesystem->noatime = 0;
1594
1595#if defined(HAVE_READDIR_R)
1595#if defined(USE_READDIR_R)
1596 /* Set maximum filename length. */
1597#if defined(HAVE_STRUCT_STATFS_F_NAMEMAX)
1598 t->current_filesystem->name_max = sfs.f_namemax;
1599#else
1600# if defined(_PC_NAME_MAX)
1601 /* Mac OS X does not have f_namemax in struct statfs. */
1602 if (tree_current_is_symblic_link_target(t)) {
1603 if (tree_enter_working_dir(t) != 0) {

--- 6 unchanged lines hidden (view full) ---

1610# else
1611 nm = -1;
1612# endif
1613 if (nm == -1)
1614 t->current_filesystem->name_max = NAME_MAX;
1615 else
1616 t->current_filesystem->name_max = nm;
1617#endif
1596 /* Set maximum filename length. */
1597#if defined(HAVE_STRUCT_STATFS_F_NAMEMAX)
1598 t->current_filesystem->name_max = sfs.f_namemax;
1599#else
1600# if defined(_PC_NAME_MAX)
1601 /* Mac OS X does not have f_namemax in struct statfs. */
1602 if (tree_current_is_symblic_link_target(t)) {
1603 if (tree_enter_working_dir(t) != 0) {

--- 6 unchanged lines hidden (view full) ---

1610# else
1611 nm = -1;
1612# endif
1613 if (nm == -1)
1614 t->current_filesystem->name_max = NAME_MAX;
1615 else
1616 t->current_filesystem->name_max = nm;
1617#endif
1618#endif /* HAVE_READDIR_R */
1618#endif /* USE_READDIR_R */
1619 return (ARCHIVE_OK);
1620}
1621
1622#elif (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)) && defined(ST_LOCAL)
1623
1624/*
1625 * Gather current filesystem properties on NetBSD
1626 */

--- 185 unchanged lines hidden (view full) ---

1812#else
1813 if (sfs.f_flag & ST_NOATIME)
1814#endif
1815 t->current_filesystem->noatime = 1;
1816 else
1817#endif
1818 t->current_filesystem->noatime = 0;
1819
1619 return (ARCHIVE_OK);
1620}
1621
1622#elif (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)) && defined(ST_LOCAL)
1623
1624/*
1625 * Gather current filesystem properties on NetBSD
1626 */

--- 185 unchanged lines hidden (view full) ---

1812#else
1813 if (sfs.f_flag & ST_NOATIME)
1814#endif
1815 t->current_filesystem->noatime = 1;
1816 else
1817#endif
1818 t->current_filesystem->noatime = 0;
1819
1820#if defined(HAVE_READDIR_R)
1820#if defined(USE_READDIR_R)
1821 /* Set maximum filename length. */
1822 t->current_filesystem->name_max = sfs.f_namelen;
1823#endif
1824 return (ARCHIVE_OK);
1825}
1826
1827#elif defined(HAVE_SYS_STATVFS_H) &&\
1828 (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS))

--- 67 unchanged lines hidden (view full) ---

1896
1897#if defined(ST_NOATIME)
1898 if (sfs.f_flag & ST_NOATIME)
1899 t->current_filesystem->noatime = 1;
1900 else
1901#endif
1902 t->current_filesystem->noatime = 0;
1903
1821 /* Set maximum filename length. */
1822 t->current_filesystem->name_max = sfs.f_namelen;
1823#endif
1824 return (ARCHIVE_OK);
1825}
1826
1827#elif defined(HAVE_SYS_STATVFS_H) &&\
1828 (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS))

--- 67 unchanged lines hidden (view full) ---

1896
1897#if defined(ST_NOATIME)
1898 if (sfs.f_flag & ST_NOATIME)
1899 t->current_filesystem->noatime = 1;
1900 else
1901#endif
1902 t->current_filesystem->noatime = 0;
1903
1904#if defined(HAVE_READDIR_R)
1904#if defined(USE_READDIR_R)
1905 /* Set maximum filename length. */
1906 t->current_filesystem->name_max = sfs.f_namemax;
1907#endif
1908 return (ARCHIVE_OK);
1909}
1910
1911#else
1912
1913/*
1914 * Generic: Gather current filesystem properties.
1915 * TODO: Is this generic function really needed?
1916 */
1917static int
1918setup_current_filesystem(struct archive_read_disk *a)
1919{
1920 struct tree *t = a->tree;
1905 /* Set maximum filename length. */
1906 t->current_filesystem->name_max = sfs.f_namemax;
1907#endif
1908 return (ARCHIVE_OK);
1909}
1910
1911#else
1912
1913/*
1914 * Generic: Gather current filesystem properties.
1915 * TODO: Is this generic function really needed?
1916 */
1917static int
1918setup_current_filesystem(struct archive_read_disk *a)
1919{
1920 struct tree *t = a->tree;
1921#if defined(_PC_NAME_MAX) && defined(HAVE_READDIR_R)
1921#if defined(_PC_NAME_MAX) && defined(USE_READDIR_R)
1922 long nm;
1923#endif
1924 t->current_filesystem->synthetic = -1;/* Not supported */
1925 t->current_filesystem->remote = -1;/* Not supported */
1926 t->current_filesystem->noatime = 0;
1927 (void)get_xfer_size(t, -1, ".");/* Dummy call to avoid build error. */
1928 t->current_filesystem->xfer_align = -1;/* Unknown */
1929 t->current_filesystem->max_xfer_size = -1;
1930 t->current_filesystem->min_xfer_size = -1;
1931 t->current_filesystem->incr_xfer_size = -1;
1932
1922 long nm;
1923#endif
1924 t->current_filesystem->synthetic = -1;/* Not supported */
1925 t->current_filesystem->remote = -1;/* Not supported */
1926 t->current_filesystem->noatime = 0;
1927 (void)get_xfer_size(t, -1, ".");/* Dummy call to avoid build error. */
1928 t->current_filesystem->xfer_align = -1;/* Unknown */
1929 t->current_filesystem->max_xfer_size = -1;
1930 t->current_filesystem->min_xfer_size = -1;
1931 t->current_filesystem->incr_xfer_size = -1;
1932
1933#if defined(HAVE_READDIR_R)
1933#if defined(USE_READDIR_R)
1934 /* Set maximum filename length. */
1935# if defined(_PC_NAME_MAX)
1936 if (tree_current_is_symblic_link_target(t)) {
1937 if (tree_enter_working_dir(t) != 0) {
1938 archive_set_error(&a->archive, errno, "fchdir failed");
1939 return (ARCHIVE_FAILED);
1940 }
1941 nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX);

--- 11 unchanged lines hidden (view full) ---

1953 /* No way to get a trusted value of maximum filename
1954 * length. */
1955 t->current_filesystem->name_max = PATH_MAX;
1956# endif /* NAME_MAX */
1957# if defined(_PC_NAME_MAX)
1958 else
1959 t->current_filesystem->name_max = nm;
1960# endif /* _PC_NAME_MAX */
1934 /* Set maximum filename length. */
1935# if defined(_PC_NAME_MAX)
1936 if (tree_current_is_symblic_link_target(t)) {
1937 if (tree_enter_working_dir(t) != 0) {
1938 archive_set_error(&a->archive, errno, "fchdir failed");
1939 return (ARCHIVE_FAILED);
1940 }
1941 nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX);

--- 11 unchanged lines hidden (view full) ---

1953 /* No way to get a trusted value of maximum filename
1954 * length. */
1955 t->current_filesystem->name_max = PATH_MAX;
1956# endif /* NAME_MAX */
1957# if defined(_PC_NAME_MAX)
1958 else
1959 t->current_filesystem->name_max = nm;
1960# endif /* _PC_NAME_MAX */
1961#endif /* HAVE_READDIR_R */
1961#endif /* USE_READDIR_R */
1962 return (ARCHIVE_OK);
1963}
1964
1965#endif
1966
1967static int
1968close_and_restore_time(int fd, struct tree *t, struct restore_time *rt)
1969{

--- 391 unchanged lines hidden (view full) ---

2361static int
2362tree_dir_next_posix(struct tree *t)
2363{
2364 int r;
2365 const char *name;
2366 size_t namelen;
2367
2368 if (t->d == NULL) {
1962 return (ARCHIVE_OK);
1963}
1964
1965#endif
1966
1967static int
1968close_and_restore_time(int fd, struct tree *t, struct restore_time *rt)
1969{

--- 391 unchanged lines hidden (view full) ---

2361static int
2362tree_dir_next_posix(struct tree *t)
2363{
2364 int r;
2365 const char *name;
2366 size_t namelen;
2367
2368 if (t->d == NULL) {
2369#if defined(HAVE_READDIR_R)
2369#if defined(USE_READDIR_R)
2370 size_t dirent_size;
2371#endif
2372
2373#if defined(HAVE_FDOPENDIR)
2374 t->d = fdopendir(tree_dup(t->working_dir_fd));
2375#else /* HAVE_FDOPENDIR */
2376 if (tree_enter_working_dir(t) == 0) {
2377 t->d = opendir(".");

--- 4 unchanged lines hidden (view full) ---

2382#endif /* HAVE_FDOPENDIR */
2383 if (t->d == NULL) {
2384 r = tree_ascend(t); /* Undo "chdir" */
2385 tree_pop(t);
2386 t->tree_errno = errno;
2387 t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
2388 return (t->visit_type);
2389 }
2370 size_t dirent_size;
2371#endif
2372
2373#if defined(HAVE_FDOPENDIR)
2374 t->d = fdopendir(tree_dup(t->working_dir_fd));
2375#else /* HAVE_FDOPENDIR */
2376 if (tree_enter_working_dir(t) == 0) {
2377 t->d = opendir(".");

--- 4 unchanged lines hidden (view full) ---

2382#endif /* HAVE_FDOPENDIR */
2383 if (t->d == NULL) {
2384 r = tree_ascend(t); /* Undo "chdir" */
2385 tree_pop(t);
2386 t->tree_errno = errno;
2387 t->visit_type = r != 0 ? r : TREE_ERROR_DIR;
2388 return (t->visit_type);
2389 }
2390#if defined(HAVE_READDIR_R)
2390#if defined(USE_READDIR_R)
2391 dirent_size = offsetof(struct dirent, d_name) +
2392 t->filesystem_table[t->current->filesystem_id].name_max + 1;
2393 if (t->dirent == NULL || t->dirent_allocated < dirent_size) {
2394 free(t->dirent);
2395 t->dirent = malloc(dirent_size);
2396 if (t->dirent == NULL) {
2397 closedir(t->d);
2398 t->d = INVALID_DIR_HANDLE;
2399 (void)tree_ascend(t);
2400 tree_pop(t);
2401 t->tree_errno = ENOMEM;
2402 t->visit_type = TREE_ERROR_DIR;
2403 return (t->visit_type);
2404 }
2405 t->dirent_allocated = dirent_size;
2406 }
2391 dirent_size = offsetof(struct dirent, d_name) +
2392 t->filesystem_table[t->current->filesystem_id].name_max + 1;
2393 if (t->dirent == NULL || t->dirent_allocated < dirent_size) {
2394 free(t->dirent);
2395 t->dirent = malloc(dirent_size);
2396 if (t->dirent == NULL) {
2397 closedir(t->d);
2398 t->d = INVALID_DIR_HANDLE;
2399 (void)tree_ascend(t);
2400 tree_pop(t);
2401 t->tree_errno = ENOMEM;
2402 t->visit_type = TREE_ERROR_DIR;
2403 return (t->visit_type);
2404 }
2405 t->dirent_allocated = dirent_size;
2406 }
2407#endif /* HAVE_READDIR_R */
2407#endif /* USE_READDIR_R */
2408 }
2409 for (;;) {
2410 errno = 0;
2408 }
2409 for (;;) {
2410 errno = 0;
2411#if defined(HAVE_READDIR_R)
2411#if defined(USE_READDIR_R)
2412 r = readdir_r(t->d, t->dirent, &t->de);
2413#ifdef _AIX
2414 /* Note: According to the man page, return value 9 indicates
2415 * that the readdir_r was not successful and the error code
2416 * is set to the global errno variable. And then if the end
2417 * of directory entries was reached, the return value is 9
2418 * and the third parameter is set to NULL and errno is
2419 * unchanged. */

--- 235 unchanged lines hidden (view full) ---

2655static void
2656tree_free(struct tree *t)
2657{
2658 int i;
2659
2660 if (t == NULL)
2661 return;
2662 archive_string_free(&t->path);
2412 r = readdir_r(t->d, t->dirent, &t->de);
2413#ifdef _AIX
2414 /* Note: According to the man page, return value 9 indicates
2415 * that the readdir_r was not successful and the error code
2416 * is set to the global errno variable. And then if the end
2417 * of directory entries was reached, the return value is 9
2418 * and the third parameter is set to NULL and errno is
2419 * unchanged. */

--- 235 unchanged lines hidden (view full) ---

2655static void
2656tree_free(struct tree *t)
2657{
2658 int i;
2659
2660 if (t == NULL)
2661 return;
2662 archive_string_free(&t->path);
2663#if defined(HAVE_READDIR_R)
2663#if defined(USE_READDIR_R)
2664 free(t->dirent);
2665#endif
2666 free(t->sparse_list);
2667 for (i = 0; i < t->max_filesystem_id; i++)
2668 free(t->filesystem_table[i].allocation_ptr);
2669 free(t->filesystem_table);
2670 free(t);
2671}
2672
2673#endif
2664 free(t->dirent);
2665#endif
2666 free(t->sparse_list);
2667 for (i = 0; i < t->max_filesystem_id; i++)
2668 free(t->filesystem_table[i].allocation_ptr);
2669 free(t->filesystem_table);
2670 free(t);
2671}
2672
2673#endif