merge ntops and namei

instead of having 2 implementations of nearly the same thing,
merge what we can. this can get closer, probably, but this is
a start.

Change-Id: I8446649e37ab0856e6e40933a44a35edbc708638
Reviewed-on: http://gerrit.openafs.org/3180
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
Derrick Brashear 2010-10-28 01:03:49 -04:00
parent bb1dd6c950
commit a8d1fe61f4
12 changed files with 740 additions and 1282 deletions

View File

@ -7184,11 +7184,7 @@ GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
lhp = IH_OPEN(V_linkHandle(vp));
if (!lhp)
return EIO;
#ifdef AFS_NT40_ENV
*lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
#else
*lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
#endif
*lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
FDH_CLOSE(lhp);
if (*lc < 0)
return -1;

View File

@ -20,6 +20,7 @@ INCFILES =\
$(INCFILEDIR)\afs\fssync.h \
$(INCFILEDIR)\afs\ihandle.h \
$(INCFILEDIR)\afs\nfs.h \
$(INCFILEDIR)\afs\namei_ops.h \
$(INCFILEDIR)\afs\ntops.h \
$(INCFILEDIR)\afs\partition.h \
$(INCFILEDIR)\afs\viceinode.h \
@ -46,6 +47,7 @@ LIBOBJS =\
$(OUT)\fssync-client.obj \
$(OUT)\fssync-server.obj \
$(OUT)\daemon_com.obj \
$(OUT)\namei_ops.obj \
$(OUT)\ntops.obj \
$(OUT)\nuke.obj \
$(OUT)\partition.obj \
@ -62,6 +64,7 @@ MT_LIBOBJS =\
$(OUT)\fssync-client_mt.obj \
$(OUT)\fssync-server_mt.obj \
$(OUT)\daemon_com_mt.obj \
$(OUT)\namei_ops.obj \
$(OUT)\ntops.obj \
$(OUT)\nuke_mt.obj \
$(OUT)\partition_mt.obj \
@ -114,6 +117,7 @@ DAFS_LIBOBJS =\
$(OUT)\fssync-client_dafs.obj \
$(OUT)\fssync-server_dafs.obj \
$(OUT)\daemon_com_dafs.obj \
$(OUT)\namei_ops.obj \
$(OUT)\ntops.obj \
$(OUT)\nuke_dafs.obj \
$(OUT)\partition_dafs.obj \

View File

@ -1034,17 +1034,21 @@ ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
}
#endif /* AFS_NAMEI_ENV */
#ifndef AFS_NT40_ENV
afs_sfsize_t
ih_size(int fd)
ih_size(FD_t fd)
{
#ifdef AFS_NT40_ENV
LARGE_INTEGER size;
if (!GetFileSizeEx(fd, &size))
return -1;
return size.QuadPart;
#else
struct afs_stat status;
if (afs_fstat(fd, &status) < 0)
return -1;
return status.st_size;
}
#endif
}
#ifndef HAVE_PIO
ssize_t

View File

