diff options
Diffstat (limited to 'fs/jfs/jfs_dtree.c')
-rw-r--r-- | fs/jfs/jfs_dtree.c | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index 0ddbeceafc62..9f4ed13d9f15 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c | |||
@@ -3002,9 +3002,9 @@ static inline struct jfs_dirent *next_jfs_dirent(struct jfs_dirent *dirent) | |||
3002 | * return: offset = (pn, index) of start entry | 3002 | * return: offset = (pn, index) of start entry |
3003 | * of next jfs_readdir()/dtRead() | 3003 | * of next jfs_readdir()/dtRead() |
3004 | */ | 3004 | */ |
3005 | int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | 3005 | int jfs_readdir(struct file *file, struct dir_context *ctx) |
3006 | { | 3006 | { |
3007 | struct inode *ip = file_inode(filp); | 3007 | struct inode *ip = file_inode(file); |
3008 | struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab; | 3008 | struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab; |
3009 | int rc = 0; | 3009 | int rc = 0; |
3010 | loff_t dtpos; /* legacy OS/2 style position */ | 3010 | loff_t dtpos; /* legacy OS/2 style position */ |
@@ -3033,7 +3033,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3033 | int overflow, fix_page, page_fixed = 0; | 3033 | int overflow, fix_page, page_fixed = 0; |
3034 | static int unique_pos = 2; /* If we can't fix broken index */ | 3034 | static int unique_pos = 2; /* If we can't fix broken index */ |
3035 | 3035 | ||
3036 | if (filp->f_pos == DIREND) | 3036 | if (ctx->pos == DIREND) |
3037 | return 0; | 3037 | return 0; |
3038 | 3038 | ||
3039 | if (DO_INDEX(ip)) { | 3039 | if (DO_INDEX(ip)) { |
@@ -3045,7 +3045,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3045 | */ | 3045 | */ |
3046 | do_index = 1; | 3046 | do_index = 1; |
3047 | 3047 | ||
3048 | dir_index = (u32) filp->f_pos; | 3048 | dir_index = (u32) ctx->pos; |
3049 | 3049 | ||
3050 | if (dir_index > 1) { | 3050 | if (dir_index > 1) { |
3051 | struct dir_table_slot dirtab_slot; | 3051 | struct dir_table_slot dirtab_slot; |
@@ -3053,25 +3053,25 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3053 | if (dtEmpty(ip) || | 3053 | if (dtEmpty(ip) || |
3054 | (dir_index >= JFS_IP(ip)->next_index)) { | 3054 | (dir_index >= JFS_IP(ip)->next_index)) { |
3055 | /* Stale position. Directory has shrunk */ | 3055 | /* Stale position. Directory has shrunk */ |
3056 | filp->f_pos = DIREND; | 3056 | ctx->pos = DIREND; |
3057 | return 0; | 3057 | return 0; |
3058 | } | 3058 | } |
3059 | repeat: | 3059 | repeat: |
3060 | rc = read_index(ip, dir_index, &dirtab_slot); | 3060 | rc = read_index(ip, dir_index, &dirtab_slot); |
3061 | if (rc) { | 3061 | if (rc) { |
3062 | filp->f_pos = DIREND; | 3062 | ctx->pos = DIREND; |
3063 | return rc; | 3063 | return rc; |
3064 | } | 3064 | } |
3065 | if (dirtab_slot.flag == DIR_INDEX_FREE) { | 3065 | if (dirtab_slot.flag == DIR_INDEX_FREE) { |
3066 | if (loop_count++ > JFS_IP(ip)->next_index) { | 3066 | if (loop_count++ > JFS_IP(ip)->next_index) { |
3067 | jfs_err("jfs_readdir detected " | 3067 | jfs_err("jfs_readdir detected " |
3068 | "infinite loop!"); | 3068 | "infinite loop!"); |
3069 | filp->f_pos = DIREND; | 3069 | ctx->pos = DIREND; |
3070 | return 0; | 3070 | return 0; |
3071 | } | 3071 | } |
3072 | dir_index = le32_to_cpu(dirtab_slot.addr2); | 3072 | dir_index = le32_to_cpu(dirtab_slot.addr2); |
3073 | if (dir_index == -1) { | 3073 | if (dir_index == -1) { |
3074 | filp->f_pos = DIREND; | 3074 | ctx->pos = DIREND; |
3075 | return 0; | 3075 | return 0; |
3076 | } | 3076 | } |
3077 | goto repeat; | 3077 | goto repeat; |
@@ -3080,13 +3080,13 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3080 | index = dirtab_slot.slot; | 3080 | index = dirtab_slot.slot; |
3081 | DT_GETPAGE(ip, bn, mp, PSIZE, p, rc); | 3081 | DT_GETPAGE(ip, bn, mp, PSIZE, p, rc); |
3082 | if (rc) { | 3082 | if (rc) { |
3083 | filp->f_pos = DIREND; | 3083 | ctx->pos = DIREND; |
3084 | return 0; | 3084 | return 0; |
3085 | } | 3085 | } |
3086 | if (p->header.flag & BT_INTERNAL) { | 3086 | if (p->header.flag & BT_INTERNAL) { |
3087 | jfs_err("jfs_readdir: bad index table"); | 3087 | jfs_err("jfs_readdir: bad index table"); |
3088 | DT_PUTPAGE(mp); | 3088 | DT_PUTPAGE(mp); |
3089 | filp->f_pos = -1; | 3089 | ctx->pos = -1; |
3090 | return 0; | 3090 | return 0; |
3091 | } | 3091 | } |
3092 | } else { | 3092 | } else { |
@@ -3094,23 +3094,22 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3094 | /* | 3094 | /* |
3095 | * self "." | 3095 | * self "." |
3096 | */ | 3096 | */ |
3097 | filp->f_pos = 0; | 3097 | ctx->pos = 0; |
3098 | if (filldir(dirent, ".", 1, 0, ip->i_ino, | 3098 | if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR)) |
3099 | DT_DIR)) | ||
3100 | return 0; | 3099 | return 0; |
3101 | } | 3100 | } |
3102 | /* | 3101 | /* |
3103 | * parent ".." | 3102 | * parent ".." |
3104 | */ | 3103 | */ |
3105 | filp->f_pos = 1; | 3104 | ctx->pos = 1; |
3106 | if (filldir(dirent, "..", 2, 1, PARENT(ip), DT_DIR)) | 3105 | if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR)) |
3107 | return 0; | 3106 | return 0; |
3108 | 3107 | ||
3109 | /* | 3108 | /* |
3110 | * Find first entry of left-most leaf | 3109 | * Find first entry of left-most leaf |
3111 | */ | 3110 | */ |
3112 | if (dtEmpty(ip)) { | 3111 | if (dtEmpty(ip)) { |
3113 | filp->f_pos = DIREND; | 3112 | ctx->pos = DIREND; |
3114 | return 0; | 3113 | return 0; |
3115 | } | 3114 | } |
3116 | 3115 | ||
@@ -3128,23 +3127,19 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3128 | * pn > 0: Real entries, pn=1 -> leftmost page | 3127 | * pn > 0: Real entries, pn=1 -> leftmost page |
3129 | * pn = index = -1: No more entries | 3128 | * pn = index = -1: No more entries |
3130 | */ | 3129 | */ |
3131 | dtpos = filp->f_pos; | 3130 | dtpos = ctx->pos; |
3132 | if (dtpos == 0) { | 3131 | if (dtpos == 0) { |
3133 | /* build "." entry */ | 3132 | /* build "." entry */ |
3134 | 3133 | if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR)) | |
3135 | if (filldir(dirent, ".", 1, filp->f_pos, ip->i_ino, | ||
3136 | DT_DIR)) | ||
3137 | return 0; | 3134 | return 0; |
3138 | dtoffset->index = 1; | 3135 | dtoffset->index = 1; |
3139 | filp->f_pos = dtpos; | 3136 | ctx->pos = dtpos; |
3140 | } | 3137 | } |
3141 | 3138 | ||
3142 | if (dtoffset->pn == 0) { | 3139 | if (dtoffset->pn == 0) { |
3143 | if (dtoffset->index == 1) { | 3140 | if (dtoffset->index == 1) { |
3144 | /* build ".." entry */ | 3141 | /* build ".." entry */ |
3145 | 3142 | if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR)) | |
3146 | if (filldir(dirent, "..", 2, filp->f_pos, | ||
3147 | PARENT(ip), DT_DIR)) | ||
3148 | return 0; | 3143 | return 0; |
3149 | } else { | 3144 | } else { |
3150 | jfs_err("jfs_readdir called with " | 3145 | jfs_err("jfs_readdir called with " |
@@ -3152,18 +3147,18 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3152 | } | 3147 | } |
3153 | dtoffset->pn = 1; | 3148 | dtoffset->pn = 1; |
3154 | dtoffset->index = 0; | 3149 | dtoffset->index = 0; |
3155 | filp->f_pos = dtpos; | 3150 | ctx->pos = dtpos; |
3156 | } | 3151 | } |
3157 | 3152 | ||
3158 | if (dtEmpty(ip)) { | 3153 | if (dtEmpty(ip)) { |
3159 | filp->f_pos = DIREND; | 3154 | ctx->pos = DIREND; |
3160 | return 0; | 3155 | return 0; |
3161 | } | 3156 | } |
3162 | 3157 | ||
3163 | if ((rc = dtReadNext(ip, &filp->f_pos, &btstack))) { | 3158 | if ((rc = dtReadNext(ip, &ctx->pos, &btstack))) { |
3164 | jfs_err("jfs_readdir: unexpected rc = %d " | 3159 | jfs_err("jfs_readdir: unexpected rc = %d " |
3165 | "from dtReadNext", rc); | 3160 | "from dtReadNext", rc); |
3166 | filp->f_pos = DIREND; | 3161 | ctx->pos = DIREND; |
3167 | return 0; | 3162 | return 0; |
3168 | } | 3163 | } |
3169 | /* get start leaf page and index */ | 3164 | /* get start leaf page and index */ |
@@ -3171,7 +3166,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3171 | 3166 | ||
3172 | /* offset beyond directory eof ? */ | 3167 | /* offset beyond directory eof ? */ |
3173 | if (bn < 0) { | 3168 | if (bn < 0) { |
3174 | filp->f_pos = DIREND; | 3169 | ctx->pos = DIREND; |
3175 | return 0; | 3170 | return 0; |
3176 | } | 3171 | } |
3177 | } | 3172 | } |
@@ -3180,7 +3175,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
3180 | if (dirent_buf == 0) { | 3175 | if (dirent_buf == 0) { |
3181 | DT_PUTPAGE(mp); | 3176 | DT_PUTPAGE(mp); |
3182 | jfs_warn("jfs_readdir: __get_free_page failed!"); | 3177 | jfs_warn("jfs_readdir: __get_free_page failed!"); |
3183 | filp->f_pos = DIREND; | 3178 | ctx->pos = DIREND; |
3184 | return -ENOMEM; | 3179 | return -ENOMEM; |
3185 | } | 3180 | } |
3186 | 3181 | ||
@@ -3295,9 +3290,9 @@ skip_one: | |||
3295 | 3290 | ||
3296 | jfs_dirent = (struct jfs_dirent *) dirent_buf; | 3291 | jfs_dirent = (struct jfs_dirent *) dirent_buf; |
3297 | while (jfs_dirents--) { | 3292 | while (jfs_dirents--) { |
3298 | filp->f_pos = jfs_dirent->position; | 3293 | ctx->pos = jfs_dirent->position; |
3299 | if (filldir(dirent, jfs_dirent->name, | 3294 | if (!dir_emit(ctx, jfs_dirent->name, |
3300 | jfs_dirent->name_len, filp->f_pos, | 3295 | jfs_dirent->name_len, |
3301 | jfs_dirent->ino, DT_UNKNOWN)) | 3296 | jfs_dirent->ino, DT_UNKNOWN)) |
3302 | goto out; | 3297 | goto out; |
3303 | jfs_dirent = next_jfs_dirent(jfs_dirent); | 3298 | jfs_dirent = next_jfs_dirent(jfs_dirent); |
@@ -3309,7 +3304,7 @@ skip_one: | |||
3309 | } | 3304 | } |
3310 | 3305 | ||
3311 | if (!overflow && (bn == 0)) { | 3306 | if (!overflow && (bn == 0)) { |
3312 | filp->f_pos = DIREND; | 3307 | ctx->pos = DIREND; |
3313 | break; | 3308 | break; |
3314 | } | 3309 | } |
3315 | 3310 | ||