]> Pileus Git - ~andy/linux/blobdiff - fs/cifs/readdir.c
[CIFS] mtime bounces from local to remote when cifs nocmtime i_flags overwritten
[~andy/linux] / fs / cifs / readdir.c
index 80e6ebd440a853b6dc2df1467abd5b6fc7779e6f..c444798f0740f91da21052def00e2a9852c383a8 100644 (file)
@@ -68,36 +68,40 @@ static int construct_dentry(struct qstr *qstring, struct file *file,
        int rc = 0;
 
        cFYI(1, ("For %s", qstring->name));
-       cifs_sb = CIFS_SB(file->f_dentry->d_sb);
+       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        pTcon = cifs_sb->tcon;
 
        qstring->hash = full_name_hash(qstring->name, qstring->len);
-       tmp_dentry = d_lookup(file->f_dentry, qstring);
+       tmp_dentry = d_lookup(file->f_path.dentry, qstring);
        if (tmp_dentry) {
                cFYI(0, ("existing dentry with inode 0x%p", tmp_dentry->d_inode));
                *ptmp_inode = tmp_dentry->d_inode;
 /* BB overwrite old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len??*/
                if(*ptmp_inode == NULL) {
-                       *ptmp_inode = new_inode(file->f_dentry->d_sb);
+                       *ptmp_inode = new_inode(file->f_path.dentry->d_sb);
                        if(*ptmp_inode == NULL)
                                return rc;
                        rc = 1;
                }
+               if(file->f_path.dentry->d_sb->s_flags & MS_NOATIME)
+                       (*ptmp_inode)->i_flags |= S_NOATIME | S_NOCMTIME;
        } else {
-               tmp_dentry = d_alloc(file->f_dentry, qstring);
+               tmp_dentry = d_alloc(file->f_path.dentry, qstring);
                if(tmp_dentry == NULL) {
                        cERROR(1,("Failed allocating dentry"));
                        *ptmp_inode = NULL;
                        return rc;
                }
 
-               *ptmp_inode = new_inode(file->f_dentry->d_sb);
+               *ptmp_inode = new_inode(file->f_path.dentry->d_sb);
                if (pTcon->nocase)
                        tmp_dentry->d_op = &cifs_ci_dentry_ops;
                else
                        tmp_dentry->d_op = &cifs_dentry_ops;
                if(*ptmp_inode == NULL)
                        return rc;
+               if(file->f_path.dentry->d_sb->s_flags & MS_NOATIME)
+                       (*ptmp_inode)->i_flags |= S_NOATIME | S_NOCMTIME;                       
                rc = 2;
        }
 
@@ -109,9 +113,9 @@ static int construct_dentry(struct qstr *qstring, struct file *file,
 static void AdjustForTZ(struct cifsTconInfo * tcon, struct inode * inode)
 {
        if((tcon) && (tcon->ses) && (tcon->ses->server)) {
-               inode->i_ctime.tv_sec += tcon->ses->server.timeAdj;
-               inode->i_mtime.tv_sec += tcon->ses->server.timeAdj;
-               inode->i_atime.tv_sec += tcon->ses->server.timeAdj;
+               inode->i_ctime.tv_sec += tcon->ses->server->timeAdj;
+               inode->i_mtime.tv_sec += tcon->ses->server->timeAdj;
+               inode->i_atime.tv_sec += tcon->ses->server->timeAdj;
        }
        return;
 }
@@ -156,9 +160,9 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
                tmp_inode->i_atime = cnvrtDosUnixTm(
                                le16_to_cpu(pfindData->LastAccessDate),
                                le16_to_cpu(pfindData->LastAccessTime));
-                tmp_inode->i_ctime = cnvrtDosUnixTm(
-                                le16_to_cpu(pfindData->LastWriteDate),
-                                le16_to_cpu(pfindData->LastWriteTime));
+               tmp_inode->i_ctime = cnvrtDosUnixTm(
+                               le16_to_cpu(pfindData->LastWriteDate),
+                               le16_to_cpu(pfindData->LastWriteTime));
                AdjustForTZ(cifs_sb->tcon, tmp_inode);
                attr = le16_to_cpu(pfindData->Attributes);
                allocation_size = le32_to_cpu(pfindData->AllocationSize);
@@ -222,7 +226,7 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
                atomic_set(&cifsInfo->inUse, 1);
        }
 
-       if (is_size_safe_to_change(cifsInfo)) {
+       if (is_size_safe_to_change(cifsInfo, end_of_file)) {
                /* can not safely change the file size here if the 
                client is writing to it due to potential races */
                i_size_write(tmp_inode, end_of_file);
@@ -234,10 +238,9 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
 
        if (allocation_size < end_of_file)
                cFYI(1, ("May be sparse file, allocation less than file size"));
-       cFYI(1, ("File Size %ld and blocks %llu and blocksize %ld",
+       cFYI(1, ("File Size %ld and blocks %llu",
                (unsigned long)tmp_inode->i_size,
-               (unsigned long long)tmp_inode->i_blocks,
-               tmp_inode->i_blksize));
+               (unsigned long long)tmp_inode->i_blocks));
        if (S_ISREG(tmp_inode->i_mode)) {
                cFYI(1, ("File inode"));
                tmp_inode->i_op = &cifs_file_inode_ops;
@@ -352,10 +355,10 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
        tmp_inode->i_gid = le64_to_cpu(pfindData->Gid);
        tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks);
 
-       if (is_size_safe_to_change(cifsInfo)) {
+       if (is_size_safe_to_change(cifsInfo, end_of_file)) {
                /* can not safely change the file size here if the 
                client is writing to it due to potential races */
-               i_size_write(tmp_inode,end_of_file);
+               i_size_write(tmp_inode, end_of_file);
 
        /* 512 bytes (2**9) is the fake blocksize that must be used */
        /* for this calculation, not the real blocksize */
@@ -433,10 +436,10 @@ static int initiate_cifs_search(const int xid, struct file *file)
        cifsFile->invalidHandle = TRUE;
        cifsFile->srch_inf.endOfSearch = FALSE;
 
-       if(file->f_dentry == NULL)
+       if(file->f_path.dentry == NULL)
                return -ENOENT;
 
-       cifs_sb = CIFS_SB(file->f_dentry->d_sb);
+       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        if(cifs_sb == NULL)
                return -EINVAL;
 
@@ -444,7 +447,7 @@ static int initiate_cifs_search(const int xid, struct file *file)
        if(pTcon == NULL)
                return -EINVAL;
 
-       full_path = build_path_from_dentry(file->f_dentry);
+       full_path = build_path_from_dentry(file->f_path.dentry);
 
        if(full_path == NULL) {
                return -ENOMEM;
@@ -610,10 +613,10 @@ static int is_dir_changed(struct file * file)
        struct inode * inode;
        struct cifsInodeInfo *cifsInfo;
 
-       if(file->f_dentry == NULL)
+       if(file->f_path.dentry == NULL)
                return 0;
 
-       inode = file->f_dentry->d_inode;
+       inode = file->f_path.dentry->d_inode;
 
        if(inode == NULL)
                return 0;
@@ -840,7 +843,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
        if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
                return -ENOENT;
 
-       if(file->f_dentry == NULL)
+       if(file->f_path.dentry == NULL)
                return -ENOENT;
 
        rc = cifs_entry_is_dot(pfindEntry,pCifsF);
@@ -848,7 +851,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
        if(rc != 0) 
                return 0;
 
-       cifs_sb = CIFS_SB(file->f_dentry->d_sb);
+       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
 
        qstring.name = scratch_buf;
        rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
@@ -897,6 +900,10 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
                     tmp_inode->i_ino,obj_type);
        if(rc) {
                cFYI(1,("filldir rc = %d",rc));
+               /* we can not return filldir errors to the caller
+               since they are "normal" when the stat blocksize
+               is too small - we return remapped error instead */
+               rc = -EOVERFLOW;
        }
 
        dput(tmp_dentry);
@@ -982,12 +989,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
 
        xid = GetXid();
 
-       if(file->f_dentry == NULL) {
+       if(file->f_path.dentry == NULL) {
                FreeXid(xid);
                return -EIO;
        }
 
-       cifs_sb = CIFS_SB(file->f_dentry->d_sb);
+       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        pTcon = cifs_sb->tcon;
        if(pTcon == NULL)
                return -EINVAL;
@@ -995,7 +1002,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
        switch ((int) file->f_pos) {
        case 0:
                if (filldir(direntry, ".", 1, file->f_pos,
-                    file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
+                    file->f_path.dentry->d_inode->i_ino, DT_DIR) < 0) {
                        cERROR(1, ("Filldir for current dir failed"));
                        rc = -ENOMEM;
                        break;
@@ -1003,7 +1010,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                file->f_pos++;
        case 1:
                if (filldir(direntry, "..", 2, file->f_pos,
-                    file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
+                    file->f_path.dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
                        cERROR(1, ("Filldir for parent dir failed"));
                        rc = -ENOMEM;
                        break;
@@ -1075,6 +1082,11 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                        we want to check for that here? */
                        rc = cifs_filldir(current_entry, file,
                                        filldir, direntry, tmp_buf, max_len);
+                       if(rc == -EOVERFLOW) {
+                               rc = 0;
+                               break;
+                       }
+
                        file->f_pos++;
                        if(file->f_pos == 
                                cifsFile->srch_inf.index_of_last_entry) {