forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetinodedata.cpp
More file actions
57 lines (49 loc) · 1.24 KB
/
getinodedata.cpp
File metadata and controls
57 lines (49 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//! @brief Retrieve the device ID and inode number of a file
#include "getinodedata.h"
#include <assert.h>
#include <errno.h>
#include <locale.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string>
//! @brief GetInodeData retrieves a file's device and inode information.
//!
//! GetInodeData
//!
//! @param[in] fileName
//! @parblock
//! A pointer to the buffer that contains the file path
//!
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
//! @endparblock
//!
//! @param[out] device
//! @parblock
//! Points to a uint64_t value that will contain the file's device ID.
//! @endparblock
//!
//! @param[out] inode
//! @parblock
//! Points to a uint64_t value that will contain the file's inode number.
//! @endparblock
//!
//! @retval 0 If the function succeeds, -1 otherwise.
//!
int32_t GetInodeData(const char* fileName, uint64_t* device, uint64_t* inode)
{
assert(fileName);
assert(device);
assert(inode);
errno = 0;
struct stat statBuf;
int ret = stat(fileName, &statBuf);
if (ret == 0)
{
*device = statBuf.st_dev;
*inode = statBuf.st_ino;
}
return ret;
}