ncplib_kernel.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. /*
  2. * ncplib_kernel.c
  3. *
  4. * Copyright (C) 1995, 1996 by Volker Lendecke
  5. * Modified for big endian by J.F. Chadima and David S. Miller
  6. * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
  7. * Modified 1999 Wolfram Pienkoss for NLS
  8. * Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
  9. *
  10. */
  11. #include "ncp_fs.h"
  12. static inline void assert_server_locked(struct ncp_server *server)
  13. {
  14. if (server->lock == 0) {
  15. DPRINTK("ncpfs: server not locked!\n");
  16. }
  17. }
  18. static void ncp_add_byte(struct ncp_server *server, __u8 x)
  19. {
  20. assert_server_locked(server);
  21. *(__u8 *) (&(server->packet[server->current_size])) = x;
  22. server->current_size += 1;
  23. return;
  24. }
  25. static void ncp_add_word(struct ncp_server *server, __le16 x)
  26. {
  27. assert_server_locked(server);
  28. put_unaligned(x, (__le16 *) (&(server->packet[server->current_size])));
  29. server->current_size += 2;
  30. return;
  31. }
  32. static void ncp_add_be16(struct ncp_server *server, __u16 x)
  33. {
  34. assert_server_locked(server);
  35. put_unaligned(cpu_to_be16(x), (__be16 *) (&(server->packet[server->current_size])));
  36. server->current_size += 2;
  37. }
  38. static void ncp_add_dword(struct ncp_server *server, __le32 x)
  39. {
  40. assert_server_locked(server);
  41. put_unaligned(x, (__le32 *) (&(server->packet[server->current_size])));
  42. server->current_size += 4;
  43. return;
  44. }
  45. static void ncp_add_be32(struct ncp_server *server, __u32 x)
  46. {
  47. assert_server_locked(server);
  48. put_unaligned(cpu_to_be32(x), (__be32 *)(&(server->packet[server->current_size])));
  49. server->current_size += 4;
  50. }
  51. static inline void ncp_add_dword_lh(struct ncp_server *server, __u32 x) {
  52. ncp_add_dword(server, cpu_to_le32(x));
  53. }
  54. static void ncp_add_mem(struct ncp_server *server, const void *source, int size)
  55. {
  56. assert_server_locked(server);
  57. memcpy(&(server->packet[server->current_size]), source, size);
  58. server->current_size += size;
  59. return;
  60. }
  61. static void ncp_add_pstring(struct ncp_server *server, const char *s)
  62. {
  63. int len = strlen(s);
  64. assert_server_locked(server);
  65. if (len > 255) {
  66. DPRINTK("ncpfs: string too long: %s\n", s);
  67. len = 255;
  68. }
  69. ncp_add_byte(server, len);
  70. ncp_add_mem(server, s, len);
  71. return;
  72. }
  73. static inline void ncp_init_request(struct ncp_server *server)
  74. {
  75. ncp_lock_server(server);
  76. server->current_size = sizeof(struct ncp_request_header);
  77. server->has_subfunction = 0;
  78. }
  79. static inline void ncp_init_request_s(struct ncp_server *server, int subfunction)
  80. {
  81. ncp_lock_server(server);
  82. server->current_size = sizeof(struct ncp_request_header) + 2;
  83. ncp_add_byte(server, subfunction);
  84. server->has_subfunction = 1;
  85. }
  86. static inline char *
  87. ncp_reply_data(struct ncp_server *server, int offset)
  88. {
  89. return &(server->packet[sizeof(struct ncp_reply_header) + offset]);
  90. }
  91. static inline u8 BVAL(const void *data)
  92. {
  93. return *(const u8 *)data;
  94. }
  95. static u8 ncp_reply_byte(struct ncp_server *server, int offset)
  96. {
  97. return *(const u8 *)ncp_reply_data(server, offset);
  98. }
  99. static inline u16 WVAL_LH(const void *data)
  100. {
  101. return get_unaligned_le16(data);
  102. }
  103. static u16
  104. ncp_reply_le16(struct ncp_server *server, int offset)
  105. {
  106. return get_unaligned_le16(ncp_reply_data(server, offset));
  107. }
  108. static u16
  109. ncp_reply_be16(struct ncp_server *server, int offset)
  110. {
  111. return get_unaligned_be16(ncp_reply_data(server, offset));
  112. }
  113. static inline u32 DVAL_LH(const void *data)
  114. {
  115. return get_unaligned_le32(data);
  116. }
  117. static __le32
  118. ncp_reply_dword(struct ncp_server *server, int offset)
  119. {
  120. return get_unaligned((__le32 *)ncp_reply_data(server, offset));
  121. }
  122. static inline __u32 ncp_reply_dword_lh(struct ncp_server* server, int offset) {
  123. return le32_to_cpu(ncp_reply_dword(server, offset));
  124. }
  125. int
  126. ncp_negotiate_buffersize(struct ncp_server *server, int size, int *target)
  127. {
  128. int result;
  129. ncp_init_request(server);
  130. ncp_add_be16(server, size);
  131. if ((result = ncp_request(server, 33)) != 0) {
  132. ncp_unlock_server(server);
  133. return result;
  134. }
  135. *target = min_t(unsigned int, ncp_reply_be16(server, 0), size);
  136. ncp_unlock_server(server);
  137. return 0;
  138. }
  139. /* options:
  140. * bit 0 ipx checksum
  141. * bit 1 packet signing
  142. */
  143. int
  144. ncp_negotiate_size_and_options(struct ncp_server *server,
  145. int size, int options, int *ret_size, int *ret_options) {
  146. int result;
  147. /* there is minimum */
  148. if (size < NCP_BLOCK_SIZE) size = NCP_BLOCK_SIZE;
  149. ncp_init_request(server);
  150. ncp_add_be16(server, size);
  151. ncp_add_byte(server, options);
  152. if ((result = ncp_request(server, 0x61)) != 0)
  153. {
  154. ncp_unlock_server(server);
  155. return result;
  156. }
  157. /* NCP over UDP returns 0 (!!!) */
  158. result = ncp_reply_be16(server, 0);
  159. if (result >= NCP_BLOCK_SIZE)
  160. size = min(result, size);
  161. *ret_size = size;
  162. *ret_options = ncp_reply_byte(server, 4);
  163. ncp_unlock_server(server);
  164. return 0;
  165. }
  166. int ncp_get_volume_info_with_number(struct ncp_server* server,
  167. int n, struct ncp_volume_info* target) {
  168. int result;
  169. int len;
  170. ncp_init_request_s(server, 44);
  171. ncp_add_byte(server, n);
  172. if ((result = ncp_request(server, 22)) != 0) {
  173. goto out;
  174. }
  175. target->total_blocks = ncp_reply_dword_lh(server, 0);
  176. target->free_blocks = ncp_reply_dword_lh(server, 4);
  177. target->purgeable_blocks = ncp_reply_dword_lh(server, 8);
  178. target->not_yet_purgeable_blocks = ncp_reply_dword_lh(server, 12);
  179. target->total_dir_entries = ncp_reply_dword_lh(server, 16);
  180. target->available_dir_entries = ncp_reply_dword_lh(server, 20);
  181. target->sectors_per_block = ncp_reply_byte(server, 28);
  182. memset(&(target->volume_name), 0, sizeof(target->volume_name));
  183. result = -EIO;
  184. len = ncp_reply_byte(server, 29);
  185. if (len > NCP_VOLNAME_LEN) {
  186. DPRINTK("ncpfs: volume name too long: %d\n", len);
  187. goto out;
  188. }
  189. memcpy(&(target->volume_name), ncp_reply_data(server, 30), len);
  190. result = 0;
  191. out:
  192. ncp_unlock_server(server);
  193. return result;
  194. }
  195. int ncp_get_directory_info(struct ncp_server* server, __u8 n,
  196. struct ncp_volume_info* target) {
  197. int result;
  198. int len;
  199. ncp_init_request_s(server, 45);
  200. ncp_add_byte(server, n);
  201. if ((result = ncp_request(server, 22)) != 0) {
  202. goto out;
  203. }
  204. target->total_blocks = ncp_reply_dword_lh(server, 0);
  205. target->free_blocks = ncp_reply_dword_lh(server, 4);
  206. target->purgeable_blocks = 0;
  207. target->not_yet_purgeable_blocks = 0;
  208. target->total_dir_entries = ncp_reply_dword_lh(server, 8);
  209. target->available_dir_entries = ncp_reply_dword_lh(server, 12);
  210. target->sectors_per_block = ncp_reply_byte(server, 20);
  211. memset(&(target->volume_name), 0, sizeof(target->volume_name));
  212. result = -EIO;
  213. len = ncp_reply_byte(server, 21);
  214. if (len > NCP_VOLNAME_LEN) {
  215. DPRINTK("ncpfs: volume name too long: %d\n", len);
  216. goto out;
  217. }
  218. memcpy(&(target->volume_name), ncp_reply_data(server, 22), len);
  219. result = 0;
  220. out:
  221. ncp_unlock_server(server);
  222. return result;
  223. }
  224. int
  225. ncp_close_file(struct ncp_server *server, const char *file_id)
  226. {
  227. int result;
  228. ncp_init_request(server);
  229. ncp_add_byte(server, 0);
  230. ncp_add_mem(server, file_id, 6);
  231. result = ncp_request(server, 66);
  232. ncp_unlock_server(server);
  233. return result;
  234. }
  235. int
  236. ncp_make_closed(struct inode *inode)
  237. {
  238. int err;
  239. err = 0;
  240. mutex_lock(&NCP_FINFO(inode)->open_mutex);
  241. if (atomic_read(&NCP_FINFO(inode)->opened) == 1) {
  242. atomic_set(&NCP_FINFO(inode)->opened, 0);
  243. err = ncp_close_file(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle);
  244. if (!err)
  245. PPRINTK("ncp_make_closed: volnum=%d, dirent=%u, error=%d\n",
  246. NCP_FINFO(inode)->volNumber,
  247. NCP_FINFO(inode)->dirEntNum, err);
  248. }
  249. mutex_unlock(&NCP_FINFO(inode)->open_mutex);
  250. return err;
  251. }
  252. static void ncp_add_handle_path(struct ncp_server *server, __u8 vol_num,
  253. __le32 dir_base, int have_dir_base,
  254. const char *path)
  255. {
  256. ncp_add_byte(server, vol_num);
  257. ncp_add_dword(server, dir_base);
  258. if (have_dir_base != 0) {
  259. ncp_add_byte(server, 1); /* dir_base */
  260. } else {
  261. ncp_add_byte(server, 0xff); /* no handle */
  262. }
  263. if (path != NULL) {
  264. ncp_add_byte(server, 1); /* 1 component */
  265. ncp_add_pstring(server, path);
  266. } else {
  267. ncp_add_byte(server, 0);
  268. }
  269. }
  270. int ncp_dirhandle_alloc(struct ncp_server* server, __u8 volnum, __le32 dirent,
  271. __u8* dirhandle) {
  272. int result;
  273. ncp_init_request(server);
  274. ncp_add_byte(server, 12); /* subfunction */
  275. ncp_add_byte(server, NW_NS_DOS);
  276. ncp_add_byte(server, 0);
  277. ncp_add_word(server, 0);
  278. ncp_add_handle_path(server, volnum, dirent, 1, NULL);
  279. if ((result = ncp_request(server, 87)) == 0) {
  280. *dirhandle = ncp_reply_byte(server, 0);
  281. }
  282. ncp_unlock_server(server);
  283. return result;
  284. }
  285. int ncp_dirhandle_free(struct ncp_server* server, __u8 dirhandle) {
  286. int result;
  287. ncp_init_request_s(server, 20);
  288. ncp_add_byte(server, dirhandle);
  289. result = ncp_request(server, 22);
  290. ncp_unlock_server(server);
  291. return result;
  292. }
  293. void ncp_extract_file_info(const void *structure, struct nw_info_struct *target)
  294. {
  295. const __u8 *name_len;
  296. const int info_struct_size = offsetof(struct nw_info_struct, nameLen);
  297. memcpy(target, structure, info_struct_size);
  298. name_len = structure + info_struct_size;
  299. target->nameLen = *name_len;
  300. memcpy(target->entryName, name_len + 1, *name_len);
  301. target->entryName[*name_len] = '\0';
  302. target->volNumber = le32_to_cpu(target->volNumber);
  303. return;
  304. }
  305. #ifdef CONFIG_NCPFS_NFS_NS
  306. static inline void ncp_extract_nfs_info(const unsigned char *structure,
  307. struct nw_nfs_info *target)
  308. {
  309. target->mode = DVAL_LH(structure);
  310. target->rdev = DVAL_LH(structure + 8);
  311. }
  312. #endif
  313. int ncp_obtain_nfs_info(struct ncp_server *server,
  314. struct nw_info_struct *target)
  315. {
  316. int result = 0;
  317. #ifdef CONFIG_NCPFS_NFS_NS
  318. __u32 volnum = target->volNumber;
  319. if (ncp_is_nfs_extras(server, volnum)) {
  320. ncp_init_request(server);
  321. ncp_add_byte(server, 19); /* subfunction */
  322. ncp_add_byte(server, server->name_space[volnum]);
  323. ncp_add_byte(server, NW_NS_NFS);
  324. ncp_add_byte(server, 0);
  325. ncp_add_byte(server, volnum);
  326. ncp_add_dword(server, target->dirEntNum);
  327. /* We must retrieve both nlinks and rdev, otherwise some server versions
  328. report zeroes instead of valid data */
  329. ncp_add_dword_lh(server, NSIBM_NFS_MODE | NSIBM_NFS_NLINKS | NSIBM_NFS_RDEV);
  330. if ((result = ncp_request(server, 87)) == 0) {
  331. ncp_extract_nfs_info(ncp_reply_data(server, 0), &target->nfs);
  332. DPRINTK(KERN_DEBUG
  333. "ncp_obtain_nfs_info: (%s) mode=0%o, rdev=0x%x\n",
  334. target->entryName, target->nfs.mode,
  335. target->nfs.rdev);
  336. } else {
  337. target->nfs.mode = 0;
  338. target->nfs.rdev = 0;
  339. }
  340. ncp_unlock_server(server);
  341. } else
  342. #endif
  343. {
  344. target->nfs.mode = 0;
  345. target->nfs.rdev = 0;
  346. }
  347. return result;
  348. }
  349. /*
  350. * Returns information for a (one-component) name relative to
  351. * the specified directory.
  352. */
  353. int ncp_obtain_info(struct ncp_server *server, struct inode *dir, const char *path,
  354. struct nw_info_struct *target)
  355. {
  356. __u8 volnum = NCP_FINFO(dir)->volNumber;
  357. __le32 dirent = NCP_FINFO(dir)->dirEntNum;
  358. int result;
  359. if (target == NULL) {
  360. printk(KERN_ERR "ncp_obtain_info: invalid call\n");
  361. return -EINVAL;
  362. }
  363. ncp_init_request(server);
  364. ncp_add_byte(server, 6); /* subfunction */
  365. ncp_add_byte(server, server->name_space[volnum]);
  366. ncp_add_byte(server, server->name_space[volnum]); /* N.B. twice ?? */
  367. ncp_add_word(server, cpu_to_le16(0x8006)); /* get all */
  368. ncp_add_dword(server, RIM_ALL);
  369. ncp_add_handle_path(server, volnum, dirent, 1, path);
  370. if ((result = ncp_request(server, 87)) != 0)
  371. goto out;
  372. ncp_extract_file_info(ncp_reply_data(server, 0), target);
  373. ncp_unlock_server(server);
  374. result = ncp_obtain_nfs_info(server, target);
  375. return result;
  376. out:
  377. ncp_unlock_server(server);
  378. return result;
  379. }
  380. #ifdef CONFIG_NCPFS_NFS_NS
  381. static int
  382. ncp_obtain_DOS_dir_base(struct ncp_server *server,
  383. __u8 ns, __u8 volnum, __le32 dirent,
  384. const char *path, /* At most 1 component */
  385. __le32 *DOS_dir_base)
  386. {
  387. int result;
  388. ncp_init_request(server);
  389. ncp_add_byte(server, 6); /* subfunction */
  390. ncp_add_byte(server, ns);
  391. ncp_add_byte(server, ns);
  392. ncp_add_word(server, cpu_to_le16(0x8006)); /* get all */
  393. ncp_add_dword(server, RIM_DIRECTORY);
  394. ncp_add_handle_path(server, volnum, dirent, 1, path);
  395. if ((result = ncp_request(server, 87)) == 0)
  396. {
  397. if (DOS_dir_base) *DOS_dir_base=ncp_reply_dword(server, 0x34);
  398. }
  399. ncp_unlock_server(server);
  400. return result;
  401. }
  402. #endif /* CONFIG_NCPFS_NFS_NS */
  403. static inline int
  404. ncp_get_known_namespace(struct ncp_server *server, __u8 volume)
  405. {
  406. #if defined(CONFIG_NCPFS_OS2_NS) || defined(CONFIG_NCPFS_NFS_NS)
  407. int result;
  408. __u8 *namespace;
  409. __u16 no_namespaces;
  410. ncp_init_request(server);
  411. ncp_add_byte(server, 24); /* Subfunction: Get Name Spaces Loaded */
  412. ncp_add_word(server, 0);
  413. ncp_add_byte(server, volume);
  414. if ((result = ncp_request(server, 87)) != 0) {
  415. ncp_unlock_server(server);
  416. return NW_NS_DOS; /* not result ?? */
  417. }
  418. result = NW_NS_DOS;
  419. no_namespaces = ncp_reply_le16(server, 0);
  420. namespace = ncp_reply_data(server, 2);
  421. while (no_namespaces > 0) {
  422. DPRINTK("get_namespaces: found %d on %d\n", *namespace, volume);
  423. #ifdef CONFIG_NCPFS_NFS_NS
  424. if ((*namespace == NW_NS_NFS) && !(server->m.flags&NCP_MOUNT_NO_NFS))
  425. {
  426. result = NW_NS_NFS;
  427. break;
  428. }
  429. #endif /* CONFIG_NCPFS_NFS_NS */
  430. #ifdef CONFIG_NCPFS_OS2_NS
  431. if ((*namespace == NW_NS_OS2) && !(server->m.flags&NCP_MOUNT_NO_OS2))
  432. {
  433. result = NW_NS_OS2;
  434. }
  435. #endif /* CONFIG_NCPFS_OS2_NS */
  436. namespace += 1;
  437. no_namespaces -= 1;
  438. }
  439. ncp_unlock_server(server);
  440. return result;
  441. #else /* neither OS2 nor NFS - only DOS */
  442. return NW_NS_DOS;
  443. #endif /* defined(CONFIG_NCPFS_OS2_NS) || defined(CONFIG_NCPFS_NFS_NS) */
  444. }
  445. int
  446. ncp_update_known_namespace(struct ncp_server *server, __u8 volume, int *ret_ns)
  447. {
  448. int ns = ncp_get_known_namespace(server, volume);
  449. if (ret_ns)
  450. *ret_ns = ns;
  451. DPRINTK("lookup_vol: namespace[%d] = %d\n",
  452. volume, server->name_space[volume]);
  453. if (server->name_space[volume] == ns)
  454. return 0;
  455. server->name_space[volume] = ns;
  456. return 1;
  457. }
  458. static int
  459. ncp_ObtainSpecificDirBase(struct ncp_server *server,
  460. __u8 nsSrc, __u8 nsDst, __u8 vol_num, __le32 dir_base,
  461. const char *path, /* At most 1 component */
  462. __le32 *dirEntNum, __le32 *DosDirNum)
  463. {
  464. int result;
  465. ncp_init_request(server);
  466. ncp_add_byte(server, 6); /* subfunction */
  467. ncp_add_byte(server, nsSrc);
  468. ncp_add_byte(server, nsDst);
  469. ncp_add_word(server, cpu_to_le16(0x8006)); /* get all */
  470. ncp_add_dword(server, RIM_ALL);
  471. ncp_add_handle_path(server, vol_num, dir_base, 1, path);
  472. if ((result = ncp_request(server, 87)) != 0)
  473. {
  474. ncp_unlock_server(server);
  475. return result;
  476. }
  477. if (dirEntNum)
  478. *dirEntNum = ncp_reply_dword(server, 0x30);
  479. if (DosDirNum)
  480. *DosDirNum = ncp_reply_dword(server, 0x34);
  481. ncp_unlock_server(server);
  482. return 0;
  483. }
  484. int
  485. ncp_mount_subdir(struct ncp_server *server,
  486. __u8 volNumber, __u8 srcNS, __le32 dirEntNum,
  487. __u32* volume, __le32* newDirEnt, __le32* newDosEnt)
  488. {
  489. int dstNS;
  490. int result;
  491. ncp_update_known_namespace(server, volNumber, &dstNS);
  492. if ((result = ncp_ObtainSpecificDirBase(server, srcNS, dstNS, volNumber,
  493. dirEntNum, NULL, newDirEnt, newDosEnt)) != 0)
  494. {
  495. return result;
  496. }
  497. *volume = volNumber;
  498. server->m.mounted_vol[1] = 0;
  499. server->m.mounted_vol[0] = 'X';
  500. return 0;
  501. }
  502. int
  503. ncp_get_volume_root(struct ncp_server *server,
  504. const char *volname, __u32* volume, __le32* dirent, __le32* dosdirent)
  505. {
  506. int result;
  507. DPRINTK("ncp_get_volume_root: looking up vol %s\n", volname);
  508. ncp_init_request(server);
  509. ncp_add_byte(server, 22); /* Subfunction: Generate dir handle */
  510. ncp_add_byte(server, 0); /* DOS namespace */
  511. ncp_add_byte(server, 0); /* reserved */
  512. ncp_add_byte(server, 0); /* reserved */
  513. ncp_add_byte(server, 0); /* reserved */
  514. ncp_add_byte(server, 0); /* faked volume number */
  515. ncp_add_dword(server, 0); /* faked dir_base */
  516. ncp_add_byte(server, 0xff); /* Don't have a dir_base */
  517. ncp_add_byte(server, 1); /* 1 path component */
  518. ncp_add_pstring(server, volname);
  519. if ((result = ncp_request(server, 87)) != 0) {
  520. ncp_unlock_server(server);
  521. return result;
  522. }
  523. *dirent = *dosdirent = ncp_reply_dword(server, 4);
  524. *volume = ncp_reply_byte(server, 8);
  525. ncp_unlock_server(server);
  526. return 0;
  527. }
  528. int
  529. ncp_lookup_volume(struct ncp_server *server,
  530. const char *volname, struct nw_info_struct *target)
  531. {
  532. int result;
  533. memset(target, 0, sizeof(*target));
  534. result = ncp_get_volume_root(server, volname,
  535. &target->volNumber, &target->dirEntNum, &target->DosDirNum);
  536. if (result) {
  537. return result;
  538. }
  539. ncp_update_known_namespace(server, target->volNumber, NULL);
  540. target->nameLen = strlen(volname);
  541. memcpy(target->entryName, volname, target->nameLen+1);
  542. target->attributes = aDIR;
  543. /* set dates to Jan 1, 1986 00:00 */
  544. target->creationTime = target->modifyTime = cpu_to_le16(0x0000);
  545. target->creationDate = target->modifyDate = target->lastAccessDate = cpu_to_le16(0x0C21);
  546. target->nfs.mode = 0;
  547. return 0;
  548. }
  549. int ncp_modify_file_or_subdir_dos_info_path(struct ncp_server *server,
  550. struct inode *dir,
  551. const char *path,
  552. __le32 info_mask,
  553. const struct nw_modify_dos_info *info)
  554. {
  555. __u8 volnum = NCP_FINFO(dir)->volNumber;
  556. __le32 dirent = NCP_FINFO(dir)->dirEntNum;
  557. int result;
  558. ncp_init_request(server);
  559. ncp_add_byte(server, 7); /* subfunction */
  560. ncp_add_byte(server, server->name_space[volnum]);
  561. ncp_add_byte(server, 0); /* reserved */
  562. ncp_add_word(server, cpu_to_le16(0x8006)); /* search attribs: all */
  563. ncp_add_dword(server, info_mask);
  564. ncp_add_mem(server, info, sizeof(*info));
  565. ncp_add_handle_path(server, volnum, dirent, 1, path);
  566. result = ncp_request(server, 87);
  567. ncp_unlock_server(server);
  568. return result;
  569. }
  570. int ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
  571. struct inode *dir,
  572. __le32 info_mask,
  573. const struct nw_modify_dos_info *info)
  574. {
  575. return ncp_modify_file_or_subdir_dos_info_path(server, dir, NULL,
  576. info_mask, info);
  577. }
  578. #ifdef CONFIG_NCPFS_NFS_NS
  579. int ncp_modify_nfs_info(struct ncp_server *server, __u8 volnum, __le32 dirent,
  580. __u32 mode, __u32 rdev)
  581. {
  582. int result = 0;
  583. ncp_init_request(server);
  584. if (server->name_space[volnum] == NW_NS_NFS) {
  585. ncp_add_byte(server, 25); /* subfunction */
  586. ncp_add_byte(server, server->name_space[volnum]);
  587. ncp_add_byte(server, NW_NS_NFS);
  588. ncp_add_byte(server, volnum);
  589. ncp_add_dword(server, dirent);
  590. /* we must always operate on both nlinks and rdev, otherwise
  591. rdev is not set */
  592. ncp_add_dword_lh(server, NSIBM_NFS_MODE | NSIBM_NFS_NLINKS | NSIBM_NFS_RDEV);
  593. ncp_add_dword_lh(server, mode);
  594. ncp_add_dword_lh(server, 1); /* nlinks */
  595. ncp_add_dword_lh(server, rdev);
  596. result = ncp_request(server, 87);
  597. }
  598. ncp_unlock_server(server);
  599. return result;
  600. }
  601. #endif
  602. static int
  603. ncp_DeleteNSEntry(struct ncp_server *server,
  604. __u8 have_dir_base, __u8 volnum, __le32 dirent,
  605. const char* name, __u8 ns, __le16 attr)
  606. {
  607. int result;
  608. ncp_init_request(server);
  609. ncp_add_byte(server, 8); /* subfunction */
  610. ncp_add_byte(server, ns);
  611. ncp_add_byte(server, 0); /* reserved */
  612. ncp_add_word(server, attr); /* search attribs: all */
  613. ncp_add_handle_path(server, volnum, dirent, have_dir_base, name);
  614. result = ncp_request(server, 87);
  615. ncp_unlock_server(server);
  616. return result;
  617. }
  618. int
  619. ncp_del_file_or_subdir2(struct ncp_server *server,
  620. struct dentry *dentry)
  621. {
  622. struct inode *inode = dentry->d_inode;
  623. __u8 volnum;
  624. __le32 dirent;
  625. if (!inode) {
  626. return 0xFF; /* Any error */
  627. }
  628. volnum = NCP_FINFO(inode)->volNumber;
  629. dirent = NCP_FINFO(inode)->DosDirNum;
  630. return ncp_DeleteNSEntry(server, 1, volnum, dirent, NULL, NW_NS_DOS, cpu_to_le16(0x8006));
  631. }
  632. int
  633. ncp_del_file_or_subdir(struct ncp_server *server,
  634. struct inode *dir, const char *name)
  635. {
  636. __u8 volnum = NCP_FINFO(dir)->volNumber;
  637. __le32 dirent = NCP_FINFO(dir)->dirEntNum;
  638. int name_space;
  639. name_space = server->name_space[volnum];
  640. #ifdef CONFIG_NCPFS_NFS_NS
  641. if (name_space == NW_NS_NFS)
  642. {
  643. int result;
  644. result=ncp_obtain_DOS_dir_base(server, name_space, volnum, dirent, name, &dirent);
  645. if (result) return result;
  646. name = NULL;
  647. name_space = NW_NS_DOS;
  648. }
  649. #endif /* CONFIG_NCPFS_NFS_NS */
  650. return ncp_DeleteNSEntry(server, 1, volnum, dirent, name, name_space, cpu_to_le16(0x8006));
  651. }
  652. static inline void ConvertToNWfromDWORD(__u16 v0, __u16 v1, __u8 ret[6])
  653. {
  654. __le16 *dest = (__le16 *) ret;
  655. dest[1] = cpu_to_le16(v0);
  656. dest[2] = cpu_to_le16(v1);
  657. dest[0] = cpu_to_le16(v0 + 1);
  658. return;
  659. }
  660. /* If both dir and name are NULL, then in target there's already a
  661. looked-up entry that wants to be opened. */
  662. int ncp_open_create_file_or_subdir(struct ncp_server *server,
  663. struct inode *dir, const char *name,
  664. int open_create_mode,
  665. __le32 create_attributes,
  666. __le16 desired_acc_rights,
  667. struct ncp_entry_info *target)
  668. {
  669. __le16 search_attribs = cpu_to_le16(0x0006);
  670. __u8 volnum;
  671. __le32 dirent;
  672. int result;
  673. volnum = NCP_FINFO(dir)->volNumber;
  674. dirent = NCP_FINFO(dir)->dirEntNum;
  675. if ((create_attributes & aDIR) != 0) {
  676. search_attribs |= cpu_to_le16(0x8000);
  677. }
  678. ncp_init_request(server);
  679. ncp_add_byte(server, 1); /* subfunction */
  680. ncp_add_byte(server, server->name_space[volnum]);
  681. ncp_add_byte(server, open_create_mode);
  682. ncp_add_word(server, search_attribs);
  683. ncp_add_dword(server, RIM_ALL);
  684. ncp_add_dword(server, create_attributes);
  685. /* The desired acc rights seem to be the inherited rights mask
  686. for directories */
  687. ncp_add_word(server, desired_acc_rights);
  688. ncp_add_handle_path(server, volnum, dirent, 1, name);
  689. if ((result = ncp_request(server, 87)) != 0)
  690. goto out;
  691. if (!(create_attributes & aDIR))
  692. target->opened = 1;
  693. /* in target there's a new finfo to fill */
  694. ncp_extract_file_info(ncp_reply_data(server, 6), &(target->i));
  695. target->volume = target->i.volNumber;
  696. ConvertToNWfromDWORD(ncp_reply_le16(server, 0),
  697. ncp_reply_le16(server, 2),
  698. target->file_handle);
  699. ncp_unlock_server(server);
  700. (void)ncp_obtain_nfs_info(server, &(target->i));
  701. return 0;
  702. out:
  703. ncp_unlock_server(server);
  704. return result;
  705. }
  706. int
  707. ncp_initialize_search(struct ncp_server *server, struct inode *dir,
  708. struct nw_search_sequence *target)
  709. {
  710. __u8 volnum = NCP_FINFO(dir)->volNumber;
  711. __le32 dirent = NCP_FINFO(dir)->dirEntNum;
  712. int result;
  713. ncp_init_request(server);
  714. ncp_add_byte(server, 2); /* subfunction */
  715. ncp_add_byte(server, server->name_space[volnum]);
  716. ncp_add_byte(server, 0); /* reserved */
  717. ncp_add_handle_path(server, volnum, dirent, 1, NULL);
  718. result = ncp_request(server, 87);
  719. if (result)
  720. goto out;
  721. memcpy(target, ncp_reply_data(server, 0), sizeof(*target));
  722. out:
  723. ncp_unlock_server(server);
  724. return result;
  725. }
  726. int ncp_search_for_fileset(struct ncp_server *server,
  727. struct nw_search_sequence *seq,
  728. int* more,
  729. int* cnt,
  730. char* buffer,
  731. size_t bufsize,
  732. char** rbuf,
  733. size_t* rsize)
  734. {
  735. int result;
  736. ncp_init_request(server);
  737. ncp_add_byte(server, 20);
  738. ncp_add_byte(server, server->name_space[seq->volNumber]);
  739. ncp_add_byte(server, 0); /* datastream */
  740. ncp_add_word(server, cpu_to_le16(0x8006));
  741. ncp_add_dword(server, RIM_ALL);
  742. ncp_add_word(server, cpu_to_le16(32767)); /* max returned items */
  743. ncp_add_mem(server, seq, 9);
  744. #ifdef CONFIG_NCPFS_NFS_NS
  745. if (server->name_space[seq->volNumber] == NW_NS_NFS) {
  746. ncp_add_byte(server, 0); /* 0 byte pattern */
  747. } else
  748. #endif
  749. {
  750. ncp_add_byte(server, 2); /* 2 byte pattern */
  751. ncp_add_byte(server, 0xff); /* following is a wildcard */
  752. ncp_add_byte(server, '*');
  753. }
  754. result = ncp_request2(server, 87, buffer, bufsize);
  755. if (result) {
  756. ncp_unlock_server(server);
  757. return result;
  758. }
  759. if (server->ncp_reply_size < 12) {
  760. ncp_unlock_server(server);
  761. return 0xFF;
  762. }
  763. *rsize = server->ncp_reply_size - 12;
  764. ncp_unlock_server(server);
  765. buffer = buffer + sizeof(struct ncp_reply_header);
  766. *rbuf = buffer + 12;
  767. *cnt = WVAL_LH(buffer + 10);
  768. *more = BVAL(buffer + 9);
  769. memcpy(seq, buffer, 9);
  770. return 0;
  771. }
  772. static int
  773. ncp_RenameNSEntry(struct ncp_server *server,
  774. struct inode *old_dir, const char *old_name, __le16 old_type,
  775. struct inode *new_dir, const char *new_name)
  776. {
  777. int result = -EINVAL;
  778. if ((old_dir == NULL) || (old_name == NULL) ||
  779. (new_dir == NULL) || (new_name == NULL))
  780. goto out;
  781. ncp_init_request(server);
  782. ncp_add_byte(server, 4); /* subfunction */
  783. ncp_add_byte(server, server->name_space[NCP_FINFO(old_dir)->volNumber]);
  784. ncp_add_byte(server, 1); /* rename flag */
  785. ncp_add_word(server, old_type); /* search attributes */
  786. /* source Handle Path */
  787. ncp_add_byte(server, NCP_FINFO(old_dir)->volNumber);
  788. ncp_add_dword(server, NCP_FINFO(old_dir)->dirEntNum);
  789. ncp_add_byte(server, 1);
  790. ncp_add_byte(server, 1); /* 1 source component */
  791. /* dest Handle Path */
  792. ncp_add_byte(server, NCP_FINFO(new_dir)->volNumber);
  793. ncp_add_dword(server, NCP_FINFO(new_dir)->dirEntNum);
  794. ncp_add_byte(server, 1);
  795. ncp_add_byte(server, 1); /* 1 destination component */
  796. /* source path string */
  797. ncp_add_pstring(server, old_name);
  798. /* dest path string */
  799. ncp_add_pstring(server, new_name);
  800. result = ncp_request(server, 87);
  801. ncp_unlock_server(server);
  802. out:
  803. return result;
  804. }
  805. int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
  806. struct inode *old_dir, const char *old_name,
  807. struct inode *new_dir, const char *new_name)
  808. {
  809. int result;
  810. __le16 old_type = cpu_to_le16(0x06);
  811. /* If somebody can do it atomic, call me... vandrove@vc.cvut.cz */
  812. result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
  813. new_dir, new_name);
  814. if (result == 0xFF) /* File Not Found, try directory */
  815. {
  816. old_type = cpu_to_le16(0x16);
  817. result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
  818. new_dir, new_name);
  819. }
  820. if (result != 0x92) return result; /* All except NO_FILES_RENAMED */
  821. result = ncp_del_file_or_subdir(server, new_dir, new_name);
  822. if (result != 0) return -EACCES;
  823. result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
  824. new_dir, new_name);
  825. return result;
  826. }
  827. /* We have to transfer to/from user space */
  828. int
  829. ncp_read_kernel(struct ncp_server *server, const char *file_id,
  830. __u32 offset, __u16 to_read, char *target, int *bytes_read)
  831. {
  832. const char *source;
  833. int result;
  834. ncp_init_request(server);
  835. ncp_add_byte(server, 0);
  836. ncp_add_mem(server, file_id, 6);
  837. ncp_add_be32(server, offset);
  838. ncp_add_be16(server, to_read);
  839. if ((result = ncp_request(server, 72)) != 0) {
  840. goto out;
  841. }
  842. *bytes_read = ncp_reply_be16(server, 0);
  843. source = ncp_reply_data(server, 2 + (offset & 1));
  844. memcpy(target, source, *bytes_read);
  845. out:
  846. ncp_unlock_server(server);
  847. return result;
  848. }
  849. /* There is a problem... egrep and some other silly tools do:
  850. x = mmap(NULL, MAP_PRIVATE, PROT_READ|PROT_WRITE, <ncpfs fd>, 32768);
  851. read(<ncpfs fd>, x, 32768);
  852. Now copying read result by copy_to_user causes pagefault. This pagefault
  853. could not be handled because of server was locked due to read. So we have
  854. to use temporary buffer. So ncp_unlock_server must be done before
  855. copy_to_user (and for write, copy_from_user must be done before
  856. ncp_init_request... same applies for send raw packet ioctl). Because of
  857. file is normally read in bigger chunks, caller provides kmalloced
  858. (vmalloced) chunk of memory with size >= to_read...
  859. */
  860. int
  861. ncp_read_bounce(struct ncp_server *server, const char *file_id,
  862. __u32 offset, __u16 to_read, char __user *target, int *bytes_read,
  863. void* bounce, __u32 bufsize)
  864. {
  865. int result;
  866. ncp_init_request(server);
  867. ncp_add_byte(server, 0);
  868. ncp_add_mem(server, file_id, 6);
  869. ncp_add_be32(server, offset);
  870. ncp_add_be16(server, to_read);
  871. result = ncp_request2(server, 72, bounce, bufsize);
  872. ncp_unlock_server(server);
  873. if (!result) {
  874. int len = get_unaligned_be16((char *)bounce +
  875. sizeof(struct ncp_reply_header));
  876. result = -EIO;
  877. if (len <= to_read) {
  878. char* source;
  879. source = (char*)bounce +
  880. sizeof(struct ncp_reply_header) + 2 +
  881. (offset & 1);
  882. *bytes_read = len;
  883. result = 0;
  884. if (copy_to_user(target, source, len))
  885. result = -EFAULT;
  886. }
  887. }
  888. return result;
  889. }
  890. int
  891. ncp_write_kernel(struct ncp_server *server, const char *file_id,
  892. __u32 offset, __u16 to_write,
  893. const char *source, int *bytes_written)
  894. {
  895. int result;
  896. ncp_init_request(server);
  897. ncp_add_byte(server, 0);
  898. ncp_add_mem(server, file_id, 6);
  899. ncp_add_be32(server, offset);
  900. ncp_add_be16(server, to_write);
  901. ncp_add_mem(server, source, to_write);
  902. if ((result = ncp_request(server, 73)) == 0)
  903. *bytes_written = to_write;
  904. ncp_unlock_server(server);
  905. return result;
  906. }
  907. #ifdef CONFIG_NCPFS_IOCTL_LOCKING
  908. int
  909. ncp_LogPhysicalRecord(struct ncp_server *server, const char *file_id,
  910. __u8 locktype, __u32 offset, __u32 length, __u16 timeout)
  911. {
  912. int result;
  913. ncp_init_request(server);
  914. ncp_add_byte(server, locktype);
  915. ncp_add_mem(server, file_id, 6);
  916. ncp_add_be32(server, offset);
  917. ncp_add_be32(server, length);
  918. ncp_add_be16(server, timeout);
  919. if ((result = ncp_request(server, 0x1A)) != 0)
  920. {
  921. ncp_unlock_server(server);
  922. return result;
  923. }
  924. ncp_unlock_server(server);
  925. return 0;
  926. }
  927. int
  928. ncp_ClearPhysicalRecord(struct ncp_server *server, const char *file_id,
  929. __u32 offset, __u32 length)
  930. {
  931. int result;
  932. ncp_init_request(server);
  933. ncp_add_byte(server, 0); /* who knows... lanalyzer says that */
  934. ncp_add_mem(server, file_id, 6);
  935. ncp_add_be32(server, offset);
  936. ncp_add_be32(server, length);
  937. if ((result = ncp_request(server, 0x1E)) != 0)
  938. {
  939. ncp_unlock_server(server);
  940. return result;
  941. }
  942. ncp_unlock_server(server);
  943. return 0;
  944. }
  945. #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
  946. #ifdef CONFIG_NCPFS_NLS
  947. /* This are the NLS conversion routines with inspirations and code parts
  948. * from the vfat file system and hints from Petr Vandrovec.
  949. */
  950. int
  951. ncp__io2vol(struct ncp_server *server, unsigned char *vname, unsigned int *vlen,
  952. const unsigned char *iname, unsigned int ilen, int cc)
  953. {
  954. struct nls_table *in = server->nls_io;
  955. struct nls_table *out = server->nls_vol;
  956. unsigned char *vname_start;
  957. unsigned char *vname_end;
  958. const unsigned char *iname_end;
  959. iname_end = iname + ilen;
  960. vname_start = vname;
  961. vname_end = vname + *vlen - 1;
  962. while (iname < iname_end) {
  963. int chl;
  964. wchar_t ec;
  965. if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) {
  966. int k;
  967. unicode_t u;
  968. k = utf8_to_utf32(iname, iname_end - iname, &u);
  969. if (k < 0 || u > MAX_WCHAR_T)
  970. return -EINVAL;
  971. iname += k;
  972. ec = u;
  973. } else {
  974. if (*iname == NCP_ESC) {
  975. int k;
  976. if (iname_end - iname < 5)
  977. goto nospec;
  978. ec = 0;
  979. for (k = 1; k < 5; k++) {
  980. unsigned char nc;
  981. nc = iname[k] - '0';
  982. if (nc >= 10) {
  983. nc -= 'A' - '0' - 10;
  984. if ((nc < 10) || (nc > 15)) {
  985. goto nospec;
  986. }
  987. }
  988. ec = (ec << 4) | nc;
  989. }
  990. iname += 5;
  991. } else {
  992. nospec:;
  993. if ( (chl = in->char2uni(iname, iname_end - iname, &ec)) < 0)
  994. return chl;
  995. iname += chl;
  996. }
  997. }
  998. /* unitoupper should be here! */
  999. chl = out->uni2char(ec, vname, vname_end - vname);
  1000. if (chl < 0)
  1001. return chl;
  1002. /* this is wrong... */
  1003. if (cc) {
  1004. int chi;
  1005. for (chi = 0; chi < chl; chi++){
  1006. vname[chi] = ncp_toupper(out, vname[chi]);
  1007. }
  1008. }
  1009. vname += chl;
  1010. }
  1011. *vname = 0;
  1012. *vlen = vname - vname_start;
  1013. return 0;
  1014. }
  1015. int
  1016. ncp__vol2io(struct ncp_server *server, unsigned char *iname, unsigned int *ilen,
  1017. const unsigned char *vname, unsigned int vlen, int cc)
  1018. {
  1019. struct nls_table *in = server->nls_vol;
  1020. struct nls_table *out = server->nls_io;
  1021. const unsigned char *vname_end;
  1022. unsigned char *iname_start;
  1023. unsigned char *iname_end;
  1024. unsigned char *vname_cc;
  1025. int err;
  1026. vname_cc = NULL;
  1027. if (cc) {
  1028. int i;
  1029. /* this is wrong! */
  1030. vname_cc = kmalloc(vlen, GFP_KERNEL);
  1031. if (!vname_cc)
  1032. return -ENOMEM;
  1033. for (i = 0; i < vlen; i++)
  1034. vname_cc[i] = ncp_tolower(in, vname[i]);
  1035. vname = vname_cc;
  1036. }
  1037. iname_start = iname;
  1038. iname_end = iname + *ilen - 1;
  1039. vname_end = vname + vlen;
  1040. while (vname < vname_end) {
  1041. wchar_t ec;
  1042. int chl;
  1043. if ( (chl = in->char2uni(vname, vname_end - vname, &ec)) < 0) {
  1044. err = chl;
  1045. goto quit;
  1046. }
  1047. vname += chl;
  1048. /* unitolower should be here! */
  1049. if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) {
  1050. int k;
  1051. k = utf32_to_utf8(ec, iname, iname_end - iname);
  1052. if (k < 0) {
  1053. err = -ENAMETOOLONG;
  1054. goto quit;
  1055. }
  1056. iname += k;
  1057. } else {
  1058. if ( (chl = out->uni2char(ec, iname, iname_end - iname)) >= 0) {
  1059. iname += chl;
  1060. } else {
  1061. int k;
  1062. if (iname_end - iname < 5) {
  1063. err = -ENAMETOOLONG;
  1064. goto quit;
  1065. }
  1066. *iname = NCP_ESC;
  1067. for (k = 4; k > 0; k--) {
  1068. unsigned char v;
  1069. v = (ec & 0xF) + '0';
  1070. if (v > '9') {
  1071. v += 'A' - '9' - 1;
  1072. }
  1073. iname[k] = v;
  1074. ec >>= 4;
  1075. }
  1076. iname += 5;
  1077. }
  1078. }
  1079. }
  1080. *iname = 0;
  1081. *ilen = iname - iname_start;
  1082. err = 0;
  1083. quit:;
  1084. if (cc)
  1085. kfree(vname_cc);
  1086. return err;
  1087. }
  1088. #else
  1089. int
  1090. ncp__io2vol(unsigned char *vname, unsigned int *vlen,
  1091. const unsigned char *iname, unsigned int ilen, int cc)
  1092. {
  1093. int i;
  1094. if (*vlen <= ilen)
  1095. return -ENAMETOOLONG;
  1096. if (cc)
  1097. for (i = 0; i < ilen; i++) {
  1098. *vname = toupper(*iname);
  1099. vname++;
  1100. iname++;
  1101. }
  1102. else {
  1103. memmove(vname, iname, ilen);
  1104. vname += ilen;
  1105. }
  1106. *vlen = ilen;
  1107. *vname = 0;
  1108. return 0;
  1109. }
  1110. int
  1111. ncp__vol2io(unsigned char *iname, unsigned int *ilen,
  1112. const unsigned char *vname, unsigned int vlen, int cc)
  1113. {
  1114. int i;
  1115. if (*ilen <= vlen)
  1116. return -ENAMETOOLONG;
  1117. if (cc)
  1118. for (i = 0; i < vlen; i++) {
  1119. *iname = tolower(*vname);
  1120. iname++;
  1121. vname++;
  1122. }
  1123. else {
  1124. memmove(iname, vname, vlen);
  1125. iname += vlen;
  1126. }
  1127. *ilen = vlen;
  1128. *iname = 0;
  1129. return 0;
  1130. }
  1131. #endif