2 * Volume management functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996, 2004 Alexandre Julliard
6 * Copyright 1999 Petr Tomasek
7 * Copyright 2000 Andreas Mohr
8 * Copyright 2003 Eric Pouech
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
33 #define WIN32_NO_STATUS
40 #include "kernel_private.h"
41 #include "wine/library.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(volume
);
47 #define SUPERBLOCK_SIZE 2048
49 #define CDFRAMES_PERSEC 75
50 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
51 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
52 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc)->TrackData[(idx) - (toc)->FirstTrack].Address)
54 #define GETWORD(buf,off) MAKEWORD(buf[(off)],buf[(off+1)])
55 #define GETLONG(buf,off) MAKELONG(GETWORD(buf,off),GETWORD(buf,off+2))
59 FS_ERROR
, /* error accessing the device */
60 FS_UNKNOWN
, /* unknown file system */
66 static const WCHAR drive_types
[][8] =
68 { 0 }, /* DRIVE_UNKNOWN */
69 { 0 }, /* DRIVE_NO_ROOT_DIR */
70 {'f','l','o','p','p','y',0}, /* DRIVE_REMOVABLE */
71 {'h','d',0}, /* DRIVE_FIXED */
72 {'n','e','t','w','o','r','k',0}, /* DRIVE_REMOTE */
73 {'c','d','r','o','m',0}, /* DRIVE_CDROM */
74 {'r','a','m','d','i','s','k',0} /* DRIVE_RAMDISK */
77 /* read a Unix symlink; returned buffer must be freed by caller */
78 static char *read_symlink( const char *path
)
85 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
87 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
90 ret
= readlink( path
, buffer
, size
);
94 HeapFree( GetProcessHeap(), 0, buffer
);
102 HeapFree( GetProcessHeap(), 0, buffer
);
107 /* get the path of a dos device symlink in the $WINEPREFIX/dosdevices directory */
108 static char *get_dos_device_path( LPCWSTR name
)
110 const char *config_dir
= wine_get_config_dir();
114 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
115 strlen(config_dir
) + sizeof("/dosdevices/") + 5 )))
117 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
120 strcpy( buffer
, config_dir
);
121 strcat( buffer
, "/dosdevices/" );
122 dev
= buffer
+ strlen(buffer
);
123 /* no codepage conversion, DOS device names are ASCII anyway */
124 for (i
= 0; i
< 5; i
++)
125 if (!(dev
[i
] = (char)tolowerW(name
[i
]))) break;
131 /* open a handle to a device root */
132 static BOOL
open_device_root( LPCWSTR root
, HANDLE
*handle
)
134 static const WCHAR default_rootW
[] = {'\\',0};
135 UNICODE_STRING nt_name
;
136 OBJECT_ATTRIBUTES attr
;
140 if (!root
) root
= default_rootW
;
141 if (!RtlDosPathNameToNtPathName_U( root
, &nt_name
, NULL
, NULL
))
143 SetLastError( ERROR_PATH_NOT_FOUND
);
146 attr
.Length
= sizeof(attr
);
147 attr
.RootDirectory
= 0;
148 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
149 attr
.ObjectName
= &nt_name
;
150 attr
.SecurityDescriptor
= NULL
;
151 attr
.SecurityQualityOfService
= NULL
;
153 status
= NtOpenFile( handle
, 0, &attr
, &io
, 0,
154 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
);
155 RtlFreeUnicodeString( &nt_name
);
156 if (status
!= STATUS_SUCCESS
)
158 SetLastError( RtlNtStatusToDosError(status
) );
164 /* get the label by reading it from a file at the root of the filesystem */
165 static void get_filesystem_label( const WCHAR
*device
, WCHAR
*label
, DWORD len
)
168 WCHAR labelW
[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
170 labelW
[0] = device
[4];
171 handle
= CreateFileW( labelW
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
172 OPEN_EXISTING
, 0, 0 );
173 if (handle
!= INVALID_HANDLE_VALUE
)
175 char buffer
[256], *p
;
178 if (!ReadFile( handle
, buffer
, sizeof(buffer
)-1, &size
, NULL
)) size
= 0;
179 CloseHandle( handle
);
181 while (p
> buffer
&& (p
[-1] == ' ' || p
[-1] == '\r' || p
[-1] == '\n')) p
--;
183 if (!MultiByteToWideChar( CP_UNIXCP
, 0, buffer
, -1, label
, len
))
189 /* get the serial number by reading it from a file at the root of the filesystem */
190 static DWORD
get_filesystem_serial( const WCHAR
*device
)
193 WCHAR serialW
[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','s','e','r','i','a','l',0};
195 serialW
[0] = device
[4];
196 handle
= CreateFileW( serialW
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
197 OPEN_EXISTING
, 0, 0 );
198 if (handle
!= INVALID_HANDLE_VALUE
)
203 if (!ReadFile( handle
, buffer
, sizeof(buffer
)-1, &size
, NULL
)) size
= 0;
204 CloseHandle( handle
);
206 return strtoul( buffer
, NULL
, 16 );
211 /* fetch the type of a drive from the registry */
212 static UINT
get_registry_drive_type( const WCHAR
*root
)
214 static const WCHAR drive_types_keyW
[] = {'M','a','c','h','i','n','e','\\',
215 'S','o','f','t','w','a','r','e','\\',
216 'W','i','n','e','\\',
217 'D','r','i','v','e','s',0 };
218 OBJECT_ATTRIBUTES attr
;
219 UNICODE_STRING nameW
;
222 UINT ret
= DRIVE_UNKNOWN
;
223 char tmp
[32 + sizeof(KEY_VALUE_PARTIAL_INFORMATION
)];
224 WCHAR driveW
[] = {'A',':',0};
226 attr
.Length
= sizeof(attr
);
227 attr
.RootDirectory
= 0;
228 attr
.ObjectName
= &nameW
;
230 attr
.SecurityDescriptor
= NULL
;
231 attr
.SecurityQualityOfService
= NULL
;
232 RtlInitUnicodeString( &nameW
, drive_types_keyW
);
233 /* @@ Wine registry key: HKLM\Software\Wine\Drives */
234 if (NtOpenKey( &hkey
, KEY_ALL_ACCESS
, &attr
) != STATUS_SUCCESS
) return DRIVE_UNKNOWN
;
236 if (root
) driveW
[0] = root
[0];
239 WCHAR path
[MAX_PATH
];
240 GetCurrentDirectoryW( MAX_PATH
, path
);
244 RtlInitUnicodeString( &nameW
, driveW
);
245 if (!NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, tmp
, sizeof(tmp
), &dummy
))
248 WCHAR
*data
= (WCHAR
*)((KEY_VALUE_PARTIAL_INFORMATION
*)tmp
)->Data
;
250 for (i
= 0; i
< sizeof(drive_types
)/sizeof(drive_types
[0]); i
++)
252 if (!strcmpiW( data
, drive_types
[i
] ))
264 /******************************************************************
265 * VOLUME_FindCdRomDataBestVoldesc
267 static DWORD
VOLUME_FindCdRomDataBestVoldesc( HANDLE handle
)
269 BYTE cur_vd_type
, max_vd_type
= 0;
271 DWORD size
, offs
, best_offs
= 0, extra_offs
= 0;
273 for (offs
= 0x8000; offs
<= 0x9800; offs
+= 0x800)
275 /* if 'CDROM' occurs at position 8, this is a pre-iso9660 cd, and
276 * the volume label is displaced forward by 8
278 if (SetFilePointer( handle
, offs
, NULL
, FILE_BEGIN
) != offs
) break;
279 if (!ReadFile( handle
, buffer
, sizeof(buffer
), &size
, NULL
)) break;
280 if (size
!= sizeof(buffer
)) break;
281 /* check for non-ISO9660 signature */
282 if (!memcmp( buffer
+ 11, "ROM", 3 )) extra_offs
= 8;
283 cur_vd_type
= buffer
[extra_offs
];
284 if (cur_vd_type
== 0xff) /* voldesc set terminator */
286 if (cur_vd_type
> max_vd_type
)
288 max_vd_type
= cur_vd_type
;
289 best_offs
= offs
+ extra_offs
;
296 /***********************************************************************
297 * VOLUME_ReadFATSuperblock
299 static enum fs_type
VOLUME_ReadFATSuperblock( HANDLE handle
, BYTE
*buff
)
303 /* try a fixed disk, with a FAT partition */
304 if (SetFilePointer( handle
, 0, NULL
, FILE_BEGIN
) != 0 ||
305 !ReadFile( handle
, buff
, SUPERBLOCK_SIZE
, &size
, NULL
))
308 if (size
< SUPERBLOCK_SIZE
) return FS_UNKNOWN
;
310 /* FIXME: do really all FAT have their name beginning with
311 * "FAT" ? (At least FAT12, FAT16 and FAT32 have :)
313 if (!memcmp(buff
+0x36, "FAT", 3) || !memcmp(buff
+0x52, "FAT", 3))
315 /* guess which type of FAT we have */
317 unsigned int sectors
,
326 sect_per_fat
= GETWORD(buff
, 0x16);
327 if (!sect_per_fat
) sect_per_fat
= GETLONG(buff
, 0x24);
328 total_sectors
= GETWORD(buff
, 0x13);
330 total_sectors
= GETLONG(buff
, 0x20);
331 num_boot_sectors
= GETWORD(buff
, 0x0e);
332 num_fats
= buff
[0x10];
333 num_root_dir_ents
= GETWORD(buff
, 0x11);
334 bytes_per_sector
= GETWORD(buff
, 0x0b);
335 sectors_per_cluster
= buff
[0x0d];
336 /* check if the parameters are reasonable and will not cause
337 * arithmetic errors in the calculation */
338 reasonable
= num_boot_sectors
< 16 &&
340 bytes_per_sector
>= 512 && bytes_per_sector
% 512 == 0 &&
341 sectors_per_cluster
> 1;
342 if (!reasonable
) return FS_UNKNOWN
;
343 sectors
= total_sectors
- num_boot_sectors
- num_fats
* sect_per_fat
-
344 (num_root_dir_ents
* 32 + bytes_per_sector
- 1) / bytes_per_sector
;
345 nclust
= sectors
/ sectors_per_cluster
;
346 if ((buff
[0x42] == 0x28 || buff
[0x42] == 0x29) &&
347 !memcmp(buff
+0x52, "FAT", 3)) return FS_FAT32
;
350 if ((buff
[0x26] == 0x28 || buff
[0x26] == 0x29) &&
351 !memcmp(buff
+0x36, "FAT", 3))
359 /***********************************************************************
360 * VOLUME_ReadCDSuperblock
362 static enum fs_type
VOLUME_ReadCDSuperblock( HANDLE handle
, BYTE
*buff
)
364 DWORD size
, offs
= VOLUME_FindCdRomDataBestVoldesc( handle
);
366 if (!offs
) return FS_UNKNOWN
;
368 if (SetFilePointer( handle
, offs
, NULL
, FILE_BEGIN
) != offs
||
369 !ReadFile( handle
, buff
, SUPERBLOCK_SIZE
, &size
, NULL
) ||
370 size
!= SUPERBLOCK_SIZE
)
373 /* check for iso9660 present */
374 if (!memcmp(&buff
[1], "CD001", 5)) return FS_ISO9660
;
379 /**************************************************************************
380 * VOLUME_GetSuperblockLabel
382 static void VOLUME_GetSuperblockLabel( const WCHAR
*device
, enum fs_type type
, const BYTE
*superblock
,
383 WCHAR
*label
, DWORD len
)
385 const BYTE
*label_ptr
= NULL
;
394 get_filesystem_label( device
, label
, len
);
397 label_ptr
= superblock
+ 0x2b;
401 label_ptr
= superblock
+ 0x47;
406 BYTE ver
= superblock
[0x5a];
408 if (superblock
[0x58] == 0x25 && superblock
[0x59] == 0x2f && /* Unicode ID */
409 ((ver
== 0x40) || (ver
== 0x43) || (ver
== 0x45)))
410 { /* yippee, unicode */
413 if (len
> 17) len
= 17;
414 for (i
= 0; i
< len
-1; i
++)
415 label
[i
] = (superblock
[40+2*i
] << 8) | superblock
[41+2*i
];
417 while (i
&& label
[i
-1] == ' ') label
[--i
] = 0;
420 label_ptr
= superblock
+ 40;
425 if (label_len
) RtlMultiByteToUnicodeN( label
, (len
-1) * sizeof(WCHAR
),
426 &label_len
, (LPCSTR
)label_ptr
, label_len
);
427 label_len
/= sizeof(WCHAR
);
428 label
[label_len
] = 0;
429 while (label_len
&& label
[label_len
-1] == ' ') label
[--label_len
] = 0;
433 /**************************************************************************
434 * VOLUME_GetSuperblockSerial
436 static DWORD
VOLUME_GetSuperblockSerial( const WCHAR
*device
, enum fs_type type
, const BYTE
*superblock
)
443 return get_filesystem_serial( device
);
445 return GETLONG( superblock
, 0x27 );
447 return GETLONG( superblock
, 0x33 );
453 sum
[0] = sum
[1] = sum
[2] = sum
[3] = 0;
454 for (i
= 0; i
< 2048; i
+= 4)
456 /* DON'T optimize this into DWORD !! (breaks overflow) */
457 sum
[0] += superblock
[i
+0];
458 sum
[1] += superblock
[i
+1];
459 sum
[2] += superblock
[i
+2];
460 sum
[3] += superblock
[i
+3];
463 * OK, another braindead one... argh. Just believe it.
464 * Me$$ysoft chose to reverse the serial number in NT4/W2K.
465 * It's true and nobody will ever be able to change it.
467 if (GetVersion() & 0x80000000)
468 return (sum
[3] << 24) | (sum
[2] << 16) | (sum
[1] << 8) | sum
[0];
470 return (sum
[0] << 24) | (sum
[1] << 16) | (sum
[2] << 8) | sum
[3];
477 /**************************************************************************
478 * VOLUME_GetAudioCDSerial
480 static DWORD
VOLUME_GetAudioCDSerial( const CDROM_TOC
*toc
)
485 for (i
= 0; i
<= toc
->LastTrack
- toc
->FirstTrack
; i
++)
486 serial
+= ((toc
->TrackData
[i
].Address
[1] << 16) |
487 (toc
->TrackData
[i
].Address
[2] << 8) |
488 toc
->TrackData
[i
].Address
[3]);
491 * dwStart, dwEnd collect the beginning and end of the disc respectively, in
493 * There it is collected for correcting the serial when there are less than
496 if (toc
->LastTrack
- toc
->FirstTrack
+ 1 < 3)
498 DWORD dwStart
= FRAME_OF_TOC(toc
, toc
->FirstTrack
);
499 DWORD dwEnd
= FRAME_OF_TOC(toc
, toc
->LastTrack
+ 1);
500 serial
+= dwEnd
- dwStart
;
506 /***********************************************************************
507 * GetVolumeInformationW (KERNEL32.@)
509 BOOL WINAPI
GetVolumeInformationW( LPCWSTR root
, LPWSTR label
, DWORD label_len
,
510 DWORD
*serial
, DWORD
*filename_len
, DWORD
*flags
,
511 LPWSTR fsname
, DWORD fsname_len
)
513 static const WCHAR audiocdW
[] = {'A','u','d','i','o',' ','C','D',0};
514 static const WCHAR fatW
[] = {'F','A','T',0};
515 static const WCHAR ntfsW
[] = {'N','T','F','S',0};
516 static const WCHAR cdfsW
[] = {'C','D','F','S',0};
518 WCHAR device
[] = {'\\','\\','.','\\','A',':',0};
520 enum fs_type type
= FS_UNKNOWN
;
524 WCHAR path
[MAX_PATH
];
525 GetCurrentDirectoryW( MAX_PATH
, path
);
530 if (!root
[0] || root
[1] != ':')
532 SetLastError( ERROR_INVALID_NAME
);
538 /* try to open the device */
540 handle
= CreateFileW( device
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
541 NULL
, OPEN_EXISTING
, 0, 0 );
542 if (handle
!= INVALID_HANDLE_VALUE
)
544 BYTE superblock
[SUPERBLOCK_SIZE
];
548 /* check for audio CD */
549 /* FIXME: we only check the first track for now */
550 if (DeviceIoControl( handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0, &toc
, sizeof(toc
), &br
, 0 ))
552 if (!(toc
.TrackData
[0].Control
& 0x04)) /* audio track */
554 TRACE( "%s: found audio CD\n", debugstr_w(device
) );
555 if (label
) lstrcpynW( label
, audiocdW
, label_len
);
556 if (serial
) *serial
= VOLUME_GetAudioCDSerial( &toc
);
557 CloseHandle( handle
);
561 type
= VOLUME_ReadCDSuperblock( handle
, superblock
);
565 type
= VOLUME_ReadFATSuperblock( handle
, superblock
);
566 if (type
== FS_UNKNOWN
) type
= VOLUME_ReadCDSuperblock( handle
, superblock
);
568 CloseHandle( handle
);
569 TRACE( "%s: found fs type %d\n", debugstr_w(device
), type
);
570 if (type
== FS_ERROR
) return FALSE
;
572 if (label
&& label_len
) VOLUME_GetSuperblockLabel( device
, type
, superblock
, label
, label_len
);
573 if (serial
) *serial
= VOLUME_GetSuperblockSerial( device
, type
, superblock
);
576 else TRACE( "cannot open device %s: err %d\n", debugstr_w(device
), GetLastError() );
578 /* we couldn't open the device, fallback to default strategy */
580 switch(GetDriveTypeW( root
))
583 case DRIVE_NO_ROOT_DIR
:
584 SetLastError( ERROR_NOT_READY
);
586 case DRIVE_REMOVABLE
:
597 if (label
&& label_len
) get_filesystem_label( device
, label
, label_len
);
598 if (serial
) *serial
= get_filesystem_serial( device
);
600 fill_fs_info
: /* now fill in the information that depends on the file system type */
605 if (fsname
) lstrcpynW( fsname
, cdfsW
, fsname_len
);
606 if (filename_len
) *filename_len
= 221;
607 if (flags
) *flags
= FILE_READ_ONLY_VOLUME
;
611 if (fsname
) lstrcpynW( fsname
, fatW
, fsname_len
);
612 if (filename_len
) *filename_len
= 255;
613 if (flags
) *flags
= FILE_CASE_PRESERVED_NAMES
; /* FIXME */
616 if (fsname
) lstrcpynW( fsname
, ntfsW
, fsname_len
);
617 if (filename_len
) *filename_len
= 255;
618 if (flags
) *flags
= FILE_CASE_PRESERVED_NAMES
;
625 /***********************************************************************
626 * GetVolumeInformationA (KERNEL32.@)
628 BOOL WINAPI
GetVolumeInformationA( LPCSTR root
, LPSTR label
,
629 DWORD label_len
, DWORD
*serial
,
630 DWORD
*filename_len
, DWORD
*flags
,
631 LPSTR fsname
, DWORD fsname_len
)
634 LPWSTR labelW
, fsnameW
;
637 if (root
&& !(rootW
= FILE_name_AtoW( root
, FALSE
))) return FALSE
;
639 labelW
= label
? HeapAlloc(GetProcessHeap(), 0, label_len
* sizeof(WCHAR
)) : NULL
;
640 fsnameW
= fsname
? HeapAlloc(GetProcessHeap(), 0, fsname_len
* sizeof(WCHAR
)) : NULL
;
642 if ((ret
= GetVolumeInformationW(rootW
, labelW
, label_len
, serial
,
643 filename_len
, flags
, fsnameW
, fsname_len
)))
645 if (label
) FILE_name_WtoA( labelW
, -1, label
, label_len
);
646 if (fsname
) FILE_name_WtoA( fsnameW
, -1, fsname
, fsname_len
);
649 HeapFree( GetProcessHeap(), 0, labelW
);
650 HeapFree( GetProcessHeap(), 0, fsnameW
);
656 /***********************************************************************
657 * SetVolumeLabelW (KERNEL32.@)
659 BOOL WINAPI
SetVolumeLabelW( LPCWSTR root
, LPCWSTR label
)
661 WCHAR device
[] = {'\\','\\','.','\\','A',':',0};
663 enum fs_type type
= FS_UNKNOWN
;
667 WCHAR path
[MAX_PATH
];
668 GetCurrentDirectoryW( MAX_PATH
, path
);
673 if (!root
[0] || root
[1] != ':')
675 SetLastError( ERROR_INVALID_NAME
);
681 /* try to open the device */
683 handle
= CreateFileW( device
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
684 NULL
, OPEN_EXISTING
, 0, 0 );
685 if (handle
!= INVALID_HANDLE_VALUE
)
687 BYTE superblock
[SUPERBLOCK_SIZE
];
689 type
= VOLUME_ReadFATSuperblock( handle
, superblock
);
690 if (type
== FS_UNKNOWN
) type
= VOLUME_ReadCDSuperblock( handle
, superblock
);
691 CloseHandle( handle
);
692 if (type
!= FS_UNKNOWN
)
694 /* we can't set the label on FAT or CDROM file systems */
695 TRACE( "cannot set label on device %s type %d\n", debugstr_w(device
), type
);
696 SetLastError( ERROR_ACCESS_DENIED
);
702 TRACE( "cannot open device %s: err %d\n", debugstr_w(device
), GetLastError() );
703 if (GetLastError() == ERROR_ACCESS_DENIED
) return FALSE
;
706 /* we couldn't open the device, fallback to default strategy */
708 switch(GetDriveTypeW( root
))
711 case DRIVE_NO_ROOT_DIR
:
712 SetLastError( ERROR_NOT_READY
);
714 case DRIVE_REMOVABLE
:
717 WCHAR labelW
[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
719 labelW
[0] = device
[4];
720 handle
= CreateFileW( labelW
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
721 CREATE_ALWAYS
, 0, 0 );
722 if (handle
!= INVALID_HANDLE_VALUE
)
727 if (!WideCharToMultiByte( CP_UNIXCP
, 0, label
, -1, buffer
, sizeof(buffer
), NULL
, NULL
))
728 buffer
[sizeof(buffer
)-1] = 0;
729 WriteFile( handle
, buffer
, strlen(buffer
), &size
, NULL
);
730 CloseHandle( handle
);
738 SetLastError( ERROR_ACCESS_DENIED
);
744 /***********************************************************************
745 * SetVolumeLabelA (KERNEL32.@)
747 BOOL WINAPI
SetVolumeLabelA(LPCSTR root
, LPCSTR volname
)
749 WCHAR
*rootW
= NULL
, *volnameW
= NULL
;
752 if (root
&& !(rootW
= FILE_name_AtoW( root
, FALSE
))) return FALSE
;
753 if (volname
&& !(volnameW
= FILE_name_AtoW( volname
, TRUE
))) return FALSE
;
754 ret
= SetVolumeLabelW( rootW
, volnameW
);
755 HeapFree( GetProcessHeap(), 0, volnameW
);
760 /***********************************************************************
761 * GetVolumeNameForVolumeMountPointA (KERNEL32.@)
763 BOOL WINAPI
GetVolumeNameForVolumeMountPointA( LPCSTR path
, LPSTR volume
, DWORD size
)
766 WCHAR volumeW
[50], *pathW
= NULL
;
767 DWORD len
= min( sizeof(volumeW
) / sizeof(WCHAR
), size
);
769 TRACE("(%s, %p, %x)\n", debugstr_a(path
), volume
, size
);
771 if (!path
|| !(pathW
= FILE_name_AtoW( path
, TRUE
)))
774 if ((ret
= GetVolumeNameForVolumeMountPointW( pathW
, volumeW
, len
)))
775 FILE_name_WtoA( volumeW
, -1, volume
, len
);
777 HeapFree( GetProcessHeap(), 0, pathW
);
781 /***********************************************************************
782 * GetVolumeNameForVolumeMountPointW (KERNEL32.@)
784 BOOL WINAPI
GetVolumeNameForVolumeMountPointW( LPCWSTR path
, LPWSTR volume
, DWORD size
)
787 static const WCHAR fmt
[] =
788 { '\\','\\','?','\\','V','o','l','u','m','e','{','%','0','2','x','}','\\',0 };
790 TRACE("(%s, %p, %x)\n", debugstr_w(path
), volume
, size
);
792 if (!path
|| !path
[0]) return FALSE
;
794 if (size
>= sizeof(fmt
) / sizeof(WCHAR
))
796 /* FIXME: will break when we support volume mounts */
797 sprintfW( volume
, fmt
, tolowerW( path
[0] ) - 'a' );
803 /***********************************************************************
804 * DefineDosDeviceW (KERNEL32.@)
806 BOOL WINAPI
DefineDosDeviceW( DWORD flags
, LPCWSTR devname
, LPCWSTR targetpath
)
810 char *path
= NULL
, *target
, *p
;
812 TRACE("%x, %s, %s\n", flags
, debugstr_w(devname
), debugstr_w(targetpath
));
814 if (!(flags
& DDD_REMOVE_DEFINITION
))
816 if (!(flags
& DDD_RAW_TARGET_PATH
))
818 FIXME( "(0x%08x,%s,%s) DDD_RAW_TARGET_PATH flag not set, not supported yet\n",
819 flags
, debugstr_w(devname
), debugstr_w(targetpath
) );
820 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
824 len
= WideCharToMultiByte( CP_UNIXCP
, 0, targetpath
, -1, NULL
, 0, NULL
, NULL
);
825 if ((target
= HeapAlloc( GetProcessHeap(), 0, len
)))
827 WideCharToMultiByte( CP_UNIXCP
, 0, targetpath
, -1, target
, len
, NULL
, NULL
);
828 for (p
= target
; *p
; p
++) if (*p
== '\\') *p
= '/';
832 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
838 /* first check for a DOS device */
840 if ((dosdev
= RtlIsDosDeviceName_U( devname
)))
844 memcpy( name
, devname
+ HIWORD(dosdev
)/sizeof(WCHAR
), LOWORD(dosdev
) );
845 name
[LOWORD(dosdev
)/sizeof(WCHAR
)] = 0;
846 path
= get_dos_device_path( name
);
848 else if (isalphaW(devname
[0]) && devname
[1] == ':' && !devname
[2]) /* drive mapping */
850 path
= get_dos_device_path( devname
);
852 else SetLastError( ERROR_FILE_NOT_FOUND
);
858 TRACE( "creating symlink %s -> %s\n", path
, target
);
860 if (!symlink( target
, path
)) ret
= TRUE
;
861 else FILE_SetDosError();
865 TRACE( "removing symlink %s\n", path
);
866 if (!unlink( path
)) ret
= TRUE
;
867 else FILE_SetDosError();
869 HeapFree( GetProcessHeap(), 0, path
);
871 HeapFree( GetProcessHeap(), 0, target
);
876 /***********************************************************************
877 * DefineDosDeviceA (KERNEL32.@)
879 BOOL WINAPI
DefineDosDeviceA(DWORD flags
, LPCSTR devname
, LPCSTR targetpath
)
881 WCHAR
*devW
, *targetW
= NULL
;
884 if (!(devW
= FILE_name_AtoW( devname
, FALSE
))) return FALSE
;
885 if (targetpath
&& !(targetW
= FILE_name_AtoW( targetpath
, TRUE
))) return FALSE
;
886 ret
= DefineDosDeviceW(flags
, devW
, targetW
);
887 HeapFree( GetProcessHeap(), 0, targetW
);
892 /***********************************************************************
893 * QueryDosDeviceW (KERNEL32.@)
895 * returns array of strings terminated by \0, terminated by \0
897 DWORD WINAPI
QueryDosDeviceW( LPCWSTR devname
, LPWSTR target
, DWORD bufsize
)
899 static const WCHAR auxW
[] = {'A','U','X',0};
900 static const WCHAR nulW
[] = {'N','U','L',0};
901 static const WCHAR prnW
[] = {'P','R','N',0};
902 static const WCHAR comW
[] = {'C','O','M',0};
903 static const WCHAR lptW
[] = {'L','P','T',0};
904 static const WCHAR rootW
[] = {'A',':','\\',0};
905 static const WCHAR com0W
[] = {'\\','?','?','\\','C','O','M','0',0};
906 static const WCHAR com1W
[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','C','O','M','1',0,0};
907 static const WCHAR lpt1W
[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','L','P','T','1',0,0};
909 UNICODE_STRING nt_name
;
910 ANSI_STRING unix_name
;
916 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
924 DWORD dosdev
, ret
= 0;
926 if ((dosdev
= RtlIsDosDeviceName_U( devname
)))
928 memcpy( name
, devname
+ HIWORD(dosdev
)/sizeof(WCHAR
), LOWORD(dosdev
) );
929 name
[LOWORD(dosdev
)/sizeof(WCHAR
)] = 0;
931 else if (devname
[0] && devname
[1] == ':' && !devname
[2])
933 memcpy( name
, devname
, 3 * sizeof(WCHAR
) );
937 SetLastError( ERROR_BAD_PATHNAME
);
941 if (!(path
= get_dos_device_path( name
))) return 0;
942 link
= read_symlink( path
);
943 HeapFree( GetProcessHeap(), 0, path
);
947 ret
= MultiByteToWideChar( CP_UNIXCP
, 0, link
, -1, target
, bufsize
);
948 HeapFree( GetProcessHeap(), 0, link
);
950 else if (dosdev
) /* look for device defaults */
952 if (!strcmpiW( name
, auxW
))
954 if (bufsize
>= sizeof(com1W
)/sizeof(WCHAR
))
956 memcpy( target
, com1W
, sizeof(com1W
) );
957 ret
= sizeof(com1W
)/sizeof(WCHAR
);
959 else SetLastError( ERROR_INSUFFICIENT_BUFFER
);
962 if (!strcmpiW( name
, prnW
))
964 if (bufsize
>= sizeof(lpt1W
)/sizeof(WCHAR
))
966 memcpy( target
, lpt1W
, sizeof(lpt1W
) );
967 ret
= sizeof(lpt1W
)/sizeof(WCHAR
);
969 else SetLastError( ERROR_INSUFFICIENT_BUFFER
);
977 strcpyW( nt_buffer
+ 4, name
);
978 RtlInitUnicodeString( &nt_name
, nt_buffer
);
979 status
= wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, TRUE
);
980 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
983 ret
= MultiByteToWideChar( CP_UNIXCP
, 0, unix_name
.Buffer
, -1, target
, bufsize
);
984 RtlFreeAnsiString( &unix_name
);
990 if (ret
< bufsize
) target
[ret
++] = 0; /* add an extra null */
991 for (p
= target
; *p
; p
++) if (*p
== '/') *p
= '\\';
996 else /* return a list of all devices */
1001 if (bufsize
<= (sizeof(auxW
)+sizeof(nulW
)+sizeof(prnW
))/sizeof(WCHAR
))
1003 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1007 memcpy( p
, auxW
, sizeof(auxW
) );
1008 p
+= sizeof(auxW
) / sizeof(WCHAR
);
1009 memcpy( p
, nulW
, sizeof(nulW
) );
1010 p
+= sizeof(nulW
) / sizeof(WCHAR
);
1011 memcpy( p
, prnW
, sizeof(prnW
) );
1012 p
+= sizeof(prnW
) / sizeof(WCHAR
);
1014 strcpyW( nt_buffer
, com0W
);
1015 RtlInitUnicodeString( &nt_name
, nt_buffer
);
1017 for (i
= 1; i
<= 9; i
++)
1019 nt_buffer
[7] = '0' + i
;
1020 if (!wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, TRUE
))
1022 RtlFreeAnsiString( &unix_name
);
1023 if (p
+ 5 >= target
+ bufsize
)
1025 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1034 strcpyW( nt_buffer
+ 4, lptW
);
1035 for (i
= 1; i
<= 9; i
++)
1037 nt_buffer
[7] = '0' + i
;
1038 if (!wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, TRUE
))
1040 RtlFreeAnsiString( &unix_name
);
1041 if (p
+ 5 >= target
+ bufsize
)
1043 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1053 strcpyW( nt_buffer
+ 4, rootW
);
1054 RtlInitUnicodeString( &nt_name
, nt_buffer
);
1056 for (i
= 0; i
< 26; i
++)
1058 nt_buffer
[4] = 'a' + i
;
1059 if (!wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, TRUE
))
1061 RtlFreeAnsiString( &unix_name
);
1062 if (p
+ 3 >= target
+ bufsize
)
1064 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1072 *p
++ = 0; /* terminating null */
1078 /***********************************************************************
1079 * QueryDosDeviceA (KERNEL32.@)
1081 * returns array of strings terminated by \0, terminated by \0
1083 DWORD WINAPI
QueryDosDeviceA( LPCSTR devname
, LPSTR target
, DWORD bufsize
)
1085 DWORD ret
= 0, retW
;
1086 WCHAR
*devnameW
= NULL
;
1089 if (devname
&& !(devnameW
= FILE_name_AtoW( devname
, FALSE
))) return 0;
1091 targetW
= HeapAlloc( GetProcessHeap(),0, bufsize
* sizeof(WCHAR
) );
1094 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1098 retW
= QueryDosDeviceW(devnameW
, targetW
, bufsize
);
1100 ret
= FILE_name_WtoA( targetW
, retW
, target
, bufsize
);
1102 HeapFree(GetProcessHeap(), 0, targetW
);
1107 /***********************************************************************
1108 * GetLogicalDrives (KERNEL32.@)
1110 DWORD WINAPI
GetLogicalDrives(void)
1112 const char *config_dir
= wine_get_config_dir();
1118 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(config_dir
) + sizeof("/dosdevices/a:") )))
1120 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1123 strcpy( buffer
, config_dir
);
1124 strcat( buffer
, "/dosdevices/a:" );
1125 dev
= buffer
+ strlen(buffer
) - 2;
1127 for (i
= 0; i
< 26; i
++)
1130 if (!stat( buffer
, &st
)) ret
|= (1 << i
);
1132 HeapFree( GetProcessHeap(), 0, buffer
);
1137 /***********************************************************************
1138 * GetLogicalDriveStringsA (KERNEL32.@)
1140 UINT WINAPI
GetLogicalDriveStringsA( UINT len
, LPSTR buffer
)
1142 DWORD drives
= GetLogicalDrives();
1145 for (drive
= count
= 0; drive
< 26; drive
++) if (drives
& (1 << drive
)) count
++;
1146 if ((count
* 4) + 1 > len
) return count
* 4 + 1;
1148 for (drive
= 0; drive
< 26; drive
++)
1150 if (drives
& (1 << drive
))
1152 *buffer
++ = 'a' + drive
;
1163 /***********************************************************************
1164 * GetLogicalDriveStringsW (KERNEL32.@)
1166 UINT WINAPI
GetLogicalDriveStringsW( UINT len
, LPWSTR buffer
)
1168 DWORD drives
= GetLogicalDrives();
1171 for (drive
= count
= 0; drive
< 26; drive
++) if (drives
& (1 << drive
)) count
++;
1172 if ((count
* 4) + 1 > len
) return count
* 4 + 1;
1174 for (drive
= 0; drive
< 26; drive
++)
1176 if (drives
& (1 << drive
))
1178 *buffer
++ = 'a' + drive
;
1189 /***********************************************************************
1190 * GetDriveTypeW (KERNEL32.@)
1192 * Returns the type of the disk drive specified. If root is NULL the
1193 * root of the current directory is used.
1197 * Type of drive (from Win32 SDK):
1199 * DRIVE_UNKNOWN unable to find out anything about the drive
1200 * DRIVE_NO_ROOT_DIR nonexistent root dir
1201 * DRIVE_REMOVABLE the disk can be removed from the machine
1202 * DRIVE_FIXED the disk cannot be removed from the machine
1203 * DRIVE_REMOTE network disk
1204 * DRIVE_CDROM CDROM drive
1205 * DRIVE_RAMDISK virtual disk in RAM
1207 UINT WINAPI
GetDriveTypeW(LPCWSTR root
) /* [in] String describing drive */
1209 FILE_FS_DEVICE_INFORMATION info
;
1215 if (!open_device_root( root
, &handle
)) return DRIVE_NO_ROOT_DIR
;
1217 status
= NtQueryVolumeInformationFile( handle
, &io
, &info
, sizeof(info
), FileFsDeviceInformation
);
1219 if (status
!= STATUS_SUCCESS
)
1221 SetLastError( RtlNtStatusToDosError(status
) );
1222 ret
= DRIVE_UNKNOWN
;
1224 else if ((ret
= get_registry_drive_type( root
)) == DRIVE_UNKNOWN
)
1226 switch (info
.DeviceType
)
1228 case FILE_DEVICE_CD_ROM_FILE_SYSTEM
: ret
= DRIVE_CDROM
; break;
1229 case FILE_DEVICE_VIRTUAL_DISK
: ret
= DRIVE_RAMDISK
; break;
1230 case FILE_DEVICE_NETWORK_FILE_SYSTEM
: ret
= DRIVE_REMOTE
; break;
1231 case FILE_DEVICE_DISK_FILE_SYSTEM
:
1232 if (info
.Characteristics
& FILE_REMOTE_DEVICE
) ret
= DRIVE_REMOTE
;
1233 else if (info
.Characteristics
& FILE_REMOVABLE_MEDIA
) ret
= DRIVE_REMOVABLE
;
1234 else ret
= DRIVE_FIXED
;
1237 ret
= DRIVE_UNKNOWN
;
1241 TRACE( "%s -> %d\n", debugstr_w(root
), ret
);
1246 /***********************************************************************
1247 * GetDriveTypeA (KERNEL32.@)
1249 * See GetDriveTypeW.
1251 UINT WINAPI
GetDriveTypeA( LPCSTR root
)
1253 WCHAR
*rootW
= NULL
;
1255 if (root
&& !(rootW
= FILE_name_AtoW( root
, FALSE
))) return DRIVE_NO_ROOT_DIR
;
1256 return GetDriveTypeW( rootW
);
1260 /***********************************************************************
1261 * GetDiskFreeSpaceExW (KERNEL32.@)
1263 * This function is used to acquire the size of the available and
1264 * total space on a logical volume.
1268 * Zero on failure, nonzero upon success. Use GetLastError to obtain
1269 * detailed error information.
1272 BOOL WINAPI
GetDiskFreeSpaceExW( LPCWSTR root
, PULARGE_INTEGER avail
,
1273 PULARGE_INTEGER total
, PULARGE_INTEGER totalfree
)
1275 FILE_FS_SIZE_INFORMATION info
;
1281 TRACE( "%s,%p,%p,%p\n", debugstr_w(root
), avail
, total
, totalfree
);
1283 if (!open_device_root( root
, &handle
)) return FALSE
;
1285 status
= NtQueryVolumeInformationFile( handle
, &io
, &info
, sizeof(info
), FileFsSizeInformation
);
1287 if (status
!= STATUS_SUCCESS
)
1289 SetLastError( RtlNtStatusToDosError(status
) );
1293 units
= info
.SectorsPerAllocationUnit
* info
.BytesPerSector
;
1294 if (total
) total
->QuadPart
= info
.TotalAllocationUnits
.QuadPart
* units
;
1295 if (totalfree
) totalfree
->QuadPart
= info
.AvailableAllocationUnits
.QuadPart
* units
;
1296 /* FIXME: this one should take quotas into account */
1297 if (avail
) avail
->QuadPart
= info
.AvailableAllocationUnits
.QuadPart
* units
;
1302 /***********************************************************************
1303 * GetDiskFreeSpaceExA (KERNEL32.@)
1305 * See GetDiskFreeSpaceExW.
1307 BOOL WINAPI
GetDiskFreeSpaceExA( LPCSTR root
, PULARGE_INTEGER avail
,
1308 PULARGE_INTEGER total
, PULARGE_INTEGER totalfree
)
1310 WCHAR
*rootW
= NULL
;
1312 if (root
&& !(rootW
= FILE_name_AtoW( root
, FALSE
))) return FALSE
;
1313 return GetDiskFreeSpaceExW( rootW
, avail
, total
, totalfree
);
1317 /***********************************************************************
1318 * GetDiskFreeSpaceW (KERNEL32.@)
1320 BOOL WINAPI
GetDiskFreeSpaceW( LPCWSTR root
, LPDWORD cluster_sectors
,
1321 LPDWORD sector_bytes
, LPDWORD free_clusters
,
1322 LPDWORD total_clusters
)
1324 FILE_FS_SIZE_INFORMATION info
;
1330 TRACE( "%s,%p,%p,%p,%p\n", debugstr_w(root
),
1331 cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
);
1333 if (!open_device_root( root
, &handle
)) return FALSE
;
1335 status
= NtQueryVolumeInformationFile( handle
, &io
, &info
, sizeof(info
), FileFsSizeInformation
);
1337 if (status
!= STATUS_SUCCESS
)
1339 SetLastError( RtlNtStatusToDosError(status
) );
1343 units
= info
.SectorsPerAllocationUnit
* info
.BytesPerSector
;
1345 if( GetVersion() & 0x80000000) { /* win3.x, 9x, ME */
1346 /* cap the size and available at 2GB as per specs */
1347 if (info
.TotalAllocationUnits
.QuadPart
* units
> 0x7fffffff) {
1348 info
.TotalAllocationUnits
.QuadPart
= 0x7fffffff / units
;
1349 if (info
.AvailableAllocationUnits
.QuadPart
* units
> 0x7fffffff)
1350 info
.AvailableAllocationUnits
.QuadPart
= 0x7fffffff / units
;
1352 /* nr. of clusters is always <= 65335 */
1353 while( info
.TotalAllocationUnits
.QuadPart
> 65535 ) {
1354 info
.TotalAllocationUnits
.QuadPart
/= 2;
1355 info
.AvailableAllocationUnits
.QuadPart
/= 2;
1356 info
.SectorsPerAllocationUnit
*= 2;
1360 if (cluster_sectors
) *cluster_sectors
= info
.SectorsPerAllocationUnit
;
1361 if (sector_bytes
) *sector_bytes
= info
.BytesPerSector
;
1362 if (free_clusters
) *free_clusters
= info
.AvailableAllocationUnits
.u
.LowPart
;
1363 if (total_clusters
) *total_clusters
= info
.TotalAllocationUnits
.u
.LowPart
;
1368 /***********************************************************************
1369 * GetDiskFreeSpaceA (KERNEL32.@)
1371 BOOL WINAPI
GetDiskFreeSpaceA( LPCSTR root
, LPDWORD cluster_sectors
,
1372 LPDWORD sector_bytes
, LPDWORD free_clusters
,
1373 LPDWORD total_clusters
)
1375 WCHAR
*rootW
= NULL
;
1377 if (root
&& !(rootW
= FILE_name_AtoW( root
, FALSE
))) return FALSE
;
1378 return GetDiskFreeSpaceW( rootW
, cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
);
1381 /***********************************************************************
1382 * GetVolumePathNameA (KERNEL32.@)
1384 BOOL WINAPI
GetVolumePathNameA(LPCSTR filename
, LPSTR volumepathname
, DWORD buflen
)
1386 FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename
), volumepathname
, buflen
);
1387 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1391 /***********************************************************************
1392 * GetVolumePathNameW (KERNEL32.@)
1394 BOOL WINAPI
GetVolumePathNameW(LPCWSTR filename
, LPWSTR volumepathname
, DWORD buflen
)
1396 FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename
), volumepathname
, buflen
);
1397 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1401 /***********************************************************************
1402 * FindFirstVolumeA (KERNEL32.@)
1404 HANDLE WINAPI
FindFirstVolumeA(LPSTR volume
, DWORD len
)
1406 FIXME("(%p, %d), stub!\n", volume
, len
);
1407 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1408 return INVALID_HANDLE_VALUE
;
1411 /***********************************************************************
1412 * FindFirstVolumeW (KERNEL32.@)
1414 HANDLE WINAPI
FindFirstVolumeW(LPWSTR volume
, DWORD len
)
1416 FIXME("(%p, %d), stub!\n", volume
, len
);
1417 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1418 return INVALID_HANDLE_VALUE
;
1421 /***********************************************************************
1422 * FindFirstVolumeMountPointA (KERNEL32.@)
1424 HANDLE WINAPI
FindFirstVolumeMountPointA(LPCSTR root
, LPSTR mount_point
, DWORD len
)
1426 FIXME("(%s, %p, %d), stub!\n", debugstr_a(root
), mount_point
, len
);
1427 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1428 return INVALID_HANDLE_VALUE
;
1431 /***********************************************************************
1432 * FindFirstVolumeMountPointW (KERNEL32.@)
1434 HANDLE WINAPI
FindFirstVolumeMountPointW(LPCWSTR root
, LPWSTR mount_point
, DWORD len
)
1436 FIXME("(%s, %p, %d), stub!\n", debugstr_w(root
), mount_point
, len
);
1437 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1438 return INVALID_HANDLE_VALUE
;
1441 /***********************************************************************
1442 * FindVolumeClose (KERNEL32.@)
1444 BOOL WINAPI
FindVolumeClose(HANDLE handle
)
1446 FIXME("(%p), stub!\n", handle
);
1447 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1451 /***********************************************************************
1452 * FindVolumeMountPointClose (KERNEL32.@)
1454 BOOL WINAPI
FindVolumeMountPointClose(HANDLE h
)
1456 FIXME("(%p), stub!\n", h
);