Blame view
fs/udf/dir.c
4.93 KB
1da177e4c
|
1 2 3 4 5 6 |
/* * dir.c * * PURPOSE * Directory handling routines for the OSTA-UDF(tm) filesystem. * |
1da177e4c
|
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
* COPYRIGHT * This file is distributed under the terms of the GNU General Public * License (GPL). Copies of the GPL can be obtained from: * ftp://prep.ai.mit.edu/pub/gnu/GPL * Each contributing author retains all rights to their own work. * * (C) 1998-2004 Ben Fennema * * HISTORY * * 10/05/98 dgb Split directory operations into its own file * Implemented directory reads via do_udf_readdir * 10/06/98 Made directory operations work! * 11/17/98 Rewrote directory to support ICBTAG_FLAG_AD_LONG * 11/25/98 blf Rewrote directory handling (readdir+lookup) to support reading * across blocks. * 12/12/98 Split out the lookup code to namei.c. bulk of directory * code now in directory.c:udf_fileident_read. */ #include "udfdecl.h" #include <linux/string.h> #include <linux/errno.h> #include <linux/mm.h> #include <linux/slab.h> |
1da177e4c
|
33 34 35 |
#include "udf_i.h" #include "udf_sb.h" |
5add2ee19
|
36 37 |
static int udf_readdir(struct file *file, struct dir_context *ctx) |
1da177e4c
|
38 |
{ |
5add2ee19
|
39 40 |
struct inode *dir = file_inode(file); struct udf_inode_info *iinfo = UDF_I(dir); |
b80697c14
|
41 |
struct udf_fileident_bh fibh = { .sbh = NULL, .ebh = NULL}; |
cb00ea352
|
42 |
struct fileIdentDesc *fi = NULL; |
1da177e4c
|
43 44 |
struct fileIdentDesc cfi; int block, iblock; |
5add2ee19
|
45 |
loff_t nf_pos; |
1da177e4c
|
46 |
int flen; |
391e8bbd3
|
47 48 |
unsigned char *fname = NULL; unsigned char *nameptr; |
1da177e4c
|
49 50 |
uint16_t liu; uint8_t lfi; |
e28d80f18
|
51 |
loff_t size = udf_ext0_offset(dir) + dir->i_size; |
ff116fc8d
|
52 |
struct buffer_head *tmp, *bha[16]; |
5ca4e4be8
|
53 |
struct kernel_lb_addr eloc; |
ff116fc8d
|
54 |
uint32_t elen; |
60448b1d6
|
55 |
sector_t offset; |
b80697c14
|
56 |
int i, num, ret = 0; |
cb00ea352
|
57 |
struct extent_position epos = { NULL, 0, {0, 0} }; |
3ee3039c5
|
58 |
struct super_block *sb = dir->i_sb; |
1da177e4c
|
59 |
|
5add2ee19
|
60 61 62 63 64 65 |
if (ctx->pos == 0) { if (!dir_emit_dot(file, ctx)) return 0; ctx->pos = 1; } nf_pos = (ctx->pos - 1) << 2; |
1da177e4c
|
66 |
if (nf_pos >= size) |
b80697c14
|
67 68 69 70 71 72 73 |
goto out; fname = kmalloc(UDF_NAME_LEN, GFP_NOFS); if (!fname) { ret = -ENOMEM; goto out; } |
1da177e4c
|
74 75 |
if (nf_pos == 0) |
e28d80f18
|
76 |
nf_pos = udf_ext0_offset(dir); |
1da177e4c
|
77 |
|
3ee3039c5
|
78 |
fibh.soffset = fibh.eoffset = nf_pos & (sb->s_blocksize - 1); |
b80697c14
|
79 |
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
3ee3039c5
|
80 |
if (inode_bmap(dir, nf_pos >> sb->s_blocksize_bits, |
b80697c14
|
81 82 83 84 85 |
&epos, &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) { ret = -ENOENT; goto out; } |
3ee3039c5
|
86 87 |
block = udf_get_lb_pblock(sb, &eloc, offset); if ((++offset << sb->s_blocksize_bits) < elen) { |
48d6d8ff7
|
88 |
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
5ca4e4be8
|
89 |
epos.offset -= sizeof(struct short_ad); |
48d6d8ff7
|
90 |
else if (iinfo->i_alloc_type == |
c0b344385
|
91 |
ICBTAG_FLAG_AD_LONG) |
5ca4e4be8
|
92 |
epos.offset -= sizeof(struct long_ad); |
28de7948a
|
93 |
} else { |
1da177e4c
|
94 |
offset = 0; |
28de7948a
|
95 |
} |
1da177e4c
|
96 |
|
3ee3039c5
|
97 |
if (!(fibh.sbh = fibh.ebh = udf_tread(sb, block))) { |
b80697c14
|
98 99 |
ret = -EIO; goto out; |
1da177e4c
|
100 |
} |
cb00ea352
|
101 |
|
3ee3039c5
|
102 103 104 105 |
if (!(offset & ((16 >> (sb->s_blocksize_bits - 9)) - 1))) { i = 16 >> (sb->s_blocksize_bits - 9); if (i + offset > (elen >> sb->s_blocksize_bits)) i = (elen >> sb->s_blocksize_bits) - offset; |
cb00ea352
|
106 |
for (num = 0; i > 0; i--) { |
3ee3039c5
|
107 108 |
block = udf_get_lb_pblock(sb, &eloc, offset + i); tmp = udf_tgetblk(sb, block); |
28de7948a
|
109 |
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) |
1da177e4c
|
110 111 112 113 |
bha[num++] = tmp; else brelse(tmp); } |
cb00ea352
|
114 |
if (num) { |
1da177e4c
|
115 |
ll_rw_block(READA, num, bha); |
cb00ea352
|
116 |
for (i = 0; i < num; i++) |
1da177e4c
|
117 118 119 |
brelse(bha[i]); } } |
1da177e4c
|
120 |
} |
cb00ea352
|
121 |
while (nf_pos < size) { |
5add2ee19
|
122 123 124 |
struct kernel_lb_addr tloc; ctx->pos = (nf_pos >> 2) + 1; |
1da177e4c
|
125 |
|
cb00ea352
|
126 127 |
fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset); |
b80697c14
|
128 129 |
if (!fi) goto out; |
1da177e4c
|
130 131 132 |
liu = le16_to_cpu(cfi.lengthOfImpUse); lfi = cfi.lengthFileIdent; |
28de7948a
|
133 |
if (fibh.sbh == fibh.ebh) { |
1da177e4c
|
134 |
nameptr = fi->fileIdent + liu; |
28de7948a
|
135 |
} else { |
1da177e4c
|
136 |
int poffset; /* Unpaded ending offset */ |
28de7948a
|
137 |
poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi; |
1da177e4c
|
138 |
|
28de7948a
|
139 140 141 |
if (poffset >= lfi) { nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); } else { |
1da177e4c
|
142 |
nameptr = fname; |
cb00ea352
|
143 144 145 146 |
memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); memcpy(nameptr + lfi - poffset, fibh.ebh->b_data, poffset); |
1da177e4c
|
147 148 |
} } |
cb00ea352
|
149 |
if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { |
3ee3039c5
|
150 |
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE)) |
1da177e4c
|
151 152 |
continue; } |
cb00ea352
|
153 154 |
if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { |
3ee3039c5
|
155 |
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE)) |
1da177e4c
|
156 157 |
continue; } |
cb00ea352
|
158 |
if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) { |
5add2ee19
|
159 160 161 |
if (!dir_emit_dotdot(file, ctx)) goto out; continue; |
1da177e4c
|
162 |
} |
3ee3039c5
|
163 |
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); |
6ce638367
|
164 |
if (flen < 0) |
5add2ee19
|
165 166 167 |
continue; tloc = lelb_to_cpu(cfi.icb.extLocation); |
3ee3039c5
|
168 |
iblock = udf_get_lb_pblock(sb, &tloc, 0); |
5add2ee19
|
169 |
if (!dir_emit(ctx, fname, flen, iblock, DT_UNKNOWN)) |
b80697c14
|
170 |
goto out; |
28de7948a
|
171 |
} /* end while */ |
1da177e4c
|
172 |
|
5add2ee19
|
173 |
ctx->pos = (nf_pos >> 2) + 1; |
1da177e4c
|
174 |
|
b80697c14
|
175 |
out: |
1da177e4c
|
176 |
if (fibh.sbh != fibh.ebh) |
3bf25cb40
|
177 178 179 |
brelse(fibh.ebh); brelse(fibh.sbh); brelse(epos.bh); |
b80697c14
|
180 |
kfree(fname); |
1da177e4c
|
181 |
|
b80697c14
|
182 |
return ret; |
1da177e4c
|
183 |
} |
934c5e601
|
184 |
|
934c5e601
|
185 186 |
/* readdir and lookup functions */ const struct file_operations udf_dir_operations = { |
ca572727d
|
187 |
.llseek = generic_file_llseek, |
934c5e601
|
188 |
.read = generic_read_dir, |
5add2ee19
|
189 |
.iterate = udf_readdir, |
2f07a88b3
|
190 |
.unlocked_ioctl = udf_ioctl, |
1b061d924
|
191 |
.fsync = generic_file_fsync, |
934c5e601
|
192 |
}; |