Replace all use of FILE* with FD_t. Switch from afs_open to OS_OPEN.
In the process:
afs_flush and afs_fsync -> OS_SYNC
afs_stat which is used to obtain the file size -> OS_SIZE
afs_close or close -> OS_CLOSE
Etc. While cleaning up, use afs_stat_st macro when declaring
a struct stat because the structure and function are not guaranteed
to be the same name on all platforms.
These changes permit Windows to build the vol package without
the use of the C runtime library.
Change-Id: I9e0a7fdbeffa76c3c87aefce87ca1af495657a2f
Reviewed-on: http://gerrit.openafs.org/4149
Reviewed-by: Rod Widdowson <rdw@steadingsoftware.com>
Tested-by: Derrick Brashear <shadow@dementia.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
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;
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 */
/*
#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 */
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,
#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
* -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)
{
#define ROOTINODE 2
static char *partition;
int Testing=0;
-int pfd;
+FD_t pfd;
#ifdef AFS_AIX32_ENV
#include <jfs/filsys.h>
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)
{
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 */
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;
}
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;
}
++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;
/*
* 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);
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;
}
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;
}
Log("Unable to read superblock on %s.\n", devName);
return -1;
}
- close(pfd);
+ OS_CLOSE(pfd);
return (0);
}
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)
{
int n_renames = 0;
int n_avail = 0;
uint64_t pino;
- struct stat status;
int errors = 0;
*forcep = 0;
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;
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;
}
#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)
{
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)
{
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;
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;
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;
}
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
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 */
}
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;
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;
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;
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;
/*
* 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;
#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;
}
#include <winnt.h>
#include <winbase.h>
#include <winsock2.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#endif
#include <errno.h>
#include <fcntl.h>
/* 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;
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;
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);
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);
* 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;
}
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"
* 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 */
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;
}
/*
* 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;
*/
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)
{
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)
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)
* 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 *);
*/
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)
{
unsigned int volid)
{
char fpath[512];
- struct afs_stat status;
+ struct afs_stat_st status;
int parm, tag;
lb64_string_t check;
#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 */
#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,
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);
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;
* 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 */
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
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 */
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)) {
* 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");
{
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];
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) {
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);
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);
*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);
* 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)
/* 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
{
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;
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 "
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
}
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;
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
* 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;
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 =
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);
(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");
}
}
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 {
}
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);
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) {
}
} 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;
}
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 */
{
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,
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) {
int
UseTheForceLuke(char *path)
{
- struct afs_stat force;
+ struct afs_stat_st force;
char target[1024];
strcpy(target,path);
strcat(target,"/FORCESALVAGE");
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);
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) {