--preserve-root and --no-preserve-root options. */
# define ROOT_DEV_INO_CHECK(Root_dev_ino, Dir_statbuf) \
- (Root_dev_ino && SAME_INODE (*Dir_statbuf, *Root_dev_ino))
+ (Root_dev_ino && PSAME_INODE (Dir_statbuf, Root_dev_ino))
# define ROOT_DEV_INO_WARN(Dirname) \
do \
error (EXIT_FAILURE, errno, _("standard output"));
/* Optimal size of i/o operations of output. */
- idx_t outsize = io_blksize (stat_buf);
+ idx_t outsize = io_blksize (&stat_buf);
/* Device and I-node number of the output. */
dev_t out_dev = stat_buf.st_dev;
}
/* Optimal size of i/o operations of input. */
- idx_t insize = io_blksize (stat_buf);
+ idx_t insize = io_blksize (&stat_buf);
fdadvise (input_desc, 0, 0, FADVISE_SEQUENTIAL);
/* required_uid and/or required_gid are specified, but don't match */
RC_excluded,
- /* SAME_INODE check failed */
+ /* The file was replaced by another file during the requested change. */
RC_inode_changed,
/* open/fchown isn't needed, isn't safe, or doesn't work due to
if (fstat (fd, &st) != 0)
status = RC_error;
- else if (! SAME_INODE (*orig_st, st))
+ else if (! psame_inode (orig_st, &st))
status = RC_inode_changed;
else if ((required_uid == (uid_t) -1 || required_uid == st.st_uid)
&& (required_gid == (gid_t) -1 || required_gid == st.st_gid))
suggests the file is sparse. */
if (! (HAVE_STRUCT_STAT_ST_BLOCKS
&& S_ISREG (sb->st_mode)
- && ST_NBLOCKS (*sb) < sb->st_size / ST_NBLOCKSIZE))
+ && STP_NBLOCKS (sb) < sb->st_size / ST_NBLOCKSIZE))
return PLAIN_SCANTYPE;
#ifdef SEEK_HOLE
/* Compare the source dev/ino from the open file to the incoming,
saved ones obtained via a previous call to stat. */
- if (! SAME_INODE (*src_sb, src_open_sb))
+ if (! psame_inode (src_sb, &src_open_sb))
{
error (0, 0,
_("skipping file %s, as it was replaced while being copied"),
if (data_copy_required)
{
/* Choose a suitable buffer size; it may be adjusted later. */
- size_t buf_size = io_blksize (sb);
- size_t hole_size = ST_BLKSIZE (sb);
+ size_t buf_size = io_blksize (&sb);
+ size_t hole_size = STP_BLKSIZE (&sb);
/* Deal with sparse files. */
enum scantype scantype = infer_scantype (source_desc, &src_open_sb,
Note we read in multiples of the reported block size
to support (unusual) devices that have this constraint. */
size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX);
- size_t blcm = buffer_lcm (io_blksize (src_open_sb), buf_size,
+ size_t blcm = buffer_lcm (io_blksize (&src_open_sb), buf_size,
blcm_max);
/* Do not bother with a buffer larger than the input file, plus one
struct stat tmp_src_sb;
bool same_link;
- bool same = SAME_INODE (*src_sb, *dst_sb);
+ bool same = psame_inode (src_sb, dst_sb);
*return_now = false;
src_sb_link = &tmp_src_sb;
dst_sb_link = &tmp_dst_sb;
- same_link = SAME_INODE (*src_sb_link, *dst_sb_link);
+ same_link = psame_inode (src_sb_link, dst_sb_link);
/* If both are symlinks, then it's ok, but only if the destination
will be unlinked before being opened. This is like the test
hard links to the same file. */
if (!S_ISLNK (src_sb_link->st_mode) && !S_ISLNK (dst_sb_link->st_mode))
{
- if (!SAME_INODE (*src_sb_link, *dst_sb_link))
+ if (!psame_inode (src_sb_link, dst_sb_link))
return true;
/* If they are the same file, it's ok if we're making hard links. */
else if (fstatat (dst_dirfd, dst_relname, &tmp_dst_sb, 0) != 0)
return true;
- if ( ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
+ if (!psame_inode (&tmp_src_sb, &tmp_dst_sb))
return true;
if (x->hard_link)
struct stat dst_back_sb;
int dst_back_status = fstatat (dst_dirfd, dst_back, &dst_back_sb, 0);
free (dst_back);
- return dst_back_status == 0 && SAME_INODE (*src_st, dst_back_sb);
+ return dst_back_status == 0 && psame_inode (src_st, &dst_back_sb);
}
/* Copy the file SRC_NAME to the file DST_NAME aka DST_DIRFD+DST_RELNAME.
|| stat (".", &dot_sb) != 0
|| (fstatat (dst_dirfd, dst_parent, &dst_parent_sb,
0) != 0)
- || SAME_INODE (dot_sb, dst_parent_sb));
+ || psame_inode (&dot_sb, &dst_parent_sb));
free (dst_parent);
if (! in_current_dir)
{
struct Src_to_dest const *a = x;
struct Src_to_dest const *b = y;
- return SAME_INODE (*a, *b) ? true : false;
+ return PSAME_INODE (a, b);
}
static void
duinfo_set (&dui,
(apparent_size
? (usable_st_size (sb) ? MAX (0, sb->st_size) : 0)
- : (uintmax_t) ST_NBLOCKS (*sb) * ST_NBLOCKSIZE),
+ : (uintmax_t) STP_NBLOCKS (sb) * ST_NBLOCKSIZE),
(time_type == time_mtime ? get_stat_mtime (sb)
: time_type == time_atime ? get_stat_atime (sb)
: get_stat_ctime (sb)));
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st))
+ if (presume_input_pipe || current_pos < 0 || size <= STP_BLKSIZE (st))
return elide_tail_bytes_pipe (filename, fd, n_elide, current_pos);
else
{
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st))
+ if (presume_input_pipe || current_pos < 0 || size <= STP_BLKSIZE (st))
return elide_tail_lines_pipe (filename, fd, n_elide, current_pos);
else
{
*/
enum { IO_BUFSIZE = 128 * 1024 };
static inline idx_t
-io_blksize (struct stat sb)
+io_blksize (struct stat const *st)
{
/* Treat impossible blocksizes as if they were IO_BUFSIZE. */
- idx_t blocksize = ST_BLKSIZE (sb) <= 0 ? IO_BUFSIZE : ST_BLKSIZE (sb);
+ idx_t blocksize = STP_BLKSIZE (st) <= 0 ? IO_BUFSIZE : STP_BLKSIZE (st);
/* Use a blocksize of at least IO_BUFSIZE bytes, keeping it a
multiple of the original blocksize. */
This misinformation can cause coreutils to use wrong-sized blocks.
Work around some of the performance bug by substituting the next
power of two when the reported blocksize is not a power of two. */
- if (S_ISREG (sb.st_mode)
- && blocksize & (blocksize - 1))
+ if (S_ISREG (st->st_mode) && blocksize & (blocksize - 1))
{
int leading_zeros = count_leading_zeros_ll (blocksize);
if (IDX_MAX < ULLONG_MAX || leading_zeros)
if (source_status != 0)
source_status = stat (source, &source_stats);
if (source_status == 0
- && SAME_INODE (source_stats, dest_stats)
+ && psame_inode (&source_stats, &dest_stats)
&& (source_stats.st_nlink == 1
|| same_nameat (AT_FDCWD, source,
destdir_fd, dest_base)))
{
struct dev_ino const *a = x;
struct dev_ino const *b = y;
- return SAME_INODE (*a, *b) ? true : false;
+ return PSAME_INODE (a, b);
}
static void
else
f->filetype = normal;
- blocks = ST_NBLOCKS (f->stat);
+ blocks = STP_NBLOCKS (&f->stat);
if (format == long_format || print_block_size)
{
char buf[LONGEST_HUMAN_READABLE + 1];
char const *blocks =
(! f->stat_ok
? "?"
- : human_readable (ST_NBLOCKS (f->stat), hbuf, human_output_opts,
+ : human_readable (STP_NBLOCKS (&f->stat), hbuf, human_output_opts,
ST_NBLOCKSIZE, output_block_size));
int blocks_width = mbswidth (blocks, MBSWIDTH_FLAGS);
for (int pad = blocks_width < 0 ? 0 : block_size_width - blocks_width;
if (print_block_size)
printf ("%*s ", format == with_commas ? 0 : block_size_width,
! f->stat_ok ? "?"
- : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
+ : human_readable (STP_NBLOCKS (&f->stat), buf, human_output_opts,
ST_NBLOCKSIZE, output_block_size));
if (print_scontext)
if (print_block_size)
len += 1 + (format == with_commas
? strlen (! f->stat_ok ? "?"
- : human_readable (ST_NBLOCKS (f->stat), buf,
+ : human_readable (STP_NBLOCKS (&f->stat), buf,
human_output_opts, ST_NBLOCKSIZE,
output_block_size))
: block_size_width);
when st_size is no greater than the block size, because
some kernels report nonsense small file sizes for
proc-like file systems. */
- if (usable_size && ST_BLKSIZE (file_stats) < file_stats.st_size)
+ if (usable_size && STP_BLKSIZE (&file_stats) < file_stats.st_size)
{
if ((uintmax_t) file_stats.st_size < n_skip)
n_skip -= file_stats.st_size;
while (true)
{
/* If we've reached the root, we're done. */
- if (SAME_INODE (dot_sb, *root_dev_ino))
+ if (PSAME_INODE (&dot_sb, root_dev_ino))
break;
find_dir_entry (&dot_sb, file_name, height++);
}
/* System call validation. */
- if (stat (wd, &st1) == 0 && stat (".", &st2) == 0 && SAME_INODE (st1, st2))
+ if (stat (wd, &st1) == 0 && stat (".", &st2) == 0 && psame_inode (&st1, &st2))
return wd;
return nullptr;
}
if (! flags->exact)
{
/* Round up to the nearest block size to clear slack space. */
- off_t remainder = size % ST_BLKSIZE (st);
- if (size && size < ST_BLKSIZE (st))
+ off_t remainder = size % STP_BLKSIZE (&st);
+ if (size && size < STP_BLKSIZE (&st))
i_size = size;
if (remainder != 0)
{
- off_t size_incr = ST_BLKSIZE (st) - remainder;
+ off_t size_incr = STP_BLKSIZE (&st) - remainder;
size += MIN (size_incr, OFF_T_MAX - size);
}
}
}
}
else if (S_ISREG (st.st_mode)
- && st.st_size < MIN (ST_BLKSIZE (st), size))
+ && st.st_size < MIN (STP_BLKSIZE (&st), size))
i_size = st.st_size;
/* Schedule the passes in random order. */
? fstat (STDIN_FILENO, &instat)
: stat (files[i].name, &instat))
== 0)
- && SAME_INODE (instat, *outst));
+ && psame_inode (&instat, outst));
}
if (same)
struct stat out_stat_buf;
if (fstat (fd, &out_stat_buf) != 0)
error (EXIT_FAILURE, errno, _("failed to stat %s"), quoteaf (name));
- if (SAME_INODE (in_stat_buf, out_stat_buf))
+ if (psame_inode (&in_stat_buf, &out_stat_buf))
error (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
quoteaf (name));
bool regularish
if (in_blk_size == 0)
{
- in_blk_size = io_blksize (in_stat_buf);
+ in_blk_size = io_blksize (&in_stat_buf);
if (SYS_BUFSIZE_MAX < in_blk_size)
in_blk_size = SYS_BUFSIZE_MAX;
}
struct stat dev_stats;
if (stat (me->me_devname, &dev_stats) == 0
- && SAME_INODE (name_stats, dev_stats))
+ && psame_inode (&name_stats, &dev_stats))
{
bind_mount = me->me_devname;
break;
out_uint (pformat, prefix_len, ST_NBLOCKSIZE);
break;
case 'b':
- out_uint (pformat, prefix_len, ST_NBLOCKS (*statbuf));
+ out_uint (pformat, prefix_len, STP_NBLOCKS (statbuf));
break;
case 'o':
- out_uint (pformat, prefix_len, ST_BLKSIZE (*statbuf));
+ out_uint (pformat, prefix_len, STP_BLKSIZE (statbuf));
break;
case 'w':
{
else if ((current_pos = lseek (fd, -n_bytes, SEEK_END)) != -1)
end_pos = current_pos + n_bytes;
}
- if (end_pos <= (off_t) ST_BLKSIZE (stats))
+ if (end_pos <= (off_t) STP_BLKSIZE (&stats))
return pipe_bytes (pretty_filename, fd, n_bytes, read_pos);
if (current_pos == -1)
current_pos = xlseek (fd, 0, SEEK_CUR, pretty_filename);
}
if (block_mode)
{
- ptrdiff_t blksize = ST_BLKSIZE (sb);
+ ptrdiff_t blksize = STP_BLKSIZE (&sb);
intmax_t ssize0 = ssize;
if (ckd_mul (&ssize, ssize, blksize))
{
}
else
{
- off_t hi_pos = end_pos - end_pos % (ST_BLKSIZE (fstatus->st) + 1);
+ off_t hi_pos = (end_pos
+ - end_pos % (STP_BLKSIZE (&fstatus->st) + 1));
if (0 <= current_pos && current_pos < hi_pos
&& 0 <= lseek (fd, hi_pos, SEEK_CUR))
bytes = hi_pos - current_pos;