@ -55,6 +55,8 @@
* FDH_REALLYCLOSE - Close a file descriptor, do not return to the cache
* FDH_SYNC - Unconditionally sync an open file.
* FDH_TRUNC - Truncate a file
* FDH_LOCKFILE - Lock a whole file
* FDH_UNLOCKFILE - Unlock a whole file
*
* status information:
* FDH_SIZE - returns the size of the file.
@ -147,10 +149,11 @@ struct IHandle_s;
*/
#ifdef AFS_NT40_ENV
typedef HANDLE FD_t;
#define INVALID_FD INVALID_HANDLE_VALUE
#else
typedef int FD_t;
#endif
#define INVALID_FD ((FD_t)-1)
#endif
/* file descriptor handle */
typedef struct FdHandle_s {
@ -279,9 +282,9 @@ typedef struct IHashBucket_s {
#ifdef AFS_NAMEI_ENV
#ifdef AFS_NT40_ENV
#include "ntops.h"
#else
#include "namei_ops.h"
#endif
#include "namei_ops.h"
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);
@ -374,14 +377,27 @@ extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offs
#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 */
#ifdef AFS_NT40_ENV
#define OS_LOCKFILE(FD, O) LockFile(FD, (O & 0xFFFFFFFF), (O >> 32), 2, 0)
#define OS_UNLOCKFILE(FD, O) UnlockFile(FD, (O & 0xFFFFFFFF), (O >> 32), 2, 0)
#define OS_ERROR(X) nterr_nt2unix(GetLastError(), X)
#define OS_UNLINK(X) nt_unlink(X)
#define OS_DIRSEP "\\"
#define OS_DIRSEPC '\\'
#else
#define OS_LOCKFILE(FD, O) flock(FD, LOCK_EX)
#define OS_UNLOCKFILE(FD, O) flock(FD, LOCK_UN)
#define OS_ERROR(X) X
#define OS_UNLINK(X) unlink(X)
#define OS_DIRSEP "/"
#define OS_DIRSEPC '/'
#endif
#ifdef AFS_NAMEI_ENV
#ifdef AFS_NT40_ENV
#define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \
nt_icreate(H, P, P1, P2, P3, P4)
#define OS_IOPEN(H) nt_iopen(H)
#define OS_OPEN(F, M, P) nt_open(F, M, P)
#define OS_CLOSE(FD) nt_close(FD)
@ -391,12 +407,6 @@ extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offs
#define OS_SYNC(FD) nt_fsync(FD)
#define OS_TRUNC(FD, L) nt_ftruncate(FD, L)
#define OS_SIZE(FD) nt_size(FD)
#define IH_INC(H, I, P) nt_inc(H, I, P)
#define IH_DEC(H, I, P) nt_dec(H, I, P)
#define IH_IREAD(H, O, B, S) nt_iread(H, O, B, S)
#define IH_IWRITE(H, O, B, S) nt_iwrite(H, O, B, S)
#else /* AFS_NT40_ENV */
@ -423,18 +433,15 @@ extern afs_sfsize_t IH_IREAD(IHandle_t * H, afs_foff_t O, void *B,
extern afs_sfsize_t IH_IWRITE(IHandle_t * H, afs_foff_t O, void *B,
afs_fsize_t S);
#ifdef O_LARGEFILE
extern off64_t OS_SEEK(int FD, off64_t O, int F);
extern int OS_TRUNC(int FD, off64_t L);
#else /* !O_LARGEFILE */
extern off_t OS_SEEK(int FD, off_t O, int F);
extern int OS_TRUNC(int FD, off_t L);
#endif /* !O_LARGEFILE */
#define OFFT off64_t
#else
#define OFFT off_t
#endif
extern OFFT OS_SEEK(int FD, OFFT O, int F);
extern int OS_TRUNC(int FD, OFFT L);
#endif /*S_SPLINT_S */
#define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \
namei_icreate(H, P, P1, P2, P3, P4)
#define OS_IOPEN(H) namei_iopen(H)
#ifdef O_LARGEFILE
#define OS_OPEN(F, M, P) open64(F, M, P)
#else /* !O_LARGEFILE */
@ -446,25 +453,24 @@ extern int OS_TRUNC(int FD, off_t L);
#define OS_WRITE(FD, B, S) write(FD, B, S)
#ifdef O_LARGEFILE
#define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F)
#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
#else /* !O_LARGEFILE */
#define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F)
#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
#endif /* !O_LARGEFILE */
#define OS_SYNC(FD) fsync(FD)
#ifdef O_LARGEFILE
#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
#else /* !O_LARGEFILE */
#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
#endif /* !O_LARGEFILE */
#define OS_SIZE(FD) ih_size(FD)
extern afs_sfsize_t ih_size(int fd);
/*@=fcnmacros =macrofcndecl@*/
#endif /* AFS_NT40_ENV */
#define IH_INC(H, I, P) namei_inc(H, I, P)
#define IH_DEC(H, I, P) namei_dec(H, I, P)
#define IH_IREAD(H, O, B, S) namei_iread(H, O, B, S)
#define IH_IWRITE(H, O, B, S) namei_iwrite(H, O, B, S)
/*@=fcnmacros =macrofcndecl@*/
#endif /* AFS_NT40_ENV */
#define IH_CREATE(H, D, P, N, P1, P2, P3, P4) \
namei_icreate(H, P, P1, P2, P3, P4)
#define OS_IOPEN(H) namei_iopen(H)
#else /* AFS_NAMEI_ENV */
extern Inode ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1,
@ -487,18 +493,13 @@ extern Inode ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1,
#ifdef O_LARGEFILE
#define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F)
#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
#else /* !O_LARGEFILE */
#define OS_SEEK(FD, O, F) lseek(FD, (off_t) (O), F)
#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
#endif /* !O_LARGEFILE */
#define OS_SYNC(FD) fsync(FD)
#ifdef O_LARGEFILE
#define OS_TRUNC(FD, L) ftruncate64(FD, (off64_t) (L))
#else /* !O_LARGEFILE */
#define OS_TRUNC(FD, L) ftruncate(FD, (off_t) (L))
#endif /* !O_LARGEFILE */
#define OS_SIZE(FD) ih_size(FD)
extern afs_sfsize_t ih_size(int fd);
#ifdef AFS_LINUX22_ENV
#define IH_INC(H, I, P) -1
@ -516,6 +517,8 @@ extern afs_sfsize_t ih_size(int fd);
#endif /* AFS_NAMEI_ENV */
#define OS_SIZE(FD) ih_size(FD)
extern afs_sfsize_t ih_size(FD_t);
#ifndef AFS_NT40_ENV
#define FDH_READV(H, I, N) readv((H)->fd_fd, I, N)
@ -536,5 +539,7 @@ extern afs_sfsize_t ih_size(int fd);
#define FDH_SYNC(H) ((H->fd_ih!=NULL) ? ( H->fd_ih->ih_synced = 1) - 1 : 1)
#define FDH_TRUNC(H, L) OS_TRUNC((H)->fd_fd, L)
#define FDH_SIZE(H) OS_SIZE((H)->fd_fd)
#define FDH_LOCKFILE(H, O) OS_LOCKFILE((H)->fd_fd, O)
#define FDH_UNLOCKFILE(H, O) OS_UNLOCKFILE((H)->fd_fd, O)
#endif /* _IHANDLE_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -14,25 +14,14 @@
#ifdef AFS_NAMEI_ENV
#ifdef notdef
/* We don't include Unix afssyscalls.h, so: */
#define VALID_INO(I) ((I != (__int64)-1) && (I != (__int64)0))
/* minimum size of string to hand to PrintInode */
#define AFS_INO_STR_LENGTH 32
typedef char afs_ino_str_t[AFS_INO_STR_LENGTH];
char *PrintInode(char *s, Inode ino);
#endif
/* Basic file operations */
extern FILE *namei_fdopen(IHandle_t * h, char *fdperms);
extern int namei_unlink(char *name);
/* Inode operations */
extern Inode namei_MakeSpecIno(int volid, int type);
extern Inode namei_icreate(IHandle_t * h, char *p, int p1, int p2, int p3,
int p4);
extern Inode namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1,
afs_uint32 p2, afs_uint32 p3, afs_uint32 p4);
extern FD_t namei_iopen(IHandle_t * h);
extern int namei_irelease(IHandle_t * h);
afs_sfsize_t namei_iread(IHandle_t * h, afs_foff_t offset, char *buf,
@ -41,7 +30,7 @@ afs_sfsize_t namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf,
afs_fsize_t size);
extern int namei_dec(IHandle_t * h, Inode ino, int p1);
extern int namei_inc(IHandle_t * h, Inode ino, int p1);
extern int namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit);
extern int namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrite);
extern int namei_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked);
extern int namei_ViceREADME(char *partition);
#include "nfs.h"
@ -59,10 +48,22 @@ int ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
afs_uint32 singleVolumeNumber, int *forcep, int forceR,
char *wpath, void *rock);
#define NAMEI_LCOMP_LEN 32
#define NAMEI_SCOMP_LEN 12
#define NAMEI_PATH_LEN 256
#ifdef AFS_NT40_ENV
#define NAMEI_DRIVE_LEN 3
#define NAMEI_HASH_LEN 2
#define NAMEI_COMP_LEN 18
typedef struct {
char n_drive[NAMEI_DRIVE_LEN];
char n_voldir[NAMEI_COMP_LEN];
char n_dir[NAMEI_HASH_LEN];
char n_inode[NAMEI_COMP_LEN];
char n_path[NAMEI_PATH_LEN];
} namei_t;
#else
#define NAMEI_SCOMP_LEN 12
typedef struct {
char n_base[NAMEI_LCOMP_LEN];
char n_voldir1[NAMEI_SCOMP_LEN];
@ -72,6 +73,7 @@ typedef struct {
char n_inode[NAMEI_LCOMP_LEN];
char n_path[NAMEI_PATH_LEN];
} namei_t;
#endif
void namei_HandleToName(namei_t * name, IHandle_t * h);
int namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId);

