1 /* This file contains routines that verify inodes and paths against the host.
3 * The entry points into this file are:
4 * verify_path check whether a path,inode pair is still valid
5 * verify_inode construct a path for an inode and verify the inode
6 * verify_dentry check a directory inode and look for a directory entry
9 * April 2009 (D.C. van Moolenbroek)
14 /*===========================================================================*
16 *===========================================================================*/
17 int verify_path(path
, ino
, attr
, stale
)
20 struct sffs_attr
*attr
;
23 /* Given a path, and the inode associated with that path, verify if the inode
24 * still matches the real world. Obtain the attributes of the file identified
25 * by the given path, and see if they match. If not, possibly mark the inode
26 * as deleted and return an error. Only upon success is the inode guaranteed
29 * The caller must set the a_mask field of the passed attr struct.
30 * If 'stale' is not NULL, the value it points to must be initialized to 0,
31 * and will be set to 1 if the path was valid but the inode wasn't.
35 attr
->a_mask
|= SFFS_ATTR_MODE
;
37 r
= sffs_table
->t_getattr(path
, attr
);
39 dprintf(("%s: verify_path: getattr('%s') returned %d\n",
43 /* If we are told that the path does not exist, delete the inode */
44 if (r
== ENOENT
|| r
== ENOTDIR
)
47 return r
; /* path isn't valid */
50 /* If the file type (reg, dir) isn't what we thought, delete the inode */
51 if ((ino
->i_flags
& I_DIR
) != MODE_TO_DIRFLAG(attr
->a_mode
)) {
54 if (stale
!= NULL
) *stale
= 1;
55 return ENOENT
; /* path is valid, inode wasn't */
58 return OK
; /* path and inode are valid */
61 /*===========================================================================*
63 *===========================================================================*/
64 int verify_inode(ino
, path
, attr
)
65 struct inode
*ino
; /* inode to verify */
66 char path
[PATH_MAX
]; /* buffer in which to store the path */
67 struct sffs_attr
*attr
; /* buffer for attributes, or NULL */
69 /* Given an inode, construct a path identifying the inode, and check whether
70 * that path is still valid for that inode (as far as we can tell). As a side
71 * effect, store attributes in the given attribute structure if not NULL (its
72 * a_mask member must then be set).
74 struct sffs_attr attr2
;
77 if ((r
= make_path(path
, ino
)) != OK
) return r
;
85 return verify_path(path
, ino
, attr
, NULL
);
88 /*===========================================================================*
90 *===========================================================================*/
91 int verify_dentry(parent
, name
, path
, res_ino
)
92 struct inode
*parent
; /* parent inode: the inode to verify */
93 char name
[NAME_MAX
+1]; /* the given directory entry path component */
94 char path
[PATH_MAX
]; /* buffer to store the resulting path in */
95 struct inode
**res_ino
; /* pointer for addressed inode (or NULL) */
97 /* Given a directory inode and a name, construct a path identifying that
98 * directory entry, check whether the path to the parent is still valid, and
99 * check whether there is an inode pointed to by the full path. Upon success,
100 * res_ino will contain either the inode for the full path, with increased
101 * refcount, or NULL if no such inode exists.
105 if ((r
= verify_inode(parent
, path
, NULL
)) != OK
)
108 dprintf(("%s: verify_dentry: given path is '%s', name '%s'\n",
109 sffs_name
, path
, name
));
111 if ((r
= push_path(path
, name
)) != OK
)
114 dprintf(("%s: verify_dentry: path now '%s'\n", sffs_name
, path
));
116 *res_ino
= lookup_dentry(parent
, name
);