2 * Copyright (c) 1980, 1986 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <afsconfig.h>
19 #include <afs/param.h>
24 #include <sys/param.h>
25 #define VICE /* allow us to put our changes in at will */
28 #include <sys/vnode.h>
29 #include <sys/mount.h>
30 #include <ufs/inode.h>
38 #else /* AFS_OSF_ENV */
39 #ifdef AFS_VFSINCL_ENV
40 #include <sys/vnode.h>
45 #include <sys/fs/ufs_inode.h>
46 #include <sys/fs/ufs_fs.h>
48 #include <sys/fs/ufs_fsdir.h>
50 #include <sys/fs/ufs_mount.h>
52 #include <ufs/inode.h>
54 #include <ufs/fsdir.h>
56 #else /* AFS_VFSINCL_ENV */
57 #include <sys/inode.h>
60 #define LONGFILENAMES 1
61 #include <sys/sysmacros.h>
63 #include <sys/signal.h>
65 #ifdef HAVE_USR_OLD_USR_INCLUDE_NDIR_H
66 #include </usr/old/usr/include/ndir.h>
74 #endif /* AFS_VFSINCL_ENV */
75 #endif /* AFS_OSF_ENV */
82 #if defined(AFS_HPUX101_ENV)
86 #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
92 long diskreads, totalreads; /* Disk cache statistics */
93 #if !defined(AFS_HPUX101_ENV)
97 #if defined(AFS_SUN_ENV)
104 #include <sys/mntent.h>
105 #include <sys/mnttab.h>
106 #include <sys/stat.h>
107 #include <sys/vfstab.h>
115 switch (dp->di_mode & IFMT) {
137 printf("bad file type 0%o\n", dp->di_mode);
152 pfatal("INTERNAL ERROR: GOT TO reply()");
153 persevere = !strcmp(question, "CONTINUE");
155 if (!persevere && (nflag || fswritefd < 0)) {
156 printf("%s? no\n\n", question);
157 #if defined(AFS_SUN_ENV)
158 iscorrupt = 1; /* known to be corrupt */
162 if (yflag || (persevere && nflag)) {
163 printf("%s? yes\n\n", question);
167 printf("%s? [yn] ", question);
168 (void)fflush(stdout);
170 while (c != '\n' && getc(stdin) != '\n')
173 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
175 if (c == 'y' || c == 'Y')
180 #if defined(AFS_SUN_ENV)
181 iscorrupt = 1; /* known to be corrupt */
187 * Malloc buffers and set up cache.
191 register struct bufarea *bp;
195 bufp = malloc((unsigned int)sblock.fs_bsize);
197 errexit("cannot allocate buffer pool\n");
198 cgblk.b_un.b_buf = bufp;
200 bufhead.b_next = bufhead.b_prev = &bufhead;
201 bufcnt = MAXBUFSPACE / sblock.fs_bsize;
202 if (bufcnt < MINBUFS)
204 for (i = 0; i < bufcnt; i++) {
205 bp = (struct bufarea *)malloc(sizeof(struct bufarea));
206 bufp = malloc((unsigned int)sblock.fs_bsize);
207 if (bp == NULL || bufp == NULL) {
210 errexit("cannot allocate buffer pool\n");
212 bp->b_un.b_buf = bufp;
213 bp->b_prev = &bufhead;
214 bp->b_next = bufhead.b_next;
215 bufhead.b_next->b_prev = bp;
219 bufhead.b_size = i; /* save number of buffers */
226 * Manage a cache of directory blocks.
229 getdatablk(blkno, size)
233 register struct bufarea *bp;
235 for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
236 if (bp->b_bno == fsbtodb(&sblock, blkno))
238 for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
239 if ((bp->b_flags & B_INUSE) == 0)
242 errexit("deadlocked buffer pool\n");
243 getblk(bp, blkno, size);
247 bp->b_prev->b_next = bp->b_next;
248 bp->b_next->b_prev = bp->b_prev;
249 bp->b_prev = &bufhead;
250 bp->b_next = bufhead.b_next;
251 bufhead.b_next->b_prev = bp;
253 bp->b_flags |= B_INUSE;
258 getblk(bp, blk, size)
259 register struct bufarea *bp;
265 dblk = fsbtodb(&sblock, blk);
266 if (bp->b_bno == dblk)
268 flush(fswritefd, bp);
270 bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size);
278 register struct bufarea *bp;
286 if (bp->b_errs != 0) {
287 pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
288 (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
293 bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
296 #if defined(AFS_HPUX101_ENV)
297 #if defined(AFS_HPUX110_ENV)
298 /* jpm: Need a fix here */
300 #else /* AFS_HPUX110_ENV */
302 (fswritefd, (char *)sblock.fs_csp[0],
303 fsbtodb(&sblock, sblock.fs_csaddr), fragroundup(&sblock,
304 sblock.fs_cssize)) ==
306 #endif /* else AFS_HPUX110_ENV */
309 ("\nUnable to write to cylinder group summary area (fs_csaddr)\n");
310 printf("\tDisk write error at block %u\n",
311 fsbtodb(&sblock, sblock.fs_csaddr));
314 #if defined(AFS_SUN56_ENV)
315 sip = (caddr_t) sblock.fs_u.fs_csp;
316 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
318 sblock.fs_cssize - i <
319 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
320 bwrite(fswritefd, sip,
321 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), size);
325 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
326 bwrite(fswritefd, (char *)sblock.fs_csp[j],
327 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
328 sblock.fs_cssize - i <
329 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize);
331 #endif /* AFS_SUN56_ENV */
332 #endif /* AFS_HPUX101_ENV */
342 pfatal("CANNOT %s: BLK %ld", mesg, blk);
343 if (reply("CONTINUE") == 0)
344 errexit("Program terminated\n");
349 register struct bufarea *bp, *nbp;
352 flush(fswritefd, &sblk);
354 if (havesb && sblk.b_bno != SBOFF / dev_bsize && !preen
355 && reply("UPDATE STANDARD SUPERBLOCK")) {
356 sblk.b_bno = SBOFF / dev_bsize;
357 #else /* AFS_NEWCG_ENV */
358 if (havesb && sblk.b_bno != SBLOCK && !preen
359 && reply("UPDATE STANDARD SUPERBLOCK")) {
361 #endif /* AFS_NEWCG_ENV */
363 flush(fswritefd, &sblk);
365 flush(fswritefd, &cgblk);
366 if (cgblk.b_un.b_buf) {
367 free(cgblk.b_un.b_buf);
368 cgblk.b_un.b_buf = NULL;
370 for (bp = bufhead.b_prev; bp != &bufhead; bp = nbp) {
372 flush(fswritefd, bp);
374 free(bp->b_un.b_buf);
380 if (bufhead.b_size != cnt)
381 errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
383 printf("cache missed %d of %d (%d%%)\n", diskreads, totalreads,
384 diskreads * 100 / totalreads);
385 (void)close(fsreadfd);
386 (void)close(fswritefd);
389 #if !defined(AFS_HPUX101_ENV)
390 bread(fd, buf, blk, size)
403 offset_t offset = (offset_t) blk << DEV_BSHIFT;
408 /* To fix a stripping related bug?? */
409 if (lseek(fd, blk * dev_bsize, 0) == -1)
412 if (llseek(fd, offset, 0) < 0)
414 if (lseek(fd, blk * dev_bsize, 0) < 0)
417 rwerror("SEEK", blk);
418 else if (read(fd, buf, (int)size) == size)
420 rwerror("READ", blk);
422 /* To fix a stripping related bug?? */
423 if (lseek(fd, blk * dev_bsize, 0) == -1)
426 if (llseek(fd, offset, 0) < 0)
428 if (lseek(fd, blk * dev_bsize, 0) < 0)
431 rwerror("SEEK", blk);
433 memset(buf, 0, (int)size);
434 printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
436 for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) {
437 addr = (offset_t) (blk + i) << DEV_BSHIFT;
438 if (llseek(fd, addr, SEEK_CUR) < 0 || read(fd, cp, (int)secsize) < 0) {
439 printf(" %d", blk + i);
441 for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
442 if (read(fd, cp, (int)secsize) < 0) {
443 lseek(fd, blk * dev_bsize + i + secsize, 0);
444 if (secsize != dev_bsize && dev_bsize != 1)
445 printf(" %d (%d),", (blk * dev_bsize + i) / secsize,
446 blk + i / dev_bsize);
448 printf(" %d,", blk + i / dev_bsize);
457 bwrite(fd, buf, blk, size)
470 offset_t offset = (offset_t) blk << DEV_BSHIFT;
475 sprintf(msg, "WARNING: Attempt to write illegal blkno %d on %s\n",
486 /* To fix a stripping related bug?? */
487 if (lseek(fd, blk * dev_bsize, 0) == -1)
490 if (llseek(fd, offset, 0) < 0)
492 if (lseek(fd, blk * dev_bsize, 0) < 0)
495 rwerror("SEEK", blk);
496 else if (write(fd, buf, (int)size) == size) {
500 rwerror("WRITE", blk);
502 /* To fix a stripping related bug?? */
503 if (lseek(fd, blk * dev_bsize, 0) == -1)
506 if (llseek(fd, offset, 0) < 0)
508 if (lseek(fd, blk * dev_bsize, 0) < 0)
511 rwerror("SEEK", blk);
512 printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
514 for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) {
516 addr = (offset_t) (blk + i) << DEV_BSHIFT;
517 if (llseek(fd, addr, SEEK_CUR) < 0
518 || (n = write(fd, cp, DEV_BSIZE)) < 0) {
519 printf(" %d", blk + i);
526 for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
527 if (write(fd, cp, (int)dev_bsize) < 0) {
528 lseek(fd, blk * dev_bsize + i + dev_bsize, 0);
529 printf(" %d,", blk + i / dev_bsize);
535 #endif /* AFS_HPUX101_ENV */
537 * allocate a data block with the specified number of fragments
542 register int i, j, k;
544 if (frags <= 0 || frags > sblock.fs_frag)
546 for (i = 0; i < maxfsblock - sblock.fs_frag; i += sblock.fs_frag) {
547 for (j = 0; j <= sblock.fs_frag - frags; j++) {
550 for (k = 1; k < frags; k++)
551 if (testbmap(i + j + k))
557 for (k = 0; k < frags; k++)
567 * Free a previously allocated block
569 freeblk(blkno, frags)
573 struct inodesc idesc;
575 idesc.id_blkno = blkno;
576 idesc.id_numfrags = frags;
583 getpathname(namebuf, curdir, ino)
589 struct inodesc idesc;
590 extern int findname();
592 if (statemap[ino] != DSTATE && statemap[ino] != DFOUND) {
593 strcpy(namebuf, "?");
596 memset((char *)&idesc, 0, sizeof(struct inodesc));
597 idesc.id_type = DATA;
598 cp = &namebuf[BUFSIZ - 1];
601 idesc.id_parent = curdir;
604 while (ino != ROOTINO) {
605 idesc.id_number = ino;
606 idesc.id_func = findino;
607 idesc.id_name = "..";
609 idesc.id_fix = NOFIX;
611 if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
614 idesc.id_number = idesc.id_parent;
615 idesc.id_parent = ino;
616 idesc.id_func = findname;
617 idesc.id_name = namebuf;
619 idesc.id_fix = NOFIX;
621 if ((ckinode(ginode(idesc.id_number), &idesc) & FOUND) == 0)
623 len = strlen(namebuf);
625 if (cp < &namebuf[MAXNAMLEN])
627 memcpy(cp, namebuf, len);
629 ino = idesc.id_number;
631 if (ino != ROOTINO) {
632 strcpy(namebuf, "?");
635 memcpy(namebuf, cp, &namebuf[BUFSIZ] - cp);
650 * When preening, allow a single quit to signal
651 * a special exit after filesystem checks complete
652 * so that reboot sequence may be interrupted.
657 extern returntosingle;
659 printf("returning to single-user after filesystem check\n");
661 (void)signal(SIGQUIT, SIG_DFL);
665 * Ignore a single quit signal; wait and flush just in case.
666 * Used by child processes in preen.
673 (void)signal(SIGQUIT, SIG_IGN);
674 (void)signal(SIGQUIT, SIG_DFL);
678 * determine whether an inode should be fixed.
681 register struct inodesc *idesc;
685 switch (idesc->id_fix) {
688 if (idesc->id_type == DATA)
689 direrror(idesc->id_number, msg);
693 printf(" (SALVAGED)\n");
697 if (reply("SALVAGE") == 0) {
698 idesc->id_fix = NOFIX;
711 errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
717 errexit(s1, s2, s3, s4)
721 printf(s1, s2, s3, s4);
730 * An unexpected inconsistency occured.
731 * Die if preening, otherwise just print message and continue.
734 pfatal(s, a1, a2, a3)
739 printf("%s: ", devname);
740 printf(s, a1, a2, a3);
742 printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", devname);
749 printf(s, a1, a2, a3);
753 * Pwarn just prints a message when not preening,
754 * or a warning (preceded by filename) when preening.
757 pwarn(s, a1, a2, a3, a4, a5, a6)
759 long a1, a2, a3, a4, a5, a6;
762 printf("%s: ", devname);
763 printf(s, a1, a2, a3, a4, a5, a6);
767 * Pwarn just prints a message when not preening,
768 * or a warning (preceded by filename) when preening.
771 pinfo(s, a1, a2, a3, a4, a5, a6)
773 long a1, a2, a3, a4, a5, a6;
776 printf("%s: ", devname);
777 printf(s, a1, a2, a3, a4, a5, a6);
782 * Stub for routines from kernel.
788 pfatal("INTERNAL INCONSISTENCY:");
793 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
800 if ((iscorrupt == 0) && (isdirty == 0))
802 if ((sblock.fs_clean != FSSTABLE) && (sblock.fs_clean != FSCLEAN))
805 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
807 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
811 sprintf(s, "WARNING: inconsistencies detected on `%s' filesystem %s",
812 sblock.fs_clean == FSSTABLE ? "stable" : "clean", devname);
818 struct bufarea cleanbuf;
821 unsigned int fsclean;
822 #if defined(AFS_SUN56_ENV)
827 /* set fsclean to its appropriate value */
828 fsclean = sblock.fs_clean;
830 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
832 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
836 /* if necessary, update fs_clean and fs_state */
853 /* if fs_clean and fs_state are ok, do nothing */
854 if ((sblock.fs_clean == fsclean) &&
856 (FSOKAY == (sblock.fs_state + sblock.fs_time)))
858 (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)))
861 sblock.fs_clean = fsclean;
863 sblock.fs_state = sblock.fs_time;
865 fs_set_state(&sblock, sblock.fs_time);
867 /* if superblock can't be written, return */
870 /* read private copy of superblock, update clean flag, and write it */
873 #if defined(AFS_SUN56_ENV)
874 sblkoff = (OFF_T) (bno) << DEV_BSHIFT;
875 if (llseek(fsreadfd, sblkoff, 0) == -1)
878 if (lseek(fsreadfd, (off_t) dbtob(bno), 0) == -1)
881 if ((cleanbuf.b_un.b_buf = malloc(size)) == NULL)
882 errexit("out of memory");
883 if (read(fsreadfd, cleanbuf.b_un.b_buf, (int)size) != size)
885 cleanbuf.b_un.b_fs->fs_clean = sblock.fs_clean;
887 cleanbuf.b_un.b_fs->fs_state = sblock.fs_state;
889 fs_set_state(cleanbuf.b_un.b_fs, fs_get_state(&sblock));
891 cleanbuf.b_un.b_fs->fs_time = sblock.fs_time;
892 #if defined(AFS_SUN56_ENV)
893 if (llseek(fswritefd, sblkoff, 0) == -1)
896 if (lseek(fswritefd, (off_t) dbtob(bno), 0) == -1)
899 if (write(fswritefd, cleanbuf.b_un.b_buf, (int)size) != size)
908 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
910 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
915 switch (sblock.fs_clean) {
929 pwarn("is %s.\n", s);
931 printf("** %s is %s.\n", devname, s);
938 register struct vfstab *vfs;
942 static char *tmpopts;
944 if (vfs->vfs_mntopts == NULL)
947 tmpopts = (char *)calloc(256, sizeof(char));
951 strncpy(tmpopts, vfs->vfs_mntopts, (sizeof(tmpopts) - 1));
954 for (; *f; f = mntopt(&opts)) {
955 if (strncmp(opt, f, strlen(opt)) == 0)
956 return (f - tmpopts + vfs->vfs_mntopts);
966 struct vfstab vfsbuf;
968 char *blkname, *unrawname();
970 vfstab = fopen(VFSTAB, "r");
971 if (vfstab == NULL) {
972 printf("can't open %s\n", VFSTAB);
975 blkname = unrawname(name);
976 if ((getvfsspec(vfstab, &vfsbuf, blkname) == 0)
977 && (vfsbuf.vfs_fstype != NULL)
978 && (strcmp(vfsbuf.vfs_fstype, MNTTYPE_UFS) == 0)
979 && (hasvfsopt(&vfsbuf, MNTOPT_RO))) {
992 struct stat device_stat, mount_stat;
993 char *blkname, *unrawname();
995 mnttab = fopen(MNTTAB, "r");
996 if (mnttab == NULL) {
997 printf("can't open %s\n", MNTTAB);
1000 blkname = unrawname(name);
1001 while ((getmntent(mnttab, &mnt)) == NULL) {
1002 if (strcmp(mnt.mnt_fstype, MNTTYPE_UFS) != 0) {
1005 if (strcmp(blkname, mnt.mnt_special) == 0) {
1006 stat(mnt.mnt_mountp, &mount_stat);
1007 stat(mnt.mnt_special, &device_stat);
1008 if (device_stat.st_rdev == mount_stat.st_dev) {
1009 if (hasmntopt(&mnt, MNTOPT_RO) != 0)
1010 found = 2; /* mounted as RO */
1012 found = 1; /* mounted as R/W */
1023 #if defined(AFS_HPUX101_ENV)
1026 #include <sys/stat.h>
1027 #include <sys/fcntl.h>
1031 bread(fd, buf, blk, size)
1040 switch (seek_options) {
1041 case BLKSEEK_ENABLED:
1045 case BLKSEEK_NOT_ENABLED: /* File */
1046 #if defined(AFS_HPUX102_ENV)
1047 lseek_offset = dbtoo(blk);
1049 lseek_offset = dbtob(blk);
1054 rwerror("BLKSEEK", blk);
1056 if (lseek(fd, (off_t) lseek_offset, 0) == (off_t) - 1)
1057 rwerror("SEEK", blk);
1058 else if (read(fd, buf, (int)size) == size)
1060 rwerror("READ", blk);
1064 bwrite(fd, buf, blk, size)
1075 switch (seek_options) {
1076 case BLKSEEK_ENABLED:
1080 case BLKSEEK_NOT_ENABLED: /* File */
1081 #if defined(AFS_HPUX102_ENV)
1082 lseek_offset = dbtoo(blk);
1084 lseek_offset = dbtob(blk);
1089 rwerror("BLKSEEK", blk);
1091 if (lseek(fd, (off_t) lseek_offset, 0) == (off_t) - 1)
1092 rwerror("SEEK", blk);
1093 else if (write(fd, buf, (int)size) == size) {
1097 rwerror("WRITE", blk);
1102 setup_block_seek(fd)
1103 int fd; /* File descriptor */
1105 int flags = 0; /* Flags to/from fcntl() */
1107 return setup_block_seek_2(fd, &flags);
1110 #define set_fserror printf
1113 setup_block_seek_2(fd, cntl_flags)
1114 int fd; /* Input. File descriptor */
1115 int *cntl_flags; /* Returned. Flags from fcntl() */
1117 int flags = 0; /* Flags to/from fcntl() */
1118 off_t lstatus; /* Status from lseek() */
1119 struct stat statarea;
1120 char dummy[MAXBSIZE];
1126 if ((flags = fcntl(fd, F_GETFL)) == -1) {
1127 set_fserror("Cannot get file control flags.");
1128 return (BLKSEEK_PROCESSING_ERROR);
1132 * Check if fd is a non-device file
1135 if (fstat(fd, &statarea) == -1) {
1136 set_fserror("Cannot get status information on file descriptor.");
1137 return (BLKSEEK_PROCESSING_ERROR);
1139 if (((statarea.st_mode & S_IFMT) != S_IFCHR)
1140 && ((statarea.st_mode & S_IFMT) != S_IFBLK)) {
1141 /* Not a device file -- BLKSEEK only works on device files */
1142 *cntl_flags = flags; /* O_BLKSEEK bit never set */
1143 return (BLKSEEK_NOT_ENABLED);
1147 * Set the fd to O_BLKSEEK
1149 if (fcntl(fd, F_SETFL, flags | O_BLKSEEK) == -1) {
1150 set_fserror("Cannot set file control flags.");
1151 return (BLKSEEK_PROCESSING_ERROR);
1153 if (flags & O_WRONLY) {
1154 /* Set lseek to location 0 before returning */
1155 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1156 set_fserror("Cannot lseek the device.");
1157 return (BLKSEEK_PROCESSING_ERROR);
1161 ("File is write only. Cannot Verify O_BLKSEEK mode set.");
1162 *cntl_flags = flags | O_BLKSEEK;
1163 return (BLKSEEK_FILE_WRITEONLY);
1167 * Verify that kernel knows how to do O_BLKSEEK
1169 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1170 set_fserror("Cannot lseek the device.");
1171 return (BLKSEEK_PROCESSING_ERROR);
1173 if (read(fd, &dummy[0], BBSIZE) != BBSIZE) { /* BBSIZE = 8192 */
1174 set_fserror("Cannot read from the device");
1175 return (BLKSEEK_PROCESSING_ERROR);
1178 if ((lstatus = lseek(fd, (off_t) 0, SEEK_CUR)) == (off_t) - 1) {
1179 set_fserror("Cannot lseek the device.");
1180 return (BLKSEEK_PROCESSING_ERROR);
1184 * Set lseek to location 0
1186 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1187 set_fserror("Cannot lseek the device.");
1188 return (BLKSEEK_PROCESSING_ERROR);
1191 if (lstatus == (off_t) (BBSIZE / DEV_BSIZE)) {
1192 *cntl_flags = flags | O_BLKSEEK;
1193 return (BLKSEEK_ENABLED); /* Successfully enabled O_BLKSEEK */
1195 *cntl_flags = flags & (~O_BLKSEEK); /* Turn off O_BLKSEEK bit */
1196 return (BLKSEEK_NOT_ENABLED); /* O_BLKSEEK not enabled */
1199 setup_all_block_seek()
1202 seek_options = setup_block_seek(fsreadfd);
1203 switch (seek_options) {
1204 case BLKSEEK_ENABLED:
1205 case BLKSEEK_NOT_ENABLED:
1208 errexit("setup_block_seek on fsreadfd");
1211 if (fswritefd == -1)
1213 switch (opt = setup_block_seek(fswritefd)) {
1214 case BLKSEEK_FILE_WRITEONLY: /* WO block or char device. */
1215 case BLKSEEK_NOT_ENABLED: /* regular file. */
1216 if (seek_options != opt)
1218 ("seek_options on fsreadfd (%d) and fswritefd (%d) do not match",
1222 errexit("setup_block_seek on fswritefd");
1227 printf("read option = %d write option = %d\n", seek_options, opt);
1232 #endif /* AFS_HPUX101_ENV */