diff --git a/src/vol/ihandle.c b/src/vol/ihandle.c index 287cfc534f..8ef2a61b37 100644 --- a/src/vol/ihandle.c +++ b/src/vol/ihandle.c @@ -1036,7 +1036,7 @@ ih_size(FD_t fd) return -1; return size.QuadPart; #else - struct afs_stat status; + struct afs_stat_st status; if (afs_fstat(fd, &status) < 0) return -1; return status.st_size; diff --git a/src/vol/ihandle.h b/src/vol/ihandle.h index 93a101c3ae..08e2d8bf57 100644 --- a/src/vol/ihandle.h +++ b/src/vol/ihandle.h @@ -288,7 +288,7 @@ typedef struct IHashBucket_s { extern void ih_clear(IHandle_t * h); extern Inode ih_create(IHandle_t * h, int dev, char *part, Inode nI, int p1, int p2, int p3, int p4); -extern FILE *ih_fdopen(FdHandle_t * h, char *fdperms); +extern FD_t *ih_fdopen(FdHandle_t * h, char *fdperms); #endif /* AFS_NAMEI_ENV */ /* @@ -372,8 +372,8 @@ extern int ih_condsync(IHandle_t * ihP); #endif /* !O_LARGEFILE */ #endif /* AFS_NT40_ENV */ #else /* !HAVE_PIO */ -extern ssize_t ih_pread(int fd, void * buf, size_t count, afs_foff_t offset); -extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset); +extern ssize_t ih_pread(FD_t fd, void * buf, size_t count, afs_foff_t offset); +extern ssize_t ih_pwrite(FD_t fd, const void * buf, size_t count, afs_foff_t offset); #define OS_PREAD(FD, B, S, O) ih_pread(FD, B, S, O) #define OS_PWRITE(FD, B, S, O) ih_pwrite(FD, B, S, O) #endif /* !HAVE_PIO */ @@ -419,13 +419,13 @@ extern Inode IH_CREATE(IHandle_t * H, int /*@alt Device @ */ D, int /*@alt unsigned @ */ P4); extern FD_t OS_IOPEN(IHandle_t * H); extern int OS_OPEN(const char *F, int M, mode_t P); -extern int OS_CLOSE(int FD); -extern ssize_t OS_READ(int FD, void *B, size_t S); -extern ssize_t OS_WRITE(int FD, void *B, size_t S); -extern ssize_t OS_PREAD(int FD, void *B, size_t S, afs_foff_t O); -extern ssize_t OS_PWRITE(int FD, void *B, size_t S, afs_foff_t O); -extern int OS_SYNC(int FD); -extern afs_sfsize_t OS_SIZE(int FD); +extern int OS_CLOSE(FD_t FD); +extern ssize_t OS_READ(FD_t FD, void *B, size_t S); +extern ssize_t OS_WRITE(FD_t FD, void *B, size_t S); +extern ssize_t OS_PREAD(FD_t FD, void *B, size_t S, afs_foff_t O); +extern ssize_t OS_PWRITE(FD_t FD, void *B, size_t S, afs_foff_t O); +extern int OS_SYNC(FD_t FD); +extern afs_sfsize_t OS_SIZE(FD_t FD); extern int IH_INC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P); extern int IH_DEC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P); extern afs_sfsize_t IH_IREAD(IHandle_t * H, afs_foff_t O, void *B, @@ -438,8 +438,8 @@ extern afs_sfsize_t IH_IWRITE(IHandle_t * H, afs_foff_t O, void *B, #define OFFT off_t #endif -extern OFFT OS_SEEK(int FD, OFFT O, int F); -extern int OS_TRUNC(int FD, OFFT L); +extern OFFT OS_SEEK(FD_t FD, OFFT O, int F); +extern int OS_TRUNC(FD_t FD, OFFT L); #endif /*S_SPLINT_S */ #ifdef O_LARGEFILE diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index d13a2a190f..8c35749978 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -33,7 +33,7 @@ * -2 - Unable to completely write temp file. Produces warning message in log. */ int -ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, afs_uint32 (*judgeInode) (), afs_uint32 judgeParam, int *forcep, int forceR, char *wpath, void *rock) { @@ -117,7 +117,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, #define ROOTINODE 2 static char *partition; int Testing=0; -int pfd; +FD_t pfd; #ifdef AFS_AIX32_ENV #include @@ -165,7 +165,7 @@ struct dinode *ginode(); int -ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (), afs_uint32 judgeParam, int *forcep, int forceR, char *wpath, void *rock) { @@ -176,7 +176,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, struct stat root_inode; int ninodes = 0, err = 0; - pfd = -1; /* initialize so we don't close on error output below. */ + pfd = INVALID_FD; /* initialize so we don't close on error output below. */ *forcep = 0; sync(); sleep(1); /* simulate operator */ @@ -250,8 +250,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, fmax = fs.s_fsize / (FSBSIZE / 512); /* first invalid blk num */ - pfd = afs_open(rdev, O_RDONLY); - if (pfd < 0) { + pfd = OS_OPEN(rdev, O_RDONLY, 0666); + if (pfd == INVALID_FD) { Log("Unable to open `%s' inode for reading\n", rdev); return -1; } @@ -297,8 +297,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0) continue; - if (inodeFile) { - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + if (inodeFile != INVALID_FD) { + if (OS_WRITE(inodeFile, &info, sizeof(info) * 1) != 1) { Log("Error writing inode file for partition %s\n", partition); goto out; } @@ -306,13 +306,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, ++ninodes; } - if (inodeFile) { - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fsync(fileno(inodeFile)) == -1) { + if (inodeFile != INVALID_FD) { + if (OS_SYNC(inodeFile) == -1) { Log("Unable to successfully fsync inode file for %s\n", partition); err = -2; goto out1; @@ -321,12 +316,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, /* * Paranoia: check that the file is really the right size */ - if (fstat(fileno(inodeFile), &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - err = -2; - goto out1; - } - if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + if (OS_SIZE(inodeFile) != ninodes * sizeof(struct ViceInodeInfo)) { Log("Wrong size (%d instead of %d) in inode file for %s\n", status.st_size, ninodes * sizeof(struct ViceInodeInfo), partition); @@ -334,14 +324,14 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, goto out1; } } - close(pfd); + OS_CLOSE(pfd); return 0; out: err = -1; out1: - if (pfd >= 0) - close(pfd); + if (pfd != INVALID_FD) + OS_CLOSE(pfd); return err; } @@ -350,10 +340,10 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, int ReadSuper(struct superblock *fs, char *devName) { - int pfd; + FD_t pfd; - pfd = afs_open(devName, O_RDONLY); - if (pfd < 0) { + pfd = OS_OPEN(devName, O_RDONLY, 0666); + if (pfd == INVALID_FD) { Log("Unable to open inode on %s for reading superblock.\n", devName); return -1; } @@ -362,7 +352,7 @@ ReadSuper(struct superblock *fs, char *devName) Log("Unable to read superblock on %s.\n", devName); return -1; } - close(pfd); + OS_CLOSE(pfd); return (0); } @@ -617,7 +607,7 @@ xfs_RenameFiles(char *dir, xfs_Rename_t * renames, int n_renames) int -xfs_ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +xfs_ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (), afs_uint32 judgeParam, int *forcep, int forceR, char *wpath, void *rock) { @@ -642,7 +632,6 @@ xfs_ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, int n_renames = 0; int n_avail = 0; uint64_t pino; - struct stat status; int errors = 0; *forcep = 0; @@ -753,9 +742,9 @@ xfs_ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, n_renames++; } - if (inodeFile) { - if (fwrite - (&info.ili_info, sizeof(vice_inode_info_t), 1, inodeFile) + if (inodeFile != INVALID_FD) { + if (OS_WRITE + (inodeFile, &info.ili_info, sizeof(vice_inode_info_t)) != 1) { Log("Error writing inode file for partition %s\n", mountedOn); goto err1_exit; @@ -778,25 +767,17 @@ xfs_ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, closedir(top_dirp); if (renames) free((char *)renames); - if (inodeFile) { - if (fflush(inodeFile) == EOF) { - ("Unable to successfully flush inode file for %s\n", mountedOn); - return errors ? -1 : -2; - } - if (fsync(fileno(inodeFile)) == -1) { + if (inodeFile != INVALID_FD) { + if (OS_SYNC(inodeFile) == -1) { Log("Unable to successfully fsync inode file for %s\n", mountedOn); return errors ? -1 : -2; } /* * Paranoia: check that the file is really the right size */ - if (fstat(fileno(inodeFile), &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - return errors ? -1 : -2; - } - if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + if (OS_SIZE(inodeFile) != ninodes * sizeof(struct ViceInodeInfo)) { Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof(struct ViceInodeInfo), + OS_SIZE(inodeFile), ninodes * sizeof(struct ViceInodeInfo), partition); return errors ? -1 : -2; } @@ -822,7 +803,7 @@ xfs_ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, #endif int -ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (), afs_uint32 judgeParam, int *forcep, int forceR, char *wpath, void *rock) { @@ -887,7 +868,7 @@ BUFAREA sblk; extern char *afs_rawname(); int -ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (), afs_uint32 judgeParam, int *forcep, int forceR, char *wpath, void *rock) { @@ -903,7 +884,6 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, int i, c, e, bufsize, code, err = 0; char dev[50], rdev[100], err1[512], *ptr1; struct dinode *inodes = NULL, *einodes, *dptr; - struct stat status; int ninodes = 0; struct dinode *p; struct ViceInodeInfo info; @@ -922,8 +902,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, sleep(10); #endif - pfd = afs_open(rdev, O_RDONLY); - if (pfd <= 0) { + pfd = OS_OPEN(rdev, O_RDONLY, 0666); + if (pfd == INVALID_FD) { sprintf(err1, "Could not open device %s to get inode list\n", rdev); perror(err1); return -1; @@ -983,8 +963,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, info.u.param[3] = auxp->aux_param4; if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0) continue; - if (inodeFile) { - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + if (inodeFile != INVALID_FD) { + if (OS_WRITE(inodeFile, &info, sizeof(info)) != 1) { Log("Error writing inode file for partition %s\n", partition); goto out; } @@ -1060,10 +1040,10 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, i = c * sblock.fs_ipg; e = i + sblock.fs_ipg; #if defined(AFS_HPUX102_ENV) - if (afs_lseek(pfd, dbtoo(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == + if (OS_SEEK(pfd, dbtoo(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == -1) { #else - if (afs_lseek(pfd, dbtob(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == + if (OS_SEEK(pfd, dbtob(fsbtodb(&sblock, itod(&sblock, i))), L_SET) == -1) { #endif #else @@ -1081,14 +1061,14 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, e = i + super.fs.fs_ipg; #ifdef AFS_OSF_ENV dblk1 = fsbtodb(&super.fs, itod(&super.fs, i)); - if (afs_lseek(pfd, (off_t) ((off_t) dblk1 * DEV_BSIZE), L_SET) == -1) { + if (OS_SEEK(pfd, (off_t) ((off_t) dblk1 * DEV_BSIZE), L_SET) == -1) { #else #if defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) f1 = fsbtodb(&super.fs, itod(&super.fs, i)); off = (offset_t) f1 << DEV_BSHIFT; - if (llseek(pfd, off, L_SET) == -1) { + if (OS_SEEK(pfd, off, L_SET) == -1) { #else - if (afs_lseek(pfd, dbtob(fsbtodb(&super.fs, itod(&super.fs, i))), L_SET) + if (OS_SEEK(pfd, dbtob(fsbtodb(&super.fs, itod(&super.fs, i))), L_SET) == -1) { #endif /* AFS_SUN5_ENV */ #endif /* AFS_OSF_ENV */ @@ -1099,7 +1079,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, } while (i < e) { if (!forceR) { - if (read(pfd, inodes, bufsize) != bufsize) { + if (OS_READ(pfd, inodes, bufsize) != bufsize) { Log("Error reading inodes for partition %s; run vfsck\n", partition); goto out; @@ -1108,10 +1088,10 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, int bj, bk; dptr = inodes; for (bj = bk = 0; bj < bufsize; bj = bj + 512, bk++) { - if ((code = read(pfd, dptr, 512)) != 512) { + if ((code = OS_READ(pfd, dptr, 512)) != 512) { Log("Error reading inode %d? for partition %s (errno = %d); run vfsck\n", bk + i, partition, errno); - if (afs_lseek(pfd, 512, L_SET) == -1) { - Log("Lseek failed\n"); + if (OS_SEEK(pfd, 512, L_SET) == -1) { + Log("OS_SEEK failed\n"); goto out; } dptr->di_mode = 0; @@ -1194,8 +1174,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, info.linkCount = p->di_nlink; if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0) continue; - if (inodeFile) { - if (fwrite(&info, sizeof info, 1, inodeFile) != 1) { + if (inodeFile != INVALID_FD) { + if (OS_WRITE(inodeFile, &info, sizeof(info)) != 1) { Log("Error writing inode file for partition %s\n", partition); goto out; @@ -1209,13 +1189,8 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, if (inodes) free(inodes); #endif - if (inodeFile) { - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", partition); - err = -2; - goto out1; - } - if (fsync(fileno(inodeFile)) == -1) { + if (inodeFile != INVALID_FD) { + if (OS_SYNC(inodeFile) == -1) { Log("Unable to successfully fsync inode file for %s\n", partition); err = -2; goto out1; @@ -1224,26 +1199,21 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, /* * Paranoia: check that the file is really the right size */ - if (fstat(fileno(inodeFile), &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", partition); - err = -2; - goto out1; - } - if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + if (OS_SIZE(inodeFile) != ninodes * sizeof(struct ViceInodeInfo)) { Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof(struct ViceInodeInfo), + OS_SIZE(inodeFile), ninodes * sizeof(struct ViceInodeInfo), partition); err = -2; goto out1; } } - close(pfd); + OS_CLOSE(pfd); return 0; out: err = -1; out1: - close(pfd); + OS_CLOSE(pfd); if (inodes) free(inodes); return err; @@ -1257,26 +1227,26 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, #endif int -bread(int fd, char *buf, daddr_t blk, afs_int32 size) +bread(FD_t fd, char *buf, daddr_t blk, afs_int32 size) { #ifdef AFS_AIX_ENV #ifdef AFS_AIX41_ENV offset_t off = (offset_t) blk << FSBSHIFT; - if (llseek(fd, off, 0) < 0) { + if (OS_SEEK(fd, off, 0) < 0) { Log("Unable to seek to offset %llu for block %u\n", off, blk); return -1; } #else /* AFS_AIX41_ENV */ - if (afs_lseek(fd, blk * Bsize, 0) < 0) { + if (OS_SEEK(fd, blk * Bsize, 0) < 0) { Log("Unable to seek to offset %u for block %u\n", blk * Bsize, blk); } #endif /* AFS_AIX41_ENV */ #else - if (afs_lseek(fd, (off_t) dbtob(blk), L_SET) < 0) { + if (OS_SEEK(fd, (off_t) dbtob(blk), L_SET) < 0) { Log("Unable to seek to offset %u for block %u\n", dbtob(blk), blk); } #endif - if (read(fd, buf, size) != size) { + if (OS_READ(fd, buf, size) != size) { Log("Unable to read block %d, partition %s\n", blk, partition); return -1; } diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 8d7585ab76..cb69e91e8b 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #endif #include #include @@ -691,7 +693,7 @@ SetOGM(FD_t fd, int parm, int tag) /* GetOGM - get parm and tag from owner, group and mode bits. */ static void -GetOGMFromStat(struct afs_stat *status, int *parm, int *tag) +GetOGMFromStat(struct afs_stat_st *status, int *parm, int *tag) { *parm = status->st_uid | (status->st_gid << 15); *parm |= (status->st_mode & 0x18) << 27; @@ -701,7 +703,7 @@ GetOGMFromStat(struct afs_stat *status, int *parm, int *tag) static int CheckOGM(namei_t *name, FdHandle_t *fdP, int p1) { - struct afs_stat status; + struct afs_stat_st status; int parm, tag; if (afs_fstat(fdP->fd_fd, &status) < 0) return -1; @@ -1154,7 +1156,7 @@ namei_copy_on_write(IHandle_t *h) FD_t fd; namei_t name; FdHandle_t *fdP; - struct afs_stat tstat; + struct afs_stat_st tstat; afs_foff_t offset; namei_HandleToName(&name, h); @@ -1572,9 +1574,9 @@ static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, unsigned int volid); static int DecodeVolumeName(char *name, unsigned int *vid); static int namei_ListAFSSubDirs(IHandle_t * dirIH, - int (*write_fun) (FILE *, + int (*write_fun) (FD_t, struct ViceInodeInfo *, - char *, char *), FILE * fp, + char *, char *), FD_t fp, int (*judgeFun) (struct ViceInodeInfo *, afs_uint32 vid, void *), afs_uint32 singleVolumeNumber, void *rock); @@ -1590,10 +1592,10 @@ static int namei_ListAFSSubDirs(IHandle_t * dirIH, * can use the same inode reading code. */ static int -WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name) +WriteInodeInfo(FD_t fp, struct ViceInodeInfo *info, char *dir, char *name) { size_t n; - n = fwrite(info, sizeof(*info), 1, fp); + n = OS_WRITE(fp, info, sizeof(*info)); return (n == 1) ? 0 : -2; } @@ -1602,7 +1604,7 @@ int mode_errors; /* Number of errors found in mode bits on directories. */ void VerifyDirPerms(char *path) { - struct afs_stat status; + struct afs_stat_st status; if (afs_stat(path, &status) < 0) { Log("Unable to stat %s. Please manually verify mode bits for this" @@ -1640,13 +1642,12 @@ VerifyDirPerms(char *path) * for this. */ int -ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock), afs_uint32 singleVolumeNumber, int *forcep, int forceR, char *wpath, void *rock) { int ninodes; - struct afs_stat status; *forcep = 0; /* no need to salvage until further notice */ @@ -1658,18 +1659,14 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, namei_ListAFSFiles(mountedOn, WriteInodeInfo, inodeFile, judgeInode, singleVolumeNumber, rock); - if (!inodeFile) + if (inodeFile == INVALID_FD) return ninodes; if (ninodes < 0) { return ninodes; } - if (fflush(inodeFile) == EOF) { - Log("Unable to successfully flush inode file for %s\n", mountedOn); - return -2; - } - if (fsync(fileno(inodeFile)) == -1) { + if (OS_SYNC(inodeFile) == -1) { Log("Unable to successfully fsync inode file for %s\n", mountedOn); return -2; } @@ -1677,13 +1674,9 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, /* * Paranoia: check that the file is really the right size */ - if (afs_fstat(fileno(inodeFile), &status) == -1) { - Log("Unable to successfully stat inode file for %s\n", mountedOn); - return -2; - } - if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { + if (OS_SIZE(inodeFile) * sizeof(struct ViceInodeInfo)) { Log("Wrong size (%d instead of %lu) in inode file for %s\n", - (int) status.st_size, + (int) OS_SIZE(inodeFile), (long unsigned int) ninodes * sizeof(struct ViceInodeInfo), mountedOn); return -2; @@ -1714,9 +1707,9 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, */ int namei_ListAFSFiles(char *dev, - int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *), - FILE * fp, + FD_t fp, int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *), afs_uint32 singleVolumeNumber, void *rock) { @@ -1831,9 +1824,9 @@ _namei_examine_special(char * path1, char * dname, IHandle_t * myIH, FdHandle_t * linkHandle, - int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *), - FILE * fp, + FD_t fp, int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *), int singleVolumeNumber, void *rock) @@ -1920,9 +1913,9 @@ _namei_examine_reg(char * path3, char * dname, IHandle_t * myIH, FdHandle_t * linkHandle, - int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *), - FILE * fp, + FD_t fp, int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *), int singleVolumeNumber, void *rock) @@ -1985,10 +1978,10 @@ struct listsubdirs_work_node { * inode, this will be pointed at the * link table */ - FILE * fp; /**< file pointer for writeFun */ + FD_t fp; /**< file pointer for writeFun */ /** function which will write inode metadata to fp */ - int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, char *); + int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *); /** inode filter function */ int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *); @@ -2315,9 +2308,9 @@ _namei_examine_file_spawn(const struct listsubdirs_work_node *work, */ static int namei_ListAFSSubDirs(IHandle_t * dirIH, - int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, + int (*writeFun) (FD_t, struct ViceInodeInfo *, char *, char *), - FILE * fp, + FD_t fp, int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *), afs_uint32 singleVolumeNumber, void *rock) { @@ -2667,7 +2660,7 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, unsigned int volid) { char fpath[512]; - struct afs_stat status; + struct afs_stat_st status; int parm, tag; lb64_string_t check; diff --git a/src/vol/namei_ops.h b/src/vol/namei_ops.h index 1d5d56077a..a950e78093 100644 --- a/src/vol/namei_ops.h +++ b/src/vol/namei_ops.h @@ -15,7 +15,7 @@ #ifdef AFS_NAMEI_ENV /* Basic file operations */ -extern FILE *namei_fdopen(IHandle_t * h, char *fdperms); +extern FD_t namei_fdopen(IHandle_t * h, char *fdperms); extern int namei_unlink(char *name); /* Inode operations */ @@ -36,13 +36,13 @@ extern int namei_ViceREADME(char *partition); #include "nfs.h" #include "viceinode.h" int namei_ListAFSFiles(char *dev, - int (*write_fun) (FILE * fp, + int (*write_fun) (FD_t fp, struct ViceInodeInfo * info, - char *dir, char *file), FILE * fp, + char *dir, char *file), FD_t fp, int (*judge_fun) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock), afs_uint32 singleVolumeNumber, void *rock); -int ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, +int ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, int (*judgeInode) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock), afs_uint32 singleVolumeNumber, int *forcep, int forceR, diff --git a/src/vol/ntops.h b/src/vol/ntops.h index e50b2e0fdc..bf1e04fbbc 100644 --- a/src/vol/ntops.h +++ b/src/vol/ntops.h @@ -35,7 +35,7 @@ extern int nt_sync(int cdrive); extern int nt_ftruncate(FD_t fd, afs_foff_t len); extern int nt_fsync(FD_t fd); extern int nt_seek(FD_t fd, afs_foff_t off, int whence); -extern FILE *nt_fdopen(IHandle_t * h, char *fdperms); +extern FD_t nt_fdopen(IHandle_t * h, char *fdperms); extern int nt_unlink(char *name); extern void nt_DevToDrive(char *drive, int dev); diff --git a/src/vol/nuke.c b/src/vol/nuke.c index c430803d22..b684811eac 100644 --- a/src/vol/nuke.c +++ b/src/vol/nuke.c @@ -104,7 +104,7 @@ int nuke(char *aname, afs_int32 avolid) { /* first process the partition containing this junk */ - struct afs_stat tstat; + struct afs_stat_st tstat; struct ilist *ti, *ni, *li=NULL; afs_int32 code; int i, forceSal; @@ -164,7 +164,7 @@ nuke(char *aname, afs_int32 avolid) * volume we're nuking. */ code = - ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal, + ListViceInodes(lastDevComp, aname, INVALID_FD, NukeProc, avolid, &forceSal, 0, wpath, &allInodes); if (code == 0) { /* actually do the idecs now */ diff --git a/src/vol/partition.c b/src/vol/partition.c index f2ca2c5a6d..48e18c2fcb 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -288,7 +288,7 @@ VInitPartition(char *path, char *devname, Device dev) int VCheckPartition(char *part, char *devname) { - struct afs_stat status; + struct afs_stat_st status; #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV) char AFSIDatPath[MAXPATHLEN]; #endif @@ -373,7 +373,7 @@ static int VIsAlwaysAttach(char *part, int *awouldattach) { #ifdef AFS_NAMEI_ENV - struct afs_stat st; + struct afs_stat_st st; char checkfile[256]; int ret; #endif /* AFS_NAMEI_ENV */ @@ -426,7 +426,7 @@ VAttachPartitions2(void) if (VIsAlwaysAttach(pname, &wouldattach)) { VCheckPartition(pname, ""); } else { - struct afs_stat st; + struct afs_stat_st st; if (wouldattach && VGetPartition(pname, 0) == NULL && afs_stat(pname, &st) == 0 && S_ISDIR(st.st_mode)) { @@ -796,7 +796,7 @@ VAttachPartitions(void) * doing this for us. */ if (programType == fileServer) { - struct afs_stat status; + struct afs_stat_st status; char salvpath[MAXPATHLEN]; strcpy(salvpath, entry.vp_dev); strcat(salvpath, "\\FORCESALVAGE"); diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 9a9f086287..7e4b3bae6a 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -435,8 +435,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name) { struct VolumeHeader header; struct VolumeDiskHeader diskHeader; - struct afs_stat status, stat; - int fd; + FD_t fd = INVALID_FD; Volume *vp; IHandle_t *ih; char headerName[1024]; @@ -445,17 +444,17 @@ HandleVolume(struct DiskPartition64 *dp, char *name) printf("volinfo: -online not supported\n"); exit(1); } else { - afs_int32 n; + afs_sfsize_t n; (void)afs_snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s", VPartitionPath(dp), name); - if ((fd = afs_open(headerName, O_RDONLY)) == -1 - || afs_fstat(fd, &status) == -1) { + if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD + || OS_SIZE(fd) < 0) { printf("Volinfo: Cannot read volume header %s\n", name); - close(fd); + OS_CLOSE(fd); exit(1); } - n = read(fd, &diskHeader, sizeof(diskHeader)); + n = OS_READ(fd, &diskHeader, sizeof(diskHeader)); if (n != sizeof(diskHeader) || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { @@ -475,12 +474,8 @@ HandleVolume(struct DiskPartition64 *dp, char *name) afs_sfsize_t size = 0; afs_sfsize_t code; - if (afs_fstat(fd, &stat) == -1) { - perror("stat"); - exit(1); - } if (!dsizeOnly && !saveinodes) { - size = stat.st_size; + size = OS_SIZE(fd); printf("Volume header (size = %d):\n", (int)size); printf("\tstamp\t= 0x%x\n", header.stamp.version); printf("\tVolId\t= %u\n", header.id); @@ -570,7 +565,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name) Vauxsize = size; Vauxsize_k = size / 1024; } - close(fd); + OS_CLOSE(fd); vp = AttachVolume(dp, name, &header); if (!vp) { printf("Volinfo: Error attaching volume header %s\n", name); @@ -719,7 +714,7 @@ GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime) *mtime = NT_date(&fi.ftLastWriteTime); *atime = NT_date(&fi.ftLastAccessTime); #else - struct afs_stat status; + struct afs_stat_st status; if (afs_fstat(fd, &status) == -1) { printf("fstat failed %d\n", errno); exit(1); diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 44a3778d04..0408d835a2 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -274,7 +274,7 @@ struct SalvInfo { * header dealt with */ int nVolumesInInodeFile; /**< Number of read-write volumes summarized */ - int inodeFd; /**< File descriptor for inode file */ + FD_t inodeFd; /**< File descriptor for inode file */ struct VolumeSummary *volumeSummaryp; /**< Holds all the volumes in a part */ int nVolumes; /**< Number of volumes (read-write and read-only) @@ -397,7 +397,7 @@ IsPartitionMounted(char *part) /* Check if the given inode is the root of the filesystem. */ #ifndef AFS_SGI_XFS_IOPS_ENV int -IsRootInode(struct afs_stat *status) +IsRootInode(struct afs_stat_st *status) { /* * The root inode is not a fixed value in XFS partitions. So we need to @@ -708,7 +708,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) { char *name, *tdir; char inodeListPath[256]; - FILE *inodeFile = NULL; + FD_t inodeFile = INVALID_FD; static char tmpDevName[100]; static char wpath[100]; struct VolumeSummary *vsp, *esp; @@ -722,9 +722,9 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) memset(salvinfo, 0, sizeof(*salvinfo)); tries++; - if (inodeFile) { - fclose(inodeFile); - inodeFile = NULL; + if (inodeFile != INVALID_FD) { + OS_CLOSE(inodeFile); + inodeFile = INVALID_FD; } if (tries > VOL_MAX_CHECKOUT_RETRIES) { Abort("Raced too many times with fileserver restarts while trying to " @@ -823,8 +823,8 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) getpid()); #endif - inodeFile = fopen(inodeListPath, "w+b"); - if (!inodeFile) { + inodeFile = OS_OPEN(inodeListPath, O_RDWR|O_TRUNC, 0666); + if (inodeFile == INVALID_FD) { Abort("Error %d when creating inode description file %s; not salvaged\n", errno, inodeListPath); } #ifdef AFS_NT40_ENV @@ -848,13 +848,13 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) } if (GetInodeSummary(salvinfo, inodeFile, singleVolumeNumber) < 0) { - fclose(inodeFile); + OS_CLOSE(inodeFile); return; } - salvinfo->inodeFd = fileno(inodeFile); - if (salvinfo->inodeFd == -1) + salvinfo->inodeFd = inodeFile; + if (salvinfo->inodeFd == INVALID_FD) Abort("Temporary file %s is missing...\n", inodeListPath); - afs_lseek(salvinfo->inodeFd, 0L, SEEK_SET); + OS_SEEK(salvinfo->inodeFd, 0L, SEEK_SET); if (ListInodeOption) { PrintInodeList(salvinfo); return; @@ -954,7 +954,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) salvinfo->fileSysPartition->name, (Testing ? " (READONLY mode)" : "")); } - fclose(inodeFile); /* SalvageVolumeGroup was the last which needed it. */ + OS_CLOSE(inodeFile); /* SalvageVolumeGroup was the last which needed it. */ } void @@ -1130,15 +1130,14 @@ OnlyOneVolume(struct ViceInodeInfo *inodeinfo, afs_uint32 singleVolumeNumber, vo * be unlinked by the caller. */ int -GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolumeNumber) +GetInodeSummary(struct SalvInfo *salvinfo, FD_t inodeFile, VolumeId singleVolumeNumber) { - struct afs_stat status; int forceSal, err; int code; struct ViceInodeInfo *ip, *ip_save; struct InodeSummary summary; char summaryFileName[50]; - FILE *summaryFile; + FD_t summaryFile = INVALID_FD; #ifdef AFS_NT40_ENV char *dev = salvinfo->fileSysPath; char *wpath = salvinfo->fileSysPath; @@ -1149,6 +1148,7 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum char *part = salvinfo->fileSysPath; char *tdir; int i; + afs_sfsize_t st_size; /* This file used to come from vfsck; cobble it up ourselves now... */ if ((err = @@ -1165,9 +1165,10 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum Log("***Forced salvage of all volumes on this partition***\n"); ForceSalvage = 1; } - fseek(inodeFile, 0L, SEEK_SET); - salvinfo->inodeFd = fileno(inodeFile); - if (salvinfo->inodeFd == -1 || afs_fstat(salvinfo->inodeFd, &status) == -1) { + OS_SEEK(inodeFile, 0L, SEEK_SET); + salvinfo->inodeFd = inodeFile; + if (salvinfo->inodeFd == INVALID_FD || + (st_size = OS_SIZE(salvinfo->inodeFd)) == -1) { Abort("No inode description file for \"%s\"; not salvaged\n", dev); } tdir = (tmpdir ? tmpdir : part); @@ -1178,8 +1179,8 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum (void)afs_snprintf(summaryFileName, sizeof summaryFileName, "%s" OS_DIRSEP "salvage.temp.%d", tdir, getpid()); #endif - summaryFile = afs_fopen(summaryFileName, "a+"); - if (summaryFile == NULL) { + summaryFile = OS_OPEN(summaryFileName, O_RDWR|O_APPEND, 0666); + if (summaryFile == INVALID_FD) { Abort("Unable to create inode summary file\n"); } @@ -1201,11 +1202,9 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum } if (!canfork || debug || Fork() == 0) { - int nInodes; - unsigned long st_size=(unsigned long) status.st_size; - nInodes = st_size / sizeof(struct ViceInodeInfo); + int nInodes = st_size / sizeof(struct ViceInodeInfo); if (nInodes == 0) { - fclose(summaryFile); + OS_CLOSE(summaryFile); if (!singleVolumeNumber) /* Remove the FORCESALVAGE file */ RemoveTheForce(salvinfo->fileSysPath); else { @@ -1225,28 +1224,28 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum } ip = (struct ViceInodeInfo *)malloc(nInodes*sizeof(struct ViceInodeInfo)); if (ip == NULL) { - fclose(summaryFile); + OS_CLOSE(summaryFile); Abort ("Unable to allocate enough space to read inode table; %s not salvaged\n", dev); } - if (read(salvinfo->inodeFd, ip, st_size) != st_size) { - fclose(summaryFile); + if (OS_READ(salvinfo->inodeFd, ip, st_size) != st_size) { + OS_CLOSE(summaryFile); Abort("Unable to read inode table; %s not salvaged\n", dev); } qsort(ip, nInodes, sizeof(struct ViceInodeInfo), CompareInodes); - if (afs_lseek(salvinfo->inodeFd, 0, SEEK_SET) == -1 - || write(salvinfo->inodeFd, ip, st_size) != st_size) { - fclose(summaryFile); + if (OS_SEEK(salvinfo->inodeFd, 0, SEEK_SET) == -1 + || OS_WRITE(salvinfo->inodeFd, ip, st_size) != st_size) { + OS_CLOSE(summaryFile); Abort("Unable to rewrite inode table; %s not salvaged\n", dev); } summary.index = 0; ip_save = ip; while (nInodes) { CountVolumeInodes(ip, nInodes, &summary); - if (fwrite(&summary, sizeof(summary), 1, summaryFile) != 1) { + if (OS_WRITE(summaryFile, &summary, sizeof(summary)) != sizeof(summary)) { Log("Difficulty writing summary file (errno = %d); %s not salvaged\n", errno, dev); - fclose(summaryFile); + OS_CLOSE(summaryFile); return -1; } summary.index += (summary.nInodes); @@ -1256,9 +1255,9 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum free(ip_save); ip = ip_save = NULL; /* Following fflush is not fclose, because if it was debug mode would not work */ - if (fflush(summaryFile) == EOF || fsync(fileno(summaryFile)) == -1) { + if (OS_SYNC(summaryFile) == -1) { Log("Unable to write summary file (errno = %d); %s not salvaged\n", errno, dev); - fclose(summaryFile); + OS_CLOSE(summaryFile); return -1; } if (canfork && !debug) { @@ -1267,27 +1266,28 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum } } else { if (Wait("Inode summary") == -1) { - fclose(summaryFile); + OS_CLOSE(summaryFile); Exit(1); /* salvage of this partition aborted */ } } - osi_Assert(afs_fstat(fileno(summaryFile), &status) != -1); - if (status.st_size != 0) { + + st_size = OS_SIZE(summaryFile); + osi_Assert(st_size >= 0); + if (st_size != 0) { int ret; - unsigned long st_status=(unsigned long)status.st_size; - salvinfo->inodeSummary = (struct InodeSummary *)malloc(st_status); + salvinfo->inodeSummary = (struct InodeSummary *)malloc(st_size); osi_Assert(salvinfo->inodeSummary != NULL); /* For GNU we need to do lseek to get the file pointer moved. */ - osi_Assert(afs_lseek(fileno(summaryFile), 0, SEEK_SET) == 0); - ret = read(fileno(summaryFile), salvinfo->inodeSummary, st_status); - osi_Assert(ret == st_status); + osi_Assert(OS_SEEK(summaryFile, 0, SEEK_SET) == 0); + ret = OS_READ(summaryFile, salvinfo->inodeSummary, st_size); + osi_Assert(ret == st_size); } - salvinfo->nVolumesInInodeFile =(unsigned long)(status.st_size) / sizeof(struct InodeSummary); + salvinfo->nVolumesInInodeFile = st_size / sizeof(struct InodeSummary); for (i = 0; i < salvinfo->nVolumesInInodeFile; i++) { salvinfo->inodeSummary[i].volSummary = NULL; } - Log("%d nVolumesInInodeFile %lu \n",salvinfo->nVolumesInInodeFile,(unsigned long)(status.st_size)); - fclose(summaryFile); + Log("%d nVolumesInInodeFile %lu \n",salvinfo->nVolumesInInodeFile,(unsigned long)st_size); + OS_CLOSE(summaryFile); return 0; } @@ -1891,10 +1891,10 @@ DoSalvageVolumeGroup(struct SalvInfo *salvinfo, struct InodeSummary *isp, int nV allInodes = inodes - isp->index; /* this would the base of all the inodes * for the partition, if all the inodes * had been read into memory */ - osi_Assert(afs_lseek + osi_Assert(OS_SEEK (salvinfo->inodeFd, isp->index * sizeof(struct ViceInodeInfo), SEEK_SET) != -1); - osi_Assert(read(salvinfo->inodeFd, inodes, size) == size); + osi_Assert(OS_READ(salvinfo->inodeFd, inodes, size) == size); /* Don't try to salvage a read write volume if there isn't one on this * partition */ @@ -4446,15 +4446,16 @@ PrintInodeList(struct SalvInfo *salvinfo) { struct ViceInodeInfo *ip; struct ViceInodeInfo *buf; - struct afs_stat status; int nInodes; afs_ino_str_t stmp; + afs_sfsize_t st_size; - osi_Assert(afs_fstat(salvinfo->inodeFd, &status) == 0); - buf = (struct ViceInodeInfo *)malloc(status.st_size); + st_size = OS_SIZE(salvinfo->inodeFd); + osi_Assert(st_size >= 0); + buf = (struct ViceInodeInfo *)malloc(st_size); osi_Assert(buf != NULL); - nInodes = status.st_size / sizeof(struct ViceInodeInfo); - osi_Assert(read(salvinfo->inodeFd, buf, status.st_size) == status.st_size); + nInodes = st_size / sizeof(struct ViceInodeInfo); + osi_Assert(OS_READ(salvinfo->inodeFd, buf, st_size) == st_size); for (ip = buf; nInodes--; ip++) { Log("Inode:%s, linkCount=%d, size=%#llx, p=(%u,%u,%u,%u)\n", PrintInode(stmp, ip->inodeNumber), ip->linkCount, @@ -4709,7 +4710,7 @@ void RemoveTheForce(char *path) { char target[1024]; - struct afs_stat force; /* so we can use afs_stat to find it */ + struct afs_stat_st force; /* so we can use afs_stat to find it */ strcpy(target,path); strcat(target,"/FORCESALVAGE"); if (!Testing && ForceSalvage) { @@ -4724,7 +4725,7 @@ RemoveTheForce(char *path) int UseTheForceLuke(char *path) { - struct afs_stat force; + struct afs_stat_st force; char target[1024]; strcpy(target,path); strcat(target,"/FORCESALVAGE"); diff --git a/src/vol/vol-salvage.h b/src/vol/vol-salvage.h index da86c6c2db..b6babab23c 100644 --- a/src/vol/vol-salvage.h +++ b/src/vol/vol-salvage.h @@ -210,7 +210,7 @@ extern void DeleteExtraVolumeHeaderFile(struct SalvInfo *salvinfo, struct VolumeSummary *vsp); extern void DistilVnodeEssence(struct SalvInfo *salvinfo, VolumeId vid, VnodeClass class, Inode ino, Unique * maxu); -extern int GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, +extern int GetInodeSummary(struct SalvInfo *salvinfo, FD_t inodeFile, VolumeId singleVolumeNumber); extern int GetVolumeSummary(struct SalvInfo *salvinfo, VolumeId singleVolumeNumber); diff --git a/src/vol/volume.c b/src/vol/volume.c index 5fc4787591..0c4f359b9d 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -6491,7 +6491,7 @@ VGetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep) name[0] = OS_DIRSEPC; (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, afs_printable_uint32_lu(volumeId)); for (dp = DiskPartitionList; dp; dp = dp->next) { - struct afs_stat status; + struct afs_stat_st status; strcpy(path, VPartitionPath(dp)); strcat(path, name); if (afs_stat(path, &status) == 0) {