~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/hpfs/name.c

Version: ~ [ linux-5.9 ] ~ [ linux-5.8.14 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.70 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.150 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.200 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.238 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.238 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/hpfs/name.c
  3  *
  4  *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5  *
  6  *  operations with filenames
  7  */
  8 
  9 #include "hpfs_fn.h"
 10 
 11 static inline int not_allowed_char(unsigned char c)
 12 {
 13         return c<' ' || c=='"' || c=='*' || c=='/' || c==':' || c=='<' ||
 14               c=='>' || c=='?' || c=='\\' || c=='|';
 15 }
 16 
 17 static inline int no_dos_char(unsigned char c)
 18 {       /* Characters that are allowed in HPFS but not in DOS */
 19         return c=='+' || c==',' || c==';' || c=='=' || c=='[' || c==']';
 20 }
 21 
 22 static inline unsigned char upcase(unsigned char *dir, unsigned char a)
 23 {
 24         if (a<128 || a==255) return a>='a' && a<='z' ? a - 0x20 : a;
 25         if (!dir) return a;
 26         return dir[a-128];
 27 }
 28 
 29 unsigned char hpfs_upcase(unsigned char *dir, unsigned char a)
 30 {
 31         return upcase(dir, a);
 32 }
 33 
 34 static inline unsigned char locase(unsigned char *dir, unsigned char a)
 35 {
 36         if (a<128 || a==255) return a>='A' && a<='Z' ? a + 0x20 : a;
 37         if (!dir) return a;
 38         return dir[a];
 39 }
 40 
 41 int hpfs_chk_name(const unsigned char *name, unsigned *len)
 42 {
 43         int i;
 44         if (*len > 254) return -ENAMETOOLONG;
 45         hpfs_adjust_length(name, len);
 46         if (!*len) return -EINVAL;
 47         for (i = 0; i < *len; i++) if (not_allowed_char(name[i])) return -EINVAL;
 48         if (*len == 1) if (name[0] == '.') return -EINVAL;
 49         if (*len == 2) if (name[0] == '.' && name[1] == '.') return -EINVAL;
 50         return 0;
 51 }
 52 
 53 unsigned char *hpfs_translate_name(struct super_block *s, unsigned char *from,
 54                           unsigned len, int lc, int lng)
 55 {
 56         unsigned char *to;
 57         int i;
 58         if (hpfs_sb(s)->sb_chk >= 2) if (hpfs_is_name_long(from, len) != lng) {
 59                 pr_err("Long name flag mismatch - name ");
 60                 for (i = 0; i < len; i++)
 61                         pr_cont("%c", from[i]);
 62                 pr_cont(" misidentified as %s.\n", lng ? "short" : "long");
 63                 pr_err("It's nothing serious. It could happen because of bug in OS/2.\nSet checks=normal to disable this message.\n");
 64         }
 65         if (!lc) return from;
 66         if (!(to = kmalloc(len, GFP_KERNEL))) {
 67                 pr_err("can't allocate memory for name conversion buffer\n");
 68                 return from;
 69         }
 70         for (i = 0; i < len; i++) to[i] = locase(hpfs_sb(s)->sb_cp_table,from[i]);
 71         return to;
 72 }
 73 
 74 int hpfs_compare_names(struct super_block *s,
 75                        const unsigned char *n1, unsigned l1,
 76                        const unsigned char *n2, unsigned l2, int last)
 77 {
 78         unsigned l = l1 < l2 ? l1 : l2;
 79         unsigned i;
 80         if (last) return -1;
 81         for (i = 0; i < l; i++) {
 82                 unsigned char c1 = upcase(hpfs_sb(s)->sb_cp_table,n1[i]);
 83                 unsigned char c2 = upcase(hpfs_sb(s)->sb_cp_table,n2[i]);
 84                 if (c1 < c2) return -1;
 85                 if (c1 > c2) return 1;
 86         }
 87         if (l1 < l2) return -1;
 88         if (l1 > l2) return 1;
 89         return 0;
 90 }
 91 
 92 int hpfs_is_name_long(const unsigned char *name, unsigned len)
 93 {
 94         int i,j;
 95         for (i = 0; i < len && name[i] != '.'; i++)
 96                 if (no_dos_char(name[i])) return 1;
 97         if (!i || i > 8) return 1;
 98         if (i == len) return 0;
 99         for (j = i + 1; j < len; j++)
100                 if (name[j] == '.' || no_dos_char(name[i])) return 1;
101         return j - i > 4;
102 }
103 
104 /* OS/2 clears dots and spaces at the end of file name, so we have to */
105 
106 void hpfs_adjust_length(const unsigned char *name, unsigned *len)
107 {
108         if (!*len) return;
109         if (*len == 1 && name[0] == '.') return;
110         if (*len == 2 && name[0] == '.' && name[1] == '.') return;
111         while (*len && (name[*len - 1] == '.' || name[*len - 1] == ' '))
112                 (*len)--;
113 }
114 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp