Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Apr 2001 17:39:39 -0400
From:      "Ken Menzel" <kenm@icarz.com>
To:        <freebsd-stable@FreeBSD.ORG>
Subject:   Tail of file larger than 2 gig fails (patch)
Message-ID:  <000901c0c399$13f7e680$711663cf@icarz.com>

next in thread | raw e-mail | index | archive | help
I had a problem today with a very large log file (3.6 gig) I wanted to
see the last few lines but 'tail' wanted to show me the last gig or
so.  Anyway I made it work,  I don't know if this is the right list,
because I have never submitted a patch before.  Could someone
committer either advise me where to send this patch or take a look at
it and commit it if it looks OK?  It should not affect the way tail
works for files smaller that 2Gig (1/2 of SIZE_T_MAX).
It also fixes the comparison of SIZE_T_MAX which never worked anyway
and does print a warning at the top of the tail if the file is larger
that 2 gig.

Thanks

Ken

--- ./kentail/forward.c Thu Apr 12 17:18:48 2001
+++ ./tail/forward.c Wed Feb 28 11:18:13 2001
@@ -268,30 +268,20 @@
  struct stat *sbp;
 {
  off_t size;
- off_t max_size;
- off_t big_off;
- size_t orig_size;
-
  char *p;
  char *start;

  if (!(size = sbp->st_size))
   return;

- max_size=SIZE_T_MAX/2;
- big_off=0;
- if (size > max_size) {
+ if (size > SIZE_T_MAX) {
   errno = EFBIG;
   ierr();
-  // Just look at back of file
-  big_off=size-max_size;
-  size=max_size;
-  // return;
+  return;
  }

- orig_size=size;
  if ((start = mmap(NULL, (size_t)size,
-     PROT_READ, MAP_SHARED, fileno(fp), (off_t)big_off)) ==
MAP_FAILED) {
+     PROT_READ, MAP_SHARED, fileno(fp), (off_t)0)) == MAP_FAILED) {
   ierr();
   return;
  }
@@ -304,13 +294,13 @@
   }

  /* Set the file pointer to reflect the length displayed. */
- size = orig_size - size;
+ size = sbp->st_size - size;
  WR(p, size);
- if (fseeko(fp, sbp->st_size, SEEK_SET) == -1) {
+ if (fseek(fp, (long)sbp->st_size, SEEK_SET) == -1) {
   ierr();
   return;
  }
- if (munmap(start, orig_size)) {
+ if (munmap(start, (size_t)sbp->st_size)) {
   ierr();
   return;
  }

-----------------------------------------------------
Ken Menzel  ICQ# 9325188
www.icarz.com  kenm@icarz.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000901c0c399$13f7e680$711663cf>