[patch 3/3] optimize attribute sending

Miklos Szeredi miklos at szeredi.hu
Fri Feb 13 08:28:14 EST 2009


This patch turns off sending unnecessary attributes:

  - the nanosecond part of timestamps if they are zero
  - the 32bit atime and mtime if the 64bit atime/mtime are sent

Index: ssh/sftp-common.c
===================================================================
--- ssh.orig/sftp-common.c	2009-02-12 14:11:31.000000000 +0100
+++ ssh/sftp-common.c	2009-02-12 15:54:13.000000000 +0100
@@ -87,12 +87,18 @@ stat_to_attrib(const struct stat *st, At
 	a->mtime = st->st_mtime;
 	a->ext_flags |= SSH2_FXE_EXTATTR_CTIME;
 	a->ctime = st->st_ctime;
-	a->ext_flags |= SSH2_FXE_EXTATTR_ATIMENSEC;
-	a->atimensec = st->st_atimensec;
-	a->ext_flags |= SSH2_FXE_EXTATTR_MTIMENSEC;
-	a->mtimensec = st->st_mtimensec;
-	a->ext_flags |= SSH2_FXE_EXTATTR_CTIMENSEC;
-	a->ctimensec = st->st_ctimensec;
+	if (st->st_atimensec) {
+		a->ext_flags |= SSH2_FXE_EXTATTR_ATIMENSEC;
+		a->atimensec = st->st_atimensec;
+	}
+	if (st->st_mtimensec) {
+		a->ext_flags |= SSH2_FXE_EXTATTR_MTIMENSEC;
+		a->mtimensec = st->st_mtimensec;
+	}
+	if (st->st_ctimensec) {
+		a->ext_flags |= SSH2_FXE_EXTATTR_CTIMENSEC;
+		a->ctimensec = st->st_ctimensec;
+	}
 	a->ext_flags |= SSH2_FXE_EXTATTR_DEV;
 	a->dev = st->st_dev;
 	a->ext_flags |= SSH2_FXE_EXTATTR_INO;
Index: ssh/sftp-server.c
===================================================================
--- ssh.orig/sftp-server.c	2009-02-12 14:37:39.000000000 +0100
+++ ssh/sftp-server.c	2009-02-12 16:00:10.000000000 +0100
@@ -1271,6 +1271,13 @@ process_extended_attrconfig(u_int32_t id
 	mask = get_int();
 	dir_ext_attr_mask = mask & SUPPORTED_EXT_ATTR;
 
+	if ((stat_ext_attr_mask & SSH2_FXE_EXTATTR_ATIME) &&
+	    (stat_ext_attr_mask & SSH2_FXE_EXTATTR_MTIME))
+		stat_attr_mask &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
+	if ((dir_ext_attr_mask & SSH2_FXE_EXTATTR_ATIME) &&
+	    (dir_ext_attr_mask & SSH2_FXE_EXTATTR_MTIME))
+		dir_attr_mask &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
+
 	debug3("request %u: attrconfig", id);
 
 	send_attrconfig_reply(id);


More information about the openssh-unix-dev mailing list