Lines Matching refs:f
56 fifolog_int_open_i(struct fifolog_file *f, const char *fname, int mode) in fifolog_int_open_i() argument
62 f->fd = open(fname, mode ? O_RDWR : O_RDONLY); in fifolog_int_open_i()
63 if (f->fd < 0) in fifolog_int_open_i()
67 i = ioctl(f->fd, DIOCGSECTORSIZE, &f->recsize); in fifolog_int_open_i()
72 i = fstat(f->fd, &st); in fifolog_int_open_i()
76 f->recsize = 512; in fifolog_int_open_i()
77 f->logsize = st.st_size; in fifolog_int_open_i()
78 } else if (f->recsize < 64) { in fifolog_int_open_i()
81 i = ioctl(f->fd, DIOCGMEDIASIZE, &f->logsize); in fifolog_int_open_i()
87 f->recbuf = malloc(f->recsize); in fifolog_int_open_i()
88 if (f->recbuf == NULL) in fifolog_int_open_i()
92 i = pread(f->fd, f->recbuf, f->recsize, 0); in fifolog_int_open_i()
93 if (i < 0 || i < (int)f->recsize) in fifolog_int_open_i()
97 if (memcmp(f->recbuf, FIFOLOG_FMT_MAGIC, strlen(FIFOLOG_FMT_MAGIC) + 1)) in fifolog_int_open_i()
100 u = be32dec(f->recbuf + FIFOLOG_OFF_BS); in fifolog_int_open_i()
104 if ((off_t)u >= f->logsize) in fifolog_int_open_i()
107 f->recsize = u; in fifolog_int_open_i()
110 if (u != f->recsize) { in fifolog_int_open_i()
111 free(f->recbuf); in fifolog_int_open_i()
112 f->recbuf = NULL; in fifolog_int_open_i()
113 f->recsize = u; in fifolog_int_open_i()
114 f->recbuf = malloc(f->recsize); in fifolog_int_open_i()
115 if (f->recbuf == NULL) in fifolog_int_open_i()
120 f->logsize /= u; in fifolog_int_open_i()
121 if (f->logsize < 10) in fifolog_int_open_i()
124 f->logsize--; /* the label record */ in fifolog_int_open_i()
128 f->zs = calloc(1, sizeof(*f->zs)); in fifolog_int_open_i()
129 if (f->zs == NULL) in fifolog_int_open_i()
138 struct fifolog_file fs, *f; in fifolog_int_open() local
142 f = &fs; in fifolog_int_open()
143 memset(f, 0, sizeof *f); in fifolog_int_open()
144 f->fd = -1; in fifolog_int_open()
145 retval = fifolog_int_open_i(f, fname, mode); in fifolog_int_open()
148 *ff = malloc(sizeof *f); in fifolog_int_open()
150 memcpy(*ff, f, sizeof *f); in fifolog_int_open()
155 fifolog_int_close(&f); in fifolog_int_open()
163 struct fifolog_file *f; in fifolog_int_close() local
165 f = *ff; in fifolog_int_close()
167 if (f == NULL) in fifolog_int_close()
170 if (f->fd >= 0) in fifolog_int_close()
171 (void)close(f->fd); in fifolog_int_close()
172 if (f->zs != NULL) in fifolog_int_close()
173 free(f->zs); in fifolog_int_close()
174 if (f->recbuf != NULL) in fifolog_int_close()
175 free(f->recbuf); in fifolog_int_close()