aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/lastcomm/readrec.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-05-23 09:29:05 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-05-23 09:29:05 +0000
commit69921123490b99c2588b0c743bc4af32bbe6601c (patch)
tree4828066c23bd9bbd1672af14fbf0a9e31e47f4a0 /usr.bin/lastcomm/readrec.c
parent5f7c516f216995249523ed43e57e3f91bd8f5ff0 (diff)
downloadsrc-69921123490b99c2588b0c743bc4af32bbe6601c.tar.gz
src-69921123490b99c2588b0c743bc4af32bbe6601c.zip
Commit the 64-bit inode project.
Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify struct dirent layout to add d_off, increase the size of d_fileno to 64-bits, increase the size of d_namlen to 16-bits, and change the required alignment. Increase struct statfs f_mntfromname[] and f_mntonname[] array length MNAMELEN to 1024. ABI breakage is mitigated by providing compatibility using versioned symbols, ingenious use of the existing padding in structures, and by employing other tricks. Unfortunately, not everything can be fixed, especially outside the base system. For instance, third-party APIs which pass struct stat around are broken in backward and forward incompatible ways. Kinfo sysctl MIBs ABI is changed in backward-compatible way, but there is no general mechanism to handle other sysctl MIBS which return structures where the layout has changed. It was considered that the breakage is either in the management interfaces, where we usually allow ABI slip, or is not important. Struct xvnode changed layout, no compat shims are provided. For struct xtty, dev_t tty device member was reduced to uint32_t. It was decided that keeping ABI compat in this case is more useful than reporting 64-bit dev_t, for the sake of pstat. Update note: strictly follow the instructions in UPDATING. Build and install the new kernel with COMPAT_FREEBSD11 option enabled, then reboot, and only then install new world. Credits: The 64-bit inode project, also known as ino64, started life many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick (mckusick) then picked up and updated the patch, and acted as a flag-waver. Feedback, suggestions, and discussions were carried by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles), and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial ports investigation followed by an exp-run by Antoine Brodin (antoine). Essential and all-embracing testing was done by Peter Holm (pho). The heavy lifting of coordinating all these efforts and bringing the project to completion were done by Konstantin Belousov (kib). Sponsored by: The FreeBSD Foundation (emaste, kib) Differential revision: https://reviews.freebsd.org/D10439
Notes
Notes: svn path=/head/; revision=318736
Diffstat (limited to 'usr.bin/lastcomm/readrec.c')
-rw-r--r--usr.bin/lastcomm/readrec.c94
1 files changed, 65 insertions, 29 deletions
diff --git a/usr.bin/lastcomm/readrec.c b/usr.bin/lastcomm/readrec.c
index 5de7c5c4c808..0a3e9306e063 100644
--- a/usr.bin/lastcomm/readrec.c
+++ b/usr.bin/lastcomm/readrec.c
@@ -38,8 +38,8 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
-int readrec_forward(FILE *f, struct acctv2 *av2);
-int readrec_backward(FILE *f, struct acctv2 *av2);
+int readrec_forward(FILE *f, struct acctv3 *av2);
+int readrec_backward(FILE *f, struct acctv3 *av2);
/*
* Reverse offsetof: return the offset of field f
@@ -90,27 +90,27 @@ decode_comp(comp_t v)
* Return EOF on error or end-of-file.
*/
static int
-readrec_v1(FILE *f, struct acctv2 *av2)
+readrec_v1(FILE *f, struct acctv3 *av3)
{
struct acctv1 av1;
int rv;
if ((rv = fread_record(&av1, sizeof(av1), f)) == EOF)
return (EOF);
- av2->ac_zero = 0;
- av2->ac_version = 2;
- av2->ac_len = av2->ac_len2 = sizeof(*av2);
- memcpy(av2->ac_comm, av1.ac_comm, AC_COMM_LEN);
- av2->ac_utime = decode_comp(av1.ac_utime) * 1000000;
- av2->ac_stime = decode_comp(av1.ac_stime) * 1000000;
- av2->ac_etime = decode_comp(av1.ac_etime) * 1000000;
- av2->ac_btime = av1.ac_btime;
- av2->ac_uid = av1.ac_uid;
- av2->ac_gid = av1.ac_gid;
- av2->ac_mem = av1.ac_mem;
- av2->ac_io = decode_comp(av1.ac_io);
- av2->ac_tty = av1.ac_tty;
- av2->ac_flagx = av1.ac_flag | ANVER;
+ av3->ac_zero = 0;
+ av3->ac_version = 3;
+ av3->ac_len = av3->ac_len2 = sizeof(*av3);
+ memcpy(av3->ac_comm, av1.ac_comm, AC_COMM_LEN);
+ av3->ac_utime = decode_comp(av1.ac_utime) * 1000000;
+ av3->ac_stime = decode_comp(av1.ac_stime) * 1000000;
+ av3->ac_etime = decode_comp(av1.ac_etime) * 1000000;
+ av3->ac_btime = av1.ac_btime;
+ av3->ac_uid = av1.ac_uid;
+ av3->ac_gid = av1.ac_gid;
+ av3->ac_mem = av1.ac_mem;
+ av3->ac_io = decode_comp(av1.ac_io);
+ av3->ac_tty = av1.ac_tty;
+ av3->ac_flagx = av1.ac_flag | ANVER;
return (0);
}
@@ -120,9 +120,40 @@ readrec_v1(FILE *f, struct acctv2 *av2)
* Return EOF on error or end-of-file.
*/
static int
-readrec_v2(FILE *f, struct acctv2 *av2)
+readrec_v2(FILE *f, struct acctv3 *av3)
{
- return (fread_record(av2, sizeof(*av2), f));
+ struct acctv2 av2;
+ int rv;
+
+ if ((rv = fread_record(&av2, sizeof(av2), f)) == EOF)
+ return (EOF);
+ av3->ac_zero = 0;
+ av3->ac_version = 3;
+ av3->ac_len = av3->ac_len2 = sizeof(*av3);
+ memcpy(av3->ac_comm, av2.ac_comm, AC_COMM_LEN);
+ av3->ac_utime = av2.ac_utime;
+ av3->ac_stime = av2.ac_stime;
+ av3->ac_etime = av2.ac_etime;
+ av3->ac_btime = av2.ac_btime;
+ av3->ac_uid = av2.ac_uid;
+ av3->ac_gid = av2.ac_gid;
+ av3->ac_mem = av2.ac_mem;
+ av3->ac_io = av2.ac_io;
+ av3->ac_tty = av2.ac_tty;
+ av3->ac_flagx = av2.ac_flagx;
+ return (0);
+}
+
+/*
+ * Read an v2 accounting record stored at the current
+ * position of stream f.
+ * Return EOF on error or end-of-file.
+ */
+static int
+readrec_v3(FILE *f, struct acctv3 *av3)
+{
+
+ return (fread_record(av3, sizeof(*av3), f));
}
/*
@@ -132,7 +163,7 @@ readrec_v2(FILE *f, struct acctv2 *av2)
* Return EOF on error or end-of-file.
*/
static int
-readrec_vx(FILE *f, struct acctv2 *av2)
+readrec_vx(FILE *f, struct acctv3 *av3)
{
uint8_t magic, version;
@@ -143,7 +174,9 @@ readrec_vx(FILE *f, struct acctv2 *av2)
return (EOF);
switch (version) {
case 2:
- return (readrec_v2(f, av2));
+ return (readrec_v2(f, av3));
+ case 3:
+ return (readrec_v3(f, av3));
/* Add handling for more versions here. */
@@ -162,7 +195,7 @@ readrec_vx(FILE *f, struct acctv2 *av2)
* or EOF on error.
*/
int
-readrec_forward(FILE *f, struct acctv2 *av2)
+readrec_forward(FILE *f, struct acctv3 *av3)
{
int magic, rv;
@@ -172,10 +205,10 @@ readrec_forward(FILE *f, struct acctv2 *av2)
return (EOF);
if (magic != 0)
/* Old record format. */
- rv = readrec_v1(f, av2);
+ rv = readrec_v1(f, av3);
else
/* New record formats. */
- rv = readrec_vx(f, av2);
+ rv = readrec_vx(f, av3);
return (rv == EOF ? EOF : 1);
}
@@ -190,7 +223,7 @@ readrec_forward(FILE *f, struct acctv2 *av2)
* or EOF on error.
*/
int
-readrec_backward(FILE *f, struct acctv2 *av2)
+readrec_backward(FILE *f, struct acctv3 *av3)
{
off_t pos;
int c;
@@ -200,17 +233,20 @@ readrec_backward(FILE *f, struct acctv2 *av2)
return (EOF);
if (pos == 0)
return (0);
- if (fseek(f, -roffsetof(struct acctv2, ac_trailer),
+ if (fseek(f, -roffsetof(struct acctv3, ac_trailer),
SEEK_CUR) == EOF ||
(c = getc(f)) == EOF)
return (EOF);
if (c & ANVER) {
- /* New record formats. */
+ /*
+ * New record formats. For v2 and v3 offset from the
+ * end for ac_len2 should be same.
+ */
if (fseeko(f, pos - roffsetof(struct acctv2, ac_len2),
SEEK_SET) == EOF ||
fread_record(&len, sizeof(len), f) == EOF ||
fseeko(f, pos - len, SEEK_SET) == EOF ||
- readrec_vx(f, av2) == EOF ||
+ readrec_vx(f, av3) == EOF ||
fseeko(f, pos - len, SEEK_SET) == EOF)
return (EOF);
else
@@ -218,7 +254,7 @@ readrec_backward(FILE *f, struct acctv2 *av2)
} else {
/* Old record format. */
if (fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF ||
- readrec_v1(f, av2) == EOF ||
+ readrec_v1(f, av3) == EOF ||
fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF)
return (EOF);
else