[PATCH] fix make rpm versioning
[linux-2.6/history.git] / fs / fat / dir.c
blobd10571657ecb9e121ddf92330556c096c400563b
1 /*
2 * linux/fs/fat/dir.c
4 * directory handling functions for fat-based filesystems
6 * Written 1992,1993 by Werner Almesberger
8 * Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu>
10 * VFAT extensions by Gordon Chaffee <chaffee@plateau.cs.berkeley.edu>
11 * Merged with msdos fs by Henrik Storner <storner@osiris.ping.dk>
12 * Rewritten for constant inumbers. Plugged buffer overrun in readdir(). AV
13 * Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de>
16 #include <linux/slab.h>
17 #include <linux/time.h>
18 #include <linux/msdos_fs.h>
19 #include <linux/dirent.h>
20 #include <linux/smp_lock.h>
21 #include <linux/buffer_head.h>
23 #include <asm/uaccess.h>
25 struct file_operations fat_dir_operations = {
26 .read = generic_read_dir,
27 .readdir = fat_readdir,
28 .ioctl = fat_dir_ioctl,
29 .fsync = file_fsync,
33 * Convert Unicode 16 to UTF8, translated Unicode, or ASCII.
34 * If uni_xlate is enabled and we can't get a 1:1 conversion, use a
35 * colon as an escape character since it is normally invalid on the vfat
36 * filesystem. The following four characters are the hexadecimal digits
37 * of Unicode value. This lets us do a full dump and restore of Unicode
38 * filenames. We could get into some trouble with long Unicode names,
39 * but ignore that right now.
40 * Ahem... Stack smashing in ring 0 isn't fun. Fixed.
42 static int
43 uni16_to_x8(unsigned char *ascii, wchar_t *uni, int uni_xlate,
44 struct nls_table *nls)
46 wchar_t *ip, ec;
47 unsigned char *op, nc;
48 int charlen;
49 int k;
51 ip = uni;
52 op = ascii;
54 while (*ip) {
55 ec = *ip++;
56 if ( (charlen = nls->uni2char(ec, op, NLS_MAX_CHARSET_SIZE)) > 0) {
57 op += charlen;
58 } else {
59 if (uni_xlate == 1) {
60 *op = ':';
61 for (k = 4; k > 0; k--) {
62 nc = ec & 0xF;
63 op[k] = nc > 9 ? nc + ('a' - 10)
64 : nc + '0';
65 ec >>= 4;
67 op += 5;
68 } else {
69 *op++ = '?';
72 /* We have some slack there, so it's OK */
73 if (op>ascii+256) {
74 op = ascii + 256;
75 break;
78 *op = 0;
79 return (op - ascii);
82 #if 0
83 static void dump_de(struct msdos_dir_entry *de)
85 int i;
86 unsigned char *p = (unsigned char *) de;
87 printk("[");
89 for (i = 0; i < 32; i++, p++) {
90 printk("%02x ", *p);
92 printk("]\n");
94 #endif
96 static inline unsigned char
97 fat_tolower(struct nls_table *t, unsigned char c)
99 unsigned char nc = t->charset2lower[c];
101 return nc ? nc : c;
104 static inline int
105 fat_short2uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *uni)
107 int charlen;
109 charlen = t->char2uni(c, clen, uni);
110 if (charlen < 0) {
111 *uni = 0x003f; /* a question mark */
112 charlen = 1;
114 return charlen;
117 static inline int
118 fat_short2lower_uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *uni)
120 int charlen;
121 wchar_t wc;
123 charlen = t->char2uni(c, clen, &wc);
124 if (charlen < 0) {
125 *uni = 0x003f; /* a question mark */
126 charlen = 1;
127 } else if (charlen <= 1) {
128 unsigned char nc = t->charset2lower[*c];
130 if (!nc)
131 nc = *c;
133 if ( (charlen = t->char2uni(&nc, 1, uni)) < 0) {
134 *uni = 0x003f; /* a question mark */
135 charlen = 1;
137 } else
138 *uni = wc;
140 return charlen;
143 static int
144 fat_strnicmp(struct nls_table *t, const unsigned char *s1,
145 const unsigned char *s2, int len)
147 while(len--)
148 if (fat_tolower(t, *s1++) != fat_tolower(t, *s2++))
149 return 1;
151 return 0;
154 static inline int
155 fat_shortname2uni(struct nls_table *nls, char *buf, int buf_size,
156 wchar_t *uni_buf, unsigned short opt, int lower)
158 int len = 0;
160 if (opt & VFAT_SFN_DISPLAY_LOWER)
161 len = fat_short2lower_uni(nls, buf, buf_size, uni_buf);
162 else if (opt & VFAT_SFN_DISPLAY_WIN95)
163 len = fat_short2uni(nls, buf, buf_size, uni_buf);
164 else if (opt & VFAT_SFN_DISPLAY_WINNT) {
165 if (lower)
166 len = fat_short2lower_uni(nls, buf, buf_size, uni_buf);
167 else
168 len = fat_short2uni(nls, buf, buf_size, uni_buf);
169 } else
170 len = fat_short2uni(nls, buf, buf_size, uni_buf);
172 return len;
176 * Return values: negative -> error, 0 -> not found, positive -> found,
177 * value is the total amount of slots, including the shortname entry.
179 int fat_search_long(struct inode *inode, const char *name, int name_len,
180 int anycase, loff_t *spos, loff_t *lpos)
182 struct super_block *sb = inode->i_sb;
183 struct buffer_head *bh = NULL;
184 struct msdos_dir_entry *de;
185 struct nls_table *nls_io = MSDOS_SB(sb)->nls_io;
186 struct nls_table *nls_disk = MSDOS_SB(sb)->nls_disk;
187 wchar_t bufuname[14];
188 unsigned char xlate_len, long_slots;
189 wchar_t *unicode = NULL;
190 char work[8], bufname[260]; /* 256 + 4 */
191 int uni_xlate = MSDOS_SB(sb)->options.unicode_xlate;
192 int utf8 = MSDOS_SB(sb)->options.utf8;
193 unsigned short opt_shortname = MSDOS_SB(sb)->options.shortname;
194 int chl, i, j, last_u, res = 0;
195 loff_t i_pos, cpos = 0;
197 while(1) {
198 if (fat_get_entry(inode,&cpos,&bh,&de,&i_pos) == -1)
199 goto EODir;
200 parse_record:
201 long_slots = 0;
202 if (de->name[0] == (__s8) DELETED_FLAG)
203 continue;
204 if (de->attr != ATTR_EXT && (de->attr & ATTR_VOLUME))
205 continue;
206 if (de->attr != ATTR_EXT && IS_FREE(de->name))
207 continue;
208 if (de->attr == ATTR_EXT) {
209 struct msdos_dir_slot *ds;
210 unsigned char id;
211 unsigned char slot;
212 unsigned char slots;
213 unsigned char sum;
214 unsigned char alias_checksum;
216 if (!unicode) {
217 unicode = (wchar_t *)
218 __get_free_page(GFP_KERNEL);
219 if (!unicode) {
220 brelse(bh);
221 return -ENOMEM;
224 parse_long:
225 slots = 0;
226 ds = (struct msdos_dir_slot *) de;
227 id = ds->id;
228 if (!(id & 0x40))
229 continue;
230 slots = id & ~0x40;
231 if (slots > 20 || !slots) /* ceil(256 * 2 / 26) */
232 continue;
233 long_slots = slots;
234 alias_checksum = ds->alias_checksum;
236 slot = slots;
237 while (1) {
238 int offset;
240 slot--;
241 offset = slot * 13;
242 fat16_towchar(unicode + offset, ds->name0_4, 5);
243 fat16_towchar(unicode + offset + 5, ds->name5_10, 6);
244 fat16_towchar(unicode + offset + 11, ds->name11_12, 2);
246 if (ds->id & 0x40) {
247 unicode[offset + 13] = 0;
249 if (fat_get_entry(inode,&cpos,&bh,&de,&i_pos)<0)
250 goto EODir;
251 if (slot == 0)
252 break;
253 ds = (struct msdos_dir_slot *) de;
254 if (ds->attr != ATTR_EXT)
255 goto parse_record;
256 if ((ds->id & ~0x40) != slot)
257 goto parse_long;
258 if (ds->alias_checksum != alias_checksum)
259 goto parse_long;
261 if (de->name[0] == (__s8) DELETED_FLAG)
262 continue;
263 if (de->attr == ATTR_EXT)
264 goto parse_long;
265 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
266 continue;
267 for (sum = 0, i = 0; i < 11; i++)
268 sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
269 if (sum != alias_checksum)
270 long_slots = 0;
273 memcpy(work, de->name, sizeof(de->name));
274 /* see namei.c, msdos_format_name */
275 if (work[0] == 0x05)
276 work[0] = 0xE5;
277 for (i = 0, j = 0, last_u = 0; i < 8;) {
278 if (!work[i]) break;
279 chl = fat_shortname2uni(nls_disk, &work[i], 8 - i,
280 &bufuname[j++], opt_shortname,
281 de->lcase & CASE_LOWER_BASE);
282 if (chl <= 1) {
283 if (work[i] != ' ')
284 last_u = j;
285 } else {
286 last_u = j;
288 i += chl;
290 j = last_u;
291 fat_short2uni(nls_disk, ".", 1, &bufuname[j++]);
292 for (i = 0; i < 3;) {
293 if (!de->ext[i]) break;
294 chl = fat_shortname2uni(nls_disk, &de->ext[i], 3 - i,
295 &bufuname[j++], opt_shortname,
296 de->lcase & CASE_LOWER_EXT);
297 if (chl <= 1) {
298 if (de->ext[i] != ' ')
299 last_u = j;
300 } else {
301 last_u = j;
303 i += chl;
305 if (!last_u)
306 continue;
308 bufuname[last_u] = 0x0000;
309 xlate_len = utf8
310 ?utf8_wcstombs(bufname, bufuname, sizeof(bufname))
311 :uni16_to_x8(bufname, bufuname, uni_xlate, nls_io);
312 if (xlate_len == name_len)
313 if ((!anycase && !memcmp(name, bufname, xlate_len)) ||
314 (anycase && !fat_strnicmp(nls_io, name, bufname,
315 xlate_len)))
316 goto Found;
318 if (long_slots) {
319 xlate_len = utf8
320 ?utf8_wcstombs(bufname, unicode, sizeof(bufname))
321 :uni16_to_x8(bufname, unicode, uni_xlate, nls_io);
322 if (xlate_len != name_len)
323 continue;
324 if ((!anycase && !memcmp(name, bufname, xlate_len)) ||
325 (anycase && !fat_strnicmp(nls_io, name, bufname,
326 xlate_len)))
327 goto Found;
331 Found:
332 res = long_slots + 1;
333 *spos = cpos - sizeof(struct msdos_dir_entry);
334 *lpos = cpos - res*sizeof(struct msdos_dir_entry);
335 EODir:
336 brelse(bh);
337 if (unicode) {
338 free_page((unsigned long) unicode);
340 return res;
343 static int fat_readdirx(struct inode *inode, struct file *filp, void *dirent,
344 filldir_t filldir, int shortnames, int both)
346 struct super_block *sb = inode->i_sb;
347 struct buffer_head *bh;
348 struct msdos_dir_entry *de;
349 struct nls_table *nls_io = MSDOS_SB(sb)->nls_io;
350 struct nls_table *nls_disk = MSDOS_SB(sb)->nls_disk;
351 wchar_t bufuname[14];
352 unsigned char long_slots;
353 wchar_t *unicode = NULL;
354 char c, work[8], bufname[56], *ptname = bufname;
355 unsigned long lpos, dummy, *furrfu = &lpos;
356 int uni_xlate = MSDOS_SB(sb)->options.unicode_xlate;
357 int isvfat = MSDOS_SB(sb)->options.isvfat;
358 int utf8 = MSDOS_SB(sb)->options.utf8;
359 int nocase = MSDOS_SB(sb)->options.nocase;
360 unsigned short opt_shortname = MSDOS_SB(sb)->options.shortname;
361 unsigned long inum;
362 int chi, chl, i, i2, j, last, last_u, dotoffset = 0;
363 loff_t i_pos, cpos;
364 int ret = 0;
366 lock_kernel();
368 cpos = filp->f_pos;
369 /* Fake . and .. for the root directory. */
370 if (inode->i_ino == MSDOS_ROOT_INO) {
371 while (cpos < 2) {
372 if (filldir(dirent, "..", cpos+1, cpos, MSDOS_ROOT_INO, DT_DIR) < 0)
373 goto out;
374 cpos++;
375 filp->f_pos++;
377 if (cpos == 2) {
378 dummy = 2;
379 furrfu = &dummy;
380 cpos = 0;
383 if (cpos & (sizeof(struct msdos_dir_entry)-1)) {
384 ret = -ENOENT;
385 goto out;
388 bh = NULL;
389 GetNew:
390 long_slots = 0;
391 if (fat_get_entry(inode,&cpos,&bh,&de,&i_pos) == -1)
392 goto EODir;
393 /* Check for long filename entry */
394 if (isvfat) {
395 if (de->name[0] == (__s8) DELETED_FLAG)
396 goto RecEnd;
397 if (de->attr != ATTR_EXT && (de->attr & ATTR_VOLUME))
398 goto RecEnd;
399 if (de->attr != ATTR_EXT && IS_FREE(de->name))
400 goto RecEnd;
401 } else {
402 if ((de->attr & ATTR_VOLUME) || IS_FREE(de->name))
403 goto RecEnd;
406 if (isvfat && de->attr == ATTR_EXT) {
407 struct msdos_dir_slot *ds;
408 unsigned char id;
409 unsigned char slot;
410 unsigned char slots;
411 unsigned char sum;
412 unsigned char alias_checksum;
414 if (!unicode) {
415 unicode = (wchar_t *)
416 __get_free_page(GFP_KERNEL);
417 if (!unicode) {
418 filp->f_pos = cpos;
419 brelse(bh);
420 ret = -ENOMEM;
421 goto out;
424 ParseLong:
425 slots = 0;
426 ds = (struct msdos_dir_slot *) de;
427 id = ds->id;
428 if (!(id & 0x40))
429 goto RecEnd;
430 slots = id & ~0x40;
431 if (slots > 20 || !slots) /* ceil(256 * 2 / 26) */
432 goto RecEnd;
433 long_slots = slots;
434 alias_checksum = ds->alias_checksum;
436 slot = slots;
437 while (1) {
438 int offset;
440 slot--;
441 offset = slot * 13;
442 fat16_towchar(unicode + offset, ds->name0_4, 5);
443 fat16_towchar(unicode + offset + 5, ds->name5_10, 6);
444 fat16_towchar(unicode + offset + 11, ds->name11_12, 2);
446 if (ds->id & 0x40) {
447 unicode[offset + 13] = 0;
449 if (fat_get_entry(inode,&cpos,&bh,&de,&i_pos) == -1)
450 goto EODir;
451 if (slot == 0)
452 break;
453 ds = (struct msdos_dir_slot *) de;
454 if (ds->attr != ATTR_EXT)
455 goto RecEnd; /* XXX */
456 if ((ds->id & ~0x40) != slot)
457 goto ParseLong;
458 if (ds->alias_checksum != alias_checksum)
459 goto ParseLong;
461 if (de->name[0] == (__s8) DELETED_FLAG)
462 goto RecEnd;
463 if (de->attr == ATTR_EXT)
464 goto ParseLong;
465 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
466 goto RecEnd;
467 for (sum = 0, i = 0; i < 11; i++)
468 sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
469 if (sum != alias_checksum)
470 long_slots = 0;
473 if ((de->attr & ATTR_HIDDEN) && MSDOS_SB(sb)->options.dotsOK) {
474 *ptname++ = '.';
475 dotoffset = 1;
478 memcpy(work, de->name, sizeof(de->name));
479 /* see namei.c, msdos_format_name */
480 if (work[0] == 0x05)
481 work[0] = 0xE5;
482 for (i = 0, j = 0, last = 0, last_u = 0; i < 8;) {
483 if (!(c = work[i])) break;
484 chl = fat_shortname2uni(nls_disk, &work[i], 8 - i,
485 &bufuname[j++], opt_shortname,
486 de->lcase & CASE_LOWER_BASE);
487 if (chl <= 1) {
488 ptname[i++] = (!nocase && c>='A' && c<='Z') ? c+32 : c;
489 if (c != ' ') {
490 last = i;
491 last_u = j;
493 } else {
494 last_u = j;
495 for (chi = 0; chi < chl && i < 8; chi++) {
496 ptname[i] = work[i];
497 i++; last = i;
501 i = last;
502 j = last_u;
503 fat_short2uni(nls_disk, ".", 1, &bufuname[j++]);
504 ptname[i++] = '.';
505 for (i2 = 0; i2 < 3;) {
506 if (!(c = de->ext[i2])) break;
507 chl = fat_shortname2uni(nls_disk, &de->ext[i2], 3 - i2,
508 &bufuname[j++], opt_shortname,
509 de->lcase & CASE_LOWER_EXT);
510 if (chl <= 1) {
511 i2++;
512 ptname[i++] = (!nocase && c>='A' && c<='Z') ? c+32 : c;
513 if (c != ' ') {
514 last = i;
515 last_u = j;
517 } else {
518 last_u = j;
519 for (chi = 0; chi < chl && i2 < 3; chi++) {
520 ptname[i++] = de->ext[i2++];
521 last = i;
525 if (!last)
526 goto RecEnd;
528 i = last + dotoffset;
529 j = last_u;
531 lpos = cpos - (long_slots+1)*sizeof(struct msdos_dir_entry);
532 if (!memcmp(de->name,MSDOS_DOT,11))
533 inum = inode->i_ino;
534 else if (!memcmp(de->name,MSDOS_DOTDOT,11)) {
535 inum = parent_ino(filp->f_dentry);
536 } else {
537 struct inode *tmp = fat_iget(sb, i_pos);
538 if (tmp) {
539 inum = tmp->i_ino;
540 iput(tmp);
541 } else
542 inum = iunique(sb, MSDOS_ROOT_INO);
545 if (isvfat) {
546 bufuname[j] = 0x0000;
547 i = utf8 ? utf8_wcstombs(bufname, bufuname, sizeof(bufname))
548 : uni16_to_x8(bufname, bufuname, uni_xlate, nls_io);
551 if (!long_slots||shortnames) {
552 if (both)
553 bufname[i] = '\0';
554 if (filldir(dirent, bufname, i, *furrfu, inum,
555 (de->attr & ATTR_DIR) ? DT_DIR : DT_REG) < 0)
556 goto FillFailed;
557 } else {
558 char longname[275];
559 int long_len = utf8
560 ? utf8_wcstombs(longname, unicode, sizeof(longname))
561 : uni16_to_x8(longname, unicode, uni_xlate,
562 nls_io);
563 if (both) {
564 memcpy(&longname[long_len+1], bufname, i);
565 long_len += i;
567 if (filldir(dirent, longname, long_len, *furrfu, inum,
568 (de->attr & ATTR_DIR) ? DT_DIR : DT_REG) < 0)
569 goto FillFailed;
572 RecEnd:
573 furrfu = &lpos;
574 filp->f_pos = cpos;
575 goto GetNew;
576 EODir:
577 filp->f_pos = cpos;
578 FillFailed:
579 if (bh)
580 brelse(bh);
581 if (unicode) {
582 free_page((unsigned long) unicode);
584 out:
585 unlock_kernel();
586 return ret;
589 int fat_readdir(struct file *filp, void *dirent, filldir_t filldir)
591 struct inode *inode = filp->f_dentry->d_inode;
592 return fat_readdirx(inode, filp, dirent, filldir, 0, 0);
595 struct fat_ioctl_filldir_callback {
596 struct dirent __user *dirent;
597 int result;
600 static int fat_ioctl_filldir(void *__buf, const char * name, int name_len,
601 loff_t offset, ino_t ino, unsigned int d_type)
603 struct fat_ioctl_filldir_callback *buf = __buf;
604 struct dirent __user *d1 = buf->dirent;
605 struct dirent __user *d2 = d1 + 1;
606 int len, slen;
607 int dotdir;
609 if (buf->result)
610 return -EINVAL;
611 buf->result++;
613 if ((name_len == 1 && name[0] == '.') ||
614 (name_len == 2 && name[0] == '.' && name[1] == '.')) {
615 dotdir = 1;
616 len = name_len;
617 } else {
618 dotdir = 0;
619 len = strlen(name);
621 if (len != name_len) {
622 slen = name_len - len;
623 if (copy_to_user(d2->d_name, name, len) ||
624 put_user(0, d2->d_name + len) ||
625 put_user(len, &d2->d_reclen) ||
626 put_user(ino, &d2->d_ino) ||
627 put_user(offset, &d2->d_off) ||
628 copy_to_user(d1->d_name, name+len+1, slen) ||
629 put_user(0, d1->d_name+slen) ||
630 put_user(slen, &d1->d_reclen))
631 goto efault;
632 } else {
633 if (put_user(0, d2->d_name) ||
634 put_user(0, &d2->d_reclen) ||
635 copy_to_user(d1->d_name, name, len) ||
636 put_user(0, d1->d_name+len) ||
637 put_user(len, &d1->d_reclen))
638 goto efault;
640 return 0;
641 efault:
642 buf->result = -EFAULT;
643 return -EFAULT;
646 int fat_dir_ioctl(struct inode * inode, struct file * filp,
647 unsigned int cmd, unsigned long arg)
649 struct fat_ioctl_filldir_callback buf;
650 struct dirent __user *d1 = (struct dirent *)arg;
651 int ret, shortname, both;
653 if (!access_ok(VERIFY_WRITE, d1, sizeof(struct dirent[2])))
654 return -EFAULT;
656 * Yes, we don't need this put_user() absolutely. However old
657 * code didn't return the right value. So, app use this value,
658 * in order to check whether it is EOF.
660 if (put_user(0, &d1->d_reclen))
661 return -EFAULT;
663 buf.dirent = d1;
664 buf.result = 0;
665 switch (cmd) {
666 case VFAT_IOCTL_READDIR_SHORT:
667 shortname = 1;
668 both = 1;
669 break;
670 case VFAT_IOCTL_READDIR_BOTH:
671 shortname = 0;
672 both = 1;
673 break;
674 default:
675 return -EINVAL;
677 ret = fat_readdirx(inode, filp, &buf, fat_ioctl_filldir,
678 shortname, both);
679 if (ret >= 0)
680 ret = buf.result;
681 return ret;
684 /***** See if directory is empty */
685 int fat_dir_empty(struct inode *dir)
687 loff_t pos, i_pos;
688 struct buffer_head *bh;
689 struct msdos_dir_entry *de;
690 int result = 0;
692 pos = 0;
693 bh = NULL;
694 while (fat_get_entry(dir,&pos,&bh,&de,&i_pos) > -1) {
695 /* Ignore vfat longname entries */
696 if (de->attr == ATTR_EXT)
697 continue;
698 if (!IS_FREE(de->name) &&
699 strncmp(de->name,MSDOS_DOT , MSDOS_NAME) &&
700 strncmp(de->name,MSDOS_DOTDOT, MSDOS_NAME)) {
701 result = -ENOTEMPTY;
702 break;
706 brelse(bh);
707 return result;
710 /* This assumes that size of cluster is above the 32*slots */
712 int fat_add_entries(struct inode *dir,int slots, struct buffer_head **bh,
713 struct msdos_dir_entry **de, loff_t *i_pos)
715 struct super_block *sb = dir->i_sb;
716 loff_t offset, curr;
717 int row;
718 struct buffer_head *new_bh;
720 offset = curr = 0;
721 *bh = NULL;
722 row = 0;
723 while (fat_get_entry(dir, &curr, bh, de, i_pos) > -1) {
724 /* check the maximum size of directory */
725 if (curr >= FAT_MAX_DIR_SIZE) {
726 brelse(*bh);
727 return -ENOSPC;
730 if (IS_FREE((*de)->name)) {
731 if (++row == slots)
732 return offset;
733 } else {
734 row = 0;
735 offset = curr;
738 if ((dir->i_ino == MSDOS_ROOT_INO) && (MSDOS_SB(sb)->fat_bits != 32))
739 return -ENOSPC;
740 new_bh = fat_extend_dir(dir);
741 if (IS_ERR(new_bh))
742 return PTR_ERR(new_bh);
743 brelse(new_bh);
744 do {
745 fat_get_entry(dir, &curr, bh, de, i_pos);
746 } while (++row < slots);
748 return offset;
751 int fat_new_dir(struct inode *dir, struct inode *parent, int is_vfat)
753 struct buffer_head *bh;
754 struct msdos_dir_entry *de;
755 __u16 date, time;
757 bh = fat_extend_dir(dir);
758 if (IS_ERR(bh))
759 return PTR_ERR(bh);
761 /* zeroed out, so... */
762 fat_date_unix2dos(dir->i_mtime.tv_sec,&time,&date);
763 de = (struct msdos_dir_entry*)&bh->b_data[0];
764 memcpy(de[0].name,MSDOS_DOT,MSDOS_NAME);
765 memcpy(de[1].name,MSDOS_DOTDOT,MSDOS_NAME);
766 de[0].attr = de[1].attr = ATTR_DIR;
767 de[0].time = de[1].time = CT_LE_W(time);
768 de[0].date = de[1].date = CT_LE_W(date);
769 if (is_vfat) { /* extra timestamps */
770 de[0].ctime = de[1].ctime = CT_LE_W(time);
771 de[0].adate = de[0].cdate =
772 de[1].adate = de[1].cdate = CT_LE_W(date);
774 de[0].start = CT_LE_W(MSDOS_I(dir)->i_logstart);
775 de[0].starthi = CT_LE_W(MSDOS_I(dir)->i_logstart>>16);
776 de[1].start = CT_LE_W(MSDOS_I(parent)->i_logstart);
777 de[1].starthi = CT_LE_W(MSDOS_I(parent)->i_logstart>>16);
778 mark_buffer_dirty(bh);
779 brelse(bh);
780 dir->i_atime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
781 mark_inode_dirty(dir);
783 return 0;
787 * Overrides for Emacs so that we follow Linus's tabbing style.
788 * Emacs will notice this stuff at the end of the file and automatically
789 * adjust the settings for this buffer only. This must remain at the end
790 * of the file.
791 * ---------------------------------------------------------------------------
792 * Local variables:
793 * c-indent-level: 8
794 * c-brace-imaginary-offset: 0
795 * c-brace-offset: -8
796 * c-argdecl-indent: 8
797 * c-label-offset: -8
798 * c-continued-statement-offset: 8
799 * c-continued-brace-offset: 0
800 * End: