Skip to content

Commit

Permalink
Upstream: Zdb inode mapping fix (openzfs#54)
Browse files Browse the repository at this point in the history
* macOS: Move INO map macros

The INO mapping macros need to also be accessable from userland.

* Upstream: zdb needs to map inodes on macOS
Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jun 30, 2021
1 parent 3b2101b commit 1cd14bf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
8 changes: 8 additions & 0 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,9 @@ parse_object_range(char *range, zopt_object_range_t *zor, char **msg)
*msg = "Invalid characters in object ID";
rc = 1;
}
#ifdef __APPLE__
zor->zor_obj_start = INO_XNUTOZFS(zor->zor_obj_start, 2);
#endif
zor->zor_obj_end = zor->zor_obj_start;
return (rc);
}
Expand Down Expand Up @@ -3707,6 +3710,11 @@ parse_object_range(char *range, zopt_object_range_t *zor, char **msg)
}
zor->zor_flags = flags;

#ifdef __APPLE__
zor->zor_obj_start = INO_XNUTOZFS(zor->zor_obj_start, 2);
zor->zor_obj_end = INO_XNUTOZFS(zor->zor_obj_end, 2);
#endif

out:
free(dup);
return (rc);
Expand Down
25 changes: 0 additions & 25 deletions include/os/macos/spl/sys/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,6 @@ vn_lock(struct vnode *vp, int fl)
return (0);
}

/*
* XNU reserves fileID 1-15, so we remap them high.
* 2 is root-of-the-mount.
* If ID is same as root, return 2. Otherwise, if it is 0-15, return
* adjusted, otherwise, return as-is.
* See hfs_format.h: kHFSRootFolderID, kHFSExtentsFileID, ...
*/
#define INO_ROOT 2ULL
#define INO_RESERVED 16ULL /* [0-15] reserved. */
#define INO_ISRESERVED(ID) ((ID) < (INO_RESERVED))
/* 0xFFFFFFFFFFFFFFF0 */
#define INO_MAP ((uint64_t)-INO_RESERVED) /* -16, -15, .., -1 */

#define INO_ZFSTOXNU(ID, ROOT) \
((ID) == (ROOT)?INO_ROOT:(INO_ISRESERVED(ID)?INO_MAP+(ID):(ID)))

/*
* This macro relies on *unsigned*.
* If asking for 2, return rootID. If in special range, adjust to
* normal, otherwise, return as-is.
*/
#define INO_XNUTOZFS(ID, ROOT) \
((ID) == INO_ROOT)?(ROOT): \
(INO_ISRESERVED((ID)-INO_MAP))?((ID)-INO_MAP):(ID)

#define VN_HOLD(vp) vnode_getwithref(vp)
#define VN_RELE(vp) vnode_put(vp)

Expand Down
25 changes: 25 additions & 0 deletions include/os/macos/zfs/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@

#define flock64_t struct flock

/*
* XNU reserves fileID 1-15, so we remap them high.
* 2 is root-of-the-mount.
* If ID is same as root, return 2. Otherwise, if it is 0-15, return
* adjusted, otherwise, return as-is.
* See hfs_format.h: kHFSRootFolderID, kHFSExtentsFileID, ...
*/
#define INO_ROOT 2ULL
#define INO_RESERVED 16ULL /* [0-15] reserved. */
#define INO_ISRESERVED(ID) ((ID) < (INO_RESERVED))
/* 0xFFFFFFFFFFFFFFF0 */
#define INO_MAP ((uint64_t)-INO_RESERVED) /* -16, -15, .., -1 */

#define INO_ZFSTOXNU(ID, ROOT) \
((ID) == (ROOT)?INO_ROOT:(INO_ISRESERVED(ID)?INO_MAP+(ID):(ID)))

/*
* This macro relies on *unsigned*.
* If asking for 2, return rootID. If in special range, adjust to
* normal, otherwise, return as-is.
*/
#define INO_XNUTOZFS(ID, ROOT) \
((ID) == INO_ROOT)?(ROOT): \
(INO_ISRESERVED((ID)-INO_MAP))?((ID)-INO_MAP):(ID)

struct spa_iokit;
typedef struct spa_iokit spa_iokit_t;

Expand Down
25 changes: 25 additions & 0 deletions lib/libspl/include/os/macos/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@
#define ZFS_EXPORTS_PATH "/etc/exports"
#define MNTTYPE_ZFS_SUBTYPE ('Z'<<24|'F'<<16|'S'<<8)

/*
* XNU reserves fileID 1-15, so we remap them high.
* 2 is root-of-the-mount.
* If ID is same as root, return 2. Otherwise, if it is 0-15, return
* adjusted, otherwise, return as-is.
* See hfs_format.h: kHFSRootFolderID, kHFSExtentsFileID, ...
*/
#define INO_ROOT 2ULL
#define INO_RESERVED 16ULL /* [0-15] reserved. */
#define INO_ISRESERVED(ID) ((ID) < (INO_RESERVED))
/* 0xFFFFFFFFFFFFFFF0 */
#define INO_MAP ((uint64_t)-INO_RESERVED) /* -16, -15, .., -1 */

#define INO_ZFSTOXNU(ID, ROOT) \
((ID) == (ROOT)?INO_ROOT:(INO_ISRESERVED(ID)?INO_MAP+(ID):(ID)))

/*
* This macro relies on *unsigned*.
* If asking for 2, return rootID. If in special range, adjust to
* normal, otherwise, return as-is.
*/
#define INO_XNUTOZFS(ID, ROOT) \
((ID) == INO_ROOT)?(ROOT): \
(INO_ISRESERVED((ID)-INO_MAP))?((ID)-INO_MAP):(ID)

struct spa_iokit;
typedef struct spa_iokit spa_iokit_t;

Expand Down

0 comments on commit 1cd14bf

Please sign in to comment.