| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | file_id structure handling
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Andrew Tridgell 2007
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | return True if two file_id structures are equal
|
|---|
| 26 | */
|
|---|
| 27 | bool file_id_equal(const struct file_id *id1, const struct file_id *id2)
|
|---|
| 28 | {
|
|---|
| 29 | return id1->inode == id2->inode && id1->devid == id2->devid &&
|
|---|
| 30 | id1->extid == id2->extid;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | /*
|
|---|
| 34 | a static string for a file_id structure
|
|---|
| 35 | */
|
|---|
| 36 | const char *file_id_string_tos(const struct file_id *id)
|
|---|
| 37 | {
|
|---|
| 38 | char *result = talloc_asprintf(talloc_tos(), "%llx:%llx:%llx",
|
|---|
| 39 | (unsigned long long)id->devid,
|
|---|
| 40 | (unsigned long long)id->inode,
|
|---|
| 41 | (unsigned long long)id->extid);
|
|---|
| 42 | SMB_ASSERT(result != NULL);
|
|---|
| 43 | return result;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | /*
|
|---|
| 47 | push a 16 byte version of a file id into a buffer. This ignores the extid
|
|---|
| 48 | and is needed when dev/inodes are stored in persistent storage (tdbs).
|
|---|
| 49 | */
|
|---|
| 50 | void push_file_id_16(char *buf, const struct file_id *id)
|
|---|
| 51 | {
|
|---|
| 52 | SIVAL(buf, 0, id->devid&0xFFFFFFFF);
|
|---|
| 53 | SIVAL(buf, 4, id->devid>>32);
|
|---|
| 54 | SIVAL(buf, 8, id->inode&0xFFFFFFFF);
|
|---|
| 55 | SIVAL(buf, 12, id->inode>>32);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /*
|
|---|
| 59 | push a 24 byte version of a file id into a buffer
|
|---|
| 60 | */
|
|---|
| 61 | void push_file_id_24(char *buf, const struct file_id *id)
|
|---|
| 62 | {
|
|---|
| 63 | SIVAL(buf, 0, id->devid&0xFFFFFFFF);
|
|---|
| 64 | SIVAL(buf, 4, id->devid>>32);
|
|---|
| 65 | SIVAL(buf, 8, id->inode&0xFFFFFFFF);
|
|---|
| 66 | SIVAL(buf, 12, id->inode>>32);
|
|---|
| 67 | SIVAL(buf, 16, id->extid&0xFFFFFFFF);
|
|---|
| 68 | SIVAL(buf, 20, id->extid>>32);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /*
|
|---|
| 72 | pull a 24 byte version of a file id from a buffer
|
|---|
| 73 | */
|
|---|
| 74 | void pull_file_id_24(char *buf, struct file_id *id)
|
|---|
| 75 | {
|
|---|
| 76 | ZERO_STRUCTP(id);
|
|---|
| 77 | id->devid = IVAL(buf, 0);
|
|---|
| 78 | id->devid |= ((uint64_t)IVAL(buf,4))<<32;
|
|---|
| 79 | id->inode = IVAL(buf, 8);
|
|---|
| 80 | id->inode |= ((uint64_t)IVAL(buf,12))<<32;
|
|---|
| 81 | id->extid = IVAL(buf, 16);
|
|---|
| 82 | id->extid |= ((uint64_t)IVAL(buf,20))<<32;
|
|---|
| 83 | }
|
|---|