Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.0 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFLABEL.C - */
  4. /* */
  5. /* Windows File System Diskette Labelling Routines */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. //#include "lstrfns.h"
  10. /*--------------------------------------------------------------------------*/
  11. /* */
  12. /* CreateVolumeLabel() - */
  13. /* */
  14. /*--------------------------------------------------------------------------*/
  15. INT
  16. APIENTRY
  17. CreateVolumeLabel(
  18. INT nDrive,
  19. LPSTR lpNewVolLabel
  20. )
  21. {
  22. HFILE fh;
  23. register INT i;
  24. register LPSTR p;
  25. CHAR szFullVolName[16]; /* Sample: A:\12345678.EXT,\0 */
  26. LPSTR lpStart = lpNewVolLabel;
  27. lstrcpy((LPSTR)szFullVolName, GetRootPath((WORD)nDrive));
  28. /* If the volume label has more than 8 chars, we must seperate the
  29. * name and the extension by a '.'
  30. */
  31. p = &szFullVolName[3];
  32. /* Copy the file 8 characters of the VolLabel */
  33. for (i=0; i < 8; i++) {
  34. if (!(*p++ = *lpNewVolLabel++))
  35. break;
  36. }
  37. if (i == 8) {
  38. /* Seperate the extension part of it with a '.' */
  39. *p++ = '.';
  40. /* Copy the extension */
  41. i = 0;
  42. while (*p++ = *lpNewVolLabel++) {
  43. if (++i == 3) {
  44. /* Make sure we do not end on a lead byte; notice this is not
  45. * necessary if the label came from an edit box with
  46. * EM_LIMITEXT of 11; also notice that according to the
  47. * DBCS seminar notes, we do NOT need this check before the '.'
  48. */
  49. for (lpNewVolLabel=lpStart; lpNewVolLabel-lpStart<11;
  50. lpNewVolLabel = AnsiNext(lpNewVolLabel))
  51. /* do nothing */ ;
  52. if (lpNewVolLabel-lpStart > 11)
  53. --p;
  54. *p = TEXT('\0');
  55. break;
  56. }
  57. }
  58. }
  59. /* Create a file with the attribute "VOLUME LABEL" */
  60. if ((fh = CreateVolumeFile(szFullVolName)) == 0)
  61. return (-1);
  62. M_lclose(fh);
  63. return (0);
  64. }
  65. /*--------------------------------------------------------------------------*/
  66. /* */
  67. /* SetVolumeLabel() - */
  68. /* */
  69. /*--------------------------------------------------------------------------*/
  70. INT
  71. APIENTRY
  72. MySetVolumeLabel(
  73. INT nDrive,
  74. BOOL bOldVolLabelExists,
  75. LPSTR lpNewVolLabel
  76. )
  77. {
  78. INT iRet = 0;
  79. CHAR szTemp[MAXFILENAMELEN];
  80. AnsiToOem(lpNewVolLabel, szTemp);
  81. // invalid chars copied from DOS user docs
  82. #ifdef STRCSPN_IS_DEFINED_OR_LABEL_MENUITEM_IS_ENABLED
  83. if (szTemp[StrCSpn(szTemp, " *?/\\|.,;:+=[]()&^<>\"")] != '\0')
  84. return (-1);
  85. #endif
  86. /* Check if there is an old volume label. */
  87. if (bOldVolLabelExists) {
  88. /* Are we changing or deleting the volume label? */
  89. if (*szTemp) {
  90. /* Yup! There is a new one too! So, change the Vol label */
  91. // EDH ChangeVolumeLabel cannot change label to an existing dir/file name,
  92. // since it uses the DOS Rename to do the work. (I consider this a bug
  93. // in DOS' Rename func.) Anyway, use delete/create to change label
  94. // instead. 13 Oct 91
  95. // iRet = ChangeVolumeLabel(nDrive, szTemp);
  96. iRet = DeleteVolumeLabel(nDrive);
  97. iRet = CreateVolumeLabel(nDrive, szTemp);
  98. } else {
  99. /* User wants to remove the Vol label. Remove it */
  100. iRet = DeleteVolumeLabel(nDrive);
  101. }
  102. } else {
  103. /* We are creating a new label. */
  104. if (*szTemp)
  105. iRet = CreateVolumeLabel(nDrive, szTemp);
  106. }
  107. return (iRet);
  108. }