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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php