Merge to kernel-2.6.20-1.2949.fc6.vs2.2.0.1
[linux-2.6.git] / fs / cifs / readdir.c
index 1596f39..d1d79fe 100644 (file)
@@ -68,30 +68,30 @@ 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;
                }
        } 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
@@ -106,6 +106,17 @@ static int construct_dentry(struct qstr *qstring, struct file *file,
        return rc;
 }
 
+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;
+       }
+       return;
+}
+
+
 static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
                char * buf, int *pobject_type, int isNewInode)
 {
@@ -135,16 +146,23 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
                tmp_inode->i_ctime =
                      cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
        } else { /* legacy, OS2 and DOS style */
+/*             struct timespec ts;*/
                FIND_FILE_STANDARD_INFO * pfindData = 
                        (FIND_FILE_STANDARD_INFO *)buf;
 
+               tmp_inode->i_mtime = cnvrtDosUnixTm(
+                               le16_to_cpu(pfindData->LastWriteDate),
+                               le16_to_cpu(pfindData->LastWriteTime));
+               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));
+               AdjustForTZ(cifs_sb->tcon, tmp_inode);
                attr = le16_to_cpu(pfindData->Attributes);
                allocation_size = le32_to_cpu(pfindData->AllocationSize);
                end_of_file = le32_to_cpu(pfindData->DataSize);
-               tmp_inode->i_atime = CURRENT_TIME;
-               /* tmp_inode->i_mtime =  BB FIXME - add dos time handling
-               tmp_inode->i_ctime = 0;   BB FIXME */
-
        }
 
        /* Linux can not store file creation time unfortunately so ignore it */
@@ -197,6 +215,10 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
                tmp_inode->i_mode |= S_IFREG;
                if (attr & ATTR_READONLY)
                        tmp_inode->i_mode &= ~(S_IWUGO);
+               else if ((tmp_inode->i_mode & S_IWUGO) == 0)
+                       /* the ATTR_READONLY flag may have been changed on   */
+                       /* server -- set any w bits allowed by mnt_file_mode */
+                       tmp_inode->i_mode |= (S_IWUGO & cifs_sb->mnt_file_mode);
        } /* could add code here - to validate if device or weird share type? */
 
        /* can not fill in nlink here as in qpathinfo version and Unx search */
@@ -414,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;
 
@@ -425,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;
@@ -591,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;
@@ -821,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);
@@ -829,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,
@@ -878,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);
@@ -938,6 +964,7 @@ static int cifs_save_resume_key(const char *current_entry,
                filename = &pFindData->FileName[0];
                /* one byte length, no name conversion */
                len = (unsigned int)pFindData->FileNameLength;
+               cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
        } else {
                cFYI(1,("Unknown findfirst level %d",level));
                return -EINVAL;
@@ -962,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;
@@ -975,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;
@@ -983,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;
@@ -1055,7 +1082,7 @@ 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!=0) {
+                       if(rc == -EOVERFLOW) {
                                rc = 0;
                                break;
                        }