Skip to content

Commit

Permalink
Add DOCUMENT_ID and WRITE_GENCOUNT support
Browse files Browse the repository at this point in the history
Add new	getattr fields DOCUMENT_ID and WRITE_GENCOUNT.
Implement new HFS ioctl	HFS_GETPATH,HFS_TRANSFER_DOCUMENT_ID,F_MAKECOMPRESSED
Add new chflags (zfs_setbsdflag) UF_TRACKED, to	store DOCUMENT_ID in
the SA attributes.
Update sa.c to ZOL's latest, more correct version.

TODO: HFS, once UF_TRACKED is set, if file is deleted, then recreated with
same name, it will get UF_TRACKED set again. Our DocumentID will match, but
we do not set UF_TRACKED. Suggested implementation is to store DocumentID
in a list, in zfs_remove for UF_TRACKED objects. Then in getattr for DocumentID
(when "not set"->"set") scan the list, and on match, call zfs_setattr_set_documentid.
List need not survive unmount.
  • Loading branch information
lundman authored and ilovezfs committed Oct 21, 2015
1 parent 0e71773 commit 4954eb6
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 278 deletions.
10 changes: 10 additions & 0 deletions include/sys/hfs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ struct user64_ext_access_t {
#define HFSIOC_GET_DESIRED_DISK _IOR('h', 29, u_int32_t)
#define HFS_FSCTL_GET_DESIRED_DISK IOCBASECMD(HFSIOC_GET_DESIRED_DISK)

/* revisiond only uses this when something transforms in a way the kernel can't track
such as "foo.rtf" -> "foo.rtfd" */
#define HFSIOC_TRANSFER_DOCUMENT_ID _IOW('h', 32, u_int32_t)
#define HFS_TRANSFER_DOCUMENT_ID IOCBASECMD(HFSIOC_TRANSFER_DOCUMENT_ID)


/* fcntl.h */
#define F_MAKECOMPRESSED 80 /* Make the file compressed; truncate & toggle BSD bits */


// END of definitions

#endif
22 changes: 21 additions & 1 deletion include/sys/zfs_znode.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ extern "C" {
#define ZFS_OFFLINE 0x0000100000000000ull
#define ZFS_SPARSE 0x0000200000000000ull

#ifdef __APPLE__
/* Unsure how we officially register new flags bits, but
* I guess we will claim the whole nibble for OSX
* 0x00n0000000000000ull : n = 1 2 4 8
*/
#define ZFS_TRACKED 0x0010000000000000ull
#endif

#define ZFS_ATTR_SET(zp, attr, value, pflags, tx) \
{ \
if (value) \
Expand Down Expand Up @@ -237,6 +245,7 @@ typedef struct znode {
#ifdef __APPLE__
list_node_t z_link_reclaim_node; /* all reclaim znodes in fs link */
uint32_t z_vid; /* OSX vnode_vid */
uint32_t z_document_id;
/* Track vnop_lookup name for Finder - not for anything else */
char z_finder_hardlink_name[MAXPATHLEN];
boolean_t z_fastpath;
Expand Down Expand Up @@ -290,7 +299,11 @@ typedef struct znode {
*/
#define ZFS_ENTER(zfsvfs) \
{ \
rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \
if (!POINTER_IS_VALID(zfsvfs)) { \
printf("ZFS: ZFS_ENTER on released %s:%d", \
__FILE__, __LINE__); \
return EIO; } \
rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \
if ((zfsvfs)->z_unmounted) { \
ZFS_EXIT(zfsvfs); \
return (EIO); \
Expand Down Expand Up @@ -445,6 +458,13 @@ int zfs_attach_vnode(znode_t *zp);
uint32_t zfs_getbsdflags(znode_t *zp);
void zfs_setbsdflags(znode_t *zp, uint32_t bsdflags);
void zfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx);
int zfs_setattr_set_documentid(znode_t *zp, boolean_t update_flags);
void zfs_setattr_generate_id(znode_t *zp, uint64_t val, char *name);

#define FNV1_32A_INIT ((uint32_t)0x811c9dc5)
uint32_t fnv_32a_str(const char *str, uint32_t hval);
uint32_t fnv_32a_buf(void *buf, size_t len, uint32_t hval);


#ifdef ZFS_DEBUG
typedef enum whereami {
Expand Down
83 changes: 0 additions & 83 deletions module/zfs/zfs_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,93 +143,10 @@ zfs_vfs_sysctl(int *name, __unused u_int namelen, user_addr_t oldp, size_t *oldl
#endif /* __APPLE__ */





#include <sys/utsname.h>
#include <string.h>


/*
* fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
*
* input:
* str - string to hash
* hval - previous hash value or 0 if first call
*
* returns:
* 32 bit hash as a static hash type
*
* NOTE: To use the recommended 32 bit FNV-1a hash, use FNV1_32A_INIT as the
* hval arg on the first call to either fnv_32a_buf() or fnv_32a_str().
*/
#define FNV1_32A_INIT ((uint32_t)0x811c9dc5)
uint32_t
fnv_32a_str(const char *str, uint32_t hval)
{
unsigned char *s = (unsigned char *)str; /* unsigned string */

/*
* FNV-1a hash each octet in the buffer
*/
while (*s) {

/* xor the bottom with the current octet */
hval ^= (uint32_t)*s++;

/* multiply by the 32 bit FNV magic prime mod 2^32 */
#if defined(NO_FNV_GCC_OPTIMIZATION)
hval *= FNV_32_PRIME;
#else
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
#endif
}

/* return our new hash value */
return hval;
}

/*
* fnv_32a_buf - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a buffer
*
* input:
*buf- start of buffer to hash
*len- length of buffer in octets
*hval- previous hash value or 0 if first call
*
* returns:
*32 bit hash as a static hash type
*
* NOTE: To use the recommended 32 bit FNV-1a hash, use FNV1_32A_INIT as the
* hval arg on the first call to either fnv_32a_buf() or fnv_32a_str().
*/
uint32_t
fnv_32a_buf(void *buf, size_t len, uint32_t hval)
{
unsigned char *bp = (unsigned char *)buf;/* start of buffer */
unsigned char *be = bp + len;/* beyond end of buffer */

/*
* FNV-1a hash each octet in the buffer
*/
while (bp < be) {

/* xor the bottom with the current octet */
hval ^= (uint32_t)*bp++;

/* multiply by the 32 bit FNV magic prime mod 2^32 */
#if defined(NO_FNV_GCC_OPTIMIZATION)
hval *= FNV_32_PRIME;
#else
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
#endif
}

/* return our new hash value */
return hval;
}


} // Extern "C"


Expand Down
Loading

0 comments on commit 4954eb6

Please sign in to comment.