File diff suppressed because it is too large Load Diff

View File

@ -10,15 +10,16 @@
#ifndef _NTOPS_H_
#define _NTOPS_H_
/* We don't include Unix afssyscalls.h, so: */
#ifdef AFS_NT40_ENV
/* We don't include Unix afssyscalls.h on Windows, so: */
#define VALID_INO(I) ((I != (__int64)-1) && (I != (__int64)0))
/* minimum size of string to hand to PrintInode */
#define AFS_INO_STR_LENGTH 32
typedef char afs_ino_str_t[AFS_INO_STR_LENGTH];
char *PrintInode(char *s, Inode ino);
extern char *PrintInode(char *, Inode);
#endif
/* Basic file operations */
extern FD_t nt_open(char *name, int flags, int mode);
@ -37,31 +38,6 @@ extern int nt_seek(FD_t fd, int off, int where);
extern FILE *nt_fdopen(IHandle_t * h, char *fdperms);
extern int nt_unlink(char *name);
/* Inode operations */
extern Inode nt_MakeSpecIno(int type);
extern Inode nt_icreate(IHandle_t * h, char *p, afs_uint32 p1, afs_uint32 p2,
afs_uint32 p3, afs_uint32 p4);
extern FD_t nt_iopen(IHandle_t * h);
extern int nt_irelease(IHandle_t * h);
int nt_iread(IHandle_t * h, int offset, char *buf, int size);
int nt_iwrite(IHandle_t * h, int offset, char *buf, int size);
extern int nt_dec(IHandle_t * h, Inode ino, int p1);
extern int nt_inc(IHandle_t * h, Inode ino, int p1);
extern int nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit);
int nt_ListAFSFiles(char *dev,
int (*write_fun) (FILE * fp, struct ViceInodeInfo *,
char *dir, char *file), FILE * fp,
int (*judge_fun) (struct ViceInodeInfo *, afs_uint32 vid, void *rock),
afs_uint32 singleVolumeNumber, void *rock);
int ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
int (*judgeInode) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock),
afs_uint32 singleVolumeNumber, int *forcep, int forceR,
char *wpath, void *rock);
int nt_HandleToName(char *name, IHandle_t * h);
char *nt_HandleToVolDir(char *name, IHandle_t * h);
extern int Testing;
extern void nt_DevToDrive(char *drive, int dev);
extern int nt_DriveToDev(char *drive);
#endif /* _NTOPS_H_ */

