cifs: Alternate Data Streams: Add support
Subsystems (2)
PATCH v4 1/2 cifs: Alternate Data Streams: Add support
From: Shirish Pargaonkar <[email protected]>
Add support of Alternate Data Streams (ads).
The generic access flags that cifs client currently employs are sufficient for alternate data streams as well (MS-CIFS 2.2.4.64.1).
The stream file and stream type are specified using : after the file name, so that is used to differentiate between a regular file and its alternate data streams and stream types.
Since they all have the same file id, each path name,
file name:stream name:stream type, has a separate inode with that same file id but a distinct private data (path name) in that inode to distinguish them.
This scheme applies only to non-posix compliant servers such as Windows.
One operation that does not work is Rename (0x7).
--- fs/cifs/cifsfs.c | 1 + fs/cifs/cifsglob.h | 2 ++ fs/cifs/inode.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletions(-)
fs/cifs/cifsfs.c +1 -0
@@ -264,6 +264,7 @@ cifs_evict_inode(struct inode *inode) {truncate_inode_pages (&inode->i_data,0 );clear_inode (inode); +kfree (inode->i_private);cifs_fscache_release_inode_cookie (inode); }
fs/cifs/cifsglob.h +2 -0
@@ -1251,6 +1251,7 @@ struct dfs_info3_param {#define CIFS_FATTR_DELETE_PENDING 0x2#define CIFS_FATTR_NEED_REVAL 0x4#define CIFS_FATTR_INO_COLLISION 0x8 +#define CIFS_FATTR_ALTDATASTR 0x10struct cifs_fattr {u32 cf_flags;
@@ -1268,6 +1269,7 @@ struct cifs_fattr {struct timespec cf_atime;struct timespec cf_mtime;struct timespec cf_ctime; +char *cf_private; };static inline void free_dfs_info_param (struct dfs_info3_param *param)
fs/cifs/inode.c +33 -1
@@ -615,10 +615,12 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,struct tcon_link *tlink;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);char *buf =NULL ; +char *altstr =NULL ;bool adjust_tz = false;struct cifs_fattr fattr;struct cifs_search_info *srchinf =NULL ; + fattr.cf_private =NULL ; tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink))return PTR_ERR (tlink);
@@ -746,14 +748,34 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, }if (!*inode) { + altstr =strchr (full_path,':' ); +if (altstr) { + fattr.cf_private =kstrdup (altstr,GFP_KERNEL ); +if (!fattr.cf_private) { + rc = -ENOMEM ; + goto cgii_exit; + } + fattr.cf_flags |=CIFS_FATTR_ALTDATASTR ; + } + *inode =cifs_iget (sb, &fattr); -if (!*inode) +if (*inode) { +if (altstr && !((*inode)->i_flags &S_PRIVATE )) { + (*inode)->i_private = +kstrdup (altstr,GFP_KERNEL ); +if ((*inode)->i_private) + (*inode)->i_flags |=S_PRIVATE ; +else + rc = -ENOMEM ; + } + }else rc = -ENOMEM ; }else {cifs_fattr_to_inode (*inode, &fattr); } cgii_exit: +kfree (fattr.cf_private);kfree (buf);cifs_put_tlink (tlink);return rc;
@@ -784,6 +806,16 @@ cifs_find_inode(struct inode *inode, void *opaque)if (S_ISDIR (inode->i_mode) && !hlist_empty (&inode->i_dentry)) fattr->cf_flags |=CIFS_FATTR_INO_COLLISION ; +/* looking for an inode of a alternate data stream (full pathname) */ +if (fattr->cf_flags &CIFS_FATTR_ALTDATASTR ) { +if (!(inode->i_flags &S_PRIVATE )) { +return 0 ; + }else { +if (strcmp (inode->i_private, fattr->cf_private)) +return 0 ; + } + } +return 1 ; }
Signature · 1 line
1.6.0.2
A message that is not in the archive (sent off-list or not yet received): 1350739560-9197-1-git-send-email-shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 33 lines · On Sat, 20 Oct 2012 08:26:00 -0500 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…
From: Shirish Pargaonkar <[email protected]>
Add support of Alternate Data Streams (ads).
The generic access flags that cifs client currently employs are sufficient for alternate data streams as well (MS-CIFS 2.2.4.64.1).
The stream file and stream type are specified using : after the file name, so that is used to differentiate between a regular file and its alternate data streams and stream types.
Since they all have the same file id, each path name,
file name:stream name:stream type, has a separate inode with that same file id but a distinct private data (path name) in that inode to distinguish them.This scheme applies only to non-posix compliant servers such as Windows.
One operation that does not work is Rename (
0x7).Signed-off-by Shirish Pargaonkar <[email protected]>--- fs/cifs/cifsfs.c | 1 + fs/cifs/cifsglob.h | 2 ++ fs/cifs/inode.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletions(-)fs/cifs/cifsfs.c +0
-0
fs/cifs/cifsfs.c cifs_evict_inode(struct inode *inode) · line 267
Quoted 4 lines
fs/cifs/cifsfs.c +1
-0@@ -264,6 +264,7 @@ cifs_evict_inode(struct inode *inode) {truncate_inode_pages (&inode->i_data,0 );clear_inode (inode); +kfree (inode->i_private);
Are you sure that i_private is always initialized to NULL? Hmm...looks like they probably are in inode_init_always. Ok...
Quoted 56 lines
fs/cifs/cifsfs.c +0
-0cifs_fscache_release_inode_cookie (inode); }fs/cifs/cifsglob.h +2
-0@@ -1251,6 +1251,7 @@ struct dfs_info3_param {#define CIFS_FATTR_DELETE_PENDING 0x2#define CIFS_FATTR_NEED_REVAL 0x4#define CIFS_FATTR_INO_COLLISION 0x8 +#define CIFS_FATTR_ALTDATASTR 0x10struct cifs_fattr {u32 cf_flags;@@ -1268,6 +1269,7 @@ struct cifs_fattr {struct timespec cf_atime;struct timespec cf_mtime;struct timespec cf_ctime; +char *cf_private; };static inline void free_dfs_info_param (struct dfs_info3_param *param)fs/cifs/inode.c +12
-1@@ -615,10 +615,12 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,struct tcon_link *tlink;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);char *buf =NULL ; +char *altstr =NULL ;bool adjust_tz = false;struct cifs_fattr fattr;struct cifs_search_info *srchinf =NULL ; + fattr.cf_private =NULL ; tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink))return PTR_ERR (tlink);@@ -746,14 +748,34 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, }if (!*inode) { + altstr =strchr (full_path,':' ); +if (altstr) { + fattr.cf_private =kstrdup (altstr,GFP_KERNEL ); +if (!fattr.cf_private) { + rc = -ENOMEM ; + goto cgii_exit; + } + fattr.cf_flags |=CIFS_FATTR_ALTDATASTR ; + } + *inode =cifs_iget (sb, &fattr); -if (!*inode)
fs/cifs/inode.c cifs_get_inode_info(struct inode **inode, const char *full_path, · line 771
Quoted 10 lines
fs/cifs/inode.c +10
-0+if (*inode) { +if (altstr && !((*inode)->i_flags &S_PRIVATE )) { + (*inode)->i_private = +kstrdup (altstr,GFP_KERNEL ); +if ((*inode)->i_private) + (*inode)->i_flags |=S_PRIVATE ; +else + rc = -ENOMEM ; + } + }else
^^^^^
Why redo the allocation and copy here? You could just hand off the one you just allocated...
Quoted 17 lines
fs/cifs/inode.c +4
-0rc = -ENOMEM ; }else {cifs_fattr_to_inode (*inode, &fattr); } cgii_exit: +kfree (fattr.cf_private);kfree (buf);cifs_put_tlink (tlink);return rc;@@ -784,6 +806,16 @@ cifs_find_inode(struct inode *inode, void *opaque)if (S_ISDIR (inode->i_mode) && !hlist_empty (&inode->i_dentry)) fattr->cf_flags |=CIFS_FATTR_INO_COLLISION ; +/* looking for an inode of a alternate data stream (full pathname) */ +if (fattr->cf_flags &CIFS_FATTR_ALTDATASTR ) { +if (!(inode->i_flags &S_PRIVATE )) {
fs/cifs/inode.c cifs_find_inode(struct inode *inode, void *opaque) · line 821
Quoted 10 lines
fs/cifs/inode.c +7
-0+return 0 ; + }else { +if (strcmp (inode->i_private, fattr->cf_private)) +return 0 ; + } + } +return 1 ; }
Looks like S_PRIVATE has some other security/permissions related effects. Do you expect any behavior change from using it here?
Signature · 1 line
Jeff Layton <[email protected]>