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>
22 #include <sys/param.h>
23 #define VICE /* allow us to put our changes in at will */
26 #include <sys/vnode.h>
27 #include <sys/mount.h>
28 #include <ufs/inode.h>
36 #else /* AFS_OSF_ENV */
37 #ifdef AFS_VFSINCL_ENV
38 #include <sys/vnode.h>
43 #include <sys/fs/ufs_inode.h>
44 #include <sys/fs/ufs_fs.h>
46 #include <sys/fs/ufs_fsdir.h>
48 #include <sys/fs/ufs_mount.h>
50 #include <ufs/inode.h>
52 #include <ufs/fsdir.h>
54 #else /* AFS_VFSINCL_ENV */
55 #include <sys/inode.h>
58 #define LONGFILENAMES 1
59 #include <sys/sysmacros.h>
61 #include <sys/signal.h>
63 #ifdef HAVE_USR_OLD_USR_INCLUDE_NDIR_H
64 #include </usr/old/usr/include/ndir.h>
72 #endif /* AFS_VFSINCL_ENV */
73 #endif /* AFS_OSF_ENV */
80 #if defined(AFS_HPUX101_ENV)
84 #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
90 long diskreads, totalreads; /* Disk cache statistics */
91 #if !defined(AFS_HPUX101_ENV)
95 #if defined(AFS_SUN_ENV)
102 #include <sys/mntent.h>
103 #include <sys/mnttab.h>
104 #include <sys/stat.h>
105 #include <sys/vfstab.h>
113 switch (dp->di_mode & IFMT) {
135 printf("bad file type 0%o\n", dp->di_mode);
150 pfatal("INTERNAL ERROR: GOT TO reply()");
151 persevere = !strcmp(question, "CONTINUE");
153 if (!persevere && (nflag || fswritefd < 0)) {
154 printf("%s? no\n\n", question);
155 #if defined(AFS_SUN_ENV)
156 iscorrupt = 1; /* known to be corrupt */
160 if (yflag || (persevere && nflag)) {
161 printf("%s? yes\n\n", question);
165 printf("%s? [yn] ", question);
166 (void)fflush(stdout);
168 while (c != '\n' && getc(stdin) != '\n')
171 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
173 if (c == 'y' || c == 'Y')
178 #if defined(AFS_SUN_ENV)
179 iscorrupt = 1; /* known to be corrupt */
185 * Malloc buffers and set up cache.
189 register struct bufarea *bp;
193 bufp = malloc((unsigned int)sblock.fs_bsize);
195 errexit("cannot allocate buffer pool\n");
196 cgblk.b_un.b_buf = bufp;
198 bufhead.b_next = bufhead.b_prev = &bufhead;
199 bufcnt = MAXBUFSPACE / sblock.fs_bsize;
200 if (bufcnt < MINBUFS)
202 for (i = 0; i < bufcnt; i++) {
203 bp = (struct bufarea *)malloc(sizeof(struct bufarea));
204 bufp = malloc((unsigned int)sblock.fs_bsize);
205 if (bp == NULL || bufp == NULL) {
208 errexit("cannot allocate buffer pool\n");
210 bp->b_un.b_buf = bufp;
211 bp->b_prev = &bufhead;
212 bp->b_next = bufhead.b_next;
213 bufhead.b_next->b_prev = bp;
217 bufhead.b_size = i; /* save number of buffers */
224 * Manage a cache of directory blocks.
227 getdatablk(blkno, size)
231 register struct bufarea *bp;
233 for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
234 if (bp->b_bno == fsbtodb(&sblock, blkno))
236 for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
237 if ((bp->b_flags & B_INUSE) == 0)
240 errexit("deadlocked buffer pool\n");
241 getblk(bp, blkno, size);
245 bp->b_prev->b_next = bp->b_next;
246 bp->b_next->b_prev = bp->b_prev;
247 bp->b_prev = &bufhead;
248 bp->b_next = bufhead.b_next;
249 bufhead.b_next->b_prev = bp;
251 bp->b_flags |= B_INUSE;
256 getblk(bp, blk, size)
257 register struct bufarea *bp;
263 dblk = fsbtodb(&sblock, blk);
264 if (bp->b_bno == dblk)
266 flush(fswritefd, bp);
268 bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size);
276 register struct bufarea *bp;
284 if (bp->b_errs != 0) {
285 pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
286 (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
291 bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
294 #if defined(AFS_HPUX101_ENV)
295 #if defined(AFS_HPUX110_ENV)
296 /* jpm: Need a fix here */
298 #else /* AFS_HPUX110_ENV */
300 (fswritefd, (char *)sblock.fs_csp[0],
301 fsbtodb(&sblock, sblock.fs_csaddr), fragroundup(&sblock,
302 sblock.fs_cssize)) ==
304 #endif /* else AFS_HPUX110_ENV */
307 ("\nUnable to write to cylinder group summary area (fs_csaddr)\n");
308 printf("\tDisk write error at block %u\n",
309 fsbtodb(&sblock, sblock.fs_csaddr));
312 #if defined(AFS_SUN56_ENV)
313 sip = (caddr_t) sblock.fs_u.fs_csp;
314 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
316 sblock.fs_cssize - i <
317 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
318 bwrite(fswritefd, sip,
319 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), size);
323 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
324 bwrite(fswritefd, (char *)sblock.fs_csp[j],
325 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
326 sblock.fs_cssize - i <
327 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize);
329 #endif /* AFS_SUN56_ENV */
330 #endif /* AFS_HPUX101_ENV */
340 pfatal("CANNOT %s: BLK %ld", mesg, blk);
341 if (reply("CONTINUE") == 0)
342 errexit("Program terminated\n");
347 register struct bufarea *bp, *nbp;
350 flush(fswritefd, &sblk);
352 if (havesb && sblk.b_bno != SBOFF / dev_bsize && !preen
353 && reply("UPDATE STANDARD SUPERBLOCK")) {
354 sblk.b_bno = SBOFF / dev_bsize;
355 #else /* AFS_NEWCG_ENV */
356 if (havesb && sblk.b_bno != SBLOCK && !preen
357 && reply("UPDATE STANDARD SUPERBLOCK")) {
359 #endif /* AFS_NEWCG_ENV */
361 flush(fswritefd, &sblk);
363 flush(fswritefd, &cgblk);
364 if (cgblk.b_un.b_buf) {
365 free(cgblk.b_un.b_buf);
366 cgblk.b_un.b_buf = NULL;
368 for (bp = bufhead.b_prev; bp != &bufhead; bp = nbp) {
370 flush(fswritefd, bp);
372 free(bp->b_un.b_buf);
378 if (bufhead.b_size != cnt)
379 errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
381 printf("cache missed %d of %d (%d%%)\n", diskreads, totalreads,
382 diskreads * 100 / totalreads);
383 (void)close(fsreadfd);
384 (void)close(fswritefd);
387 #if !defined(AFS_HPUX101_ENV)
388 bread(fd, buf, blk, size)
401 offset_t offset = (offset_t) blk << DEV_BSHIFT;
406 /* To fix a stripping related bug?? */
407 if (lseek(fd, blk * dev_bsize, 0) == -1)
410 if (llseek(fd, offset, 0) < 0)
412 if (lseek(fd, blk * dev_bsize, 0) < 0)
415 rwerror("SEEK", blk);
416 else if (read(fd, buf, (int)size) == size)
418 rwerror("READ", blk);
420 /* To fix a stripping related bug?? */
421 if (lseek(fd, blk * dev_bsize, 0) == -1)
424 if (llseek(fd, offset, 0) < 0)
426 if (lseek(fd, blk * dev_bsize, 0) < 0)
429 rwerror("SEEK", blk);
431 memset(buf, 0, (int)size);
432 printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
434 for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) {
435 addr = (offset_t) (blk + i) << DEV_BSHIFT;
436 if (llseek(fd, addr, SEEK_CUR) < 0 || read(fd, cp, (int)secsize) < 0) {
437 printf(" %d", blk + i);
439 for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
440 if (read(fd, cp, (int)secsize) < 0) {
441 lseek(fd, blk * dev_bsize + i + secsize, 0);
442 if (secsize != dev_bsize && dev_bsize != 1)
443 printf(" %d (%d),", (blk * dev_bsize + i) / secsize,
444 blk + i / dev_bsize);
446 printf(" %d,", blk + i / dev_bsize);
455 bwrite(fd, buf, blk, size)
468 offset_t offset = (offset_t) blk << DEV_BSHIFT;
473 sprintf(msg, "WARNING: Attempt to write illegal blkno %d on %s\n",
484 /* To fix a stripping related bug?? */
485 if (lseek(fd, blk * dev_bsize, 0) == -1)
488 if (llseek(fd, offset, 0) < 0)
490 if (lseek(fd, blk * dev_bsize, 0) < 0)
493 rwerror("SEEK", blk);
494 else if (write(fd, buf, (int)size) == size) {
498 rwerror("WRITE", blk);
500 /* To fix a stripping related bug?? */
501 if (lseek(fd, blk * dev_bsize, 0) == -1)
504 if (llseek(fd, offset, 0) < 0)
506 if (lseek(fd, blk * dev_bsize, 0) < 0)
509 rwerror("SEEK", blk);
510 printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
512 for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) {
514 addr = (offset_t) (blk + i) << DEV_BSHIFT;
515 if (llseek(fd, addr, SEEK_CUR) < 0
516 || (n = write(fd, cp, DEV_BSIZE)) < 0) {
517 printf(" %d", blk + i);
524 for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
525 if (write(fd, cp, (int)dev_bsize) < 0) {
526 lseek(fd, blk * dev_bsize + i + dev_bsize, 0);
527 printf(" %d,", blk + i / dev_bsize);
533 #endif /* AFS_HPUX101_ENV */
535 * allocate a data block with the specified number of fragments
540 register int i, j, k;
542 if (frags <= 0 || frags > sblock.fs_frag)
544 for (i = 0; i < maxfsblock - sblock.fs_frag; i += sblock.fs_frag) {
545 for (j = 0; j <= sblock.fs_frag - frags; j++) {
548 for (k = 1; k < frags; k++)
549 if (testbmap(i + j + k))
555 for (k = 0; k < frags; k++)
565 * Free a previously allocated block
567 freeblk(blkno, frags)
571 struct inodesc idesc;
573 idesc.id_blkno = blkno;
574 idesc.id_numfrags = frags;
581 getpathname(namebuf, curdir, ino)
587 struct inodesc idesc;
588 extern int findname();
590 if (statemap[ino] != DSTATE && statemap[ino] != DFOUND) {
591 strcpy(namebuf, "?");
594 memset((char *)&idesc, 0, sizeof(struct inodesc));
595 idesc.id_type = DATA;
596 cp = &namebuf[BUFSIZ - 1];
599 idesc.id_parent = curdir;
602 while (ino != ROOTINO) {
603 idesc.id_number = ino;
604 idesc.id_func = findino;
605 idesc.id_name = "..";
607 idesc.id_fix = NOFIX;
609 if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
612 idesc.id_number = idesc.id_parent;
613 idesc.id_parent = ino;
614 idesc.id_func = findname;
615 idesc.id_name = namebuf;
617 idesc.id_fix = NOFIX;
619 if ((ckinode(ginode(idesc.id_number), &idesc) & FOUND) == 0)
621 len = strlen(namebuf);
623 if (cp < &namebuf[MAXNAMLEN])
625 memcpy(cp, namebuf, len);
627 ino = idesc.id_number;
629 if (ino != ROOTINO) {
630 strcpy(namebuf, "?");
633 memcpy(namebuf, cp, &namebuf[BUFSIZ] - cp);
648 * When preening, allow a single quit to signal
649 * a special exit after filesystem checks complete
650 * so that reboot sequence may be interrupted.
655 extern returntosingle;
657 printf("returning to single-user after filesystem check\n");
659 (void)signal(SIGQUIT, SIG_DFL);
663 * Ignore a single quit signal; wait and flush just in case.
664 * Used by child processes in preen.
671 (void)signal(SIGQUIT, SIG_IGN);
672 (void)signal(SIGQUIT, SIG_DFL);
676 * determine whether an inode should be fixed.
679 register struct inodesc *idesc;
683 switch (idesc->id_fix) {
686 if (idesc->id_type == DATA)
687 direrror(idesc->id_number, msg);
691 printf(" (SALVAGED)\n");
695 if (reply("SALVAGE") == 0) {
696 idesc->id_fix = NOFIX;
709 errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
715 errexit(s1, s2, s3, s4)
719 printf(s1, s2, s3, s4);
728 * An unexpected inconsistency occured.
729 * Die if preening, otherwise just print message and continue.
732 pfatal(s, a1, a2, a3)
737 printf("%s: ", devname);
738 printf(s, a1, a2, a3);
740 printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", devname);
747 printf(s, a1, a2, a3);
751 * Pwarn just prints a message when not preening,
752 * or a warning (preceded by filename) when preening.
755 pwarn(s, a1, a2, a3, a4, a5, a6)
757 long a1, a2, a3, a4, a5, a6;
760 printf("%s: ", devname);
761 printf(s, a1, a2, a3, a4, a5, a6);
765 * Pwarn just prints a message when not preening,
766 * or a warning (preceded by filename) when preening.
769 pinfo(s, a1, a2, a3, a4, a5, a6)
771 long a1, a2, a3, a4, a5, a6;
774 printf("%s: ", devname);
775 printf(s, a1, a2, a3, a4, a5, a6);
780 * Stub for routines from kernel.
786 pfatal("INTERNAL INCONSISTENCY:");
791 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
798 if ((iscorrupt == 0) && (isdirty == 0))
800 if ((sblock.fs_clean != FSSTABLE) && (sblock.fs_clean != FSCLEAN))
803 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
805 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
809 sprintf(s, "WARNING: inconsistencies detected on `%s' filesystem %s",
810 sblock.fs_clean == FSSTABLE ? "stable" : "clean", devname);
816 struct bufarea cleanbuf;
819 unsigned int fsclean;
820 #if defined(AFS_SUN56_ENV)
825 /* set fsclean to its appropriate value */
826 fsclean = sblock.fs_clean;
828 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
830 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
834 /* if necessary, update fs_clean and fs_state */
851 /* if fs_clean and fs_state are ok, do nothing */
852 if ((sblock.fs_clean == fsclean) &&
854 (FSOKAY == (sblock.fs_state + sblock.fs_time)))
856 (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)))
859 sblock.fs_clean = fsclean;
861 sblock.fs_state = sblock.fs_time;
863 fs_set_state(&sblock, sblock.fs_time);
865 /* if superblock can't be written, return */
868 /* read private copy of superblock, update clean flag, and write it */
871 #if defined(AFS_SUN56_ENV)
872 sblkoff = (OFF_T) (bno) << DEV_BSHIFT;
873 if (llseek(fsreadfd, sblkoff, 0) == -1)
876 if (lseek(fsreadfd, (off_t) dbtob(bno), 0) == -1)
879 if ((cleanbuf.b_un.b_buf = malloc(size)) == NULL)
880 errexit("out of memory");
881 if (read(fsreadfd, cleanbuf.b_un.b_buf, (int)size) != size)
883 cleanbuf.b_un.b_fs->fs_clean = sblock.fs_clean;
885 cleanbuf.b_un.b_fs->fs_state = sblock.fs_state;
887 fs_set_state(cleanbuf.b_un.b_fs, fs_get_state(&sblock));
889 cleanbuf.b_un.b_fs->fs_time = sblock.fs_time;
890 #if defined(AFS_SUN56_ENV)
891 if (llseek(fswritefd, sblkoff, 0) == -1)
894 if (lseek(fswritefd, (off_t) dbtob(bno), 0) == -1)
897 if (write(fswritefd, cleanbuf.b_un.b_buf, (int)size) != size)
906 if (FSOKAY != (sblock.fs_state + sblock.fs_time))
908 if (FSOKAY != (fs_get_state(&sblock) + sblock.fs_time))
913 switch (sblock.fs_clean) {
927 pwarn("is %s.\n", s);
929 printf("** %s is %s.\n", devname, s);
936 register struct vfstab *vfs;
940 static char *tmpopts;
942 if (vfs->vfs_mntopts == NULL)
945 tmpopts = (char *)calloc(256, sizeof(char));
949 strncpy(tmpopts, vfs->vfs_mntopts, (sizeof(tmpopts) - 1));
952 for (; *f; f = mntopt(&opts)) {
953 if (strncmp(opt, f, strlen(opt)) == 0)
954 return (f - tmpopts + vfs->vfs_mntopts);
964 struct vfstab vfsbuf;
966 char *blkname, *unrawname();
968 vfstab = fopen(VFSTAB, "r");
969 if (vfstab == NULL) {
970 printf("can't open %s\n", VFSTAB);
973 blkname = unrawname(name);
974 if ((getvfsspec(vfstab, &vfsbuf, blkname) == 0)
975 && (vfsbuf.vfs_fstype != NULL)
976 && (strcmp(vfsbuf.vfs_fstype, MNTTYPE_UFS) == 0)
977 && (hasvfsopt(&vfsbuf, MNTOPT_RO))) {
990 struct stat device_stat, mount_stat;
991 char *blkname, *unrawname();
993 mnttab = fopen(MNTTAB, "r");
994 if (mnttab == NULL) {
995 printf("can't open %s\n", MNTTAB);
998 blkname = unrawname(name);
999 while ((getmntent(mnttab, &mnt)) == NULL) {
1000 if (strcmp(mnt.mnt_fstype, MNTTYPE_UFS) != 0) {
1003 if (strcmp(blkname, mnt.mnt_special) == 0) {
1004 stat(mnt.mnt_mountp, &mount_stat);
1005 stat(mnt.mnt_special, &device_stat);
1006 if (device_stat.st_rdev == mount_stat.st_dev) {
1007 if (hasmntopt(&mnt, MNTOPT_RO) != 0)
1008 found = 2; /* mounted as RO */
1010 found = 1; /* mounted as R/W */
1021 #if defined(AFS_HPUX101_ENV)
1024 #include <sys/stat.h>
1025 #include <sys/fcntl.h>
1029 bread(fd, buf, blk, size)
1038 switch (seek_options) {
1039 case BLKSEEK_ENABLED:
1043 case BLKSEEK_NOT_ENABLED: /* File */
1044 #if defined(AFS_HPUX102_ENV)
1045 lseek_offset = dbtoo(blk);
1047 lseek_offset = dbtob(blk);
1052 rwerror("BLKSEEK", blk);
1054 if (lseek(fd, (off_t) lseek_offset, 0) == (off_t) - 1)
1055 rwerror("SEEK", blk);
1056 else if (read(fd, buf, (int)size) == size)
1058 rwerror("READ", blk);
1062 bwrite(fd, buf, blk, size)
1073 switch (seek_options) {
1074 case BLKSEEK_ENABLED:
1078 case BLKSEEK_NOT_ENABLED: /* File */
1079 #if defined(AFS_HPUX102_ENV)
1080 lseek_offset = dbtoo(blk);
1082 lseek_offset = dbtob(blk);
1087 rwerror("BLKSEEK", blk);
1089 if (lseek(fd, (off_t) lseek_offset, 0) == (off_t) - 1)
1090 rwerror("SEEK", blk);
1091 else if (write(fd, buf, (int)size) == size) {
1095 rwerror("WRITE", blk);
1100 setup_block_seek(fd)
1101 int fd; /* File descriptor */
1103 int flags = 0; /* Flags to/from fcntl() */
1105 return setup_block_seek_2(fd, &flags);
1108 #define set_fserror printf
1111 setup_block_seek_2(fd, cntl_flags)
1112 int fd; /* Input. File descriptor */
1113 int *cntl_flags; /* Returned. Flags from fcntl() */
1115 int flags = 0; /* Flags to/from fcntl() */
1116 off_t lstatus; /* Status from lseek() */
1117 struct stat statarea;
1118 char dummy[MAXBSIZE];
1124 if ((flags = fcntl(fd, F_GETFL)) == -1) {
1125 set_fserror("Cannot get file control flags.");
1126 return (BLKSEEK_PROCESSING_ERROR);
1130 * Check if fd is a non-device file
1133 if (fstat(fd, &statarea) == -1) {
1134 set_fserror("Cannot get status information on file descriptor.");
1135 return (BLKSEEK_PROCESSING_ERROR);
1137 if (((statarea.st_mode & S_IFMT) != S_IFCHR)
1138 && ((statarea.st_mode & S_IFMT) != S_IFBLK)) {
1139 /* Not a device file -- BLKSEEK only works on device files */
1140 *cntl_flags = flags; /* O_BLKSEEK bit never set */
1141 return (BLKSEEK_NOT_ENABLED);
1145 * Set the fd to O_BLKSEEK
1147 if (fcntl(fd, F_SETFL, flags | O_BLKSEEK) == -1) {
1148 set_fserror("Cannot set file control flags.");
1149 return (BLKSEEK_PROCESSING_ERROR);
1151 if (flags & O_WRONLY) {
1152 /* Set lseek to location 0 before returning */
1153 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1154 set_fserror("Cannot lseek the device.");
1155 return (BLKSEEK_PROCESSING_ERROR);
1159 ("File is write only. Cannot Verify O_BLKSEEK mode set.");
1160 *cntl_flags = flags | O_BLKSEEK;
1161 return (BLKSEEK_FILE_WRITEONLY);
1165 * Verify that kernel knows how to do O_BLKSEEK
1167 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1168 set_fserror("Cannot lseek the device.");
1169 return (BLKSEEK_PROCESSING_ERROR);
1171 if (read(fd, &dummy[0], BBSIZE) != BBSIZE) { /* BBSIZE = 8192 */
1172 set_fserror("Cannot read from the device");
1173 return (BLKSEEK_PROCESSING_ERROR);
1176 if ((lstatus = lseek(fd, (off_t) 0, SEEK_CUR)) == (off_t) - 1) {
1177 set_fserror("Cannot lseek the device.");
1178 return (BLKSEEK_PROCESSING_ERROR);
1182 * Set lseek to location 0
1184 if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) - 1) {
1185 set_fserror("Cannot lseek the device.");
1186 return (BLKSEEK_PROCESSING_ERROR);
1189 if (lstatus == (off_t) (BBSIZE / DEV_BSIZE)) {
1190 *cntl_flags = flags | O_BLKSEEK;
1191 return (BLKSEEK_ENABLED); /* Successfully enabled O_BLKSEEK */
1193 *cntl_flags = flags & (~O_BLKSEEK); /* Turn off O_BLKSEEK bit */
1194 return (BLKSEEK_NOT_ENABLED); /* O_BLKSEEK not enabled */
1197 setup_all_block_seek()
1200 seek_options = setup_block_seek(fsreadfd);
1201 switch (seek_options) {
1202 case BLKSEEK_ENABLED:
1203 case BLKSEEK_NOT_ENABLED:
1206 errexit("setup_block_seek on fsreadfd");
1209 if (fswritefd == -1)
1211 switch (opt = setup_block_seek(fswritefd)) {
1212 case BLKSEEK_FILE_WRITEONLY: /* WO block or char device. */
1213 case BLKSEEK_NOT_ENABLED: /* regular file. */
1214 if (seek_options != opt)
1216 ("seek_options on fsreadfd (%d) and fswritefd (%d) do not match",
1220 errexit("setup_block_seek on fswritefd");
1225 printf("read option = %d write option = %d\n", seek_options, opt);
1230 #endif /* AFS_HPUX101_ENV */