View File

@ -117,12 +117,9 @@ nuke(char *aname, afs_int32 avolid)
char *lastDevComp;
struct DiskPartition64 *dp;
#ifdef AFS_NAMEI_ENV
#ifdef AFS_NT40_ENV
char path[MAX_PATH];
#else
char *path;
namei_t ufs_name;
#endif
#endif /* AFS_NAMEI_ENV */
#ifndef AFS_NAMEI_ENV
char devName[64];
@ -186,15 +183,14 @@ nuke(char *aname, afs_int32 avolid)
#ifdef AFS_NT40_ENV
IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid,
ti->inode[i]);
nt_HandleToName(path, fileH);
#else
IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid,
ti->inode[i]);
#endif /* AFS_NT40_ENV */
namei_HandleToName(&ufs_name, fileH);
path = ufs_name.n_path;
#endif /* AFS_NT40_ENV */
IH_RELEASE(fileH);
if (unlink(path) < 0) {
if (OS_UNLINK(path) < 0) {
Log("Nuke: Failed to remove %s\n", path);
}
#else /* AFS_NAMEI_ENV */

View File

@ -872,11 +872,7 @@ PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
{
#if defined(AFS_NAMEI_ENV)
IHandle_t *ihtmpp;
#if !defined(AFS_NT40_ENV)
namei_t filename;
#else
char filename[MAX_PATH];
#endif
#endif
afs_fsize_t fileLength;
@ -899,12 +895,11 @@ PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
#if defined(AFS_NAMEI_ENV)
if (PrintFileNames) {
IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino);
#if !defined(AFS_NT40_ENV)
namei_HandleToName(&filename, ihtmpp);
#if !defined(AFS_NT40_ENV)
printf(" UFS-Filename: %s", filename.n_path);
#else
nt_HandleToName(filename, ihtmpp);
printf(" NTFS-Filename: %s", filename);
printf(" NTFS-Filename: %s", filename.n_path);
#endif
}
#endif

View File

@ -1905,11 +1905,7 @@ DoSalvageVolumeGroup(struct SalvInfo *salvinfo, struct InodeSummary *isp, int nV
for (i = 0; i < nVols; i++) {
ip = allInodes + isp[i].index;
for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++) {
#ifdef AFS_NT40_ENV
nt_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
#else
namei_SetLinkCount(fdP, ip[j].inodeNumber, 1, 1);
#endif
}
}
}

View File

@ -221,11 +221,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
IHandle_t *lh;
int code;
#ifdef AFS_NT40_ENV
*(p->inode) = nt_MakeSpecIno(VI_LINKTABLE);
#else
*(p->inode) = namei_MakeSpecIno(vol.parentId, VI_LINKTABLE);
#endif
IH_INIT(lh, device, parentId, *(p->inode));
fdP = IH_OPEN(lh);
if (fdP == NULL) {