2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* I/O operations for the Unix open by name (namei) interface. */
12 #include <afsconfig.h>
13 #include <afs/param.h>
35 #include <sys/param.h>
38 #include <afs/afs_assert.h>
41 #include <afs/afsutil.h>
44 #include <afs/afsint.h>
48 #include "viceinode.h"
50 #include "partition.h"
52 #include "volume_inline.h"
54 #include <afs/errors.h>
56 #include <afs/errmap_nt.h>
59 /*@+fcnmacros +macrofcndecl@*/
62 #endif /*S_SPLINT_S */
63 #define afs_stat stat64
64 #define afs_fstat fstat64
66 #define afs_open nt_open
68 #define afs_open open64
70 #define afs_fopen fopen64
71 #else /* !O_LARGEFILE */
73 #endif /*S_SPLINT_S */
75 #define afs_fstat fstat
77 #define afs_open nt_open
81 #define afs_fopen fopen
82 #endif /* !O_LARGEFILE */
83 /*@=fcnmacros =macrofcndecl@*/
86 #define LOCK_SH 1 /* shared lock */
87 #define LOCK_EX 2 /* exclusive lock */
88 #define LOCK_NB 4 /* don't block when locking */
89 #define LOCK_UN 8 /* unlock */
94 #include <afs/work_queue.h>
95 #include <afs/thread_pool.h>
96 #include <vol/vol-salvage.h>
99 #if !defined(HAVE_FLOCK) && !defined(AFS_NT40_ENV)
103 * This function emulates a subset of flock()
106 emul_flock(int fd, int cmd)
109 memset(&f, 0, sizeof (f));
118 return fcntl(fd, (cmd & LOCK_NB) ? F_SETLK : F_SETLKW, &f);
121 #define flock(f,c) emul_flock(f,c)
128 namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
137 nBytes = FDH_PREAD(fdP, buf, size, offset);
143 namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
152 nBytes = FDH_PWRITE(fdP, buf, size, offset);
160 /* Inode number format:
161 * low 32 bits - if a regular file or directory, the vnode. Else the type.
162 * 32-36 - unquifier tag and index into counts array for this vnode. Only
163 * two of the available bits are currently used. The rest are
164 * present in case we ever increase the number of types of volumes
165 * in the volume group.
166 * bit 37 : 1 == special, 0 == regular
168 #define NAMEI_VNODEMASK 0x00ffffffff
169 #define NAMEI_TAGSHIFT 32
170 #define NAMEI_INODESPECIAL 0x2000000000
171 #define NAMEI_SPECDIR "R"
173 /* Inode number format:
174 * low 26 bits - vnode number - all 1's if volume special file.
176 * next 3 bits spare (0's)
177 * high 32 bits - uniquifier (regular) or type if spare
179 #define NAMEI_VNODEMASK 0x003ffffff
180 #define NAMEI_TAGSHIFT 26
181 #define NAMEI_UNIQMASK 0xffffffff
182 #define NAMEI_UNIQSHIFT 32
183 #define NAMEI_INODESPECIAL ((Inode)NAMEI_VNODEMASK)
184 /* dir1 is the high 8 bits of the 26 bit vnode */
185 #define VNO_DIR1(vno) ((vno >> 14) & 0xff)
186 /* dir2 is the next 9 bits */
187 #define VNO_DIR2(vno) ((vno >> 9) & 0x1ff)
188 /* "name" is the low 9 bits of the vnode, the 3 bit tag and the uniq */
189 #define NAMEI_SPECDIR "special"
191 #define NAMEI_TAGMASK 0x7
192 #define NAMEI_VNODESPECIAL NAMEI_VNODEMASK
194 #define NAMEI_SPECDIRLEN (sizeof(NAMEI_SPECDIR)-1)
196 #define NAMEI_MAXVOLS 5 /* Maximum supported number of volumes per volume
197 * group, not counting temporary (move) volumes.
198 * This is the number of separate files, all having
199 * the same vnode number, which can occur in a volume
210 static int GetFreeTag(IHandle_t * ih, int vno);
212 /* namei_HandleToInodeDir
214 * Construct the path name of the directory holding the inode data.
215 * Format: /<vicepx>/INODEDIR
220 namei_HandleToInodeDir(namei_t * name, IHandle_t * ih)
222 memset(name, '\0', sizeof(*name));
223 nt_DevToDrive(name->n_drive, ih->ih_dev);
224 strlcpy(name->n_path, name->n_drive, sizeof(name->n_path));
228 /* Format: /<vicepx>/INODEDIR */
229 #define PNAME_BLEN 64
231 namei_HandleToInodeDir(namei_t * name, IHandle_t * ih)
235 memset(name, '\0', sizeof(*name));
238 * Add the /vicepXX string to the start of name->n_base and then calculate
239 * offset as the number of bytes we know we added.
241 * FIXME: This embeds knowledge of the vice partition naming scheme and
242 * mapping from device numbers. There needs to be an API that tells us
245 volutil_PartitionName_r(ih->ih_dev, name->n_base, sizeof(name->n_base));
246 offset = VICE_PREFIX_SIZE + (ih->ih_dev > 25 ? 2 : 1);
247 name->n_base[offset] = '/';
249 strlcpy(name->n_base + offset, INODEDIR, sizeof(name->n_base) - offset);
250 strlcpy(name->n_path, name->n_base, sizeof(name->n_path));
254 #define addtoname(N, C) \
256 strlcat((N)->n_path, OS_DIRSEP, sizeof((N)->n_path)); \
257 strlcat((N)->n_path, (C), sizeof((N)->n_path)); \
263 namei_HandleToVolDir(namei_t * name, IHandle_t * ih)
265 /* X:\Vol_XXXXXXX.data */
269 namei_HandleToInodeDir(name, ih);
270 addtoname(name, name->n_drive);
271 namep = name->n_voldir;
272 (void)memcpy(namep, "\\Vol_", 5);
274 (void)strcpy(namep, int_to_base32(str1, ih->ih_vid));
275 namep += strlen(namep);
276 memcpy(namep, ".data", 5);
279 addtoname(name, name->n_voldir);
283 namei_HandleToVolDir(namei_t * name, IHandle_t * ih)
287 namei_HandleToInodeDir(name, ih);
288 (void)int32_to_flipbase64(tmp, (int64_t) (ih->ih_vid & 0xff));
289 strlcpy(name->n_voldir1, tmp, sizeof(name->n_voldir1));
290 addtoname(name, name->n_voldir1);
291 (void)int32_to_flipbase64(tmp, (int64_t) ih->ih_vid);
292 strlcpy(name->n_voldir2, tmp, sizeof(name->n_voldir2));
293 addtoname(name, name->n_voldir2);
297 /* namei_HandleToName
299 * Constructs a file name for the fully qualified handle.
302 /* Note that special files end up in X:\Vol_XXXXXXX.data\R */
304 namei_HandleToName(namei_t * name, IHandle_t * ih)
306 int vno = (int)(ih->ih_ino & NAMEI_VNODEMASK);
307 int tag = (int)((ih->ih_ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK);
310 namei_HandleToVolDir(name, ih);
312 if (vno == NAMEI_VNODESPECIAL) {
313 name->n_dir[0] = 'R';
316 name->n_dir[0] = 'Q';
318 name->n_dir[0] = ((vno & 0x1f) >> 1) + 'A';
321 name->n_dir[1] = '\0';
322 addtoname(name, name->n_dir);
323 /* X:\Vol_XXXXXXX.data\X\V_XXXXXXX.XXX */
324 namep = name->n_inode;
325 (void)memcpy(namep, "\\V_", 3);
327 (void)strcpy(namep, int_to_base32(str1, vno));
328 namep += strlen(namep);
330 (void)strcpy(namep, int_to_base32(str1, tag));
331 namep += strlen(namep);
332 addtoname(name, name->n_inode);
335 /* Note that special files end up in /vicepX/InodeDir/Vxx/V*.data/special */
337 namei_HandleToName(namei_t * name, IHandle_t * ih)
339 int vno = (int)(ih->ih_ino & NAMEI_VNODEMASK);
342 namei_HandleToVolDir(name, ih);
344 if (vno == NAMEI_VNODESPECIAL) {
345 strlcpy(name->n_dir1, NAMEI_SPECDIR, sizeof(name->n_dir1));
346 addtoname(name, name->n_dir1);
347 name->n_dir2[0] = '\0';
349 (void)int32_to_flipbase64(str, VNO_DIR1(vno));
350 strlcpy(name->n_dir1, str, sizeof(name->n_dir1));
351 addtoname(name, name->n_dir1);
352 (void)int32_to_flipbase64(str, VNO_DIR2(vno));
353 strlcpy(name->n_dir2, str, sizeof(name->n_dir2));
354 addtoname(name, name->n_dir2);
356 (void)int64_to_flipbase64(str, (int64_t) ih->ih_ino);
357 strlcpy(name->n_inode, str, sizeof(name->n_inode));
358 addtoname(name, name->n_inode);
363 /* The following is a warning to tell sys-admins to not muck about in this
366 #define VICE_README "These files and directories are a part of the AFS \
367 namespace. Modifying them\nin any way will result in loss of AFS data,\n\
368 ownership and permissions included.\n"
370 namei_ViceREADME(char *partition)
375 /* Create the inode directory if we're starting for the first time */
376 (void)afs_snprintf(filename, sizeof filename, "%s/%s", partition,
378 mkdir(filename, 0700);
380 (void)afs_snprintf(filename, sizeof filename, "%s/%s/README", partition,
382 fd = afs_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444);
384 (void)write(fd, VICE_README, strlen(VICE_README));
391 /* namei_CreateDataDirectories
393 * If creating the file failed because of ENOENT or ENOTDIR, try
394 * creating all the directories first.
398 namei_CreateDataDirectories(namei_t * name, int *created)
405 afs_snprintf(tmp, 256, "%s\\%s", name->n_drive, name->n_voldir);
407 if (mkdir(tmp) < 0) {
418 for (i = 'A'; i <= 'R'; i++) {
420 if (mkdir(tmp) < 0 && errno != EEXIST)
426 #define create_dir() \
428 if (mkdir(tmp, 0700)<0) { \
429 if (errno != EEXIST) \
437 #define create_nextdir(A) \
439 strcat(tmp, "/"); strcat(tmp, A); create_dir(); \
443 namei_CreateDataDirectories(namei_t * name, int *created)
449 strlcpy(tmp, name->n_base, sizeof(tmp));
452 create_nextdir(name->n_voldir1);
453 create_nextdir(name->n_voldir2);
454 create_nextdir(name->n_dir1);
455 if (name->n_dir2[0]) {
456 create_nextdir(name->n_dir2);
463 /* delTree(): Deletes an entire tree of directories (no files)
465 * root : Full path to the subtree. Should be big enough for PATH_MAX
466 * tree : the subtree to be deleted is rooted here. Specifies only the
467 * subtree beginning at tree (not the entire path). It should be
468 * a pointer into the "root" buffer.
470 * errp : errno of the first error encountered during the directory cleanup.
471 * *errp should have been initialized to 0.
474 * -1 : If errors were encountered during cleanup and error is set to
478 * If there are errors, we try to work around them and delete as many
479 * directories as possible. We don't attempt to remove directories that still
480 * have non-dir entries in them.
483 delTree(char *root, char *tree, int *errp)
491 /* delete the children first */
492 cp = strchr(tree, '/');
494 delTree(root, cp + 1, errp);
497 cp = tree + strlen(tree); /* move cp to the end of string tree */
499 /* now delete all entries in this dir */
500 if ((ds = opendir(root)) != (DIR *) NULL) {
502 while ((dirp = readdir(ds))) {
503 /* ignore . and .. */
504 if (!strcmp(dirp->d_name, ".") || !strcmp(dirp->d_name, ".."))
506 /* since root is big enough, we reuse the space to
507 * concatenate the dirname to the current tree
510 strcat(root, dirp->d_name);
511 if (afs_stat(root, &st) == 0 && S_ISDIR(st.st_mode)) {
512 /* delete this subtree */
513 delTree(root, cp + 1, errp);
515 *errp = *errp ? *errp : errno;
517 /* recover path to our cur tree by truncating it to
522 /* if (!errno) -- closedir not implicit if we got an error */
526 /* finally axe the current dir */
528 *errp = *errp ? *errp : errno;
530 #ifndef AFS_PTHREAD_ENV /* let rx get some work done */
532 #endif /* !AFS_PTHREAD_ENV */
537 /* if we encountered errors during cleanup, we return a -1 */
546 /* namei_RemoveDataDirectories
548 * Returns 0 on success.
549 * Returns -1 on error. Typically, callers ignore this error because we
550 * can continue running if the removes fail. The salvage process will
551 * finish tidying up for us.
556 namei_RemoveDataDirectories(namei_t * name)
563 afs_snprintf(tmp, 256, "%s\\%s", name->n_drive, name->n_voldir);
566 path += strlen(path);
569 for (i = 'A'; i <= 'R'; i++) {
571 if (rmdir(name->n_path) < 0 && errno != ENOENT)
576 /* Delete the Vol_NNNNNN.data directory. */
579 if (rmdir(name->n_path) < 0 && errno != ENOENT) {
587 * We only use the n_base and n_voldir1 entries
588 * and only do rmdir's.
591 namei_RemoveDataDirectories(namei_t * name)
595 int prefixlen = strlen(name->n_base), err = 0;
596 int vollen = strlen(name->n_voldir1);
597 char pbuf[MAXPATHLEN];
601 strlcpy(path, name->n_path, sizeof(pbuf));
603 /* move past the prefix and n_voldir1 */
604 path = path + prefixlen + 1 + vollen + 1; /* skip over the trailing / */
606 /* now delete all dirs upto path */
607 code = delTree(pbuf, path, &err);
609 /* We've now deleted everything under /n_base/n_voldir1/n_voldir2 that
610 * we could. Do not delete /n_base/n_voldir1, since doing such might
611 * interrupt another thread trying to create a volume. We could introduce
612 * some locking to make this safe (or only remove it for whole-partition
613 * salvages), but by not deleting it we only leave behind a maximum of
614 * 256 empty directories. So at least for now, don't bother. */
619 /* Create the file in the name space.
621 * Parameters stored as follows:
623 * p1 - volid - implied in containing directory.
624 * p2 - vnode - name is <vno:31-23>/<vno:22-15>/<vno:15-0><uniq:31-5><tag:2-0>
625 * p3 - uniq -- bits 4-0 are in mode bits 4-0
626 * p4 - dv ---- dv:15-0 in uid, dv:29-16 in gid, dv:31-30 in mode:6-5
628 * p1 - volid - creation time - dwHighDateTime
629 * p2 - vnode - -1 means special, file goes in "S" subdirectory.
630 * p3 - type -- name is <type>.<tag> where tag is a file name unqiquifier.
631 * p4 - parid - parent volume id - implied in containing directory.
633 * Return value is the inode number or (Inode)-1 if error.
634 * We "know" there is only one link table, so return EEXIST if there already
635 * is a link table. It's up to the calling code to test errno and increment
641 * This function is called by VCreateVolume to hide the implementation
642 * details of the inode numbers. This only allows for 7 volume special
643 * types, but if we get that far, this could should be dead by then.
646 namei_MakeSpecIno(int volid, int type)
649 ino = NAMEI_INODESPECIAL;
653 type &= NAMEI_TAGMASK;
654 ino |= ((Inode) type) << NAMEI_TAGSHIFT;
655 ino |= ((Inode) volid) << NAMEI_UNIQSHIFT;
660 /* SetOGM - set owner group and mode bits from parm and tag */
662 SetOGM(FD_t fd, int parm, int tag)
666 * owner - low 15 bits of parm.
667 * group - next 15 bits of parm.
668 * mode - 2 bits of parm, then lowest = 3 bits of tag.
670 int owner, group, mode;
672 owner = parm & 0x7fff;
673 group = (parm >> 15) & 0x7fff;
674 if (fchown(fd, owner, group) < 0)
677 mode = (parm >> 27) & 0x18;
679 if (fchmod(fd, mode) < 0)
687 CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
689 WIN32_FIND_DATA info;
693 FindFirstFileEx(name->n_path, FindExInfoStandard, &info,
694 FindExSearchNameMatch, NULL,
695 FIND_FIRST_EX_CASE_SENSITIVE);
698 return -1; /* Can't get info, leave alone */
702 if (info.ftCreationTime.dwHighDateTime != (unsigned int)p1)
708 /* GetOGM - get parm and tag from owner, group and mode bits. */
710 GetOGMFromStat(struct afs_stat *status, int *parm, int *tag)
712 *parm = status->st_uid | (status->st_gid << 15);
713 *parm |= (status->st_mode & 0x18) << 27;
714 *tag = status->st_mode & 0x7;
718 CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
720 struct afs_stat status;
722 if (afs_fstat(fdP->fd_fd, &status) < 0)
725 GetOGMFromStat(&status, &parm, &tag);
733 int big_vno = 0; /* Just in case we ever do 64 bit vnodes. */
735 /* Derive the name and create it O_EXCL. If that fails we have an error.
736 * Get the tag from a free column in the link table.
740 namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4)
743 FD_t fd = INVALID_FD;
754 memset((void *)&tmp, 0, sizeof(IHandle_t));
756 tmp.ih_dev = nt_DriveToDev(part);
757 if (tmp.ih_dev == -1) {
763 /* Parameters for special file:
764 * p1 - volume id - goes into owner/group/mode
767 * p4 - parent volume id
769 ftime.dwHighDateTime = p1;
770 ftime.dwLowDateTime = p2;
772 tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */
773 tmp.ih_ino = namei_MakeSpecIno(p1, p3);
775 int vno = p2 & NAMEI_VNODEMASK;
776 /* Parameters for regular file:
790 tmp.ih_ino = (Inode) p2;
791 ftime.dwHighDateTime = p3;
792 ftime.dwLowDateTime = p4;
795 namei_HandleToName(&name, &tmp);
796 p = strrchr((char *)&name.n_path, '.');
798 for (i = 0; i < NAMEI_MAXVOLS; i++) {
799 *p = *int_to_base32(str1, i);
800 fd = nt_open((char *)&name.n_path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 0666);
801 if (fd != INVALID_FD)
803 if (p2 == -1 && p3 == VI_LINKTABLE)
806 if (fd == INVALID_FD) {
810 tmp.ih_ino &= ~((Inode) NAMEI_TAGMASK << NAMEI_TAGSHIFT);
811 tmp.ih_ino |= ((Inode) i << NAMEI_TAGSHIFT);
814 if (!SetFileTime((HANDLE) fd, &ftime, NULL, NULL)) {
815 errno = OS_ERROR(EBADF);
822 if (fd == INVALID_FD) {
824 code = nt_unlink((char *)&name.n_path);
833 code = namei_SetLinkCount(fdP, tmp.ih_ino, 1, 0);
835 } else if (p2 == -1 && p3 == VI_LINKTABLE) {
836 if (fd == INVALID_FD)
838 /* hack at tmp to setup for set link count call. */
840 code = namei_SetLinkCount(&tfd, (Inode) 0, 1, 0);
845 if (fd != INVALID_FD)
848 if (code || (fd == INVALID_FD)) {
852 namei_SetLinkCount(fdP, tmp.ih_ino, 0, 0);
858 int save_errno = errno;
859 namei_RemoveDataDirectories(&name);
863 return (code || (fd == INVALID_FD)) ? (Inode) - 1 : tmp.ih_ino;
867 namei_icreate(IHandle_t * lh, char *part, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4)
879 memset((void *)&tmp, 0, sizeof(IHandle_t));
881 tmp.ih_dev = volutil_GetPartitionID(part);
882 if (tmp.ih_dev == -1) {
888 /* Parameters for special file:
889 * p1 - volume id - goes into owner/group/mode
892 * p4 - parent volume id
897 tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */
898 tmp.ih_ino = namei_MakeSpecIno(p1, p3);
900 int vno = p2 & NAMEI_VNODEMASK;
901 /* Parameters for regular file:
913 /* If GetFreeTag succeeds, it atomically sets link count to 1. */
914 tag = GetFreeTag(lh, p2);
919 tmp.ih_ino = (Inode) p2;
920 /* name is <uniq(p3)><tag><vno(p2)> */
921 tmp.ih_ino |= ((Inode) tag) << NAMEI_TAGSHIFT;
922 tmp.ih_ino |= ((Inode) p3) << NAMEI_UNIQSHIFT;
927 namei_HandleToName(&name, &tmp);
928 fd = afs_open(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
930 if (errno == ENOTDIR || errno == ENOENT) {
931 if (namei_CreateDataDirectories(&name, &created_dir) < 0)
933 fd = afs_open(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR,
941 if (SetOGM(fd, ogm_parm, tag) < 0) {
947 if (p2 == -1 && p3 == VI_LINKTABLE) {
948 /* hack at tmp to setup for set link count call. */
949 memset((void *)&tfd, 0, sizeof(FdHandle_t)); /* minimalistic still, but a little cleaner */
952 code = namei_SetLinkCount(&tfd, (Inode) 0, 1, 0);
960 if (code || (fd < 0)) {
964 namei_SetLinkCount(fdP, tmp.ih_ino, 0, 0);
969 return (code || (fd < 0)) ? (Inode) - 1 : tmp.ih_ino;
975 namei_iopen(IHandle_t * h)
980 /* Convert handle to file name. */
981 namei_HandleToName(&name, h);
982 fd = afs_open((char *)&name.n_path, O_RDWR, 0666);
986 /* Need to detect vol special file and just unlink. In those cases, the
987 * handle passed in _is_ for the inode. We only check p1 for the special
991 namei_dec(IHandle_t * ih, Inode ino, int p1)
998 if ((ino & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) {
1000 int type = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK);
1002 /* Verify this is the right file. */
1003 IH_INIT(tmp, ih->ih_dev, ih->ih_vid, ino);
1005 namei_HandleToName(&name, tmp);
1010 errno = OS_ERROR(ENOENT);
1014 if (CheckOGM(&name, fdP, p1) < 0) {
1015 FDH_REALLYCLOSE(fdP);
1017 errno = OS_ERROR(EINVAL);
1021 /* If it's the link table itself, decrement the link count. */
1022 if (type == VI_LINKTABLE) {
1023 if ((count = namei_GetLinkCount(fdP, (Inode) 0, 1, 0, 1)) < 0) {
1024 FDH_REALLYCLOSE(fdP);
1030 if (namei_SetLinkCount(fdP, (Inode) 0, count < 0 ? 0 : count, 1) <
1032 FDH_REALLYCLOSE(fdP);
1038 FDH_REALLYCLOSE(fdP);
1044 if ((code = OS_UNLINK(name.n_path)) == 0) {
1045 if (type == VI_LINKTABLE) {
1046 /* Try to remove directory. If it fails, that's ok.
1047 * Salvage will clean up.
1049 (void)namei_RemoveDataDirectories(&name);
1052 FDH_REALLYCLOSE(fdP);
1055 /* Get a file descriptor handle for this Inode */
1061 if ((count = namei_GetLinkCount(fdP, ino, 1, 0, 1)) < 0) {
1062 FDH_REALLYCLOSE(fdP);
1068 if (namei_SetLinkCount(fdP, ino, count, 1) < 0) {
1069 FDH_REALLYCLOSE(fdP);
1074 IH_INIT(th, ih->ih_dev, ih->ih_vid, ino);
1075 Log("Warning: Lost ref on ihandle dev %d vid %d ino %" AFS_INT64_FMT "\n",
1076 th->ih_dev, th->ih_vid, (afs_int64)th->ih_ino);
1079 /* If we're less than 0, someone presumably unlinked;
1080 don't bother setting count to 0, but we need to drop a lock */
1081 if (namei_SetLinkCount(fdP, ino, 0, 1) < 0) {
1082 FDH_REALLYCLOSE(fdP);
1088 IH_INIT(th, ih->ih_dev, ih->ih_vid, ino);
1090 namei_HandleToName(&name, th);
1092 code = OS_UNLINK(name.n_path);
1101 namei_inc(IHandle_t * h, Inode ino, int p1)
1107 if ((ino & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) {
1108 int type = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK);
1109 if (type != VI_LINKTABLE)
1114 /* Get a file descriptor handle for this Inode */
1120 if ((count = namei_GetLinkCount(fdP, ino, 1, 0, 1)) < 0)
1125 errno = OS_ERROR(EINVAL);
1129 if (namei_SetLinkCount(fdP, ino, count, 1) < 0)
1133 FDH_REALLYCLOSE(fdP);
1140 #ifndef AFS_NT40_ENV
1142 namei_replace_file_by_hardlink(IHandle_t *hLink, IHandle_t *hTarget)
1148 /* Convert handle to file name. */
1149 namei_HandleToName(&nameLink, hLink);
1150 namei_HandleToName(&nameTarget, hTarget);
1152 unlink(nameLink.n_path);
1153 code = link(nameTarget.n_path, nameLink.n_path);
1158 namei_copy_on_write(IHandle_t *h)
1160 afs_int32 fd, code = 0;
1163 struct afs_stat tstat;
1166 namei_HandleToName(&name, h);
1167 if (afs_stat(name.n_path, &tstat) < 0)
1169 if (tstat.st_nlink > 1) { /* do a copy on write */
1178 afs_snprintf(path, sizeof(path), "%s-tmp", name.n_path);
1179 fd = afs_open(path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
1191 size = tstat.st_size;
1194 tlen = size > 8192 ? 8192 : size;
1195 if (FDH_PREAD(fdP, buf, tlen, offset) != tlen)
1197 if (write(fd, buf, tlen) != tlen)
1203 FDH_REALLYCLOSE(fdP);
1208 unlink(name.n_path);
1209 code = rename(path, name.n_path);
1216 /************************************************************************
1217 * File Name Structure
1218 ************************************************************************
1220 * Each AFS file needs a unique name and it needs to be findable with
1221 * minimal lookup time. Note that the constraint on the number of files and
1222 * directories in a volume is the size of the vnode index files and the
1223 * max file size AFS supports (for internal files) of 2^31. Since a record
1224 * in the small vnode index file is 64 bytes long, we can have at most
1225 * (2^31)/64 or 33554432 files. A record in the large index file is
1226 * 256 bytes long, giving a maximum of (2^31)/256 = 8388608 directories.
1227 * Another layout parameter is that there is roughly a 16 to 1 ratio between
1228 * the number of files and the number of directories.
1230 * Using this information we can see that a layout of 256 directories, each
1231 * with 512 subdirectories and each of those having 512 files gives us
1232 * 256*512*512 = 67108864 AFS files and directories.
1234 * The volume, vnode, uniquifier and data version, as well as the tag
1235 * are required, either for finding the file or for salvaging. It's best to
1236 * restrict the name to something that can be mapped into 64 bits so the
1237 * "Inode" is easily comparable (using "==") to other "Inodes". The tag
1238 * is used to distinguish between different versions of the same file
1239 * which are currently in the RW and clones of a volume. See "Link Table
1240 * Organization" below for more information on the tag. The tag is
1241 * required in the name of the file to ensure a unique name.
1243 * ifdef AFS_NT40_ENV
1244 * The data for each volume group is in a separate directory. The name of the
1245 * volume is of the form: Vol_NNNNNN.data, where NNNNNN is a base 32
1246 * representation of the RW volume ID (even where the RO is the only volume
1247 * on the partition). Below that are separate subdirectories for the
1248 * AFS directories and special files. There are also 16 directories for files,
1249 * hashed on the low 5 bits (recall bit0 is always 0) of the vnode number.
1250 * These directories are named:
1251 * A - P - 16 file directories.
1252 * Q ----- data directory
1253 * R ----- special files directory
1255 * The vnode is hashed into the directory using the low bits of the
1258 * The format of a file name for a regular file is:
1259 * Y:\Vol_NNNNNN.data\X\V_IIIIII.J
1260 * Y - partition encoded as drive letter, starting with D
1261 * NNNNNN - base 32 encoded volume number of RW volume
1262 * X - hash directory, as above
1263 * IIIIII - base 32 encoded vnode number
1264 * J - base 32 encoded tag
1266 * uniq is stored in the dwHighDateTime creation time field
1267 * dv is stored in the dwLowDateTime creation time field
1269 * Special inodes are always in the R directory, as above, and are
1271 * True child volid is stored in the dwHighDateTime creation time field
1272 * vnode number is always -1 (Special)
1273 * type is the IIIIII part of the filename
1274 * uniq is the J part of the filename
1275 * parent volume id is implied in the containing directory
1278 * We can store data in the uid, gid and mode bits of the files, provided
1279 * the directories have root only access. This gives us 15 bits for each
1280 * of uid and gid (GNU chown considers 65535 to mean "don't change").
1281 * There are 9 available mode bits. Adn we need to store a total of
1282 * 32 (volume id) + 26 (vnode) + 32 (uniquifier) + 32 (data-version) + 3 (tag)
1283 * or 131 bits somewhere.
1285 * The format of a file name for a regular file is:
1286 * /vicepX/AFSIDat/V1/V2/AA/BB/<tag><uniq><vno>
1287 * V1 - low 8 bits of RW volume id
1288 * V2 - all bits of RW volume id
1289 * AA - high 8 bits of vnode number.
1290 * BB - next 9 bits of vnode number.
1291 * <tag><uniq><vno> - file name
1293 * Volume special files are stored in a separate directory:
1294 * /vicepX/AFSIDat/V1/V2/special/<tag><uniq><vno>
1297 * The vnode is hashed into the directory using the high bits of the
1298 * vnode number. This is so that consecutively created vnodes are in
1299 * roughly the same area on the disk. This will at least be optimal if
1300 * the user is creating many files in the same AFS directory. The name
1301 * should be formed so that the leading characters are different as quickly
1302 * as possible, leading to faster discards of incorrect matches in the
1310 /************************************************************************
1311 * Link Table Organization
1312 ************************************************************************
1314 * The link table volume special file is used to hold the link counts that
1315 * are held in the inodes in inode based AFS vice filesystems. For user
1316 * space access, the link counts are being kept in a separate
1317 * volume special file. The file begins with the usual version stamp
1318 * information and is then followed by one row per vnode number. vnode 0
1319 * is used to hold the link count of the link table itself. That is because
1320 * the same link table is shared among all the volumes of the volume group
1321 * and is deleted only when the last volume of a volume group is deleted.
1323 * Within each row, the columns are 3 bits wide. They can each hold a 0 based
1324 * link count from 0 through 7. Each colume represents a unique instance of
1325 * that vnode. Say we have a file shared between the RW and a RO and a
1326 * different version of the file (or a different uniquifer) for the BU volume.
1327 * Then one column would be holding the link count of 2 for the RW and RO
1328 * and a different column would hold the link count of 1 for the BU volume.
1329 * # ifdef AFS_NT40_ENV
1330 * The column used is determined for NT by the uniquifier tag applied to
1331 * generate a unique file name in the NTFS namespace. The file name is
1332 * of the form "V_<vno>.<tag>" . And the <tag> is also the column number
1333 * in the link table.
1335 * Note that we allow only 5 volumes per file, giving 15 bits used in the
1339 #define LINKTABLE_WIDTH 2
1340 #define LINKTABLE_SHIFT 1 /* log 2 = 1 */
1343 * compute namei link table file and bit offset from inode number.
1345 * @param[in] ino inode number
1346 * @param[out] offset link table file offset
1347 * @param[out] index bit offset within 2-byte record
1352 namei_GetLCOffsetAndIndexFromIno(Inode ino, afs_foff_t * offset, int *index)
1354 int toff = (int)(ino & NAMEI_VNODEMASK);
1355 int tindex = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK);
1357 *offset = (afs_foff_t) ((toff << LINKTABLE_SHIFT) + 8); /* * 2 + sizeof stamp */
1358 *index = (tindex << 1) + tindex;
1361 #ifdef AFS_PTHREAD_ENV
1362 /* XXX do static initializers work for WINNT/pthread? */
1363 pthread_mutex_t _namei_glc_lock = PTHREAD_MUTEX_INITIALIZER;
1364 #define NAMEI_GLC_LOCK MUTEX_ENTER(&_namei_glc_lock)
1365 #define NAMEI_GLC_UNLOCK MUTEX_EXIT(&_namei_glc_lock)
1366 #else /* !AFS_PTHREAD_ENV */
1367 #define NAMEI_GLC_LOCK
1368 #define NAMEI_GLC_UNLOCK
1369 #endif /* !AFS_PTHREAD_ENV */
1372 * get the link count of an inode.
1374 * @param[in] h namei link count table file handle
1375 * @param[in] ino inode number for which we are requesting a link count
1376 * @param[in] lockit if asserted, return with lock held on link table file
1377 * @param[in] fixup if asserted, write 1 to link count when read() returns
1379 * @param[in] nowrite return success on zero byte read or ZLC
1381 * @post if lockit asserted and lookup was successful, will return with write
1382 * lock on link table file descriptor
1384 * @return link count
1385 * @retval -1 namei link table i/o error
1390 namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrite)
1392 unsigned short row = 0;
1397 /* there's no linktable yet. the salvager will create one later */
1398 if (h->fd_fd == INVALID_FD && fixup)
1400 namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
1403 if (FDH_LOCKFILE(h, offset) != 0)
1407 rc = FDH_PREAD(h, (char*)&row, sizeof(row), offset);
1408 if ((rc == 0 || !((row >> index) & NAMEI_TAGMASK)) && fixup && nowrite)
1410 if (rc == 0 && fixup) {
1412 * extend link table and write a link count of 1 for ino
1414 * in order to make MT-safe, truncation (extension really)
1415 * must happen under a mutex
1418 if (FDH_SIZE(h) >= offset+sizeof(row)) {
1420 goto bad_getLinkByte;
1422 FDH_TRUNC(h, offset+sizeof(row));
1424 rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset);
1427 if (rc != sizeof(row)) {
1428 goto bad_getLinkByte;
1431 if (fixup && !((row >> index) & NAMEI_TAGMASK)) {
1435 * in order to make this mt-safe, we need to do the read-modify-write
1436 * under a mutex. thus, we repeat the read inside the lock.
1439 rc = FDH_PREAD(h, (char *)&row, sizeof(row), offset);
1440 if (rc == sizeof(row)) {
1442 rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset);
1445 if (rc != sizeof(row))
1446 goto bad_getLinkByte;
1449 return (int)((row >> index) & NAMEI_TAGMASK);
1453 FDH_UNLOCKFILE(h, offset);
1458 namei_SetNonZLC(FdHandle_t * h, Inode ino)
1460 return namei_GetLinkCount(h, ino, 0, 1, 0);
1463 /* Return a free column index for this vnode. */
1465 GetFreeTag(IHandle_t * ih, int vno)
1479 /* Only one manipulates at a time. */
1480 if (FDH_LOCKFILE(fdP, offset) != 0) {
1481 FDH_REALLYCLOSE(fdP);
1485 offset = (vno << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */
1487 nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset);
1488 if (nBytes != sizeof(row)) {
1494 /* Now find a free column in this row and claim it. */
1495 for (col = 0; col < NAMEI_MAXVOLS; col++) {
1496 coldata = 7 << (col * 3);
1497 if ((row & coldata) == 0)
1500 if (col >= NAMEI_MAXVOLS) {
1505 coldata = 1 << (col * 3);
1508 if (FDH_PWRITE(fdP, (char *)&row, sizeof(row), offset) != sizeof(row)) {
1512 FDH_UNLOCKFILE(fdP, offset);
1513 FDH_REALLYCLOSE(fdP);
1517 FDH_UNLOCKFILE(fdP, offset);
1518 FDH_REALLYCLOSE(fdP);
1524 /* namei_SetLinkCount
1525 * If locked is set, assume file is locked. Otherwise, lock file before
1526 * proceeding to modify it.
1529 namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked)
1535 ssize_t nBytes = -1;
1537 namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
1540 if (FDH_LOCKFILE(fdP, offset) != 0) {
1545 nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset);
1546 if (nBytes != sizeof(row)) {
1548 errno = OS_ERROR(EBADF);
1549 goto bad_SetLinkCount;
1554 bytesRead = 7 << index;
1556 row &= (unsigned short)~bytesRead;
1557 row |= (unsigned short)count;
1559 if (FDH_PWRITE(fdP, (char *)&row, sizeof(short), offset) != sizeof(short)) {
1560 errno = OS_ERROR(EBADF);
1561 goto bad_SetLinkCount;
1569 FDH_UNLOCKFILE(fdP, offset);
1571 /* disallowed above 7, so... */
1576 /* ListViceInodes - write inode data to a results file. */
1577 static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
1578 unsigned int volid);
1579 static int DecodeVolumeName(char *name, unsigned int *vid);
1580 static int namei_ListAFSSubDirs(IHandle_t * dirIH,
1581 int (*write_fun) (FILE *,
1582 struct ViceInodeInfo *,
1583 char *, char *), FILE * fp,
1584 int (*judgeFun) (struct ViceInodeInfo *,
1585 afs_uint32 vid, void *),
1586 afs_uint32 singleVolumeNumber, void *rock);
1591 * Write the inode data to the results file.
1593 * Returns -2 on error, 0 on success.
1595 * This is written as a callback simply so that other listing routines
1596 * can use the same inode reading code.
1599 WriteInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name)
1602 n = fwrite(info, sizeof(*info), 1, fp);
1603 return (n == 1) ? 0 : -2;
1607 int mode_errors; /* Number of errors found in mode bits on directories. */
1609 VerifyDirPerms(char *path)
1611 struct afs_stat status;
1613 if (afs_stat(path, &status) < 0) {
1614 Log("Unable to stat %s. Please manually verify mode bits for this"
1615 " directory\n", path);
1617 if (((status.st_mode & 0777) != 0700) || (status.st_uid != 0))
1623 * Fill the results file with the requested inode information.
1625 * This code optimizes single volume salvages by just looking at that one
1626 * volume's directory.
1628 * @param[in] devname device name string
1629 * @param[in] moutnedOn vice partition mount point
1630 * @param[in] resultFile result file in which to write inode
1631 * metadata. If NULL, write routine is not
1633 * @param[in] judgeInode filter function pointer. if not NULL, only
1634 * inodes for which this routine returns non-
1635 * zero will be written to the results file.
1636 * @param[in] singleVolumeNumber volume id filter
1637 * @param[out] forcep always set to 0 for namei impl
1638 * @param[in] forceR not used by namei impl
1639 * @param[in] wpath not used by namei impl
1640 * @param[in] rock opaque pointer passed to judgeInode
1642 * @return operation status
1644 * @retval -1 complete failure, salvage should terminate.
1645 * @retval -2 not enough space on partition, salvager has error message
1649 ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile,
1650 int (*judgeInode) (struct ViceInodeInfo * info, afs_uint32 vid, void *rock),
1651 afs_uint32 singleVolumeNumber, int *forcep, int forceR, char *wpath,
1655 struct afs_stat status;
1657 *forcep = 0; /* no need to salvage until further notice */
1659 /* Verify protections on directories. */
1661 VerifyDirPerms(mountedOn);
1664 namei_ListAFSFiles(mountedOn, WriteInodeInfo, inodeFile, judgeInode,
1665 singleVolumeNumber, rock);
1674 if (fflush(inodeFile) == EOF) {
1675 Log("Unable to successfully flush inode file for %s\n", mountedOn);
1678 if (fsync(fileno(inodeFile)) == -1) {
1679 Log("Unable to successfully fsync inode file for %s\n", mountedOn);
1684 * Paranoia: check that the file is really the right size
1686 if (afs_fstat(fileno(inodeFile), &status) == -1) {
1687 Log("Unable to successfully stat inode file for %s\n", mountedOn);
1690 if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) {
1691 Log("Wrong size (%d instead of %lu) in inode file for %s\n",
1692 (int) status.st_size,
1693 (long unsigned int) ninodes * sizeof(struct ViceInodeInfo),
1702 * Collect all the matching AFS files on the drive.
1703 * If singleVolumeNumber is non-zero, just return files for that volume.
1705 * @param[in] dev vice partition path
1706 * @param[in] writeFun function pointer to a function which
1707 * writes inode information to FILE fp
1708 * @param[in] fp file stream where inode metadata is sent
1709 * @param[in] judgeFun filter function pointer. if not NULL,
1710 * only entries for which a non-zero value
1711 * is returned are written to fp
1712 * @param[in] singleVolumeNumber volume id filter. if nonzero, only
1713 * process files for that specific volume id
1714 * @param[in] rock opaque pointer passed into writeFun and
1717 * @return operation status
1719 * @retval >=0 number of matching files found
1722 namei_ListAFSFiles(char *dev,
1723 int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
1726 int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
1727 afs_uint32 singleVolumeNumber, void *rock)
1734 #ifndef AFS_NT40_ENV
1740 static void FreeZLCList(void);
1743 memset((void *)&ih, 0, sizeof(IHandle_t));
1745 ih.ih_dev = nt_DriveToDev(dev);
1747 ih.ih_dev = volutil_GetPartitionID(dev);
1750 if (singleVolumeNumber) {
1751 ih.ih_vid = singleVolumeNumber;
1752 namei_HandleToVolDir(&name, &ih);
1754 namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun,
1755 singleVolumeNumber, rock);
1759 /* Find all volume data directories and descend through them. */
1760 namei_HandleToInodeDir(&name, &ih);
1762 dirp1 = opendir(name.n_path);
1765 while ((dp1 = readdir(dirp1))) {
1767 /* Heirarchy is one level on Windows */
1768 if (!DecodeVolumeName(dp1->d_name, &ih.ih_vid)) {
1770 namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun,
1774 if (*dp1->d_name == '.')
1776 afs_snprintf(path2, sizeof(path2), "%s/%s", name.n_path,
1778 dirp2 = opendir(path2);
1780 while ((dp2 = readdir(dirp2))) {
1781 if (*dp2->d_name == '.')
1783 if (!DecodeVolumeName(dp2->d_name, &ih.ih_vid)) {
1785 namei_ListAFSSubDirs(&ih, writeFun, fp, judgeFun,
1802 static void AddToZLCDeleteList(char dir, char *name);
1803 static void DeleteZLCFiles(char *path);
1807 * examine a namei volume special file.
1809 * @param[in] path1 volume special directory path
1810 * @param[in] dname directory entry name
1811 * @param[in] myIH inode handle to volume directory
1812 * @param[out] linkHandle namei link count fd handle. if
1813 * the inode in question is the link
1814 * table, then the FdHandle is populated
1815 * @param[in] writeFun metadata write function pointer
1816 * @param[in] fp file pointer where inode metadata
1817 * is written by (*writeFun)()
1818 * @param[in] judgeFun inode filter function pointer. if
1819 * not NULL, only inodes for which this
1820 * function returns non-zero are recorded
1821 * into fp by writeFun
1822 * @param[in] singleVolumeNumer volume id filter. if non-zero, only
1823 * inodes associated with this volume id
1824 * are recorded by writeFun
1825 * @param[in] rock opaque pointer passed to writeFun and
1828 * @return operation status
1829 * @retval 1 count this inode
1830 * @retval 0 don't count this inode
1831 * @retval -1 failure
1836 _namei_examine_special(char * path1,
1839 FdHandle_t * linkHandle,
1840 int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
1843 int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
1844 int singleVolumeNumber,
1848 struct ViceInodeInfo info;
1850 if (DecodeInode(path1, dname, &info, myIH->ih_vid) < 0) {
1855 if (info.u.param[2] != VI_LINKTABLE) {
1859 /* Open this handle */
1860 (void)afs_snprintf(path2, sizeof(path2),
1861 "%s/%s", path1, dname);
1862 linkHandle->fd_fd = afs_open(path2, Testing ? O_RDONLY : O_RDWR, 0666);
1864 namei_GetLinkCount(linkHandle, (Inode) 0, 1, 1, Testing);
1868 (*judgeFun) (&info, singleVolumeNumber, rock)) {
1870 if ((*writeFun) (fp, &info, path1, dname) < 0) {
1880 * examine a namei file.
1882 * @param[in] path1 volume special directory path
1883 * @param[in] dname directory entry name
1884 * @param[in] myIH inode handle to volume directory
1885 * @param[in] linkHandle namei link count fd handle.
1886 * @param[in] writeFun metadata write function pointer
1887 * @param[in] fp file pointer where inode metadata
1888 * is written by (*writeFun)()
1889 * @param[in] judgeFun inode filter function pointer. if
1890 * not NULL, only inodes for which this
1891 * function returns non-zero are recorded
1892 * into fp by writeFun
1893 * @param[in] singleVolumeNumer volume id filter. if non-zero, only
1894 * inodes associated with this volume id
1895 * are recorded by writeFun
1896 * @param[in] rock opaque pointer passed to writeFun and
1899 * @return operation status
1900 * @retval 1 count this inode
1901 * @retval 0 don't count this inode
1902 * @retval -1 failure
1903 * @retval -2 request ZLC delete
1908 _namei_examine_reg(char * path3,
1911 FdHandle_t * linkHandle,
1912 int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
1915 int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
1916 int singleVolumeNumber,
1920 struct ViceInodeInfo info;
1922 int i; /* Windows-only (one level hash dir) */
1925 if (DecodeInode(path3, dname, &info, myIH->ih_vid) < 0) {
1930 namei_GetLinkCount(linkHandle,
1931 info.inodeNumber, 1, 1, Testing);
1932 if (info.linkCount == 0) {
1934 Log("Found 0 link count file %s/%s, deleting it.\n", path3, dname);
1935 #ifdef AFS_SALSRV_ENV
1936 /* defer -- the AddToZLCDeleteList() interface is not MT-safe */
1938 #else /* !AFS_SALSRV_ENV */
1939 AddToZLCDeleteList((char)i, dname);
1940 #endif /* !AFS_SALSRV_ENV */
1941 #else /* !DELETE_ZLC */
1942 Log("Found 0 link count file %s/%s.\n", path3,
1949 (*judgeFun) (&info, singleVolumeNumber, rock)) {
1951 if ((*writeFun) (fp, &info, path3, dname) < 0) {
1961 * listsubdirs work queue node.
1963 struct listsubdirs_work_node {
1964 #ifdef AFS_SALSRV_ENV
1965 int *error; /**< *error set if an error was
1966 * encountered in any listsubdirs
1970 IHandle_t * IH; /**< volume directory handle */
1971 FdHandle_t *linkHandle; /**< namei link count fd handle. when
1972 * examinining the link table special
1973 * inode, this will be pointed at the
1976 FILE * fp; /**< file pointer for writeFun */
1978 /** function which will write inode metadata to fp */
1979 int (*writeFun) (FILE *, struct ViceInodeInfo *, char *, char *);
1981 /** inode filter function */
1982 int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *);
1983 int singleVolumeNumber; /**< volume id filter */
1984 void * rock; /**< pointer passed to writeFun and judgeFun */
1985 int code; /**< return code from examine function */
1986 int special; /**< asserted when this is a volume
1991 * simple wrapper around _namei_examine_special and _namei_examine_reg.
1993 * @param[in] work the struct listsubdirs_work_node for the associated
1994 * "list subdirs" job
1995 * @param[in] dir the directory to examine
1996 * @param[in] filename the filename in 'dir' to examine
1998 * @return operation status
1999 * @retval 1 count this inode
2000 * @retval 0 don't count this inode
2001 * @retval -1 failure
2004 _namei_examine_file(const struct listsubdirs_work_node *work, char *dir,
2007 if (work->special) {
2008 return _namei_examine_special(dir, filename, work->IH,
2009 work->linkHandle, work->writeFun, work->fp,
2010 work->judgeFun, work->singleVolumeNumber,
2013 return _namei_examine_reg(dir, filename, work->IH,
2014 work->linkHandle, work->writeFun, work->fp,
2015 work->judgeFun, work->singleVolumeNumber,
2021 #ifdef AFS_SALSRV_ENV
2022 /** @addtogroup afs_vol_salsrv_pario */
2026 * arguments for the _namei_examine_file_cbk callback function.
2028 struct listsubdirs_args {
2029 const struct listsubdirs_work_node *work; /**< arguments that are the same
2030 * for all invocations of
2031 * _namei_examine_file_cbk, in
2033 int *result; /**< where we can store the return code of _namei_examine_file */
2035 char dir[512]; /**< directory to examine */
2036 char filename[256]; /**< filename in 'dir' to examine */
2040 * a node in the list of results of listsubdir jobs.
2042 struct listsubdirs_result {
2044 int inodes; /**< return value from _namei_examine_file */
2048 * clean up a list of 'struct listsubdirs_result's and interpret the results.
2050 * @param[in] resultlist a list of 'struct listsubdirs_result's
2052 * @return number of inodes found
2056 _namei_listsubdirs_cleanup_results(struct rx_queue *resultlist)
2058 struct listsubdirs_result *res, *nres;
2061 for(queue_Scan(resultlist, res, nres, listsubdirs_result)) {
2063 /* noop, retain erroneous error code */
2064 } else if (res->inodes < 0) {
2079 * wait for the spawned listsubdirs jobs to finish, and return how many inodes
2082 * @param[in] queue queue to wait to finish
2083 * @param[in] resultlist list of 'struct listsubdirs_result's that the queued
2084 * jobs are storing their results in
2086 * @return number of inodes found
2090 _namei_listsubdirs_wait(struct afs_work_queue *queue, struct rx_queue *resultlist)
2094 code = afs_wq_wait_all(queue);
2099 return _namei_listsubdirs_cleanup_results(resultlist);
2103 * work queue entry point for examining namei files.
2105 * @param[in] queue pointer to struct Vwork_queue
2106 * @param[in] node pointer to struct Vwork_queue_node
2107 * @param[in] queue_rock opaque pointer to struct salsrv_pool_state
2108 * @param[in] node_rock opaque pointer to struct listsubdirs_work_node
2109 * @param[in] caller_rock opaque pointer to struct salsrv_worker_thread_state
2111 * @return operation status
2113 * @see Vwork_queue_callback_func_t
2118 _namei_examine_file_cbk(struct afs_work_queue *queue,
2119 struct afs_work_queue_node *node,
2125 struct listsubdirs_args *args = node_rock;
2126 const struct listsubdirs_work_node * work = args->work;
2127 char *dir = args->dir;
2128 char *filename = args->filename;
2130 code = _namei_examine_file(work, dir, filename);
2132 *(args->result) = code;
2136 /* we've errored, so no point in letting more jobs continue */
2137 afs_wq_shutdown(queue);
2143 static pthread_once_t wq_once = PTHREAD_ONCE_INIT;
2144 static pthread_key_t wq_key;
2147 * create the wq_key key for storing a work queue.
2150 _namei_wq_keycreate(void)
2152 osi_Assert(pthread_key_create(&wq_key, NULL) == 0);
2156 * set the work queue for this thread to use for backgrounding namei ops.
2158 * The work queue will be used in ListAFSSubdirs (called indirectly by
2159 * ListViceInodes) to examine files in parallel.
2161 * @param[in] wq the work queue to use
2164 namei_SetWorkQueue(struct afs_work_queue *wq)
2166 osi_Assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0);
2168 osi_Assert(pthread_setspecific(wq_key, wq) == 0);
2172 * enqueue an examine file work unit.
2174 * @param[in] work the _namei_examine_file arguments that are common to
2175 * all callers within the same ListAFSFiles operation
2176 * @param[in] dir the specific directory to look at (string will be
2177 * copied; can be stack/temporary memory)
2178 * @param[in] filename the filename to look at (string will be copied; can be
2179 * stack/temporary memory)
2180 * @param[in] wq work queue to enqueue this work unit to
2181 * @param[in] resultlist the list to append the 'struct listsubdirs_result' to
2182 * for the enqueued work unit
2184 * @return operation status
2186 * @retval -1 fatal error
2188 * @note errors MUST be indicated by a -1 error code and nothing else, to be
2189 * compatible with _namei_examine_reg and _namei_examine_special
2194 _namei_examine_file_spawn(const struct listsubdirs_work_node *work,
2195 const char *dir, const char *filename,
2196 struct afs_work_queue *wq,
2197 struct rx_queue *resultlist)
2200 struct listsubdirs_args *args = NULL;
2201 struct listsubdirs_result *result = NULL;
2202 struct afs_work_queue_node *node = NULL;
2203 struct afs_work_queue_add_opts opts;
2205 args = malloc(sizeof(*args));
2211 result = malloc(sizeof(*result));
2212 if (result == NULL) {
2217 code = afs_wq_node_alloc(&node);
2222 code = afs_wq_node_set_detached(node);
2229 args->result = &result->inodes;
2230 strlcpy(args->dir, dir, sizeof(args->dir));
2231 strlcpy(args->filename, filename, sizeof(args->filename));
2233 code = afs_wq_node_set_callback(node,
2234 &_namei_examine_file_cbk,
2242 afs_wq_add_opts_init(&opts);
2245 code = afs_wq_add(wq, node, &opts);
2252 queue_Append(resultlist, result);
2257 afs_wq_node_put(node);
2273 #else /* !AFS_SALSRV_ENV */
2274 # define _namei_examine_file_spawn(work, dir, file, wq, resultlist) \
2275 _namei_examine_file(work, dir, file)
2276 #endif /* !AFS_SALSRV_ENV */
2279 * traverse and check inodes.
2281 * @param[in] dirIH volume group directory handle
2282 * @param[in] writeFun function pointer which will write inode
2283 * metadata to FILE stream fp
2284 * @param[in] fp file stream where inode metadata gets
2286 * @param[in] judgeFun inode filter function. if not NULL, only
2287 * inodes for which the filter returns non-zero
2288 * will be written out by writeFun
2289 * @param[in] singleVolumeNumber volume id filter. only inodes matching this
2290 * filter are written out by writeFun
2291 * @param[in] rock opaque pointer passed to judgeFun and writeFun
2293 * @return operation status
2295 * @retval >=0 number of matching inodes found
2297 * @todo the salsrv implementation may consume a lot of
2298 * memory for a large volume. at some point we should
2299 * probably write a background thread to asynchronously
2300 * clean up the resultlist nodes to reduce memory footprint
2305 namei_ListAFSSubDirs(IHandle_t * dirIH,
2306 int (*writeFun) (FILE *, struct ViceInodeInfo *, char *,
2309 int (*judgeFun) (struct ViceInodeInfo *, afs_uint32, void *),
2310 afs_uint32 singleVolumeNumber, void *rock)
2312 int code = 0, ret = 0;
2313 IHandle_t myIH = *dirIH;
2315 char path1[512], path3[512];
2316 DIR *dirp1, *dirp2, *dirp3;
2317 #ifndef AFS_NT40_ENV
2321 struct dirent *dp1, *dp3;
2322 FdHandle_t linkHandle;
2324 struct listsubdirs_work_node work;
2325 #ifdef AFS_SALSRV_ENV
2327 struct afs_work_queue *wq;
2329 struct rx_queue resultlist;
2333 static void AddToZLCDeleteList(char dir, char *name);
2334 static void DeleteZLCFiles(char *path);
2337 namei_HandleToVolDir(&name, &myIH);
2338 strlcpy(path1, name.n_path, sizeof(path1));
2340 /* Do the directory containing the special files first to pick up link
2343 (void)strcat(path1, OS_DIRSEP);
2344 (void)strcat(path1, NAMEI_SPECDIR);
2346 linkHandle.fd_fd = INVALID_FD;
2347 #ifdef AFS_SALSRV_ENV
2348 osi_Assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0);
2350 wq = pthread_getspecific(wq_key);
2356 queue_Init(&resultlist);
2359 memset(&work, 0, sizeof(work));
2360 work.linkHandle = &linkHandle;
2363 work.writeFun = writeFun;
2364 work.judgeFun = judgeFun;
2365 work.singleVolumeNumber = singleVolumeNumber;
2368 #ifdef AFS_SALSRV_ENV
2369 work.error = &error;
2372 dirp1 = opendir(path1);
2374 while ((dp1 = readdir(dirp1))) {
2375 if (*dp1->d_name == '.')
2378 #ifdef AFS_SALSRV_ENV
2384 #endif /* AFS_SALSRV_ENV */
2386 code = _namei_examine_file_spawn(&work, path1, dp1->d_name, wq, &resultlist);
2396 /* count this inode */
2397 #ifndef AFS_SALSRV_ENV
2406 #ifdef AFS_SALSRV_ENV
2407 /* effectively a barrier */
2408 code = _namei_listsubdirs_wait(wq, &resultlist);
2409 if (code < 0 || error) {
2417 /* Now run through all the other subdirs */
2418 namei_HandleToVolDir(&name, &myIH);
2419 strlcpy(path1, name.n_path, sizeof(path1));
2423 dirp1 = opendir(path1);
2425 while ((dp1 = readdir(dirp1))) {
2426 #ifndef AFS_NT40_ENV
2427 if (*dp1->d_name == '.')
2430 if (!strcmp(dp1->d_name, NAMEI_SPECDIR))
2433 #ifndef AFS_NT40_ENV /* This level missing on Windows */
2434 /* Now we've got a next level subdir. */
2435 afs_snprintf(path2, sizeof(path2), "%s/%s", path1, dp1->d_name);
2436 dirp2 = opendir(path2);
2438 while ((dp2 = readdir(dirp2))) {
2439 if (*dp2->d_name == '.')
2442 /* Now we've got to the actual data */
2443 afs_snprintf(path3, sizeof(path3), "%s/%s", path2,
2446 /* Now we've got to the actual data */
2447 afs_snprintf(path3, sizeof(path3), "%s\\%s", path1,
2450 dirp3 = opendir(path3);
2452 while ((dp3 = readdir(dirp3))) {
2453 #ifndef AFS_NT40_ENV
2454 if (*dp3->d_name == '.')
2458 #ifdef AFS_SALSRV_ENV
2466 #endif /* AFS_SALSRV_ENV */
2468 code = _namei_examine_file_spawn(&work, path3,
2481 #ifndef AFS_SALSRV_ENV
2489 #ifndef AFS_NT40_ENV /* This level missing on Windows */
2498 #ifdef AFS_SALSRV_ENV
2499 /* effectively a barrier */
2500 code = _namei_listsubdirs_wait(wq, &resultlist);
2501 if (code < 0 || error) {
2511 /* Then why does this directory exist? Blow it away. */
2512 namei_HandleToVolDir(&name, dirIH);
2513 namei_RemoveDataDirectories(&name);
2517 #ifdef AFS_SALSRV_ENV
2519 afs_wq_wait_all(wq);
2521 _namei_listsubdirs_cleanup_results(&resultlist);
2523 if (linkHandle.fd_fd != INVALID_FD)
2524 OS_CLOSE(linkHandle.fd_fd);
2536 DecodeVolumeName(char *name, unsigned int *vid)
2538 /* Name begins with "Vol_" and ends with .data. See nt_HandleToVolDir() */
2545 if (strncmp(name, "Vol_", 4))
2547 if (strcmp(name + len - 5, ".data"))
2550 stmp[len - 5] = '\0';
2551 *vid = base32_to_int(stmp + 4);
2556 DecodeVolumeName(char *name, unsigned int *vid)
2558 if (strlen(name) < 1)
2560 *vid = (unsigned int)flipbase64_to_int64(name);
2568 * Get the inode number from the name.
2573 DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
2578 WIN32_FIND_DATA data;
2582 FdHandle_t linkHandle;
2585 afs_snprintf(fpath, sizeof(fpath), "%s\\%s", dpath, name);
2587 dirH = FindFirstFileEx(fpath, FindExInfoStandard, &data,
2588 FindExSearchNameMatch, NULL,
2589 FIND_FIRST_EX_CASE_SENSITIVE);
2590 if (dirH == INVALID_HANDLE_VALUE)
2593 (void)strcpy(stmp, name);
2594 s = strrchr(stmp, '_');
2598 t = strrchr(s, '.');
2603 vno = base32_to_int(s);
2604 tag = base32_to_int(t+1);
2605 info->inodeNumber = (Inode) tag << NAMEI_TAGSHIFT;
2606 info->inodeNumber |= (Inode) vno;
2607 info->byteCount = data.nFileSizeLow;
2609 dirl = dpath[strlen(dpath)-1];
2610 if (dirl == 'R') { /* Special inode. */
2611 info->inodeNumber |= NAMEI_INODESPECIAL;
2612 info->u.param[0] = data.ftCreationTime.dwHighDateTime;
2613 info->u.param[1] = data.ftCreationTime.dwLowDateTime;
2614 info->u.param[2] = tag;
2615 info->u.param[3] = volid;
2616 if (tag != VI_LINKTABLE)
2617 info->linkCount = 1;
2619 /* Open this handle */
2621 (void)sprintf(lpath, "%s\\%s", fpath, data.cFileName);
2622 linkHandle.fd_fd = nt_open(lpath, O_RDONLY, 0666);
2624 namei_GetLinkCount(&linkHandle, (Inode) 0, 0, 0, 0);
2628 namei_GetLinkCount(&linkHandle, info->inodeNumber, 0, 0, 0);
2629 if (info->linkCount == 0) {
2631 Log("Found 0 link count file %s\\%s, deleting it.\n",
2632 fpath, data.cFileName);
2633 AddToZLCDeleteList(dirl, data.cFileName);
2635 Log("Found 0 link count file %s\\%s.\n", path,
2639 info->u.param[2] = data.ftCreationTime.dwHighDateTime;
2640 info->u.param[3] = data.ftCreationTime.dwLowDateTime;
2641 info->u.param[1] = vno;
2642 info->u.param[0] = volid;
2649 DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,
2653 struct afs_stat status;
2655 lb64_string_t check;
2657 afs_snprintf(fpath, sizeof(fpath), "%s/%s", dpath, name);
2659 if (afs_stat(fpath, &status) < 0) {
2663 info->byteCount = status.st_size;
2664 info->inodeNumber = (Inode) flipbase64_to_int64(name);
2666 int64_to_flipbase64(check, info->inodeNumber);
2667 if (strcmp(name, check))
2670 GetOGMFromStat(&status, &parm, &tag);
2671 if ((info->inodeNumber & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) {
2672 /* p1 - vid, p2 - -1, p3 - type, p4 - rwvid */
2673 info->u.param[0] = parm;
2674 info->u.param[1] = -1;
2675 info->u.param[2] = tag;
2676 info->u.param[3] = volid;
2678 /* p1 - vid, p2 - vno, p3 - uniq, p4 - dv */
2679 info->u.param[0] = volid;
2680 info->u.param[1] = (int)(info->inodeNumber & NAMEI_VNODEMASK);
2681 info->u.param[2] = (int)((info->inodeNumber >> NAMEI_UNIQSHIFT)
2682 & (Inode) NAMEI_UNIQMASK);
2683 info->u.param[3] = parm;
2690 * Convert the VolumeInfo file from RO to RW
2691 * this routine is called by namei_convertROtoRWvolume()
2694 #ifdef FSSYNC_BUILD_CLIENT
2696 convertVolumeInfo(FD_t fdr, FD_t fdw, afs_uint32 vid)
2698 struct VolumeDiskData vd;
2701 if (OS_READ(fdr, (char *)&vd, sizeof(struct VolumeDiskData)) !=
2702 sizeof(struct VolumeDiskData)) {
2703 Log("1 convertVolumeInfo: read failed for %lu with code %d\n",
2704 afs_printable_uint32_lu(vid),
2708 vd.restoredFromId = vd.id; /* remember the RO volume here */
2710 vd.id = vd.parentId;
2714 vd.uniquifier += 5000; /* just in case there are still file copies from
2715 * the old RW volume around */
2716 p = strrchr(vd.name, '.');
2717 if (p && !strcmp(p, ".readonly")) {
2720 if (OS_WRITE(fdw, (char *)&vd, sizeof(struct VolumeDiskData)) !=
2721 sizeof(struct VolumeDiskData)) {
2722 Log("1 convertVolumeInfo: write failed for %lu with code %d\n",
2723 afs_printable_uint32_lu(vid),
2732 * Convert a RO-volume into a RW-volume
2734 * This function allows to recover very fast from the loss of a partition
2735 * from RO-copies if all RO-Copies exist on another partition.
2736 * Then these RO-volumes can be made to the new RW-volumes.
2737 * Backup of RW-volumes then consists in "vos release".
2739 * We must make sure in this partition exists only the RO-volume which
2740 * is typical for remote replicas.
2742 * Then the linktable is already ok,
2743 * the vnode files need to be renamed
2744 * the volinfo file needs to be replaced by another one with
2745 * slightly different contents and new name.
2746 * The volume header file of the RO-volume in the /vicep<x> directory
2747 * is destroyed by this call. A new header file for the RW-volume must
2748 * be created after return from this routine.
2752 namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId)
2755 #ifdef FSSYNC_BUILD_CLIENT
2757 char dir_name[512], oldpath[512], newpath[512];
2772 struct DiskPartition64 *partP;
2773 struct ViceInodeInfo info;
2774 struct VolumeDiskHeader h;
2775 # ifdef AFS_DEMAND_ATTACH_FS
2777 # endif /* AFS_DEMAND_ATTACH_FS */
2779 for (partP = DiskPartitionList; partP && strcmp(partP->name, pname);
2780 partP = partP->next);
2782 Log("1 namei_ConvertROtoRWvolume: Couldn't find DiskPartition for %s\n", pname);
2787 # ifdef AFS_DEMAND_ATTACH_FS
2788 locktype = VVolLockType(V_VOLUPD, 1);
2789 code = VLockVolumeByIdNB(volumeId, partP, locktype);
2795 # endif /* AFS_DEMAND_ATTACH_FS */
2797 if (VReadVolumeDiskHeader(volumeId, partP, &h)) {
2798 Log("1 namei_ConvertROtoRWvolume: Couldn't read header for RO-volume %lu.\n",
2799 afs_printable_uint32_lu(volumeId));
2804 FSYNC_VolOp(volumeId, pname, FSYNC_VOL_BREAKCBKS, 0, NULL);
2806 ino = namei_MakeSpecIno(h.parent, VI_LINKTABLE);
2807 IH_INIT(ih, partP->device, h.parent, ino);
2809 namei_HandleToName(&n, ih);
2810 strlcpy(dir_name, n.n_path, sizeof(dir_name));
2811 p = strrchr(dir_name, OS_DIRSEPC);
2813 dirp = opendir(dir_name);
2815 Log("1 namei_ConvertROtoRWvolume: Could not opendir(%s)\n", dir_name);
2820 while ((dp = readdir(dirp))) {
2821 /* struct ViceInodeInfo info; */
2822 #ifndef AFS_NT40_ENV
2823 if (*dp->d_name == '.')
2826 if (DecodeInode(dir_name, dp->d_name, &info, ih->ih_vid) < 0) {
2827 Log("1 namei_ConvertROtoRWvolume: DecodeInode failed for %s/%s\n",
2828 dir_name, dp->d_name);
2833 if (info.u.param[1] != -1) {
2834 Log("1 namei_ConvertROtoRWvolume: found other than volume special file %s/%s\n", dir_name, dp->d_name);
2839 if (info.u.param[0] != volumeId) {
2840 if (info.u.param[0] == ih->ih_vid) {
2841 if (info.u.param[2] == VI_LINKTABLE) { /* link table */
2846 Log("1 namei_ConvertROtoRWvolume: found special file %s/%s"
2847 " for volume %lu\n", dir_name, dp->d_name,
2848 afs_printable_uint32_lu(info.u.param[0]));
2853 if (info.u.param[2] == VI_VOLINFO) { /* volume info file */
2854 strlcpy(infoName, dp->d_name, sizeof(infoName));
2856 } else if (info.u.param[2] == VI_SMALLINDEX) { /* small vnodes file */
2857 strlcpy(smallName, dp->d_name, sizeof(smallName));
2859 } else if (info.u.param[2] == VI_LARGEINDEX) { /* large vnodes file */
2860 strlcpy(largeName, dp->d_name, sizeof(largeName));
2864 Log("1 namei_ConvertROtoRWvolume: unknown type %d of special file found : %s/%s\n", info.u.param[2], dir_name, dp->d_name);
2871 if (!infoSeen || !smallSeen || !largeSeen || !linkSeen) {
2872 Log("1 namei_ConvertROtoRWvolume: not all special files found in %s\n", dir_name);
2878 * If we come here then there was only a RO-volume and we can safely
2882 memset(&t_ih, 0, sizeof(t_ih));
2883 t_ih.ih_dev = ih->ih_dev;
2884 t_ih.ih_vid = ih->ih_vid;
2886 (void)afs_snprintf(oldpath, sizeof oldpath, "%s" OS_DIRSEP "%s", dir_name,
2888 fd = afs_open(oldpath, O_RDWR, 0);
2890 Log("1 namei_ConvertROtoRWvolume: could not open RO info file: %s\n",
2895 t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_VOLINFO);
2896 namei_HandleToName(&n, &t_ih);
2897 fd2 = afs_open(n.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
2899 Log("1 namei_ConvertROtoRWvolume: could not create RW info file: %s\n", n.n_path);
2904 code = convertVolumeInfo(fd, fd2, ih->ih_vid);
2908 OS_UNLINK(n.n_path);
2912 SetOGM(fd2, ih->ih_vid, 1);
2915 t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_SMALLINDEX);
2916 namei_HandleToName(&n, &t_ih);
2917 (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
2919 fd = afs_open(newpath, O_RDWR, 0);
2921 Log("1 namei_ConvertROtoRWvolume: could not open SmallIndex file: %s\n", newpath);
2925 SetOGM(fd, ih->ih_vid, 2);
2928 MoveFileEx(n.n_path, newpath, MOVEFILE_WRITE_THROUGH);
2930 link(newpath, n.n_path);
2934 t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_LARGEINDEX);
2935 namei_HandleToName(&n, &t_ih);
2936 (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name,
2938 fd = afs_open(newpath, O_RDWR, 0);
2940 Log("1 namei_ConvertROtoRWvolume: could not open LargeIndex file: %s\n", newpath);
2944 SetOGM(fd, ih->ih_vid, 3);
2947 MoveFileEx(n.n_path, newpath, MOVEFILE_WRITE_THROUGH);
2949 link(newpath, n.n_path);
2956 h.volumeInfo_hi = h.id;
2957 h.smallVnodeIndex_hi = h.id;
2958 h.largeVnodeIndex_hi = h.id;
2959 h.linkTable_hi = h.id;
2961 if (VCreateVolumeDiskHeader(&h, partP)) {
2962 Log("1 namei_ConvertROtoRWvolume: Couldn't write header for RW-volume %lu\n",
2963 afs_printable_uint32_lu(h.id));
2968 if (VDestroyVolumeDiskHeader(partP, volumeId, h.parent)) {
2969 Log("1 namei_ConvertROtoRWvolume: Couldn't unlink header for RO-volume %lu\n",
2970 afs_printable_uint32_lu(volumeId));
2973 FSYNC_VolOp(volumeId, pname, FSYNC_VOL_DONE, 0, NULL);
2974 FSYNC_VolOp(h.id, pname, FSYNC_VOL_ON, 0, NULL);
2977 # ifdef AFS_DEMAND_ATTACH_FS
2979 VUnlockVolumeById(volumeId, partP);
2981 # endif /* AFS_DEMAND_ATTACH_FS */
2989 * returns a static string used to print either 32 or 64 bit inode numbers.
2992 PrintInode(char *s, Inode ino)
2994 static afs_ino_str_t result;
2998 (void)afs_snprintf(s, sizeof(afs_ino_str_t), "%" AFS_UINT64_FMT, (afs_uintmax_t) ino);
3005 /* Routines to facilitate removing zero link count files. */
3006 #define MAX_ZLC_NAMES 32
3007 #define MAX_ZLC_NAMELEN 16
3008 typedef struct zlcList_s {
3009 struct zlcList_s *zlc_next;
3011 char zlc_names[MAX_ZLC_NAMES][MAX_ZLC_NAMELEN];
3014 static zlcList_t *zlcAnchor = NULL;
3015 static zlcList_t *zlcCur = NULL;
3018 AddToZLCDeleteList(char dir, char *name)
3020 osi_Assert(strlen(name) <= MAX_ZLC_NAMELEN - 3);
3022 if (!zlcCur || zlcCur->zlc_n >= MAX_ZLC_NAMES) {
3023 if (zlcCur && zlcCur->zlc_next)
3024 zlcCur = zlcCur->zlc_next;
3026 zlcList_t *tmp = (zlcList_t *) malloc(sizeof(zlcList_t));
3032 zlcCur->zlc_next = tmp;
3036 zlcCur->zlc_next = NULL;
3041 (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name);
3043 (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%s", name);
3049 DeleteZLCFiles(char *path)
3055 for (z = zlcAnchor; z; z = z->zlc_next) {
3056 for (i = 0; i < z->zlc_n; i++) {
3058 (void)sprintf(fname, "%s\\%s", path, z->zlc_names[i]);
3060 (void)sprintf(fname, "%s", z->zlc_names[i]);
3061 if (namei_unlink(fname) < 0) {
3062 Log("ZLC: Can't unlink %s, dos error = %d\n", fname,
3066 z->zlc_n = 0; /* Can reuse space. */
3079 tnext = i->zlc_next;
3083 zlcCur = zlcAnchor = NULL;
3087 #endif /* AFS_NAMEI_ENV */